monte carlo程序matlab,monte carlo(matlab)
导读:本文共1036字符,通常情况下阅读需要3分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: %% Simulation de monte carlo d'un actif de rpix Spot 100, de volatilit� % sigma, et de drift InterestRate. % Vincent Leclercq, The MathWorks, 2007. [email protected] clear all; close all; %% Sta... ...
目录
(为您整理了一些要点),点击可以直达。%% Simulation de monte carlo d'un actif de rpix Spot 100, de volatilit�
% sigma, et de drift InterestRate.
% Vincent Leclercq, The MathWorks, 2007. [email protected]
clear all;
close all;
%% Starting parameters
tic;
nActifs = 2;
CorrelationMatrix = [1 0.9;0.9 1];
Vols = [0.5 0.9];
DivYelds = [0 0];
StartValues = [100 100];
ExpCovariance = corr2cov(Vols, CorrelationMatrix);
CholFactor = chol(ExpCovariance);
InterestRate = 0.03;
TimeToMaturity = 0.5; % in years
NSimulation = 10000;
nSteps = 20;
%% Time Step
Dt = TimeToMaturity/nSteps;
%% Generate Random numbers
UniforRandom = rand (nSteps , NSimulation, nActifs );
CorrelatedRandomNumbers = zeros (nSteps , NSimulation, nActifs );
RandomNumbers = norminv(UniforRandom,0,1);
%% To Store the result
Paths = zeros (nSteps , NSimulation, nActifs);
%% Preserve Correlation for each realisation
for i = 1 : NSimulation
CorrelatedRandomNumbers (:,i,:) = squeeze(RandomNumbers(:,i,:)) * CholFactor;
end
%%
for i = 1 : nActifs
% Generate the dt returns
Paths(:,:,i) = exp( (InterestRate-DivYelds(i)-Vols(i)^2/2)*Dt + Vols(i)*sqrt(Dt).* CorrelatedRandomNumbers (:,:,i));
Paths(:,:,i) = cumprod(Paths(:,:,i), 1);
Paths(:,:,i) = Paths(:,:,i) * StartValues(i);
%
end;
%% Compare for the first time step the Simualtions of the 2 assets
h1 = figure;plot(Paths(1,:,1),Paths(1, : ,2),'r.');
set(h1,'WindowStyle','Docked');
ylim(gca(h1),xlim);
h2 = figure;plot(1 : 20 ,[Paths(:,1 ,1),Paths(:,1 ,2)],'-');
set(h2,'WindowStyle','Docked');
Correlationcoeff = corrcoef(Paths(:,:,1),Paths(:,:,2))
monte carlo程序matlab,monte carlo(matlab)的详细内容,希望对您有所帮助,信息来源于网络。