Skip to content

Instantly share code, notes, and snippets.

@TAJD
Forked from jwmerrill/gbm.jl
Created February 6, 2018 15:26
Show Gist options
  • Save TAJD/e25ade3f38dc94a9cedfc6669c854b12 to your computer and use it in GitHub Desktop.
Save TAJD/e25ade3f38dc94a9cedfc6669c854b12 to your computer and use it in GitHub Desktop.
Faster geometric brownian motion
function genS_jl(I)
s0 = 600.0
r = 0.02
sigma = 2.0
T = 1.0
M = 100
dt = T/M
a = (r - 0.5*sigma^2)*dt
b = sigma*sqrt(dt)
paths = zeros(Float64, M, I)
for i in 1:I
paths[1, i] = st = s0
for j in 2:M
st *= exp(a + b*randn())
paths[j, i] = st
end
end
return paths
end
genS_jl(10) # Warm up JIT
@elapsed genS_jl(100000) # Outputs 0.538962298
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment