如何识别与非工作日对应的日期数字,并在MATLAB中的下一个可用工作日更换它们 [英] How to identify date numbers corresponding to non-business days and replace them with by the next available business day in MATLAB

查看:1060
本文介绍了如何识别与非工作日对应的日期数字,并在MATLAB中的下一个可用工作日更换它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MATLAB中的时间序列数据。我有两个日期数字向量,其中一个依赖于一个主观的数据源。如果两个向量都是完全准确的,则所有日期数字都应该对应于交易日,而一个向量将是另一个向量的正确子集。不幸的是,情况并非如此,因为其中一个向量包含与非工作日对应的几个日期数字。我想在下一个可用的工作日找到一种方法来替代此向量中的所有非工作日。



示例:

  datenumbers = [736062; 736063; 736064; 736065; 736066; 736067] 
%对应于[wed,thu,fri,sat,sun,mon]

这包含 [736065; 736066] 对应于即将到来的周末。因为这些不工作日,我想确定对应于下​​一个星期一的日期数字,并更改两个条目,以便:

  datenumbers = [736062; 736063; 736064; 736067; 736067; 736067] 
%对应于[wed,thu,fri,mon,mon,mon]


解决方案

一种方法是循环使用所有的值,如果是星期六或星期日,则更改它们。 >

  datenumbers = [736062; 736063; 736064; 736065; 736066; 736067]; 
for i = 1:length(datenumbers)
weekDay = mod(datenumbers(i),7);
如果weekDay == 1 || weekDay == 2
datenumbers(i)=(3-weekDay)+ datenumbers(i);
end
end


I am working with time series data in MATLAB. I have got two vectors of date numbers, one of which relies on a somewhat subjective data source. If both vectors were perfectly accurate, all date numbers should correspond to trading days while one vector would be a 'proper subset' of the other. Unfortunately this is not the case because one of the vectors contains several date numbers which correspond to non-business days. I would like to find a way to replace all non-business days in this vector with the next available business day.

Example:

datenumbers = [736062;736063;736064;736065;736066;736067]
% corresponds to [wed, thu, fri, sat, sun, mon]

This contains [736065;736066] which corresponds to the upcoming weekend. Because these are not working days I would like to identify the date number corresponding to the subsequent monday and change both entries so that:

datenumbers = [736062;736063;736064;736067;736067;736067]
% corresponds to [wed, thu, fri, mon, mon, mon]

解决方案

One way to do it is simply to loop through all your values and change them if they are Saturday or Sunday.

datenumbers = [736062;736063;736064;736065;736066;736067];
for i = 1:length(datenumbers)
    weekDay = mod(datenumbers(i),7);
    if weekDay == 1 || weekDay == 2 
        datenumbers(i) = (3-weekDay) + datenumbers(i);
    end
end

这篇关于如何识别与非工作日对应的日期数字,并在MATLAB中的下一个可用工作日更换它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆