Skip to content

Commit

Permalink
workaround for vector based significance level
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkuperman committed Feb 13, 2022
1 parent faf7bfb commit 8b38e03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 6 additions & 3 deletions examples/mixture_normal_var.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ using MarketRisk
ω = [0.75, 0.25]
μ = [0.0, -0.1]
Σ = [0.2, 0.4]
αs = 0.001
α = 0.001
αs = [0.001, 0.01, 0.1]
h = 10 / 250

m = MixtureModel(Normal, [(h * μ[i], sqrt(h) * Σ[i]) for i in 1:2], ω)

mixture_var = ValueAtRisk(μ, Σ, h, αs, m)
compute(mixture_var)
mixture_var = ValueAtRisk(μ, Σ, h, α, m)
mixture_var1 = ValueAtRisk(μ, Σ, h, αs, m)

compute(mixture_var)
compute(mixture_var1)
16 changes: 15 additions & 1 deletion src/value_at_risk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@ end
function compute(var::ParametricValueAtRisk{V, M, H, A, MixtureModel{B, D, Normal, F}}) where {V, M, H, A, B, D, F}
@unpack μ, Σ, h, α, dist = var

opt(x, α) = cdf(dist, x) - α
D_opt(f) = x -> ForwardDiff.derivative(f, float(x))

@. - find_zero((x -> cdf(dist, x) - α, D_opt(x -> opt_func(x, α))), 0.0, Roots.Newton())
- find_zero((x -> opt(x, α), D_opt(x -> opt(x, α))), 0.0, Roots.Newton())[1]
end

function compute(var::ParametricValueAtRisk{V, M, H, A, MixtureModel{B, D, Normal, F}}) where {V, M, H, A<:Vector{<:Real}, B, D, F}
@unpack μ, Σ, h, α, dist = var

opt(x, α) = cdf(dist, x) - α
D_opt(f) = x -> ForwardDiff.derivative(f, float(x))

v = zeros(eltype(α), length(α))
for i in 1:length(α)
v[i] = - find_zero((x -> opt(x, α[i]), D_opt(x -> opt(x, α[i]))), 0.0, Roots.Newton())[1]
end
v
end

0 comments on commit 8b38e03

Please sign in to comment.