PDA

View Full Version : How to simulate Brownian motion for multiple trajectories?



Miracle
04-03-2017, 08:32 AM
I would like to simulate a geometric Brownian motion for 20,000 trajectories with VBA. Since the number of trajectories is huge, doing it by hand would be troublesome.
The formula is as follows

X(n) = X(n-1) + u*X(n-1)*Delta_t + Sigma*X(n-1)*En*sqrt(Delta_t)
where u is the drift: u = 0.2
Delta_t = 1/250 year
Volatility: Sigma = 0.3
En = NORMSINV(Rand()) a standard normal random variable

I have trouble incorporating number of trajectories in to the VBA code.

Paul_Hossler
04-03-2017, 12:16 PM
Not sure I understand 'trajectories' but if you mean iterations, something like this maybe




Option Explicit

Sub Brownian()
Const Drift As Double = 0.2
Const Delta_t As Double = 1# / 250#
Const Volatility As Double = 0.3

Dim N_1 As Double, N As Double
Dim i As Long

N_1 = 0.1 ' guess

For i = 1 To 20000
'X(N) = X(N - 1) + U * X(N - 1) * Delta_t + Sigma * X(N - 1) * En * sqrt(Delta_t)
N = N_1 + (Drift * N_1 * Delta_t) + (Volatility * N_1 * Application.WorksheetFunction.NormSInv(Rnd()) * Sqr(Delta_t))
N_1 = N
Next I

MsgBox N

End Sub