随机模拟方法的模拟实例
资产组合模拟:
假设有五种资产,其日收益率(%)分别为
0.02460.0189 0.0273 0.0141 0.0311
标准差分别为
0.95091.4259, 1.5227, 1.1062, 1.0877
相关系数矩阵为
1.0000 0.4403 0.4735 0.4334 0.6855
0.4403 1.00000.7597 0.7809 0.4343
0.4735 0.75971.0000 0.6978 0.4926
0.4334 0.78090.6978 1.0000 0.4289
0.6855 0.43430.4926 0.4289 1.0000
假设初始价格都为100,模拟天数为504天,模拟线程为2,程序如下
%run.m
ExpReturn = [0.0246 0.0189 0.0273 0.0141 0.0311]/100; %期望收益
Sigmas = [0.9509 1.4259, 1.5227, 1.1062, 1.0877]/100;%标准差
Correlations = [1.0000 0.4403 0.4735 0.4334 0.6855
0.4403 1.00000.7597 0.7809 0.4343
0.4735 0.75971.0000 0.6978 0.4926
0.4334 0.78090.6978 1.0000 0.4289
0.6855 0.43430.4926 0.4289 1.0000
];%相关系数
ExpCov = corr2cov(Sigmas, Correlations);%协方差
StartPrice = 100;%初始价格
NumObs = 504;
NumSim = 2;
RetIntervals = 1;
NumAssets = 5;
%开始模拟
randn('state', 0);
RetExact = portsim(ExpReturn, ExpCov, NumObs, RetIntervals, NumSim);
Weights = ones(NumAssets, 1)/NumAssets;
PortRetExact = zeros(NumObs, NumSim);
for i = 1:NumSim
PortRetExact(:, i) = RetExact(:,:,i)*Weights;
end
PortExact = ret2tick(PortRetExact,repmat(StartPrice, 1, NumSim));
plot(PortExact, '-r');
2024-09-19 广告