Simulating stochastic financial assets
4 ビュー (過去 30 日間)
古いコメントを表示
I want to simulate how financial wealth will evolve over 30 years, using the fact that the financial wealth follows a stochastic brownian motion process (with known moments (mu, sigma)).
The idea is to simulate 10.000 random outcomes each year for 30 years. Thus, i want to create a 10.000 x 30 matrix.
Do anyone know how to set up the system of equations in matlab and generate the simulation
The code below does not do the job, but gives a sense of which equations, I want to simulate
rho = 0.01;
N = 10000; % number of time steps
T = 30; % terminal time
r = 0.01; % interest rate
muS = 0.06; % drift of stock
muY = 0.01; % drift of human capital
muF = 0 + (muS - r);
sigmaS = 0.2; % volatility of stock
sigmaY = 0.05; % volatility of human capital
sigmaF = sigmaS;
S0 = 100; % initial traded stock
Y0 = 100; % initial human capital
F0 = 100;
t = (0:30:1);
W1 = [0; cumsum(randn(N,1))]/sqrt(N); % S is running sum of N(0,1/N) variables
W2 = [0; cumsum(randn(N,1))]/sqrt(N); % S is running sum of N(0,1/N) variables
t = t*T;
W1 = W1*sqrt(T); % create brownian motion
W2 = W2*sqrt(T); % create orthogonal brownian motion
S = S0*exp((muS-(sigmaS^2)/2)*t + sigmaS*W1);
Y = Y0*exp((muY-(sigmaY^2)/2)*t + sigmaY*(rho*W1+sqrt(1-rho^2)*W2));
F = F0*exp((muF-(sigmaF^2)/2)*t + sigmaF*W1) + Y'*t;
plot(t,Y,'linewidth',1.5);
hold on
0 件のコメント
回答 (1 件)
Brandon Eidson
2016 年 10 月 7 日
編集済み: Brandon Eidson
2016 年 10 月 7 日
Hey Hardeep,
After a quick glance, I am seeing a few possible errors in your code. Because of the way you are populating "W1" and "W2" and your description of wanting 10,000 time steps per year, I am assuming that you are wanting "N" number of elements per year for a total of "T" years. Therefore, you want length(t) = N*T and you want the elements of "t" equally spaced between 0 and T-1.
If these assumptions are correct, you need to delete the following two lines of code.
t = (0:30:1); % Note that this line will result in "t=0"
t = t*T;
Then, in place of the first line of code that you deleted, insert the following line of code.
t = linspace(0,(T-1),T*N)';
If the above is correct, you also need to update your calculations of W1 and W2.
W1 = [0; cumsum(randn(T*N-1,1))]/sqrt(T*N);
W2 = [0; cumsum(randn(T*N-1,1))]/sqrt(T*N);
If it helps, there are examples of implementing "Brownian Motion" models at the bottom of the documentation at the following link.
参考
カテゴリ
Help Center および File Exchange で Stochastic Differential Equation (SDE) Models についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!