Skip to content

Commit 9ae7bd3

Browse files
committed
Added carr madan for generic distributions
1 parent f815aa5 commit 9ae7bd3

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

examples/carr_madan.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ payoff = VanillaOption(strike, expiry, Hedgehog2.European(), Hedgehog2.Call(), H
1717
# Define carr madan method
1818
boundary = 32
1919
α = 1
20-
method = Hedgehog2.CarrMadanBS(α, boundary)
20+
method = Hedgehog2.CarrMadan(α, boundary; market_inputs=market_inputs)
2121

2222
# Define pricer
2323
carr_madan_pricer = Pricer(payoff, market_inputs, method)

src/pricing_methods/carr_madan.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
using QuadGK, Dates
1+
using QuadGK, Dates, Distributions
22

33
# at the moment, only for black scholes. The dynamics should be use to get more generality.
4-
struct CarrMadanBS <: AbstractPricingMethod
4+
struct CarrMadan <: AbstractPricingMethod
55
α
66
bound
7+
log_distribution
78
end
89

9-
function characteristic_function(t, market_inputs::BlackScholesInputs, method::CarrMadanBS)
10-
r = market_inputs.rate
11-
σ = market_inputs.sigma
12-
return u -> exp(im * (r - σ^2 / 2) * u * t - u^2 * t * σ^2 / 2)
10+
function CarrMadan(α, bound; market_inputs::BlackScholesInputs)
11+
distribution(t) = Normal((market_inputs.rate - market_inputs.sigma^2 / 2) * t, market_inputs.sigma * sqrt(t))
12+
return CarrMadan(α, bound, distribution)
1313
end
1414

15-
function compute_price(payoff::VanillaOption{European, Call, Spot}, market_inputs::BlackScholesInputs, method::CarrMadanBS)
15+
# in distribution.jl t is Real, hence we need to redefine it.
16+
cf(d::Normal, t) = exp(im * t * d.μ - d.σ^2 / 2 * t^2)
17+
18+
function compute_price(payoff::VanillaOption{European, Call, Spot}, market_inputs::BlackScholesInputs, method::CarrMadan)
1619
damp = exp(- method.α * log(payoff.strike)) / 2π
1720
T = Dates.value(payoff.expiry - market_inputs.referenceDate) / 365
18-
ϕ = characteristic_function(T, market_inputs, method)
21+
ϕ(u) = cf(method.log_distribution(T), u)
1922
integrand(v) = call_transform(market_inputs.rate, T, ϕ, v, method) * exp(- im * v * log(payoff.strike))
2023
integral, error = quadgk(integrand, -method.bound, method.bound)
2124
return real(damp * integral)
2225
end
2326

24-
function call_transform(rate, time, ϕ, v, method::CarrMadanBS)
27+
function call_transform(rate, time, ϕ, v, method::CarrMadan)
2528
numerator = exp(- rate * time) * ϕ(v - (method.α + 1)im)
2629
denominator = method.α^2 + method.α - v^2 + v * (2 * method.α + 1)im
2730
return numerator / denominator

0 commit comments

Comments
 (0)