Skip to content
13

X at Risk

PortfolioOptimisers.ValueatRiskFormulation Type
julia
abstract type ValueatRiskFormulation <: AbstractAlgorithm

Abstract supertype for all Value-at-Risk formulation algorithms in PortfolioOptimisers.jl.

All concrete and/or abstract types representing the formulation for computing Value-at-Risk (e.g., mixed-integer programming, distribution-based) should be subtypes of ValueatRiskFormulation.

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    alg::ValueatRiskFormulation,
    args...;
    kwargs...
) -> DistributionValueatRisk{_A, _B, _C, <:Distributions.Distribution{F, S}} where {_A, _B, _C, F<:Distributions.VariateForm, S<:Distributions.ValueSupport}

Return the Value-at-Risk formulation alg unchanged.

Identity pass-through for formulation types that do not depend on prior results.

Related

source
PortfolioOptimisers.port_opt_view Method
julia
port_opt_view(r, args...)

Get a view or subset of a Value-at-Risk formulation for slicing.

Returns the formulation unchanged (for non-distribution types) or sliced (for distribution-based types). Used internally in hierarchical optimisation.

Arguments

  • r: Value-at-Risk formulation.

  • args...: Additional arguments (index, etc.).

Returns

  • Sliced or unchanged formulation.

Related

source
PortfolioOptimisers.port_opt_view Method
julia
port_opt_view(x, i, args...; kwargs...) -> nothing_scalar_array_view(x, i)

Universal fallback for port_opt_view. Any value that has no more specific port_opt_view method is treated as leaf data: it is delegated to nothing_scalar_array_view, which slices arrays/VecScalars and passes scalars, nothing, estimators, and algorithms through unchanged. Composed structs that need to recurse into children define their own (more specific) method — emitted by the @vprop tag or hand-written.

The threaded tail args... (typically the returns matrix X for the JuMP families) and any kwargs are accepted and dropped here, so a macro-threaded port_opt_view(child, i, X) never MethodErrors on a leaf field.

Related

source
julia
port_opt_view(r, args...)

Get a view or subset of a Value-at-Risk formulation for slicing.

Returns the formulation unchanged (for non-distribution types) or sliced (for distribution-based types). Used internally in hierarchical optimisation.

Arguments

  • r: Value-at-Risk formulation.

  • args...: Additional arguments (index, etc.).

Returns

  • Sliced or unchanged formulation.

Related

source
PortfolioOptimisers.MIPValueatRisk Type
julia
struct MIPValueatRisk{__T_b, __T_s} <: ValueatRiskFormulation

Mixed-integer programming (MIP) formulation for Value-at-Risk.

MIPValueatRisk specifies bounds used in the binary variable formulation of Value-at-Risk within a JuMP optimisation model.

Fields

  • b: Big-M upper bound for MIP formulations.

  • s: Small-M lower bound for MIP formulations.

Constructors

julia
MIPValueatRisk(;
    b::Option{<:Number} = nothing,
    s::Option{<:Number} = nothing
) -> MIPValueatRisk

Keywords correspond to the struct's fields.

Validation

  • If b is not nothing: b > 0.

  • If s is not nothing: s > 0.

  • If both are not nothing: b > s.

Examples

julia
julia> MIPValueatRisk()
MIPValueatRisk
  b ┼ nothing
  s ┴ nothing

Related

source
PortfolioOptimisers.DistributionValueatRisk Type
julia
struct DistributionValueatRisk{__T_mu, __T_sigma, __T_chol, __T_dist} <: ValueatRiskFormulation

Distribution-based formulation for Value-at-Risk.

DistributionValueatRisk specifies a parametric distribution for computing Value-at-Risk analytically. The distribution parameters can be overridden by prior results during optimisation.

Fields

  • mu: Optional mean for centering.

  • sigma: Covariance matrix features × features.

  • chol: Cholesky factorisation of the covariance matrix.

  • dist: Probability distribution.

Constructors

julia
DistributionValueatRisk(;
    mu::Option{<:VecNum} = nothing,
    sigma::Option{<:MatNum} = nothing,
    chol::Option{<:MatNum} = nothing,
    dist::Distributions.Distribution = Distributions.Normal()
) -> DistributionValueatRisk

Keywords correspond to the struct's fields.

Validation

  • If mu is not nothing: !isempty(mu).

  • If sigma is not nothing: !isempty(sigma) and size(sigma, 1) == size(sigma, 2).

  • If chol is not nothing: !isempty(chol).

Examples

julia
julia> DistributionValueatRisk()
DistributionValueatRisk
     mu ┼ nothing
  sigma ┼ nothing
   chol ┼ nothing
   dist ┴ Distributions.Normal{Float64}: Distributions.Normal{Float64}=0.0, σ=1.0)

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    alg::DistributionValueatRisk,
    pr::AbstractPriorResult,
    args...;
    kwargs...
) -> DistributionValueatRisk{_A, _B, _C, <:Distributions.Distribution{F, S}} where {_A, _B, _C, F<:Distributions.VariateForm, S<:Distributions.ValueSupport}

Create an instance of DistributionValueatRisk by selecting distribution parameters from the formulation or falling back to the prior result.

Related

source
PortfolioOptimisers.ValueatRisk Type
julia
struct ValueatRisk{__T_settings, __T_alpha, __T_w, __T_alg} <: RiskMeasure

Represents the Value-at-Risk (VaR) risk measure.

ValueatRisk quantifies the maximum expected loss at a given confidence level alpha over a specified time horizon. It can be computed using empirical quantiles (weighted or unweighted) or via a parametric distribution.

Mathematical definition

Let x=(x1,,xT) be the portfolio returns vector and x(k) the k-th order statistic (k-th smallest value). The empirical VaR at significance level α is:

VaRα(x)=x(αT).

Where:

  • VaRα(x): Value-at-Risk at significance level α.

  • x=(x1,,xT): Portfolio returns vector.

  • x(k): k-th order statistic (k-th smallest value) of x.

  • α: Significance level (e.g., α=0.05 for 95% VaR).

  • T: Number of observations.

For observation-weighted samples with weight vector w summing to Sw, VaR is the αSw-quantile of the weighted empirical distribution.

Fields

  • settings: Risk measure settings.

  • alpha: Quantile level for the lower tail.

  • w: Optional observation weights vector observations × 1, or a concrete subtype of DynamicAbstractWeights. If nothing, the computation is unweighted.

  • alg: Risk measure optimisation formulation algorithm.

Constructors

julia
ValueatRisk(;
    settings::RiskMeasureSettings = RiskMeasureSettings(),
    alpha::Number = 0.05,
    w::Option{<:ObsWeights} = nothing,
    alg::ValueatRiskFormulation = MIPValueatRisk()
) -> ValueatRisk

Keywords correspond to the struct's fields.

Validation

  • 0 < alpha < 1.

  • If w is not nothing: !isempty(w).

Functor

julia
(r::ValueatRisk)(x::VecNum)

Computes the Value-at-Risk of a portfolio returns vector x.

Arguments

  • x::VecNum: Portfolio returns vector.

Examples

julia
julia> ValueatRisk()
ValueatRisk
  settings ┼ RiskMeasureSettings
           │   scale ┼ Float64: 1.0
           │      ub ┼ nothing
           │     rke ┴ Bool: true
     alpha ┼ Float64: 0.05
         w ┼ nothing
       alg ┼ MIPValueatRisk
           │   b ┼ nothing
           │   s ┴ nothing

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    r::ValueatRisk,
    pr::AbstractPriorResult,
    args...;
    kwargs...
) -> ValueatRisk{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, var"#s179", _A, <:ValueatRiskFormulation} where {__T_scale, __T_ub, __T_rke, var"#s179"<:Number, _A}

Create an instance of ValueatRisk by selecting observation weights and formulation from the risk-measure instance or falling back to the prior result.

Related

source
PortfolioOptimisers.ValueatRiskRange Type
julia
struct ValueatRiskRange{__T_settings, __T_alpha, __T_beta, __T_w, __T_alg} <: RiskMeasure

Represents the Value-at-Risk Range risk measure.

ValueatRiskRange computes the difference between the lower-tail Value-at-Risk (at level alpha) and the upper-tail Value-at-Risk (at level beta), measuring the spread between downside and upside tail risks.

Mathematical definition

VaRRangeα,β(x)=VaRα(x)VaRβ(x),.

Where:

  • VaRRangeα,β(x): Value-at-Risk Range.

  • VaRα(x): Lower-tail loss quantile.

  • VaRβ(x): Upper-tail gain quantile.

  • x: Portfolio returns vector.

  • α: Lower-tail significance level.

  • β: Upper-tail significance level.

Fields

  • settings: Risk measure settings.

  • alpha: Quantile level for the lower tail.

  • beta: Quantile level for the upper tail.

  • w: Optional observation weights vector observations × 1, or a concrete subtype of DynamicAbstractWeights. If nothing, the computation is unweighted.

  • alg: Risk measure optimisation formulation algorithm.

Constructors

julia
ValueatRiskRange(;
    settings::RiskMeasureSettings = RiskMeasureSettings(),
    alpha::Number = 0.05,
    beta::Number = 0.05,
    w::Option{<:ObsWeights} = nothing,
    alg::ValueatRiskFormulation = MIPValueatRisk()
) -> ValueatRiskRange

Keywords correspond to the struct's fields.

Validation

  • 0 < alpha < 1.

  • 0 < beta < 1.

  • If w is not nothing: !isempty(w).

Functor

julia
(r::ValueatRiskRange)(x::VecNum)

Computes the VaR Range of a portfolio returns vector x.

Arguments

  • x::VecNum: Portfolio returns vector.

Examples

julia
julia> ValueatRiskRange()
ValueatRiskRange
  settings ┼ RiskMeasureSettings
           │   scale ┼ Float64: 1.0
           │      ub ┼ nothing
           │     rke ┴ Bool: true
     alpha ┼ Float64: 0.05
      beta ┼ Float64: 0.05
         w ┼ nothing
       alg ┼ MIPValueatRisk
           │   b ┼ nothing
           │   s ┴ nothing

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    r::ValueatRiskRange,
    pr::AbstractPriorResult,
    args...;
    kwargs...
) -> ValueatRiskRange{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, var"#s179", var"#s1791", _A, <:ValueatRiskFormulation} where {__T_scale, __T_ub, __T_rke, var"#s179"<:Number, var"#s1791"<:Number, _A}

Create an instance of ValueatRiskRange by selecting observation weights and formulation from the risk-measure instance or falling back to the prior result.

Related

source
PortfolioOptimisers.DrawdownatRisk Type
julia
struct DrawdownatRisk{__T_settings, __T_alpha, __T_w, __T_b, __T_s} <: RiskMeasure

Represents the Drawdown-at-Risk (DaR) risk measure.

DrawdownatRisk quantifies the maximum drawdown not exceeded at a given confidence level alpha. It operates on absolute drawdowns computed from the portfolio returns series.

Mathematical definition

Define the cumulative wealth process and absolute drawdown at time t:

ct=s=1txs,dt=ctmax0stcs0.

Where:

  • x: Portfolio returns vector T×1.

  • ct: Cumulative simple portfolio return at period t.

  • dt0: Absolute drawdown at period t.

The Drawdown-at-Risk at level α is the αT-th smallest (most extreme) drawdown:

DaRα(x)=d(αT).

Where:

  • DaRα(x): Drawdown-at-Risk at level α.

  • α: Significance level (left tail probability), α(0,1).

  • T: Number of observations.

  • dt0: Absolute drawdown at period t.

  • d(k): k-th order statistic (sorted ascending) of the drawdown series.

Fields

  • settings: Risk measure settings.

  • alpha: Quantile level for the lower tail.

  • w: Optional observation weights vector observations × 1, or a concrete subtype of DynamicAbstractWeights. If nothing, the computation is unweighted.

  • b: Big-M upper bound for MIP formulations.

  • s: Small-M lower bound for MIP formulations.

Constructors

julia
DrawdownatRisk(;
    settings::RiskMeasureSettings = RiskMeasureSettings(),
    alpha::Number = 0.05,
    w::Option{<:ObsWeights} = nothing,
    b::Option{<:Number} = nothing,
    s::Option{<:Number} = nothing
) -> DrawdownatRisk

Keywords correspond to the struct's fields.

Validation

  • 0 < alpha < 1.

  • If w is not nothing: !isempty(w).

  • If b is not nothing: b > 0.

  • If s is not nothing: s > 0.

  • If both b and s are not nothing: b > s.

Functor

julia
(r::DrawdownatRisk)(x::VecNum)

Computes the Drawdown-at-Risk of a portfolio returns vector x.

Arguments

  • x::VecNum: Portfolio returns vector.

Examples

julia
julia> DrawdownatRisk()
DrawdownatRisk
  settings ┼ RiskMeasureSettings
           │   scale ┼ Float64: 1.0
           │      ub ┼ nothing
           │     rke ┴ Bool: true
     alpha ┼ Float64: 0.05
         w ┼ nothing
         b ┼ nothing
         s ┴ nothing

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    r::DrawdownatRisk,
    pr::AbstractPriorResult,
    args...;
    kwargs...
) -> DrawdownatRisk

Create an instance of DrawdownatRisk by selecting observation weights from the risk-measure instance or falling back to the prior result.

Related

source
PortfolioOptimisers.RelativeDrawdownatRisk Type
julia
struct RelativeDrawdownatRisk{__T_settings, __T_alpha, __T_w} <: HierarchicalRiskMeasure

Represents the Relative Drawdown-at-Risk risk measure for hierarchical optimisation.

RelativeDrawdownatRisk quantifies the maximum relative (compounded) drawdown not exceeded at a given confidence level alpha. It operates on relative drawdowns computed from the portfolio returns series.

Mathematical definition

Define the compounded wealth process and relative drawdown at time t:

Ct=s=1t(1+xs),rdt=Ctmax0stCs10.

Where:

  • x: Portfolio returns vector T×1.

  • Ct: Compound wealth process at period t.

  • rdt0: Relative drawdown at period t.

The Relative Drawdown-at-Risk at level α is:

RDaRα(x)=rd(αT).

Where:

  • RDaRα(x): Relative Drawdown-at-Risk at level α.

  • α: Significance level (left tail probability), α(0,1).

  • T: Number of observations.

  • rdt0: Relative drawdown at period t.

  • rd(k): k-th order statistic (sorted ascending) of the relative drawdown series.

Fields

  • settings: Risk measure settings.

  • alpha: Quantile level for the lower tail.

  • w: Optional observation weights vector observations × 1, or a concrete subtype of DynamicAbstractWeights. If nothing, the computation is unweighted.

Constructors

julia
    settings::HierarchicalRiskMeasureSettings = HierarchicalRiskMeasureSettings(),
    alpha::Number = 0.05,
    w::Option{<:ObsWeights} = nothing
) -> RelativeDrawdownatRisk

Keywords correspond to the struct's fields.

Validation

  • 0 < alpha < 1.

  • If w is not nothing: !isempty(w).

Functor

julia
(r::RelativeDrawdownatRisk)(x::VecNum)

Computes the Relative Drawdown-at-Risk of a portfolio returns vector x.

Arguments

  • x::VecNum: Portfolio returns vector.

Examples

julia
julia> RelativeDrawdownatRisk()
RelativeDrawdownatRisk
  settings ┼ HierarchicalRiskMeasureSettings
           │   scale ┴ Float64: 1.0
     alpha ┼ Float64: 0.05
         w ┴ nothing

Related

source
PortfolioOptimisers.factory Method
julia
factory(
    r::RelativeDrawdownatRisk,
    pr::AbstractPriorResult,
    args...;
    kwargs...
) -> RelativeDrawdownatRisk{HierarchicalRiskMeasureSettings{__T_scale}, <:Number} where __T_scale

Create an instance of RelativeDrawdownatRisk by selecting observation weights from the risk-measure instance or falling back to the prior result.

Related

source
PortfolioOptimisers.CholRM Type
julia
const CholRM = Union{<:Variance, <:StandardDeviation, <:DistributionValueatRisk}

Union of risk measures that support Cholesky-factor-based computation.

Related

source
PortfolioOptimisers.absolute_drawdown_vec Function
julia
absolute_drawdown_vec(x::VecNum) -> Vector

Compute the absolute drawdown series for a single-asset return vector.

Each element of the result is the difference between the current cumulative return and its running maximum (always ≤ 0).

Arguments

  • x::VecNum: Return series vector (modified in place temporarily, then restored).

Returns

  • Vector: Drawdown vector of the same length as x.

Related

source
PortfolioOptimisers.relative_drawdown_vec Method
julia
relative_drawdown_vec(x)

Compute the relative drawdown vector for a vector of portfolio returns.

Returns the relative drawdown at each time step, computed as the current portfolio value relative to its running maximum.

Arguments

  • x: Vector of portfolio returns.

Returns

  • Relative drawdown vector.

Related

source