You are on page 1of 1

Code to generate asset price paths by Monte Carlo simulation

Code to generate asset price paths by Monte Carlo simulation


1 % A s s e t P a t h s .m
2 % code to g e n e r a t e a s s e t p r i c e paths
3 f u n c t i o n SPaths=AssetPaths ( S0 , mu , sigma , T , NSteps , NRepl )
4 SPaths = z e r o s ( NRepl , 1 + NSteps ) ;
5 SPaths ( : , 1 ) = S0 ;
6 dt = T / NSteps ;
7 nudt = ( mu −( 0. 5∗ sigma ˆ 2 ) ) ∗ dt ;
8 sidt = sigma ∗ s q r t ( dt ) ;
9 f o r i =1: NRepl
10 f o r j =1: NSteps
11 SPaths ( i , j+1)=SPaths ( i , j ) ∗ e x p ( nudt + sidt ∗ r a n d n ) ;
12 end
13 end
14

Next, we generate and plot ten one-year sample paths for an HP Laptop with an initial price
20,000 CZK, drift 0.1, and volatility 0.7 (on a yearly basis), assuming that the time step is one
day and I assume that a year consists of 365 trading days.

Martyns Nwaokocha An application of Monte-Carlo Simulation January 27, 2021 23 / 36

You might also like