X at Risk
PortfolioOptimisers.ValueatRiskFormulation Type
abstract type ValueatRiskFormulation <: AbstractAlgorithmAbstract 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
sourcePortfolioOptimisers.factory Method
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
sourcePortfolioOptimisers.port_opt_view Method
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
sourcePortfolioOptimisers.port_opt_view Method
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
sourceport_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
sourcePortfolioOptimisers.MIPValueatRisk Type
struct MIPValueatRisk{__T_b, __T_s} <: ValueatRiskFormulationMixed-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
MIPValueatRisk(;
b::Option{<:Number} = nothing,
s::Option{<:Number} = nothing
) -> MIPValueatRiskKeywords correspond to the struct's fields.
Validation
If
bis notnothing:b > 0.If
sis notnothing:s > 0.If both are not
nothing:b > s.
Examples
julia> MIPValueatRisk()
MIPValueatRisk
b ┼ nothing
s ┴ nothingRelated
sourcePortfolioOptimisers.DistributionValueatRisk Type
struct DistributionValueatRisk{__T_mu, __T_sigma, __T_chol, __T_dist} <: ValueatRiskFormulationDistribution-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 matrixfeatures × features.chol: Cholesky factorisation of the covariance matrix.dist: Probability distribution.
Constructors
DistributionValueatRisk(;
mu::Option{<:VecNum} = nothing,
sigma::Option{<:MatNum} = nothing,
chol::Option{<:MatNum} = nothing,
dist::Distributions.Distribution = Distributions.Normal()
) -> DistributionValueatRiskKeywords correspond to the struct's fields.
Validation
If
muis notnothing:!isempty(mu).If
sigmais notnothing:!isempty(sigma)andsize(sigma, 1) == size(sigma, 2).If
cholis notnothing:!isempty(chol).
Examples
julia> DistributionValueatRisk()
DistributionValueatRisk
mu ┼ nothing
sigma ┼ nothing
chol ┼ nothing
dist ┴ Distributions.Normal{Float64}: Distributions.Normal{Float64}(μ=0.0, σ=1.0)Related
sourcePortfolioOptimisers.factory Method
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
sourcePortfolioOptimisers.ValueatRisk Type
struct ValueatRisk{__T_settings, __T_alpha, __T_w, __T_alg} <: RiskMeasureRepresents 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
Where:
: Value-at-Risk at significance level . : Portfolio returns vector. : -th order statistic ( -th smallest value) of . : Significance level (e.g., for 95% VaR). : Number of observations.
For observation-weighted samples with weight vector
Fields
settings: Risk measure settings.alpha: Quantile level for the lower tail.w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.alg: Risk measure optimisation formulation algorithm.
Constructors
ValueatRisk(;
settings::RiskMeasureSettings = RiskMeasureSettings(),
alpha::Number = 0.05,
w::Option{<:ObsWeights} = nothing,
alg::ValueatRiskFormulation = MIPValueatRisk()
) -> ValueatRiskKeywords correspond to the struct's fields.
Validation
0 < alpha < 1.If
wis notnothing:!isempty(w).
Functor
(r::ValueatRisk)(x::VecNum)Computes the Value-at-Risk of a portfolio returns vector x.
Arguments
x::VecNum: Portfolio returns vector.
Examples
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 ┴ nothingRelated
PortfolioOptimisers.factory Method
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
sourcePortfolioOptimisers.ValueatRiskRange Type
struct ValueatRiskRange{__T_settings, __T_alpha, __T_beta, __T_w, __T_alg} <: RiskMeasureRepresents 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
Where:
: Value-at-Risk Range. : Lower-tail loss quantile. : Upper-tail gain quantile. : 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 vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.alg: Risk measure optimisation formulation algorithm.
Constructors
ValueatRiskRange(;
settings::RiskMeasureSettings = RiskMeasureSettings(),
alpha::Number = 0.05,
beta::Number = 0.05,
w::Option{<:ObsWeights} = nothing,
alg::ValueatRiskFormulation = MIPValueatRisk()
) -> ValueatRiskRangeKeywords correspond to the struct's fields.
Validation
0 < alpha < 1.0 < beta < 1.If
wis notnothing:!isempty(w).
Functor
(r::ValueatRiskRange)(x::VecNum)Computes the VaR Range of a portfolio returns vector x.
Arguments
x::VecNum: Portfolio returns vector.
Examples
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 ┴ nothingRelated
sourcePortfolioOptimisers.factory Method
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
sourcePortfolioOptimisers.DrawdownatRisk Type
struct DrawdownatRisk{__T_settings, __T_alpha, __T_w, __T_b, __T_s} <: RiskMeasureRepresents 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
Where:
: Portfolio returns vector . : Cumulative simple portfolio return at period . : Absolute drawdown at period .
The Drawdown-at-Risk at level
Where:
: Drawdown-at-Risk at level . : Significance level (left tail probability), . : Number of observations. : Absolute drawdown at period . : -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 vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.b: Big-M upper bound for MIP formulations.s: Small-M lower bound for MIP formulations.
Constructors
DrawdownatRisk(;
settings::RiskMeasureSettings = RiskMeasureSettings(),
alpha::Number = 0.05,
w::Option{<:ObsWeights} = nothing,
b::Option{<:Number} = nothing,
s::Option{<:Number} = nothing
) -> DrawdownatRiskKeywords correspond to the struct's fields.
Validation
0 < alpha < 1.If
wis notnothing:!isempty(w).If
bis notnothing:b > 0.If
sis notnothing:s > 0.If both
bandsare notnothing:b > s.
Functor
(r::DrawdownatRisk)(x::VecNum)Computes the Drawdown-at-Risk of a portfolio returns vector x.
Arguments
x::VecNum: Portfolio returns vector.
Examples
julia> DrawdownatRisk()
DrawdownatRisk
settings ┼ RiskMeasureSettings
│ scale ┼ Float64: 1.0
│ ub ┼ nothing
│ rke ┴ Bool: true
alpha ┼ Float64: 0.05
w ┼ nothing
b ┼ nothing
s ┴ nothingRelated
sourcePortfolioOptimisers.factory Method
factory(
r::DrawdownatRisk,
pr::AbstractPriorResult,
args...;
kwargs...
) -> DrawdownatRiskCreate an instance of DrawdownatRisk by selecting observation weights from the risk-measure instance or falling back to the prior result.
Related
sourcePortfolioOptimisers.RelativeDrawdownatRisk Type
struct RelativeDrawdownatRisk{__T_settings, __T_alpha, __T_w} <: HierarchicalRiskMeasureRepresents 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
Where:
: Portfolio returns vector . : Compound wealth process at period . : Relative drawdown at period .
The Relative Drawdown-at-Risk at level
Where:
: Relative Drawdown-at-Risk at level . : Significance level (left tail probability), . : Number of observations. : Relative drawdown at period . : -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 vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.
Constructors
settings::HierarchicalRiskMeasureSettings = HierarchicalRiskMeasureSettings(),
alpha::Number = 0.05,
w::Option{<:ObsWeights} = nothing
) -> RelativeDrawdownatRiskKeywords correspond to the struct's fields.
Validation
0 < alpha < 1.If
wis notnothing:!isempty(w).
Functor
(r::RelativeDrawdownatRisk)(x::VecNum)Computes the Relative Drawdown-at-Risk of a portfolio returns vector x.
Arguments
x::VecNum: Portfolio returns vector.
Examples
julia> RelativeDrawdownatRisk()
RelativeDrawdownatRisk
settings ┼ HierarchicalRiskMeasureSettings
│ scale ┴ Float64: 1.0
alpha ┼ Float64: 0.05
w ┴ nothingRelated
PortfolioOptimisers.factory Method
factory(
r::RelativeDrawdownatRisk,
pr::AbstractPriorResult,
args...;
kwargs...
) -> RelativeDrawdownatRisk{HierarchicalRiskMeasureSettings{__T_scale}, <:Number} where __T_scaleCreate an instance of RelativeDrawdownatRisk by selecting observation weights from the risk-measure instance or falling back to the prior result.
Related
sourcePortfolioOptimisers.CholRM Type
const CholRM = Union{<:Variance, <:StandardDeviation, <:DistributionValueatRisk}Union of risk measures that support Cholesky-factor-based computation.
Related
sourcePortfolioOptimisers.absolute_drawdown_vec Function
absolute_drawdown_vec(x::VecNum) -> VectorCompute 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 asx.
Related
sourcePortfolioOptimisers.relative_drawdown_vec Method
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