Skip to content
13

Expected Risk

PortfolioOptimisers.MatNum_Pr Type
julia
const MatNum_Pr = Union{<:MatNum, <:AbstractPriorResult, <:ReturnsResult}

Union of matrix-like types accepted as the data argument in risk_contribution and related functions.

Related

source
PortfolioOptimisers.RkRatioRM Type
julia
const RkRatioRM = Union{<:RiskRatioRiskMeasure, <:NonOptimisationRiskRatioRiskMeasure}

Union of all risk-ratio risk measures, where the expected risk is defined as the ratio of two component risk values.

Related

source
PortfolioOptimisers.expected_risk Function
julia
expected_risk(r, args...; kwargs...)

Compute the expected value of a risk measure.

Generic function extended by concrete risk measure types. Each method computes the risk value associated with its risk measure type, given a portfolio (or its return distribution).

Related

source
PortfolioOptimisers.expected_risk_from_returns Function
julia
expected_risk_from_returns(r, X; kwargs...)

Compute the expected risk of a measure from a precomputed net-return series.

Generic function extended by concrete risk measure types that support the precomputed-returns contract. Only measures with supports_precomputed_returns(r) == true should implement this method.

Related

source
PortfolioOptimisers.supports_precomputed_returns Method
julia
supports_precomputed_returns(
    r::Union{NonOptimisationRiskRatioRiskMeasure, RiskRatioRiskMeasure}
) -> Any

Return whether RkRatioRM r supports evaluation on a precomputed return series.

Returns true only when both constituent risk measures support precomputed returns.

Related

source
PortfolioOptimisers.supports_precomputed_returns Method
julia
supports_precomputed_returns(r::MeanReturnRiskRatio) -> Any

Return whether MeanReturnRiskRatio r supports evaluation on a precomputed return series.

Returns true only when both the return measure rt and the risk measure rk support precomputed returns.

Related

source
PortfolioOptimisers.expected_risk_from_returns Method
julia
expected_risk_from_returns(r::AbstractBaseRiskMeasure, X::VecNum; kwargs...) -> Number

Contract entry for evaluating a risk measure on an already-reduced net-return series X (ADR 0007). Consults supports_precomputed_returns: for an eligible measure it returns r(X); for an ineligible one it throws an explanatory ArgumentError instead of silently consuming X as weights (a WeightsInput measure) or hitting an opaque MethodError (a moment measure with a per-asset mu).

Internal call sites that hold a precomputed series — cross-validation prediction scoring — route through here rather than calling the functor directly.

Related

source
PortfolioOptimisers.expected_risk_from_returns Method
julia
expected_risk_from_returns(
    r::AbstractBaseRiskMeasure,
    X::AbstractVector{<:AbstractVector{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}}};
    kwargs...
) -> Any

Evaluate a risk measure on each element of a vector of precomputed return series.

Maps expected_risk_from_returns over each Xi in X.

Related

source
PortfolioOptimisers.number_effective_assets Function
julia
number_effective_assets(w::VecNum)

Compute the effective number of assets (Herfindahl-Hirschman inverse index).

Mathematical definition

Neff=1iwi2.

Where:

  • Neff: Effective number of assets.

  • w: Portfolio weights vector N×1.

Returns the number of equally-weighted assets that would produce the same level of concentration as the given weight vector w.

Arguments

  • w::VecNum: Portfolio weight vector.

Returns

  • Number: Effective number of assets.

Related

source
PortfolioOptimisers.risk_contribution Function
julia
risk_contribution(
    r::AbstractBaseRiskMeasure,
    w::VecNum,
    X::MatNum_Pr,
    fees::Option{<:Fees} = nothing;
    delta::Number = 1e-6,
    marginal::Bool = false,
    kwargs...
) -> Vector

Compute the risk contribution of each asset to the total portfolio risk using numerical differentiation.

Mathematical definition

The risk contribution of asset i is defined as:

RCi=wiρ(w)wi.

Where:

  • RCi: Risk contribution of asset i.

  • w: Portfolio weights vector N×1.

  • ρ: Portfolio risk measure.

  • wi: Weight of asset i.

The partial derivative is approximated using a two-sided finite difference with step size delta. When marginal = true, the function omits the weighting by wi (i.e., only the marginal risk ρ/wi is returned).

Arguments

  • r::AbstractBaseRiskMeasure: Risk measure to differentiate.

  • w::VecNum: Portfolio weights vector.

  • X::MatNum_Pr: Asset returns matrix or prior result.

  • fees::Option{<:Fees}: Optional fee structure.

Keyword Arguments

  • delta::Number = 1e-6: Finite difference step size.

  • marginal::Bool = false: If true, returns marginal risk contributions (without wi weighting).

Returns

  • Vector: Risk contributions (or marginal risks) for each asset.

Related

source
PortfolioOptimisers.factor_risk_contribution Function
julia
factor_risk_contribution(
    r::AbstractBaseRiskMeasure,
    w::VecNum,
    X::MatNum_Pr,
    fees::Option{<:Fees} = nothing;
    re::RegE_Reg = StepwiseRegression(),
    rd::ReturnsResult = ReturnsResult(),
    delta::Number = 1e-6,
    kwargs...
) -> Vector

Compute the risk contribution of each factor (and the idiosyncratic component) to the total portfolio risk using a factor regression.

Mathematical definition

The factor risk contributions partition total portfolio risk into factor-specific components using the Brinson attribution framework:

FRCk=(Bw)k(Bρ)k.

Where:

  • FRCk: Risk contribution of factor k.

  • w: Portfolio weights vector N×1.

  • B: Factor loading matrix N×K, estimated by regression.

  • ρ: Gradient of the risk measure with respect to the weights.

Arguments

  • r::AbstractBaseRiskMeasure: Risk measure to decompose.

  • w::VecNum: Portfolio weights vector.

  • X::MatNum_Pr: Asset returns matrix or prior result.

  • fees::Option{<:Fees}: Optional fee structure.

Keyword Arguments

  • re::RegE_Reg = StepwiseRegression(): Regression estimator for factor loadings.

  • rd::ReturnsResult = ReturnsResult(): Returns result providing factor data.

  • delta::Number = 1e-6: Finite difference step size.

Returns

  • Vector: Risk contributions for each factor, with the last element being the idiosyncratic (off-factor) contribution.

Related

source
PortfolioOptimisers.rolling_window_measure Function
julia
rolling_window_measure(
    r::AbstractBaseRiskMeasure,
    w::AbstractVector{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}},
    X::AbstractMatrix{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}},
    fees::Union{Nothing, Fees},
    window::Integer
) -> Any

Compute the expected risk of a risk measure over rolling windows of the returns data.

Arguments

  • r::AbstractBaseRiskMeasure: Risk measure to evaluate.

  • w::VecNum: Portfolio weights vector.

  • X::MatNum: Asset returns matrix.

  • fees::Option{<:Fees}: Optional fee structure.

  • window::Integer: Size of the rolling window (number of periods).

Returns

  • risks::VecNum: Expected risk values for each rolling window.

Related

source