如何使用Matlab每月匹配每日数据?

时间:2012-08-23 12:14:10

标签: matlab time-series datetime-select

我有蒙特利的宏观经济数据系列,我打算将它们用于每周(每周一)的回归分析。如何将每月发布一次的数据点与我的日期模板(自该新版本发布以来的4次)相匹配,等等。

for u=2:size(daily,1)
    l=find(dailytemplate(u)==monthly)

    %# when the monthly date is not equal to my daily template
    if isempty(l)
       %# I need a clearver code for this part to find the previous release
       dailyclose(u)=dailyclose(u-1)
    else 
        dailyclose(u)=monthlyclose(l) 
    end
end
来自评论的

更新

我有以下每月宏观数据。我想用它们来提供每周日期。例如,在2012年3月31日,M-input2.7。因此,该日期之后的每周日期应为

W_output=2.7

直到2012年4月30日。然后,每周W_output将是2.3,这是新的月度点M_input。下表提供了每周W_ouput和每月M_Input的示例:

08/06/2012 1.7
30/06/2012 1.7
01/06/2012 1.7
31/05/2012 1.7
25/05/2012 2.3
30/04/2012 2.3
18/05/2012 2.3
31/03/2012 2.7
11/05/2012 2.3
29/02/2012 2.9
04/05/2012 2.3
31/01/2012 2.9
27/04/2012 2.7
31/12/2011 3
20/04/2012 2.7

1 个答案:

答案 0 :(得分:0)

format long g

%Create a vector of dates (what I am assuming your date template looks like, this is march 31 and the next 9 mondays that follow it)
datetemplate = [datenum('2012/03/31')];
for i = 1:10
    datetemplate(i + 1) = datetemplate(i) + 7;
end
datetemplate';

%Your macro ecos input and dates
macrochangedate = [datenum('2012/03/31');datenum('2012/04/30')]
macrochangedate = [macrochangedate [2.7; 2.3]]

for i = 1:size(macrochangedate,1)
    result(datetemplate >= macrochangedate(i,1)) = macrochangedate(i,2);
end

结果:

result = 
             2.7
             2.7
             2.7
             2.7
             2.7
             2.3
             2.3
             2.3
             2.3
             2.3
             2.3

datestr(datetemplate)

ans =

31-Mar-2012
07-Apr-2012
14-Apr-2012
21-Apr-2012
28-Apr-2012
05-May-2012
12-May-2012
19-May-2012
26-May-2012
02-Jun-2012
09-Jun-2012
相关问题