Using for loop to match quarterly series with daily time series
2 次查看(过去 30 天)
显示 更早的评论
I have two time series span over the period between 2000-01-01 and 2017-04-01, one is daily data of stock returns with 4500 observations, and the other one is quarterly with 69 observations. I want to make the quarterly data as lenghty as the daily series by repeating the quarterly observation all over the daily dates of the corresponding quarter, in each quarter there is 66 trading days, so each quarterly observation should be repeated 66 times. I tried to use for loop to do that
y = xlsread('Stock.xlsx','sheet1','B2:B4501') ./ 100; %importing the daily series
nobs = size(y,1);
xQuarter = xlsread('Stock.xlsx','sheet2','B2:B70');%importing the quarterly series
[~,yDate] = xlsread('Stock.xlsx','sheet1','A2:A4501');%importing the dates of the daily series
[~,yDateQuarter] = datevec(yDate);%this vector is created for repeating the quartely observations
xDay = NaN(nobs,1);%creating vector of NaNs matching the lenght of the daily series
count = 1;
%Running the for loop
for t = 1:nobs
if t > 1 && yDateQuarter(t) ~= yDateQuarter(t-1)
count = count + 1;
if count > length(xQuarter)
break
end
end
xDay(t) = xQuarter(count);
end
The 'xDay' is the vector of the repeated quarterly observations that is supposed to match the daily series, after running the code I'm still getting NaNs in this vector
How can I fix this problem?
0 个评论
采纳的回答
Cris LaPierre
2020-5-5
If you can convert your data to timetables, I'd use the retime function. To do that, you might want to consider updating your import function to use readtable or readtimetable instead of xlsread.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Financial Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!