SAS金融應(yīng)用程序舉例_第1頁(yè)
SAS金融應(yīng)用程序舉例_第2頁(yè)
SAS金融應(yīng)用程序舉例_第3頁(yè)
SAS金融應(yīng)用程序舉例_第4頁(yè)
SAS金融應(yīng)用程序舉例_第5頁(yè)
已閱讀5頁(yè),還剩190頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、2.2.1 創(chuàng)建單期收益計(jì)算環(huán)境data a;set stoindif.a1a0001;year=year(date);qtr=qtr(date);month=month(date);proc sort data=a;by year qtr month;run;data b;set a;last_y=last.year; /*標(biāo)出某年的最后一個(gè)交易日 */last_q=last.qtr; /*標(biāo)出某季的最后一個(gè)交易日 */last_m=last.month; /*標(biāo)出某月的最后一個(gè)交易日 */by year qtr month;run;2.2.2 年收益計(jì)算data r_year(keep=d

2、ate r_pct r_log label=年收益);set b;if last_y=1; /* 取各年最后一個(gè)交易日的數(shù)據(jù) */r_pct=dif(clpr)/lag(clpr_r); /* 計(jì)算百分比收益 */r_log=log(clpr_r)-log(lag(clpr_r); /* 計(jì)算對(duì)數(shù)收益 */*函數(shù)log(x)是以e為底的自然對(duì)數(shù),其它對(duì)數(shù)函數(shù)還有l(wèi)og2(x),log10(x)*/run;2.2.3 季收益計(jì)算data r_qtr (keep=date r_pct r_log label=季收益);set b;if last_q=1; /* 取各季最后一個(gè)交易日的數(shù)據(jù) */r_

3、pct=dif(clpr_r)/lag(clpr_r);r_log=log(clpr_r)-log(lag(clpr_r);run;2.2.4 月收益計(jì)算data r_month (keep=date r_pct r_log label=月收益);set b;if last_m=1; /* 取各月最后一個(gè)交易日的數(shù)據(jù) */r_pct=dif(clpr_r)/lag(clpr_r);r_log=log(clpr_r)-log(lag(clpr_r);run;2.2.5 周收益計(jì)算程序一:data a;set stoindif.a1a0001;wd=weekday(date);dif=dif(wd

4、);dif2=dif(date);if (dif=7 then index=1;else index=0;data a(keep=date clpr_r index);set a;date=lag(date);clpr_r=lag(clpr_r);if index=1;data r_week(keep=date r_pct r_log);set a;r_pct=dif(clpr_r)/lag(clpr_r);r_log=log(clpr_r)-log(lag(clpr_r);if r_log=. then delete;run;程序二:data b;set stoindif.a1a0001;

5、wk=int(date-3)/7+2); /* wk為周的標(biāo)號(hào),設(shè)定1960年1月1日為第一周。由于1960年1月1日為周五,所以第一周共有三天。注意該周(1960年1月1日到3日)對(duì)應(yīng)日期按sas的標(biāo)準(zhǔn)分別為0, 1和2(于是(date-3)/7都等于-1)。由此可以理解為什么這樣設(shè)定表達(dá)式*/proc sort;by date;run;data b;set b;last_wk=last.wk;by wk;run;data b(keep=date r_pct1 r_log1);set b;if last_wk=1;r_pct1=dif(clpr)/lag(clpr);r_log1=log(c

6、lpr)-log(lag(clpr);run;data c;/*檢測(cè)程序一和程序二的一致性*/merge r_week b;by date;if r_pct=r_pct1 then aa=1;else aa=0;/*最后一個(gè)不一樣*/run; 2.2.6 日收益計(jì)算data r_day (keep=date r_pct r_log label=日收益);set stoindif.a1a0001;r_pct=dif(clpr_r)/lag(clpr_r);r_log=log(clpr_r)-log(lag(clpr_r);run;2.2.7 日復(fù)權(quán)收益直接計(jì)算data return(keep=d

7、ate);set stoindif.a1a0001;where 1997=year(date)=2000;data a(keep=date r_1);set stoindif.a600601;where 1997=year(date)=2000; r_1=log(clpr)-log(lag(clpr);clpr_1=clpr*(1+divrat+rigrat+reisvol/lag(shrout)-rigpr*rigrat reispr* reisvol/lag(shrout)+divamt; /* clpr_1為復(fù)權(quán)價(jià)格 */if clpr_1=. then clpr_1=clpr;r_2=

8、log(clpr_1)-log(lag(clpr_1);if exdt=. then r_2=0;if exdt=. then r_1=0;r_1=r_1+r_2;if r_1=. then r_1=0;else r_1=r_1;data return(rename=(r_1=r600601);merge return a;by date;data return;set return;if r600601=. then r600601=0;else r600601= r600601;run;2.2.8 繪制收益圖proc gplot data=r_day ;plot r_pct*date /

9、vref=0;plot r_log*date / vref=0; run;2.2.9 多期平均收益率計(jì)算/*建立滿足條件的數(shù)據(jù)集*/data a1;set r_year;where 1995 = year(date) = 2000;proc print;run;/*對(duì)數(shù)據(jù)集轉(zhuǎn)置*/proc transpose data=a1 out=a2;var r_pct;proc print;run;/*計(jì)算年平均收益*/data a3(keep=am gm);set a2;c1=col1+1; c2=col2+1;c3=col3+1; c4=col4+1; c5=col5+1;c6=col6+1; gm

10、=(c1*c2*c3*c4*c5*c6)*(1/6)-1;am=mean(of col1-col6);proc print;run;/*變量太多時(shí),用數(shù)組的方法處理簡(jiǎn)單些*/data a4(keep=am gm);set a2;t=6;array col(6) col1-col6;array c(6) c1-c6;do i=1 to 6;c(i)=col(i)+1;end;gm=( c1*c2*c3*c4*c5*c6)*(1/t)-1; am=mean(of col1-col6); proc print;run;data a5 ;set b;if last_y=1 and 1995= year

11、(date) = 2000;run;data a6;retain begin end;set a5 end=lastobs;if _n_=1 then begin=clpr_r; /* 將數(shù)據(jù)集第一個(gè)觀測(cè)值的復(fù)權(quán)價(jià)賦給變量begin */if lastobs then do;end=clpr_r; /* 將數(shù)據(jù)集最后一個(gè)觀測(cè)值的復(fù)權(quán)價(jià)賦給變量end */output;end;data a6(keep=gm);set a6;gm=(end/begin)*(1/6)-1;proc print;run; /*該方法主要優(yōu)點(diǎn)是精確*/2.3.1 由最新股票標(biāo)識(shí)數(shù)據(jù)集創(chuàng)建宏文本創(chuàng)建全部a股股票宏文本:全

12、部a股票.txtdata a(drop=hexcd);set compufin.header;if substr(hstocd,3,1)=6 or substr(hstocd,1,5)=21000; /* substr()為取子串函數(shù) */run;data a;length hexcd $6.;set a;hexcd=substr(hstocd,3,6);label hexcd=最新交易所代碼;run;data a;set a;a=%a(;b=,;c=); ;file d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufin宏文本全部a股.txt ;put a $ hexcd $ b $ hcomna

13、m $ c $ ;run;創(chuàng)建宏文本:滬市全部a股.txtdata ;set a;if substr(hexcd,1,1)=6;a=%a(;b=,;c=); ;file d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufin宏文本滬市全部a股.txt ;put a $ hexcd $ b $ hcomnam $ c $ ;run;創(chuàng)建宏文本:深市全部a股.txt;data ;set a;if substr(hexcd,1,1)=0;a=%a(;b=,;c=); ;file d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufin宏文本深市全部a股.txt ;put a $ hexcd $ b $ hcomn

14、am $ c $ ;run;2.3.2 由個(gè)股數(shù)據(jù)集目錄文件創(chuàng)建宏文本形成文件名數(shù)據(jù)集:data a;input files $20.;cards;/*上面選擇文件名一列構(gòu)成數(shù)據(jù)行 */;run;全部a股代碼.txt的形成:data;set a;hexcd=substr(files,2,6);a=%a(;b=,;c=); ;file d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufin宏文本全部a股代碼.txt;put a $ hexcd $ c $ ;run;2.3.3 多股票收益計(jì)算程序滬市a股日對(duì)數(shù)收益計(jì)算程序:options nodate nonotes nosource; /*不輸出時(shí)間

15、、注釋和源程序到日志log上 */data stoindiv.lg_shanghai(keep=date);set stoindiv.a1a0001;where 1995=year(date)=2000;%macro a(x,y);data a(keep=date r_1);set stoindiv.a&x;where 1995=year(date)=2000; r_1=log(clpr)-log(lag(clpr);clpr_1=clpr*(1+divrat+rigrat+reisvol/lag(shrout)-rigpr*rigrat reispr* reisvol/lag(shrout)

16、+divamt;if clpr_1=. then clpr_1=clpr;r_2=log(clpr_1)-log(lag(clpr_1);if exdt=. then r_2=0;if exdt=. then r_1=0;r_1=r_1+r_2;if r_1=. then r_1=0;else r_1=r_1;data stoindiv.lg_shanghai(rename=(r_1=r&x);merge stoindiv.lg_shanghai a;by date;data stoindiv.lg_shanghai;set stoindiv.lg_shanghai;if r&x=. then

17、 r&x=0;else r&x= r&x;%mend a;%include d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufin宏文本滬市全部a股.txt;run;滬市a股日百分比收益計(jì)算程序:options nodate nonotes nosource;data stoindiv.r_shanghai(keep=date);set stoindiv.a1a0001;where 1995=year(date)=2000;%macro a(x,y);data a(keep=date r_1);set stoindiv.a&x;where 1995=year(date)=2000; r_1=(clp

18、r-lag(clpr)/lag(clpr);clpr_1=clpr*(1+divrat+rigrat+reisvol/lag(shrout)-rigpr*rigrat reispr* reisvol/lag(shrout)+divamt;if clpr_1=. then clpr_1=clpr;r_2=(clpr_1-lag(clpr_1)/lag(clpr_1);if exdt=. then r_2=0;if exdt=. then r_1=0;r_1=r_1+r_2;if r_1=. then r_1=0;else r_1=r_1;data stoindiv.r_shanghai(rena

19、me=(r_1=r&x);merge stoindiv.r_shanghai a;by date;data stoindiv.r_shanghai;set stoindiv.r_shanghai;if r&x=. then r&x=0;else r&x= r&x;%mend a;%include d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufin宏文本滬市全部a股.txt;run;深市a股日對(duì)數(shù)收益計(jì)算程序:options nodate nonotes nosource;data stoindiv.lg_shenzhen(keep=date);set stoindiv.szcz;where 19

20、95=year(date)=2000;%macro a(x,y);data a(keep=date r_1);set stoindiv.a&x;where 1995=year(date)=2000; r_1=log(clpr)-log(lag(clpr);clpr_1=clpr*(1+divrat+rigrat+reisvol/lag(shrout)-rigpr*rigrat reispr* reisvol/lag(shrout)+divamt;if clpr_1=. then clpr_1=clpr;r_2=log(clpr_1)-log(lag(clpr_1);if exdt=. then

21、 r_2=0;if exdt=. then r_1=0;r_1=r_1+r_2;if r_1=. then r_1=0;else r_1=r_1;data stoindiv.lg_shenzhen(rename=(r_1=r&x);merge stoindiv.lg_shenzhen a;by date;data stoindiv.lg_shenzhen;set stoindiv.lg_shenzhen;if r&x=. then r&x=0;else r&x= r&x;%mend a;%include d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufin宏文本深市全部a股.txt;run;深市a

22、股日百分比收益計(jì)算程序:data stoindiv.r_shenzhen(keep=date);set stoindiv.szcz;where 1995=year(date)=2000;%macro a(x,y);data a(keep=date r_1);set stoindiv.a&x;where 1995=year(date)=2000; r_1=(clpr-lag(clpr)/lag(clpr);clpr_1=clpr*(1+divrat+rigrat+reisvol/lag(shrout)-rigpr*rigrat reispr* reisvol/lag(shrout)+divamt

23、;if clpr_1=. then clpr_1=clpr;r_2=(clpr_1-lag(clpr_1)/lag(clpr_1);if exdt=. then r_2=0;if exdt=. then r_1=0;r_1=r_1+r_2;if r_1=. then r_1=0;else r_1=r_1;data stoindiv.r_shenzhen(rename=(r_1=r&x);merge stoindiv.r_shenzhen a;by date;data stoindiv.r_shenzhen;set stoindiv.r_shenzhen;if r&x=. then r&x=0;

24、else r&x= r&x;%mend a;%include d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufin宏文本深市全部a股.txt;run;2.3.4 收益sas數(shù)據(jù)集轉(zhuǎn)換為excel數(shù)據(jù)表proc transpose data=stoindiv.lg_shanghai out=stoindiv.lg_shanghai_tr;run;data stoindiv.lg_shanghai_tr_1;set stoindiv.lg_shanghai_tr;if _n_200;run;proc transpose data= stoindiv.lg_shanghai_tr_1 out= stoi

25、ndiv.lg_shanghai_1;data stoindiv.lg_shanghai_1;set stoindiv.lg_shanghai_1;format date yymmdd10.;run;data stoindiv.lg_shanghai_tr_2;set stoindiv.lg_shanghai_tr;if 201=_n_400;run;proc transpose data= stoindiv.lg_shanghai_tr_2 out= stoindiv.lg_shanghai_2;data stoindiv.lg_shanghai_2;set stoindiv.lg_shan

26、ghai_2;format date yymmdd10.;run;data stoindiv.lg_shanghai_tr_3;set stoindiv.lg_shanghai_tr;if 401=_n_;run;proc transpose data= stoindiv.lg_shanghai_tr_3 out= stoindiv.lg_shanghai_3;data stoindiv.lg_shanghai_3;set stoindiv.lg_shanghai_3;format date yymmdd10.;run;proc export data=stoindiv.lg_shanghai

27、_1 outfile=d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufinlg_shanghai_1.xlsdbms=excel2000 replace;run;proc export data=stoindiv.lg_shanghai_2 outfile=d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufinlg_shanghai_2.xls dbms=excel2000 replace;run;proc export data=stoindiv.lg_shanghai_3outfile=d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufinlg_shanghai_3.xlsdbms=excel2000 r

28、eplace;run;同樣,可以轉(zhuǎn)換其他收益sas數(shù)據(jù)集為相應(yīng)的excel表。2.4.1 由股本變動(dòng)歷史數(shù)據(jù)集創(chuàng)建宏文本挑選出1998年前上市的全部a股股票程序:%macro a(x);data a;length hexcd $6.;set compufin.shares;if year(date)&x;if substr(hstocd,3,1)=6 or substr(hstocd,1,5)=21000;hexcd=substr(hstocd,3,6);label hexcd=最新交易所代碼;proc sort data=a;by hexcd ;data a;set a;by hexcd;i

29、f first.hexcd=1; /* 以hexcd分組,取每組的第一個(gè)觀測(cè)值 */run;data compufin.y%eval(&x)_list ;set a;a=%a(;c=);file d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufin宏文本alistedbefore%str(&x).txt;put a $ hexcd $ c $;%mend a;%a(1998);run;2.4.2 隨機(jī)抽股票%macro a(x);proc sql; /* sql過(guò)程創(chuàng)建視圖 */ create view _tmp_ as select *, ranuni(5) as _ran_ from comp

30、ufin.y%eval(&x)_list order by calculated _ran_;quit;data random; set _tmp_(obs = 20); drop _ran_;a=%a(;c=);file d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufin宏文本random%str(&x).txt;put a $ hexcd $ c $;%mend a;%a(1998);run;2.4.3 單個(gè)股票收益計(jì)算對(duì)上面隨機(jī)抽取20支股票,計(jì)算19972000年的日百分比收益:data compufin.r_port20(keep=date);set stoindiv.a1a0001;

31、where 1997=year(date)=2000;%macro a(x);data a(keep=date r_1);set stoindiv.a&x;where 1997=year(date)=2000; r_1=(clpr-lag(clpr)/lag(clpr);clpr_1=clpr*(1+divrat+rigrat+reisvol/lag(shrout)-rigpr*rigrat reispr* reisvol/lag(shrout)+divamt;if clpr_1=. then clpr_1=clpr;r_2=(clpr_1-lag(clpr_1)/lag(clpr_1);if

32、 exdt=. then r_2=0;if exdt=. then r_1=0;r_1=r_1+r_2;if r_1=. then r_1=0;else r_1=r_1;data compufin.r_port20 (rename=(r_1=r&x);merge compufin.r_port20 a;by date;data compufin.r_port20;set compufin.r_port20;if r&x=. then r&x=0;else r&x= r&x;%mend a;%include d:基于sas系統(tǒng)的金融計(jì)算光盤(pán)compufin宏文本random1998.txt;ru

33、n;2.4.4 股票組合的隨機(jī)賦權(quán)重方法一:data rv;id=1; retain _seed_ 3; do _i_ = 1 to 20; w= 0 + (1 - 0) * ranuni(_seed_); output; end; drop _seed_ _i_;data a(keep=sumw id);set rv end=obs_last;sumw+w;if obs_last=1;id=1;data b(keep=w);merge rv a;by id ;w=w/sumw;run;方法二:proc iml;rv=uniform(repeat(0,20,1); /* 0為種子值,20為隨機(jī)

34、數(shù)個(gè)數(shù),1為隨機(jī)數(shù)列數(shù) */sum=rv+,;b=rv/sum;sumb=b+,;create b from b; /* 由矩陣b創(chuàng)建sas數(shù)據(jù)集b */append from b;print sumb; /* 看權(quán)數(shù)相加不否為1 */quit;2.4.5 組合收益計(jì)算由compufin.r_port20得到數(shù)據(jù)集a,便于以后形成矩陣:data a(drop=date);set compufin.r_port20;if _n_=1 then delete;proc iml;use a; read all var _num_ into xx; /* 由數(shù)據(jù)集a的所有數(shù)值變量的觀測(cè)創(chuàng)建矩陣xx *

35、/create xx from xx; /* 由矩陣xx創(chuàng)建數(shù)據(jù)集xx */append from xx;close xx;use b;read all into w;create w from w;append from w;close w;aaa=xx*w; /*矩陣xx乘向量w */create aaa from aaa; /* 由矩陣aaa創(chuàng)建數(shù)據(jù)集aaa */append from aaa;close aaa;show names; quit;run;最后得到隨機(jī)抽取20支股票投資組合的收益數(shù)據(jù)集r_port20:data a;set compufin.r_port20;if _n_

36、=1 then delete; data r_port20;merge a aaa(rename=(col1=r_port20) ;run;3.1.1 內(nèi)生收益率計(jì)算試錯(cuò)法計(jì)算內(nèi)生收益率通用程序:data a;delete;run;%macro a(r, n, d, par);data a1;p1=0;%do i=1 %to &n ;p1=p1+&d/(1+&r)* &i;output;%end;data a1;set a1 end=lasobs;if lasobs;p2=&par/(1+&r)*&n;p=p1+p2;r=200*&r;r1=100*&r;n=&n;data a;set a a

37、1;%mend a;/* %a(r, n, d, par)內(nèi)的具體參數(shù)值 */proc print data=a ;run;例3.2 利用通用程序,a(r, n, d, par)取值如下:%a(0.00625, 360, 349.6, 0);%a(0.006667, 360, 349.6, 0);%a(0.007083, 360, 349.6, 0);%a(0.0075, 360, 349.6, 0);本例計(jì)算程序:%macro a(r);data;p=2000/(1+&r)+2000/(1+&r)*2+2500/(1+&r)*3+4000/(1+&r)*4;r=100*&r;put r= p

38、=;%mend a;%a(0.1);%a(0.14);%a(0.12);run; 3.1.2 有效年利率計(jì)算例3.4計(jì)算程序:%macro a(r,m);data;i=(1+&r)*&m-1;r=100*&r;put r= i=;%mend a;%a(0.02,4);run;3.1.3 到期收益率計(jì)算例3.5 利用通用程序,a(r, n, d, par)取值如下:%a(0.0325, 36, 30, 1000);%a(0.035, 36, 30, 1000);%a(0.0375, 36, 30, 1000);%a(0.04, 36, 30, 1000);%a(0.0425, 36, 30, 1

39、000);%a(0.045, 36, 30, 1000);%a(0.0475, 36, 30, 1000);3.1.5 第一個(gè)贖回日收益率計(jì)算例3.6 利用通用程序,a(r, n, d, par)取值如下:%a(0.056, 10, 30, 1030);%a(0.0585, 10, 30, 1030);%a(0.061, 10, 30, 1030);%a(0.0635, 10, 30, 1030);%a(0.066, 10, 30, 1030);%a(0.0685, 10, 30, 1030);%a(0.071, 10, 30, 1030);%a(0.0735, 10, 30, 1030);%

40、a(0.076, 10, 30, 1030);3.1.6 清算日處于兩個(gè)到期日之間的到期收益率計(jì)算計(jì)算程序:data ;date0=01mar1997d;date1=17jul1997d;date2=01sep1997d;days02=datdif(date0, date2, 30/360); /*美國(guó)公司債適合30/360標(biāo)準(zhǔn) */days12=datdif(date1, date2, 30/360); n=2*(2003-1997)-1;w=days12/days02;put days02/days12/n/w;call symput(n, n); /*創(chuàng)建一個(gè)值來(lái)自data步的宏變量n*

41、/call symput(w, w); /*創(chuàng)建一個(gè)值來(lái)自data步的宏變量w*/data a;delete;%macro a(r);data a1;p1=0;do i=1 to &n ;p1=p1+5/(1+&r)*(i-1+&w);output;end;data a1;set a1 end=lasobs;if lasobs;p2=105/(1+&r)*(&n-1+&w);p=p1+p2;r=200*&r;r1=100*&r;data a(drop=i);set a a1;w=&w;n=&n;%mend a;%a(0.0363);%a(0.03735);proc print data=a;r

42、un;例3.8計(jì)算程序:data ;date0=01mar1997d;date1=17jul1997d;date2=01sep1997d;days02=datdif(date0, date2, act/act); /*美國(guó)政府債適合的標(biāo)準(zhǔn) */days12=datdif(date1, date2, act/act); n=2*(2003-1997)-1;w=days12/days02;put days02/days12/n/w;call symput(n, n); /*創(chuàng)建一個(gè)值來(lái)自data步的宏變量n*/call symput(w, w); /*創(chuàng)建一個(gè)值來(lái)自data步的宏變量w*/data

43、 a;delete;%macro a(r);data a1;p1=0;do i=1 to &n ;p1=p1+5/(1+&r)*(i-1+&w);output;end;data a1;set a1 end=lasobs;if lasobs;p2=105/(1+&r)*(&n-1+&w);p=p1+p2;r=200*&r;r1=100*&r;data a(drop=i);set a a1;w=&w;n=&n;%mend a;%a(0.03627);%a(0.0363);proc print data=a;run;3.1.7 投資組合內(nèi)生收益率計(jì)算例3.9 %macro a(y);data a;a

44、p1=0;do n=1 to 9 ;ap1=ap1+350000/(1+&y)*n;output;end;data a;set a end=lasobs;if lasobs;ap2=10350000/(1+&y)*10;ap=ap1+ap2;data b;bp1=0;do n=1 to 13 ;bp1=bp1+1050000/(1+&y)*n;output;end;data b;set b end=lasobs;if lasobs;bp2=21050000/(1+&y)*14;bp=bp1+bp2;data c;cp1=0;do n=1 to 5 ;cp1=cp1+900000/(1+&y)*

45、n;output;end;data c;set c end=lasobs;if lasobs;cp2=30900000/(1+&y)*6;cp=cp1+cp2;%mend a;%a(0.0476966);data abc;merge a b c;p=ap+bp+cp;put p=;run;3.2.1 浮動(dòng)利率債券貼現(xiàn)差額計(jì)算計(jì)算程序:data a ;delete;%macro a(y,z,x);data a1;do n=1 to 12 ;if n12 then p&x=5.4/(1+&y+&z)*n;else p&x=105.4/(1+&y+&z)*n;output;end;data a1;s

46、et a1;sump&x+p&x;data a;merge a a1;%mend a;%a(0.05, 0.004,80);%a(0.05, 0.0042,84);%a(0.05, 0.0044,88);%a(0.05, 0.0048,96);%a(0.05, 0.005,100);proc print data=a noobs;run;3.2.2 債券價(jià)格與必要收益率例3.11 data a;delete;%macro a(y);data a1;p1=45*(1-(1/(1+&y)*40)/&y;p2=1000*(1/(1+&y)*40);p=p1+p2;y=200*&y;data a;se

47、t a a1;%mend a;%a(0.025);%a(0.03);%a(0.035);%a(0.04);%a(0.045);%a(0.05);%a(0.055);%a(0.06);%a(0.065);%a(0.07);proc print data=a;run;不含期權(quán)債券價(jià)格與收益率關(guān)系圖:proc gplot data=a ;plot p*y=1;symbol1 v=none i=join r=1 c=black; title2 不含期權(quán)債券價(jià)格與收益率關(guān)系圖;labelp=價(jià)格y=必要收益率;run;3.2.3 債券價(jià)格時(shí)間軌跡例3.12 作表程序:title2;data a;do n

48、=40 to 0 by -2 ;p1=45*(1-(1/(1+0.06)*n)/0.06;p2=1000*(1/(1+0.06)*n);p=p1+p2;year=n/2;output;end;proc print data=a noobs;var year p1 p2 p;run;假定必要收益率不變的情況下, 貼水債券時(shí)間軌跡圖程序:data a;set a;p0=1000;proc gplot data=a ;plot p*year=1 p0*year=2/overlay;symbol1 v=none i=join r=1 c=black; symbol2 v=none i=join r=1

49、 c=black;title2 假定必要收益率不變的情況下,貼水債券時(shí)間軌跡;labelp=價(jià)格year=剩余到期年數(shù);run;例3.13 生成圖表程序:data a;do n=40 to 0 by -2 ;p1=45*(1-(1/(1+0.035)*n)/0.035;p2=1000*(1/(1+0.035)*n);p=p1+p2;year=n/2;output;end;proc print data=a noobs;var year p1 p2 p;run;data a;set a;p0=1000;proc gplot data=a ;plot p*year=1 p0*year=2/over

50、lay;symbol1 v=none i=join r=1 c=black;symbol2 v=none i=join r=1 c=black;labelp=價(jià)格year=剩余到期年數(shù);title2 假定必要收益率不變的情況下,升水債券時(shí)間軌跡;run; 例3.14 data a;delete;%macro a(y);data a1;date1=17jul1997d;date2=01sep1997d;days1=datdif(date1, date2, 30/360);w=days1/180;%let x=w; p1=0;do n=1 to 12 ;p1=p1+5/(1+&y)*(n-1+&x

51、);output;end;data a1;set a1 end=lasobs;if lasobs;p2=105/(1+&y)*(12-1+&x);p=p1+p2;y=200*&y;y1=100*&y;data a;set a a1;%mend a;%a(0.0325);proc print data=a;run;3.2.4 債券組合的到期收益率計(jì)算例3.15 收益率計(jì)算:%macro r(v1,v0,d);data;r=(&v1-&v0+&d)/&v0;put r=;%mend r(v1,v0,d);%r(112000000,100000000,5000000);run;例3.16 算術(shù)平均時(shí)序收益率程序:%macro r(r1,r2,r3,r4,n);data a;r=(

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論