Simulation geometric brownian motions

조회 수: 4 (최근 30일)
Cecilie Pedersen
Cecilie Pedersen 2016년 10월 22일
댓글: Star Strider 2016년 10월 22일
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