-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissue.jl
More file actions
38 lines (28 loc) · 795 Bytes
/
Copy pathissue.jl
File metadata and controls
38 lines (28 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using DifferentialEquations
using DiffEqFinancial
using Statistics
include("solution.jl")
r = 0.03
sigma = 0.2
S0 = 100
t=0
T=1.0
days = 252
dt = 1/days
prob = GeometricBrownianMotionProblem(r, sigma, S0, (t,T))
#prob = MyGeometricBrownianMotionProblem(r, sigma, S0, (t,T))
sol = solve(prob;dt=dt)
monte_prob = EnsembleProblem(prob)
sol = solve(monte_prob, EM(); dt=dt,trajectories=100000)
# Simulated price paths
us=[sol[i].u for i in eachindex(sol)]
# Mean of all paths at all time steps
simulated = mean(us)
tsteps = collect(0:dt:T)
# Expected value of GBM at every simulated time step
expected = S0 * exp.(r * tsteps)
println("Stock price at T=1.0:")
println("Simulated = ", simulated[end])
println("Expected = ", expected[end])
# Error
#error = sum(abs2.(simulated .- expected))