-
-
Save TAJD/e25ade3f38dc94a9cedfc6669c854b12 to your computer and use it in GitHub Desktop.
Faster geometric brownian motion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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