SAS ——*VAR*的蒙特卡罗估计法及评价
作者:互联网
SAS ——VAR的蒙特卡罗估计法及评价
【程序一】
data c;
set sjk7_1a;
sgm=0;
if n <1;
proc means data=sjk7_1a;
output out=c1 mean (r _ log)=m;
data c1;
modify c1;
if n >0 then remove;
data a;
set sjk7_1a;
if date >=19990101;
options nodate nonotes nosource;
%macro zsvar;
%do n =1% to 258;
data b;
set a;
if n <=259;
retain sgm;
if n =1 then sgm=r_log;
else sgm=sqrt(r_log2/16.667+0.94*sgm2);
data b;
modify b;
if n ^=259 then remove;
proc append base=c data=b;
proc means data=a;
output out=b1 mean(r_log)=m;
proc append base=c1 data=b1;
data a;
modify a;
if n =1 then remove;
%end;
%mend zsvar;
%zsvar;
run;
data c2;
merge c1 c2;
data c3;
set c2;
keep m sgm;
run;
【程序二】
data a;
do n =1 to 258;
output;
end;
data c4;
set a;
array x (1000) x1 - x1000;
do k=1 to 1000;
x(k)=rannor(2*k+1);
end;
run;
【程序三】
data a;
set sjk7_1a;
where data >=20000101;
keep close;
data a1;
merge a c3 c4;
array mcl (1000) mcl1 - mcl1000;
array r (1000) r1 -r1000;
array x (1000) x1 - x1000;
do i = 1 to 1000;
mcl (i) =close +close*(m+sgm*x(i));
r(i) =log(mcl(i)) - log(close);
end;
run;
【程序四】
data a2;
set a1;
Keep r1- r1000;
data c;
var1 =1;
data c;
modify c;
if n >= 1 then remove;
options nodate nonotes nosource;
%macro mnvar;
%do n =1 % to 258;
data b;
set a2;
if n = 1;
proc transpose data= b out =b1 prefix =var;
proc sort data=b1;
by var1;
data b1;
modify b1;
if n ^= 11 then remove;
data b2;
set b1;
keep var1;
proc append base=c date=b2;
data a2;
modify a2;
if n = 1 then remove;
%end;
%mend mnvar;
%mnvar;
run;
data a;
set sjk7_1a;
where date >= 20000101;
data a1;
merge c a;
if abs (var1) +r_log<0 then liwai=1;
else liwai =0;
run;
标签:set,run,proc,SAS,sgm,b1,法及,VAR,data 来源: https://blog.csdn.net/weixin_54408854/article/details/112364656