fints toweekly vs timetable retime
이전 댓글 표시
Hello,
I have some code that used the now deprecated FINTS timeseries from the financial package. In particular I need to resample a daily series to get only the points from each wednesday and, if it is a holiday, from the previous business day. The code below shows the expected behavior:
sampleDates = (datetime(2018, 11, 30):datetime(2019, 01, 31))';
[dayNumber, dayName] = weekday(sampleDates, 'en_US');
isWorking = isbusday(sampleDates);
data = (1:length(sampleDates))';
fts = fints(datenum(sampleDates), [dayNumber, isWorking, data], {'dayNumber', 'isWorking', 'data'});
ftsWeekly = toweekly(fts, 'CalcMethod', 'Exact', 'BusDays', 1, 'EOW', 5, 'EndPtTol', [0, -1]);
I correctly get all wednesdays and the previous working day for the two cases (26.12.2018 and 02.01.2019) when it was a holiday, where it takes the previous working day.
How should I do the same with the recommended retime function on timeseries (since the fints will be removed)?
I tried the following:
tt = timetable(sampleDates, dayNumber, dayName, isWorking, data);
ttWeekly = retime(tt, 'weekly', 'nearest');
but this gives me the sunday days and I don't see how to configure it to get the wednesdays.
Any help would be great
채택된 답변
추가 답변 (2개)
Guillaume
2019년 2월 4일
I'm afraid that retime is not a suitable replacement for what you did and I doubt it will ever be.
However, I also don't think you need it for what you do. The following is untested, I don't have the financial toolbox.
tt = timetable(sampleDates, data); %your starting point. Don't need the extra columns.
%NOTE: the following assume that SampleDates are daily
dweek = day(tt.SampleDates, 'dayofweek');
tokeep = find(dweek == 4); %for wednesday
isholiday = ~isbusday(tt.SampleDates(tokeep)); %requires financial toolbox. I'm not aware of an equivalent in base matlab
while any(isholiday) %go back one day for holidays. This allows to go back multiple days if consecutive days are holidays.
tokeep(isholiday) = tokeep(isholiday) - 1;
tokeep(tokeep < 0) = []; %went back in time before the start. Drop entry
isholiday = ~isbusday(tt.SampleDates(tokeep));
end
ttWeekly = tt(tokeep, :)
Rick
2019년 2월 5일
0 개 추천
Nicola,
Could you please explain your coment "I correctly get all wednesdays and the previous working day for the two cases (26.12.2018 and 02.01.2019) when it was a holiday, where it takes the previous working day."
Your code segment reports the actual data values for 02-Jan-2019 (34) and 26-Dec-2018 (27), both of which are Wednesdays and working days according to your code.
Thanks, Rick
카테고리
도움말 센터 및 File Exchange에서 Calendar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!