-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions for Vanilla asset option simulation
- asset_variance functions for models and path - VanillaAssetOption payoff - VanillaAssetOptionFlow cash flow
- Loading branch information
1 parent
0f605e9
commit 492df05
Showing
13 changed files
with
413 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
|
||
""" | ||
struct VanillaAssetOption <: Payoff | ||
obs_time::ModelTime | ||
expiry_time::ModelTime | ||
forward_price::ForwardAsset | ||
strike_price::Payoff | ||
call_put::ModelValue | ||
end | ||
The time-t forward price of an option paying [ϕ(F-K)]^+. Forward asset price *F* is determined | ||
at `expiry_time`. | ||
Option forward price is calculated as expectation in T-forward measure where T corresponds | ||
to the expiry time. Conditioning (for time-t price) is on information at `obs_time`. | ||
""" | ||
struct VanillaAssetOption <: Payoff | ||
obs_time::ModelTime | ||
expiry_time::ModelTime | ||
forward_price::ForwardAsset | ||
strike_price::Payoff | ||
call_put::ModelValue | ||
end | ||
|
||
""" | ||
VanillaAssetOption( | ||
forward_price::ForwardAsset, | ||
strike_price::Payoff, | ||
call_put::ModelValue, | ||
) | ||
Create a `VanillaAssetOption` payoff. | ||
""" | ||
function VanillaAssetOption( | ||
forward_price::ForwardAsset, | ||
strike_price::Payoff, | ||
call_put::ModelValue, | ||
) | ||
# | ||
@assert obs_time(strike_price) ≤ forward_price.obs_time # payoff must be time-t measurable | ||
@assert call_put in (+1.0, -1.0) | ||
return VanillaAssetOption( | ||
forward_price.obs_time, | ||
forward_price.maturity_time, | ||
forward_price, | ||
strike_price, | ||
call_put, | ||
) | ||
end | ||
|
||
|
||
""" | ||
obs_time(p::VanillaAssetOption) | ||
Return VanillaAssetOption observation time. | ||
""" | ||
function obs_time(p::VanillaAssetOption) | ||
return p.obs_time | ||
end | ||
|
||
|
||
""" | ||
obs_times(p::VanillaAssetOption) | ||
Return all VanillaAssetOption observation times. | ||
""" | ||
function obs_times(p::VanillaAssetOption) | ||
times = Set(obs_time(p)) | ||
times = union(times, obs_times(p.strike_price)) | ||
return times | ||
end | ||
|
||
|
||
""" | ||
at(p::VanillaAssetOption, path::AbstractPath) | ||
Evaluate a `VanillaAssetOption` at a given `path`, *X(omega)*. | ||
""" | ||
function at(p::VanillaAssetOption, path::AbstractPath) | ||
F = at(p.forward_price, path) | ||
K = at(p.strike_price, path) | ||
ν² = asset_variance(path, p.obs_time, p.expiry_time, p.forward_price.key) | ||
if all(ν² .≤ 0.0) | ||
# calculate intrinsic value | ||
return max.(p.call_put*(F - K), 0.0) | ||
end | ||
V = black_price(K, F, sqrt.(ν²), p.call_put) | ||
return V | ||
end | ||
|
||
|
||
""" | ||
string(p::VanillaAssetOption) | ||
Formatted (and shortened) output for VanillaAssetOption payoff. | ||
""" | ||
string(p::VanillaAssetOption) = begin | ||
type = "" | ||
if p.call_put == 1.0 | ||
type = "Call" | ||
end | ||
if p.call_put == -1.0 | ||
type = "Put" | ||
end | ||
@sprintf("%s(%s, %s)", type, string(p.forward_price), string(p.strike_price)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
""" | ||
struct VanillaAssetOptionFlow <: CashFlow | ||
expiry_time::ModelTime | ||
pay_time::ModelTime | ||
strike_price::ModelValue | ||
call_put::ModelValue | ||
asset_key::String | ||
end | ||
A `CashFlow` representing a Call or Put option on an `Asset`. | ||
""" | ||
struct VanillaAssetOptionFlow <: CashFlow | ||
expiry_time::ModelTime | ||
pay_time::ModelTime | ||
strike_price::ModelValue | ||
call_put::ModelValue | ||
asset_key::String | ||
end | ||
|
||
|
||
""" | ||
amount(cf::VanillaAssetOptionFlow) | ||
Return the payoff of the `VanillaAssetOptionFlow`. | ||
""" | ||
function amount(cf::VanillaAssetOptionFlow) | ||
S = Asset(cf.expiry_time, cf.asset_key) | ||
return Max(cf.call_put*(S - cf.strike_price), 0.0) | ||
end | ||
|
||
|
||
""" | ||
expected_amount(cf::VanillaAssetOptionFlow, obs_time::ModelTime) | ||
Return the payoff representing the simulated expected amount of the `VanillaAssetOptionFlow`. | ||
This implementation is an approximation and does not capture convexity adjustments. | ||
""" | ||
function expected_amount(cf::VanillaAssetOptionFlow, obs_time::ModelTime) | ||
if obs_time ≥ cf.expiry_time | ||
return amount(cf) | ||
end | ||
F = ForwardAsset(obs_time, cf.expiry_time, cf.asset_key) | ||
K = Fixed(cf.strike_price) | ||
return VanillaAssetOption(F, K, cf.call_put) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
using DiffFusion | ||
using Test | ||
using UnicodePlots | ||
|
||
@testset "Test asset option simulation" begin | ||
|
||
if !@isdefined(TestModels) | ||
include("../../test_models.jl") | ||
end | ||
|
||
function plot_scens(scens, title) | ||
plt = lineplot(scens.times, scens.X[1,:,:], | ||
title = title, | ||
name = scens.leg_aliases, | ||
xlabel = "obs_time", | ||
ylabel = "price (EUR)", | ||
width = 80, | ||
height = 30, | ||
) | ||
println() | ||
display(plt) | ||
println() | ||
end | ||
|
||
|
||
@testset "Test VanillaAssetOption simulation" begin | ||
model = TestModels.hybrid_model_full | ||
ch = TestModels.ch_full | ||
times = 0.0:1.0:6.0 | ||
n_paths = 2^13 | ||
sim = DiffFusion.simple_simulation(model, ch, times, n_paths, with_progress_bar = false) | ||
path = DiffFusion.path(sim, TestModels.ts_list, TestModels.context, DiffFusion.LinearPathInterpolation) | ||
# | ||
call_leg = DiffFusion.cashflow_leg( | ||
"leg/C/EUR-USD/5y/1.25", | ||
[ DiffFusion.VanillaAssetOptionFlow(5.0, 5.0, 1.25, +1.0, "EUR-USD"), ], | ||
[ 1.0, ], | ||
"USD" | ||
) | ||
put_leg = DiffFusion.cashflow_leg( | ||
"leg/P/EUR-USD/5y/1.25", | ||
[ DiffFusion.VanillaAssetOptionFlow(5.0, 5.0, 1.25, -1.0, "EUR-USD"), ], | ||
[ 1.0, ], | ||
"USD" | ||
) | ||
scens = DiffFusion.scenarios([call_leg, put_leg], times, path, "") | ||
mv = DiffFusion.aggregate(scens, true, false) | ||
# | ||
plot_scens(mv, "EUR-USD option mv") | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.