Skip to content

Commit 772ae9a

Browse files
committed
WOrking on bumping montecarlo
1 parent e84a4e2 commit 772ae9a

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

examples/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
33
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
44
DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0"
55
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
6+
DiffEqNoiseProcess = "77a26b50-5914-5dd7-bc55-306e6241c503"
7+
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
68
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
79
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
810
Hedgehog2 = "7f16798b-0e18-40de-98af-932948254698"

examples/bumped_montecarlo.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using DifferentialEquations
2+
using DiffEqNoiseProcess
3+
using Plots
4+
5+
# Parameters
6+
μ = 0.05
7+
σ = 0.2
8+
t0 = 0.0
9+
T = 1.0
10+
W0 = 100.0
11+
tspan = (t0, T)
12+
N = 250
13+
dt = (T - t0) / N
14+
15+
# Step 1: Simulate base GBM and save the noise
16+
gbm = GeometricBrownianMotionProcess(μ, σ, t0, W0)
17+
gbm_noise = NoiseProblem(gbm, tspan, seed=1)
18+
sol = DifferentialEquations.solve(gbm_noise, dt=dt)
19+
20+
# Step 2: Reuse the noise and simulate with bumped μ
21+
μ_bumped = μ
22+
σ_bumped = σ + 0.1
23+
gbm_bumped = GeometricBrownianMotionProcess(μ_bumped, σ_bumped, t0, W0)
24+
gbm_bumped_noise = NoiseProblem(gbm_bumped, tspan, seed=1)
25+
ensemble_problem_bumped = EnsembleProblem(gbm_bumped_noise)
26+
sol_bumped = DifferentialEquations.solve(gbm_bumped_noise, dt=dt)
27+
28+
# Step 3: Plot both
29+
plot(sol.t, sol.u, label="μ = ", linewidth=2)
30+
plot!(sol_bumped.t, sol_bumped.u, label="μ = $μ_bumped", linestyle=:dash, linewidth=2)
31+
xlabel!("Time")
32+
ylabel!("GBM Value")
33+
title!("GBM with Drift Bump and Reused Noise")

examples/montecarlo_bs.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ prob = PricingProblem(payoff, market_inputs)
2323

2424
# -- Monte Carlo Method
2525
trajectories = 10_000
26-
strategy = BlackScholesExact(trajectories)
26+
strategy = BlackScholesExact(trajectories, seed=1)
2727
dynamics = LognormalDynamics()
2828
method_mc = MonteCarlo(dynamics, strategy)
2929

3030
# -- Analytic Method
3131
method_analytic = BlackScholesAnalytic()
32-
32+
3333
# -- Solve Both
3434
solution_analytic = solve(prob, method_analytic)
3535
solution_mc = solve(prob, method_mc)
@@ -38,6 +38,6 @@ println("Analytic price: ", solution_analytic.price)
3838
println("Monte Carlo price:", solution_mc.price)
3939

4040
# -- Benchmark
41-
println("\n--- Benchmarking ---")
42-
@btime solve($prob, $method_analytic).price
43-
@btime solve($prob, $method_mc).price
41+
# println("\n--- Benchmarking ---")
42+
# @btime solve($prob, $method_analytic).price
43+
# @btime solve($prob, $method_mc).price

0 commit comments

Comments
 (0)