专业 年级 班 姓名 学号
上机操作题:(该大题共有4小题,总分30分)
对数据进行整理,利用益率数据。(5分)/*导入stk数据*/ data stk;
infile \"D:\eacher\\stk.txt\" dlm='09'x firstobs=2; informat date yymmdd10.; format date date9.;
input stkcd$ name$ date clpr; run;
/*导入idx数据*/ data idx;
infile \"D:\\idx.txt\" dlm='09'x firstobs=2; informat date yymmdd10.; format date date9.; input sdate idx; run;
/*导入rfr数据*/ data rfr;
infile \"D:\eacher\\rfr.txt\" dlm='09'x firstobs=2; informat date yymmdd10.; format date date6.; input date rate; run;
proc sort data=stk; by stkcd date; run;
/*计算收益率,并去除各个股票第一个收益率,因为其是通过与上只股票最后一个数计算得到的,无实际意义*/ data stk1; set stk;
fid=first.stkcd; by stkcd;
mret=dif(log(clpr))/lag(log(clpr)); if fid=0;
keep stkcd date mret name; run;
proc sort data=idx; by date; run; data idx1;
把单只股票以及大盘的日价格数据转换为日收
set idx;
fad=first.data;
ret=dif(log(idx))/lag(log(idx)); if fad^=1; keep date ret;
run;
把单只股票以及大盘的日收益率数据转化为剔除无风险利率后的日收益率数据。(10分)
data stk2; set stk1;
ym=year(date)*100+month(date); run;
proc sort data=stk2; by stkcd ym; run; data idx2; set idx1;
ym=year(date)*100+month(date); run;
proc sort data=idx2; by ym; run; data rfr1; set rfr;
ym=year(date)*100+month(date); run;
proc sort data=rfr1; by ym; run; data new1; merge stk2 rfr; by ym; run; data new2; merge idx rfr; by ym; run; data new1; set new1;
mmret=mret-rate; by ym; run; data new2; set new2; mmret=ret-rate;
by ym;
(3)分年计算系数。(10分)
proc sort data=new1; by date; run;
proc sort data=new2; by date; run; data new3; merge new1 new2; by ym; if clpr^=.;
run;
*计算风险系数的宏程序; %macro mrisk(id); data r1; set new3;
if date>='01jul2010'd & id=&id; run;
proc reg data=r1 outest=mrisk(keep=id idxret) noprint; model r_pct=idxret; run; quit;
%mend mrisk; %macro port; %do i=1 %to 47; %mrisk(&i); %mret(&i); data a;
merge mret mrisk; run;
data rslt;
%if &i=1 %then %do; set a; %end; %else %do; set rslt a; %end; run; %end; %mend port;
%port;
1) 作折线图比较不同年份系数的变化趋势。(5分)
2) 3) 4) 5) 6) 7) 8) 9)
/*对收益率进行降序排列*/ proc sort data=rslt; by decending ret ; run;
/*做出收益率与风险系数的图*/ proc sgplot data=rslt; scatter x=ret y=idxret; run;
10)
因篇幅问题不能全部显示,请点此查看更多更全内容