-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAssetVolatility.jl
76 lines (70 loc) · 2.14 KB
/
AssetVolatility.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
asset_variance(
ast_model::LognormalAssetModel,
dom_model::Union{GaussianHjmModel, Nothing},
for_model::Union{GaussianHjmModel, Nothing},
ch::CorrelationHolder,
s::ModelTime,
t::ModelTime,
X::Union{ModelState, Nothing} = nothing,
)
Calculate lognormal variance in hybrid asset model.
The method is defined for a `LognormalAssetModel`. It should also work
for other asset models. But then we need to calculate a vector and this
requires more testing.
"""
function asset_variance(
ast_model::Union{LognormalAssetModel, Nothing},
dom_model::Union{GaussianHjmModel, Nothing},
for_model::Union{GaussianHjmModel, Nothing},
ch::CorrelationHolder,
s::ModelTime,
t::ModelTime,
X::Union{ModelState, Nothing} = nothing,
)
models_ = Model[ ]
e = ones(0)
if !isnothing(ast_model)
models_ = Model[ ast_model ]
e = ones(1)
end
if !isnothing(dom_model)
models_ = vcat(models_, dom_model)
n = length(state_alias(dom_model))
e = vcat(e, zeros(n-1), ones(1))
end
if !isnothing(for_model)
models_ = vcat(models_, for_model)
n = length(state_alias(for_model))
e = vcat(e, zeros(n-1), -1.0*ones(1))
end
model = simple_model("", models_)
cov = covariance(model, ch, s, t, X)
@assert(size(cov) == (length(e), length(e)))
ν² = e' * cov * e
return ν²
end
"""
model_implied_volatilties(
ast_model::LognormalAssetModel,
dom_model::Union{GaussianHjmModel, Nothing},
for_model::Union{GaussianHjmModel, Nothing},
ch::CorrelationHolder,
option_times::AbstractVector,
)
Calculate model-implied volatilities in hybrid asset model.
"""
function model_implied_volatilties(
ast_model::LognormalAssetModel,
dom_model::Union{GaussianHjmModel, Nothing},
for_model::Union{GaussianHjmModel, Nothing},
ch::CorrelationHolder,
option_times::AbstractVector,
)
#
ν² = [
asset_variance(ast_model, dom_model, for_model, ch, 0.0, T)
for T in option_times
]
return sqrt.( ν² ./ option_times )
end