Skip to content

Commit 5b9d0ad

Browse files
committed
added montecarlo blacksholes pricer
1 parent ef00517 commit 5b9d0ad

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

src/Hedgehog2.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ include("market_inputs/market_inputs.jl")
1111
include("pricing_methods/pricing_methods.jl")
1212
include("pricing_methods/black_scholes.jl")
1313
include("pricing_methods/cox_ross_rubinstein.jl")
14+
include("pricing_methods/montecarlo.jl")
15+
1416
include("sensitivity_methods/delta_methods.jl")
1517
include("stochastic_processes/stochastic_processes.jl")
1618

src/pricing_methods/black_scholes.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Black-Scholes pricing function for European vanilla options
22

3+
export BlackScholesMethod
4+
5+
"""
6+
The Black-Scholes pricing method.
7+
8+
This struct represents the Black-Scholes pricing model for option pricing, which assumes a lognormal distribution for the underlying asset and continuous hedging.
9+
"""
10+
struct BlackScholesMethod <: AbstractPricingMethod end
11+
312
"""
413
Computes the price of a vanilla European call or put option using the Black-Scholes model.
514

src/pricing_methods/cox_ross_rubinstein.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Cox-Ross-Rubinstein Binomial Tree Pricing Implementation
22

3+
export CoxRossRubinsteinMethod
4+
35
"""
46
The Cox-Ross-Rubinstein binomial tree pricing method.
57

src/pricing_methods/montecarlo.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# a montecarlo method is defined by an SDEProblem or a NoiseProblem.
2+
# the SDE problem needs market data and a payoff to be defined
3+
abstract type MontecarloMethod <: AbstractPricingMethod end
4+
5+
struct BSMontecarlo <: MontecarloMethod
6+
trajectories
7+
end
8+
9+
# we could make an ExactMontecarlo, dispath to get the noise problem and always make just one step.
10+
function compute_price(payoff::VanillaOption{European, C, Spot}, market_inputs::BlackScholesInputs, method::BSMontecarlo) where {C}
11+
T = Dates.value.(payoff.expiry .- marketInputs.referenceDate) ./ 365 # Assuming 365-day convention
12+
noise = GeometricBrownianMotionProcess(market_inputs.r, market_inputs.sigma, market_inputs.referenceDate, 0)
13+
problem = NoiseProblem(noise, (0, T))
14+
ensemble_problem = EnsembleProblem(problem)
15+
solution = solve(ensemble_problem; dt=T, trajectories = method.trajectories) # its an exact simulation, hence we use just one step
16+
mean_payoff = mean(payoff.(last.(solution.u)))
17+
return mean_payoff
18+
end

src/pricing_methods/pricing_methods.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Exported Types and Functions
2-
export AbstractPricingMethod, BlackScholesMethod, Pricer, compute_price, CoxRossRubinsteinMethod
2+
export AbstractPricingMethod, Pricer, compute_price
33

44
"""
55
An abstract type representing a pricing method.
@@ -8,13 +8,6 @@ All pricing methods, such as Black-Scholes or binomial trees, should inherit fro
88
"""
99
abstract type AbstractPricingMethod end
1010

11-
"""
12-
The Black-Scholes pricing method.
13-
14-
This struct represents the Black-Scholes pricing model for option pricing, which assumes a lognormal distribution for the underlying asset and continuous hedging.
15-
"""
16-
struct BlackScholesMethod <: AbstractPricingMethod end
17-
1811
"""
1912
A pricer that calculates the price of a derivative using a given payoff, market data, and a pricing model.
2013

0 commit comments

Comments
 (0)