SAS:每日价值的滚动 window 回归

SAS: Rolling window regressions for daily values

我需要每天滚动回归输出。数据集是股票 returns 和体积,模型只有 return=体积。 我需要过去 30 天的回归系数,每天更进一步,以便 30 天 window 保持不变。

根据这个问题,我了解到您想 运行 每个月对一个庞大的数据集进行追溯建模。这是我最近做过的类似的事情。

/*Select the parts of the data from base data based on input.*/
%macro model_by_dates(id, date1, date2);
    data to_model;
        set begin(where=( &date1. < date_var < &date2.));
    run;

   /*YOUR model code here*/

    data result_file; 
        set From_model; 
        id=&id; /*To recognize from which model this is from.*/
    run;

    /*If you have huge files, do permanent data after every 10 loops or so. Depends.*/
    proc append base=all_Results data=result_file force; run;
%mend model_by_dates;

/*here we create the dates list. You can do this in multiple ways. Datdiff maybe?*/

%let maxmonths=3;

data dates;
    do i=0 to &maxmonths. by 1;
        begin=date()-(i*30);
        end = date()-( (i+1)*30);
        output;
    end;
run;


/*This is the master switch. It executes the macro for each row of the dates.*/
data _NULL_;
    set dates;
    call execute('%nrstr(%model_by_dates('
            ||strip(id)||','
            ||strip(begin)||','
            ||strip(end)||
    '))');
run;

编辑 根据进一步的说明,我正在更改日期列表创建:

data dates;
    do i=0 to 30 by 1;
        begin=date()-(i+30);
        end = date()- i ;
        output;
    end;
run;