全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1137 0
2016-02-08
    我想要计算股指累计60个月的收益率,用了以下的宏,但是2016年1月也有数值,我不知道是否这个程序有问题,或者应该怎么理解我跑出来的结果,求大神指教~
76C7.tm.png

%macro calcret;
data paper.IDX_Idxtrdmth1;
set paper.IDX_Idxtrdmth1;
  by indexcd;

/* Take natural logs of the index return (idxrtn)  */

   lidxrtn=log(idxrtn+1);

/* Define arrays to create the lagged values */

    array lagidxrtn[59] lagidxrtn1-lagidxrtn59;

/* This is the macro portion: a "do-loop" to create the 59 necessary lags */

    %do j=1 %to 59;
       lagidxrtn&j=lag&j(lidxrtn);
    %end;

/* The following statements set to missing lagged values that */
/* are reading the data corresponding to the previous idxcd  */

    if first.indexcd then count=1;
    do i=count to 59;
      lagidxrtn = .;
    end;
    count +1 ;

/* Calculate the cumulative returns by adding the logs of the returns*/

    idxcumret= exp( sum(of lidxrtn lagidxrtn1-lagidxrtn59)) -1;

/* Drop unnecessary variables */

    drop l: count i;

%mend calcret;  /* End of macro  */
%calcret;       /* Run the macro */



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群