Skip to content

Commit

Permalink
updated var structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkuperman committed Sep 4, 2021
1 parent 9769653 commit 39c25c7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
26 changes: 10 additions & 16 deletions examples/value_at_risk.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
using MarketRisk

μ = 0.0462 * 1 / 250
Σ = sqrt(0.1757 ^ 2 * 1 / 250)
μ = 0.0462
Σ = sqrt(0.1757 ^ 2)

h = 1 / 250
αs = [0.1, 0.01, 0.001]

ν = 4.14

N = Normal()
T = TDist(ν)

normal_var = ValueAtRisk(μ, Σ, N)
student_var = ValueAtRisk(μ, Σ, T)

h = 1.
αs = [0.1, 0.01, 0.001]

nvars = Float64[]
svars = Float64[]
normal_var = ValueAtRisk(μ, Σ, h, αs, N)
student_var = ValueAtRisk(μ, Σ, h, αs, T)

for α in αs
push!(nvars, compute(normal_var, h, α))
push!(svars, compute(student_var, h, α))
end
compute(normal_var)
compute(student_var)


nvars
svars
27 changes: 14 additions & 13 deletions src/value_at_risk.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
struct ParametricValueAtRisk{V, M, D<:Distribution} <: MarketRiskMeasure
struct ParametricValueAtRisk{V, M, H, A, D<:Distribution} <: MarketRiskMeasure
μ::V
Σ::M
h::H
α::A
dist::D
end

function ValueAtRisk(μ, Σ, dist)
return ParametricValueAtRisk(μ, Σ, dist)
function ValueAtRisk(μ, Σ, h, α, dist)
return ParametricValueAtRisk(μ, Σ, h, α, dist)
end

# function ValueAtRisk(portfolio, dist)
# return ParametricValueAtRisk
# end

function ValueAtRisk(portfolio, dist)
return ParametricValueAtRisk
end

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

sqrt(h) * quantile(dist, 1 - alpha) * Σ - h * μ
@. sqrt(h) * quantile(dist, 1 - α) * Σ - h * μ
end

function compute(var::ParametricValueAtRisk{V, M, D}, h, alpha) where {V, M, D<:TDist}
@unpack μ, Σ, dist = var
function compute(var::ParametricValueAtRisk{V, M, H, A, D}) where {V, M, H, A, D<:TDist}
@unpack μ, Σ, h, α, dist = var
@unpack ν = dist

sqrt((ν - 2) / ν) * sqrt(h) * quantile(dist, 1 - alpha) * Σ - h * μ
@. sqrt((ν - 2) / ν) * sqrt(h) * quantile(dist, 1 - α) * Σ - h * μ
end


Expand Down

0 comments on commit 39c25c7

Please sign in to comment.