金融MATLAB实验报告三解析.docx
- 文档编号:5742349
- 上传时间:2022-12-31
- 格式:DOCX
- 页数:23
- 大小:408.70KB
金融MATLAB实验报告三解析.docx
《金融MATLAB实验报告三解析.docx》由会员分享,可在线阅读,更多相关《金融MATLAB实验报告三解析.docx(23页珍藏版)》请在冰豆网上搜索。
金融MATLAB实验报告三解析
安徽财经大学金融证券实验室
实验报告
实验课程名称《金融MATLAB》
开课系部金融学院
班级
学号
姓名
指导教师
2015年**月**日
实验名称
MATLAB金融数量分析
学院
学号
姓名
实验准备
实验目的
学会使用MATLA金融工具箱进行金融数量分析,如:
期权定价分析、投资组合绩效分析、收益和风险的计算、有效前沿的计算、固定收益证券的久期和凸度计算、利率的期限结构、技术指标计算等。
实验设计方案
使用MATLAB^融工具箱对下述6个主题进行数量分析,数据来源自行在网上搜寻,要求是2014年之后的数据。
(可参照各章的例题)
1.期权定价分析(第10章)
2.收益、风险和有效前沿的计算(第12章)
3.投资组合绩效分析(第13章)
4.固定收益证券的久期和凸度计算(第17章)
5.利率的期限结构(第18章)
6.技术指标分析(第22章)
本头验报告不指疋具体的题目,请大豕自仃设疋,同学相互之1可不要出现雷同。
实验分析过程
一、收益、风险和有效前沿的计算
从Wind咨询金融终端分别下载三只股票(美好集团、石油化服和首开股份)从2013年年初至今的
日收盘价价格,经过相关处理得出三只股票的收益率均值、标准差以及协方差矩阵等数据,如下表。
现根据表格数据进行关于收益、风险和有效前沿计算。
收益率均值
收益率标准差
协方差矩阵
美好集团
0.0018
0.0312
0.00100.00040.0005
石油化服
0.0016
0.0411
0.00040.00170.0003
首开股份
0.0006
0.0361
0.00050.00030.0013
1.收益率和风险计算函数
例1•假设等权重配置美好集团、石油化服、首开股份,计算资产组合的风险和收益。
解:
>>>ExpReturn=[0.0018,0.0016,0.0006];
ExpCovariiance=[0.0010,0.0004,0.0005;0.0004,0.0017,0.0003;0.0005,0.0003,0.0013];
PortWts=1/3*ones(1,3);
[PortRisk,PortReturn]=portstats(ExpReturn,ExpCovariance,PortWts)
PortRisk=
0.0170
PortReturn=
0.0013
2.有效前沿计算函数
例2.
(1)怎样配置美好集团、石油化服和首开股份,则资产组合为最优组合?
解:
>>ExpReturn=[0.0018,0.0016,0.0006];
>>ExpCovariiance=[0.0010,0.0004,0.0005;0.0004,0.0017,0.0003;0.0005,0.0003,0.0013];
>>NumPorts=10;
>>[PortRisk,PortReturn,PortWts]=frontcon(ExpReturn,ExpCovarianee,NumPorts)PortRisk=
0.0137
0.0139
0.0144
0.0151
0.0158
0.0166
0.0175
0.0184
0.0194
0.0229
PortReturn=
0.0006
0.0008
0.0009
0.0010
0.0012
0.0013
0.0014
0.0015
0.0017
0.0018
PortWts=
0
0.0439
0.9561
0
0.1724
0.8276
0.0275
0.2678
0.7047
0.1032
0.3054
0.5914
0.1789
0.3430
0.4781
0.2546
0.3806
0.3647
0.3303
0.4183
0.2514
0.4060
0.4559
0.1381
0.4817
0.4935
0.0248
1.0000
0
0
画图:
frontcon(ExpReturn,ExpCovarianee,NumPorts)
0.0130.014O.O'fS0.0160.0170.0180.0190020.02100220.C23
-''"■i■I4,;i:
:
i:
.
(2)例2中如果各个资产投资上限为50%,求解有效前沿?
>>ExpReturn=[0.0018,0.0016,0.0006];
ExpCovariiance=[0.0010,0.0004,0.0005;
0.0004,0.0017,0.0003;
0.0005,0.0003,0.0013];
NumPorts=10;
AssetBounds=[0,0,0;0.5,0.5,0.5];
[PortRisk,PortReturn,PortWts]=frontcon(ExpReturn,ExpCovarianee,NumPorts,[],AssetBounds)PortRisk=
0.0156
0.0160
0.0164
0.0168
0.0173
0.0177
0.0182
0.0187
0.0192
0.0197
PortReturn=
0.0011
0.0012
0.0013
0.0013
0.0014
0.0014
0.0015
0.0016
0.0016
0.0017
PortWts=
0.11960.38040.5000
0.19670.35190.4514
0.23440.37060.3949
0.27220.38940.3385
0.30990.40810.2820
0.34760.42680.2256
0.38530.44560.1691
0.42300.46430.1126
0.46080.48310.0562
0.50000.50000
frontcon(ExpReturn,ExpCovarianee,NumPorts,[],AssetBounds)
Risk(StandardDeviation)
3•约束条件下有效前沿
例3.例配置美好集团、石油化服、首开股份三个资产,美好集团最大配置60%,石油化服最大配置70%,首开股份最大配置50%,美好集团为资产集合A,石油化服、首开股份组成资产计划B,集合A的最大
配置为70%,集合B的最大配置为50%,集合A的配置不能超过集合B的3倍,则如何配置?
解:
>>NumAssets=3;
ExpReturn=[0.0018,0.0016,0.0006];
ExpCovariiance=[0.0010,0.0004,0.0005;
0.0004,0.0017,0.0003;
0.0005,0.0003,0.0013];
NumPorts=5;
PVal=1;
AssetMin=0;
AssetMax=[0.6,0.7,0.5];
GroupA=[100];GroupB=[011];
GroupMax=[0.7,0.5];
AtoBmax=3;
ConSet=portcons('PortValue',PVal,NumAssets,'AssetLims',...
AssetMin,AssetMax,NumAssets,'GroupComparison',GroupA,NaN,...
AtoBmax,GroupB,GroupMax);
[PortRisk,PortReturn,PortWts]=portopt(ExpReturn,ExpCovarianee,NumPorts,[],ConSet)PortRisk=
0.0156
0.0165
0.0176
0.0187
0.0199
PortReturn=
0.0011
0.0013
0.0014
0.0016
0.0017
PortWts=
0.1196
0.3804
0.5000
0.2468
0.3768
0.3764
0.3346
0.4204
0.2450
0.4225
0.4640
0.1135
0.6000
0.4000
0
画图
>>portopt(ExpReturn,ExpCovariance,NumPorts,[],ConSet)
Mean-Variance-EfficientFrontier
1.4
1.3
1.2
1.1
0.01550.016001650.0170.017500180.01850G19C.01950.02
Risk(StandardDeviation)
解:
1.读取数据
>>[typ,desc,fmt]=xlsfinfo('HHHZ.xlsX');
>>[data,textdate]=xlsread('HHHZ.xlsX');
>>HHHZ=data;
>>saveHHHZHHHZ
2.三只股票和一只指数的精致曲线
>>loadHHHZ
>>figure;
>>holdon>>plot(HHHZ(:
1)/HHHZ(1,1),'k')
>>plot(HHHZ(:
2)/HHHZ(1,2),'r-.')
>>plot(HHHZ(:
3)/HHHZ(1,3),'bo')
>>plot(HHHZ(:
4)/HHHZ(1,4),'g--')>>xlabel('time')
>>ylabel('price')
>>legend('中证800','华丽家族','华远地产','合肥城建')
8
中证日00
7.华丽家族
0JJJ111LL1
Q5D10015020025030D3504D0450
3.Beta与Alpha计算
以中证800作为市场收益,使用portbeta函数分别计算华丽家族、华远地产、合肥城建的beta值。
过程如
下:
(1)betaj计算
loadHHHZ
Rate=price1ret(HHHZ);
BSbeta=portbeta(Rate(:
4),Rate(:
1));
(2)Alpha计算
以中证800作为市场收益,使用portalpha函数分别计算华丽家族、华远地产、合肥城建的beta值。
过程
如下:
>>loadHHHZ
Rate=price2ret(HHHZ);
zz800=Rate(:
1);
hljz=Rate(:
2);
hydc=Rate(:
3);
hfcj=Rate(:
4);
daynum=fix(length(Rate)/2);
cash=(1+0.03F(1/daynum)-1;
cash=cash*ones(daynum,1);
RatioHL2013=daynum*portalpha(hljz(1:
daynum),zz800(1:
daynum),cash,'capm')
RatioHL2014=daynum*portalpha(hljz(daynum+1:
2*daynum),zz800(daynum+1:
2*daynum),cash,'capm')
RatioHY2013=daynum*portalpha(hydc(1:
daynum),zz800(1:
daynum),cash,'capm')
RatioHY2014=daynum*portalpha(hydc(daynum+1:
2*daynum),zz800(daynum+1:
2*daynum),cash,'capm')RatioHF2014=daynum*portalpha(hfcj(1:
daynum),zz800(1:
daynum),cash,'capm')
RatioHF2013=daynum*portalpha(hfcj(daynum+1:
2*daynum),zz800(daynum+1:
2*daynum),cash,'capm')RatioHL2013=
0.3119
RatioHL2014=
0.2903
RatioHY2013=
0.1122
RatioHY2014=
0.1566
RatioHF2013=
0.1046
RatioHF2014=
0.0315
4.夏普比率
计算华丽家族、华远地产、合肥城建的夏普比率
>>loadHHHZ
Rate=price2ret(HHHZ);
hljz=Rate(:
2);
hydc=Rate(:
3);
hfcj=Rate(:
4);
daynum=fix(length(Rate)/2);
Cash=(1+0.03F(1/daynum)-1;
RatioHL2013=sharpe(hljz(1:
daynum),Cash)
RatioHL2014=sharpe(hljz(daynum+1:
2*daynum),Cash)
RatioHYDC2013=sharpe(hydc(1:
daynum),Cash)
RatioHYDC2014=sharpe(hydc(daynum+1:
2*daynum),Cash)
RatioHF2013=sharpe(hfcj(1:
daynum),Cash)
RatioHF2014=sharpe(hfcj(daynum+1:
2*daynum),Cash)
结果:
RatioHL2013=
0.0768
RatioHL2014=
0.0549
RatioHYDC2013=
0.0493
RatioHYDC2014=
0.0460
RatioHF2013=
0.0876
RatioHF2014=
0.0377
5.信息比率
以中证800指数作为业绩比较基准,计算华丽家族、华远地产、合肥城建成长的信息比率编码:
>>loadHHHZ
Rate=price2ret(HHHZ);
zz800=Rate(:
1);
hljz=Rate(:
2);
hydc=Rate(:
3);
hfcj=Rate(:
4);
daynum=fix(length(Rate)/2);
RatioHL2013=inforatio(hljz(1:
daynum),zz800(1:
daynum))
RatioHL2014=inforatio(hljz(daynum+1:
2*daynum),zz800(daynum+1:
2*daynum))
RatioHYDC2013=inforatio(hydc(1:
daynum),zz800(1:
daynum))
RatioHYDC2014=inforatio(hydc(daynum+1:
2*daynum),zz800(daynum+1:
2*daynum))
RatioHF2013=inforatio(hfcj(1:
daynum),zz800(1:
daynum))
RatioHF2014=inforatio(hfcj(daynum+1:
2*daynum),zz800(daynum+1:
2*daynum))
7.市场指数变化的最大回撤图根据中证800指数数据画出最大收益回撤
>>loadHHHZZZ800price=HHHZ(:
1);N=length(ZZ800price);RetraceRatio=zeros(N,1);
fori=2:
N
C=max(ZZ800price(1:
i));
ifC==ZZ800price(i)
RetraceRatio(i)=0;
elseRetraceRatio(i)=(ZZ800price(i)-C)/C;
end
end
TRate=ZZ800price/ZZ800price
(1)-1;f=figure;
fill([1:
N,N],[RetraceRatio;0],'r')
holdonplot(TRate);xlabel('time')ylabel('Rate/RetraceRatio')
-^1
450
40n
o
30
on
2
50
III-
-11
50
e
Im
三、固定收益证券的久期和凸度计算
从wind资讯金融终端下载三只国债的相关信息如下,进行国定收益证券的久期和凸度的计算。
证券编号
固定收益证券
到期收益率
票面利率
结算日
到期日
计息方式
150007
15附息国债07
3.0450
3.5400
16-Apr-15
16-Apr-22
每年付息一次
150026
15附息国债26
3.0600
3.0500
22-Oct-15
22-Oct-22
每年付息一次
150019
15附息国债19
2.9050
3.1400
8-Sep
15
8-Sep-20
每年付息一次
1.三种债券的价格及计算日的利息计算
(1)15附息国债07的价格和结算日利息计算
>>Yield=[0.03045];
CouponRate=0.0354;
Settle='16-Apr-2015:
Maturity='16-Apr-2022:
Period=1;
Basis=0;
[Price,Accruedlnt]=bndprice(Yield,CouponRate,Settle,Maturity,Period,Basis)
Price=
102.9320
AccruedInt=
0
(2)15附息国债26的价格和结算日利息计算
>>Yield=[0.036];
CouponRate=0.0305;
Settle='22-Oct-2015:
Maturity='22-Oct-22';
Period=1;
Basis=0;
[Price,AccruedInt]=bndprice(Yield,CouponRate,Settle,Maturity,Period,Basis)
Price=
96.4564
AccruedInt=
0
(2)15附息国债19的价格和结算日利息计算
>>Yield=[0.02905];
CouponRate=0.0314;
Settle='8-Sep-2015';
Maturity='8-Sep-2020';
Period=1;
Basis=0;
[Price,AccruedInt]=bndprice(Yield,CouponRate,Settle,Maturity,Period,Basis)
Price=
100.9817
AccruedInt=
013
2.根据债券价格计算久期
(1)15附息国债07的久期计算
PRICE=[102.9320];
CouponRate=0.0354;
Settle='16-Apr-2015:
Maturity='16-Apr-2022:
Period=1;
Basis=0;
[ModDuration,YearDuration,PerDuration]=bnddurp(Price,CouponRate,Settle,Maturity,Period,Basis)
ModDuration=
6.2212
YearDuration=
6.3255
PerDuration=
12.6509
(2)15附息国债26的久期计算
>>PRICE=[96.4564];
CouponRate=0.0305;
Settle='22-Oct-2015';
Maturity='22-Oct-22';
Period=1;
Basis=0;
[ModDuration,YearDuration,PerDuration]=bnddurp(Price,CouponRate,Settle,Maturity,Period,Basis)
ModDuration=
6.3209
YearDuration=
6.4116
PerDuration=
12.8233
(3)15附息国债19的久期计算
>>Price=[100.9817];
CouponRate=0.0314;
Settle='8-Sep-2015';
Maturity='8-Sep-2020';
Period=1;
Basis=0;
[ModDuration,YearDuration,PerDuration]=bnddurp(Price,CouponRate,Settle,Maturity,Period,Basis)
ModDuration=
4.6390
YearDuration=
4.7064
PerDuration=
9.4127
3.根据债券收益率计算久期
(1)15附息国债07的久期计算
>>Yield=[0.03045];
CouponRate=0.0354;
Settle='16-Apr-2015:
Maturity='16-Apr-2022:
Period=1;
Basis=0;
[ModDuration,YearDuration,PerDuration]=bnddurp(Yield,CouponRate,Settle,Maturity,Period,Basis)
ModDuration=
0.0931
YearDuration=
1.0086
PerDuration=
2.0172
(2)15附息国债26的久期计算
>>Yield=[0.036];
CouponRate=0.0305;
Settle='22-Oct-2015:
Maturity='22-Oct-22:
Period=1;
Basis=0;
[ModDuration,YearDuration,PerDuration]=bnddurp(Yield,CouponRate,Settle,Maturity,Period,Basis)
ModDuration=
0.1093
YearDuration=
1.0118
PerDuration=
2.0236
(3)15附息国债19的久期计算
>>Yield=[0.02905];
CouponRate=0.0314;
Settle='8-Sep-2015:
Maturity='8-Sep-2020:
Period=1;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 金融 MATLAB 实验 报告 解析