Simulation geometric brownian motions

4 次查看(过去 30 天)
Hey I am trying to simulate wealth dynamics over time using the fact that stock price follows a geometric brownian motion and the income is also a stochastic proces. There is a problem in the code regarding matrix algebra, stating the error "Matrix dimensions must agree"
Can anyone help me solve the problem? :)
% function [F]=Wealth(F0,rate,phi,muS,volS,Y0,muY,volY,rho,T,N,n)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function simulates a geometric brownian motion.
%--------------------------------------------------------------------------
% Note:
% F0: Initial wealth of the simulation.
% rate: Risk free rate
% phi: Fraction of risky assets
% muS: Growth rate of stocks.
% volS: Volatility of stocks.
% Y0: Initial income of the simulation.
% muY: Growth rate of income.
% volY: Volatility of income.
% rho: Correlation between income and equity
% N: number of simulation per path.
% n: number of simulated paths.
%--------------------------------------------------------------------------
% Each row in the output of this function is one individual simulation of
% a geometric brownian motion path.
%--------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Construct price process:
dt=T/N;
dW1=sqrt(dt)*randn(N-1,n);
dW2=sqrt(dt)*randn(N-1,n);
Y=Y0*exp(cumsum(muY-1/2*volY^2)*dt+volY*rho*dW1+sqrt(1-rho)*volY*dW2);
Y=[ones(1,n)*Y0;Y];
F=F0*exp(cumsum((rate+phi.'*(muS-rate))-1/2*phi.'^2*volS^2)*dt+phi.'*volS*dW1+Y*dt);
F=[ones(1,n)*F0;F];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
  1 个评论
Star Strider
Star Strider 2016-10-22
We cannot run your code.
Check the size of all your matrices. Be certain they are appropriate to the mathematical operations you want to perform on them.
Also, consider using the bsxfun function. It may do the calculations you want to perform.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Financial Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by