Expected Risk
PortfolioOptimisers.MatNum_Pr Type
const MatNum_Pr = Union{<:MatNum, <:AbstractPriorResult, <:ReturnsResult}Union of matrix-like types accepted as the data argument in risk_contribution and related functions.
Related
sourcePortfolioOptimisers.RkRatioRM Type
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
sourcePortfolioOptimisers.expected_risk Function
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
sourcePortfolioOptimisers.expected_risk_from_returns Function
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
sourcePortfolioOptimisers.supports_precomputed_returns Method
supports_precomputed_returns(
r::Union{NonOptimisationRiskRatioRiskMeasure, RiskRatioRiskMeasure}
) -> AnyReturn whether RkRatioRM r supports evaluation on a precomputed return series.
Returns true only when both constituent risk measures support precomputed returns.
Related
sourcePortfolioOptimisers.supports_precomputed_returns Method
supports_precomputed_returns(r::MeanReturnRiskRatio) -> AnyReturn 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
sourcePortfolioOptimisers.expected_risk_from_returns Method
expected_risk_from_returns(r::AbstractBaseRiskMeasure, X::VecNum; kwargs...) -> NumberContract 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
sourcePortfolioOptimisers.expected_risk_from_returns Method
expected_risk_from_returns(
r::AbstractBaseRiskMeasure,
X::AbstractVector{<:AbstractVector{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}}};
kwargs...
) -> AnyEvaluate a risk measure on each element of a vector of precomputed return series.
Maps expected_risk_from_returns over each Xi in X.
Related
sourcePortfolioOptimisers.number_effective_assets Function
number_effective_assets(w::VecNum)Compute the effective number of assets (Herfindahl-Hirschman inverse index).
Mathematical definition
Where:
: Effective number of assets. : Portfolio weights vector .
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
sourcePortfolioOptimisers.risk_contribution Function
risk_contribution(
r::AbstractBaseRiskMeasure,
w::VecNum,
X::MatNum_Pr,
fees::Option{<:Fees} = nothing;
delta::Number = 1e-6,
marginal::Bool = false,
kwargs...
) -> VectorCompute the risk contribution of each asset to the total portfolio risk using numerical differentiation.
Mathematical definition
The risk contribution of asset
Where:
: Risk contribution of asset . : Portfolio weights vector . : Portfolio risk measure. : Weight of asset .
The partial derivative is approximated using a two-sided finite difference with step size delta. When marginal = true, the function omits the weighting by
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: Iftrue, returns marginal risk contributions (withoutweighting).
Returns
Vector: Risk contributions (or marginal risks) for each asset.
Related
sourcePortfolioOptimisers.factor_risk_contribution Function
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...
) -> VectorCompute 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:
Where:
: Risk contribution of factor . : Portfolio weights vector . : Factor loading matrix , 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
sourcePortfolioOptimisers.rolling_window_measure Function
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
) -> AnyCompute 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