【问题标题】:How to match daily data from monthly using Matlab?如何使用 Matlab 匹配每月的每日数据?
【发布时间】:2012-08-23 12:14:09
【问题描述】:

我有每月一次的宏观经济数据系列,我计划将它们用于每周(每周一)的回归分析。自新点发布以来,如何将每月发布一次的数据点与我的日期模板(当月 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

【问题讨论】:

    标签: matlab time-series datetime-select


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 2015-10-31
      • 2013-06-18
      • 1970-01-01
      • 2021-06-19
      • 2015-04-14
      • 2021-02-23
      • 2013-05-02
      • 2021-08-27
      • 2015-06-11
      相关资源
      最近更新 更多