Skip to content

Commit 36a8774

Browse files
committed
Adjusting inputs form bs, scaling corrected in carr madan
1 parent f12a0d1 commit 36a8774

File tree

9 files changed

+21
-18
lines changed

9 files changed

+21
-18
lines changed

examples/binomial_tree_vega.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ american_payoff = VanillaOption(strike, expiry, Hedgehog2.American(), call_put,
99
# define market inputs
1010
reference_date = Date(2017, 6, 29)
1111
rate = 0.013047467783283154
12-
forward = 5.6525
12+
T = Dates.values(expiry - reference_date) / 365
13+
spot = 5.6525 * exp(-rate*T)
1314
sigma = 0.1689900715
14-
market_inputs = BlackScholesInputs(reference_date, rate, forward, sigma)
15+
market_inputs = BlackScholesInputs(reference_date, rate, spot, sigma)
1516

1617
# create Cox Ross Rubinstein pricer
1718
steps = 800

examples/binomial_tree_vega_pluto.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ american_payoff = VanillaOption(strike, expiry, Hedgehog2.American(), call_put,
4040

4141
# define market inputs
4242
reference_date = Date(2017, 6, 29)
43+
T = Dates.values(expiry - reference_date) / 365
4344
rate = 0.013047467783283154
44-
forward = 5.6525
45+
spot = 5.6525 * exp(r*T)
4546
sigma = 0.1689900715
46-
market_inputs = BlackScholesInputs(reference_date, rate, forward, sigma)
47+
market_inputs = BlackScholesInputs(reference_date, rate, spot, sigma)
4748

4849
# create Cox Ross Rubinstein pricer
4950
steps = 800

examples/black_vs_binomial_tree.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ euro_payoff = VanillaOption(strike, expiry, Hedgehog2.European(), call_put, unde
1111
# define market inputs
1212
reference_date = Date(2020, 1, 1)
1313
rate = 0.2
14-
forward = 1
14+
spot = 1
1515
sigma = 0.4
16-
market_inputs = BlackScholesInputs(reference_date, rate, forward, sigma)
16+
market_inputs = BlackScholesInputs(reference_date, rate, spot, sigma)
1717

1818
# create analytical black scholes pricer
1919
bs_method = BlackScholesMethod()

examples/carr_madan.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ using Revise, Hedgehog2, BenchmarkTools, Dates
55
# Define market inputs
66
reference_date = Date(2020, 1, 1)
77
rate=0.2
8-
spot=1
8+
spot=100
99
sigma=0.4
1010
market_inputs = BlackScholesInputs(reference_date, rate, spot, sigma)
11-
market_inputs_bs = BlackScholesInputs(reference_date, rate, exp(rate)*spot, sigma)
1211

1312
# Define payoff
1413
expiry = reference_date + Day(365)
15-
strike = 1.5
14+
strike = 150
1615
payoff = VanillaOption(strike, expiry, Hedgehog2.European(), Hedgehog2.Call(), Hedgehog2.Spot())
1716

1817
# Define carr madan method
@@ -24,7 +23,7 @@ method = Hedgehog2.CarrMadan(α, boundary)
2423
carr_madan_pricer = Pricer(payoff, market_inputs, method)
2524

2625
# Define analytical pricer
27-
analytical_pricer = Pricer(payoff, market_inputs_bs, BlackScholesMethod())
26+
analytical_pricer = Pricer(payoff, market_inputs, BlackScholesMethod())
2827

2928
println(analytical_pricer())
3029
println(carr_madan_pricer())

examples/carr_madan_heston.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ V0 = 0.010201 # Initial variance
1515
r = 0.0319 # Risk-free rate
1616
T = 1.0 # Time to maturity
1717
market_inputs = Hedgehog2.HestonInputs(reference_date, r, S0, V0, κ, θ, σ, ρ, r)
18-
bs_market_inputs = BlackScholesInputs(reference_date, r, S0, sqrt(V0))
18+
bs_market_inputs = BlackScholesInputs(reference_date, r, exp(rate)*S0, sqrt(V0))
1919
# Define payoff
2020
expiry = reference_date + Day(365)
2121
strike = 100

src/market_inputs/market_inputs.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ It is assumed that the volatility is annual.
1616
struct BlackScholesInputs <: AbstractMarketInputs
1717
referenceDate
1818
rate
19-
forward
19+
spot
2020
sigma
2121
end
2222

2323
function log_distribution(m::BlackScholesInputs)
24-
r, σ = m.rate, m.sigma
25-
d(t) = Normal((r - σ^2 / 2)t, σt)
24+
r, σ, S0 = m.rate, m.sigma, m.spot
25+
d(t) = Normal(log(S0) + (r - σ^2 / 2)t, σt)
2626
return d
2727
end
2828

src/pricing_methods/black_scholes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ where:
4646
- The function supports both call and put options through the `cp` factor, ensuring a unified formula.
4747
"""
4848
function compute_price(payoff::VanillaOption{European, A, B}, marketInputs::BlackScholesInputs, ::BlackScholesMethod) where {A,B}
49-
F = marketInputs.forward
5049
K = payoff.strike
5150
r = marketInputs.rate
5251
σ = marketInputs.sigma
5352
cp = payoff.call_put()
5453
T = Dates.value.(payoff.expiry .- marketInputs.referenceDate) ./ 365 # Assuming 365-day convention
54+
F = marketInputs.spot*exp(r*T)
5555
d1 = (log(F / K) + 0.5 * σ^2 * T) /* sqrt(T))
5656
d2 = d1 - σ * sqrt(T)
5757
return exp(-r*T) * cp * (F * cdf(Normal(), cp * d1) - K * cdf(Normal(), cp * d2))

src/pricing_methods/carr_madan.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct CarrMadan <: AbstractPricingMethod
77
end
88

99
# in distribution.jl t is Real, hence we need to redefine it.
10-
cf(d::Normal, t) = exp(im * t * d.μ- d.σ^2 / 2 * t^2)
10+
cf(d::Normal, t) = exp(im * t * d.μ - d.σ^2 / 2 * t^2)
1111

1212
function compute_price(payoff::VanillaOption{European, Call, Spot}, market_inputs::I, method::CarrMadan) where I <: AbstractMarketInputs
1313
damp = exp(- method.α * log(payoff.strike)) / 2π

src/pricing_methods/cox_ross_rubinstein.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ Computes the price of a vanilla option using the Cox-Ross-Rubinstein binomial tr
108108
"""
109109
function compute_price(payoff, market_inputs, method::CoxRossRubinsteinMethod)
110110
steps = method.steps
111-
ΔT = Dates.value.(payoff.expiry - market_inputs.referenceDate) / 365 / steps # Assuming ACT/365 day count
111+
T = Dates.value.(payoff.expiry - market_inputs.referenceDate) / 365
112+
forward = market_inputs.spot * exp(market_inputs.rate * T)
113+
ΔT = T / steps # Assuming ACT/365 day count
112114
u = exp(market_inputs.sigma * sqrt(ΔT)) # Up-move factor
113-
forward_at_i(i) = market_inputs.forward * u .^ (-i:2:i)
115+
forward_at_i(i) = forward * u .^ (-i:2:i)
114116
underlying_at_i(i) = binomial_tree_underlying(i, forward_at_i(i), market_inputs.rate, ΔT, payoff.underlying)
115117

116118
# Up probability in forward measure

0 commit comments

Comments
 (0)