Moment Risk Measures
PortfolioOptimisers.FirstLowerMoment — Type
struct FirstLowerMoment <: LowOrderMomentMeasureAlgorithmMeasures the mean shortfall of the net portfolio returns below the Moment Target.
It is the lower partial moment of order one. Equation 7.45 of [12] states the lower partial moment, and it names [191] as the source. No copy of that work was found. A number in mu is a minimum acceptable return, and mu = nothing gives the mean shortfall below the mean, the semi-deviation of order one.
Mathematical definition
\[\begin{align} R(\boldsymbol{w}) &= \mathbb{E}\left[\max(\tau - \hat{r}_t,\, 0)\right] = -\mathbb{E}\left[d_t^{-}\right]\,. \end{align}\]
Where:
- $R(\boldsymbol{w})$: Portfolio risk.
- $\mathbb{E}[z] = \sum_{t=1}^{T} w_t z_t / \sum_{t=1}^{T} w_t$: Observation mean of a series $z_t$, with $w_t = 1$ for every $t$ when the measure holds no observation weights.
- $\hat{r}_t$: Net portfolio return at observation $t$, $\boldsymbol{x}_t^\intercal \boldsymbol{w}$ less the fees charged at $t$.
- $\tau$: Moment Target, the value from which the measure measures the deviations. It is $\mathbb{E}[\hat{\boldsymbol{r}}]$ when
muisnothing, $\boldsymbol{\mu}^\intercal \boldsymbol{w} - \bar{F}(\boldsymbol{w})$ whenmuis a vector $\boldsymbol{\mu}$, $\boldsymbol{v}^\intercal \boldsymbol{w} + s - \bar{F}(\boldsymbol{w})$ whenmuis aVecScalarwith fields $\boldsymbol{v}$ and $s$, andmuitself when it is a number. - $d_t^{-} = \min(d_t, 0)$: Lower part of the moment deviation of observation $t$.
Related
LowOrderMomentMeasureAlgorithmMeanAbsoluteDeviation: the two-sided deviation from the same target.LowOrderMoment
References
- [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 7.2.2.2, Equation 7.45 with $q = 1$. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
- [191] P. C. Fishburn. Mean-risk analysis with risk associated with below-target returns. The American Economic Review 67, 116–126 (1977).
PortfolioOptimisers.MeanAbsoluteDeviation — Type
struct MeanAbsoluteDeviation <: LowOrderMomentMeasureAlgorithmMeasures the mean absolute deviation of the net portfolio returns from the Moment Target.
Equation 7.31 of [12] states it with the mean as the target, and it names [192] as the source. No copy of that work was found. The library adds the other targets of the mu slot.
Mathematical definition
\[\begin{align} R(\boldsymbol{w}) &= \mathbb{E}\left[\left\lvert d_t \right\rvert\right] = 2\, \mathbb{E}\left[\max(\tau - \hat{r}_t,\, 0)\right] + \mathbb{E}\left[\hat{r}_t\right] - \tau\,. \end{align}\]
Where:
- $R(\boldsymbol{w})$: Portfolio risk.
- $\mathbb{E}[z] = \sum_{t=1}^{T} w_t z_t / \sum_{t=1}^{T} w_t$: Observation mean of a series $z_t$, with $w_t = 1$ for every $t$ when the measure holds no observation weights.
- $d_t = \hat{r}_t - \tau$: Moment deviation of observation $t$.
- $\hat{r}_t$: Net portfolio return at observation $t$, $\boldsymbol{x}_t^\intercal \boldsymbol{w}$ less the fees charged at $t$.
- $\tau$: Moment Target, the value from which the measure measures the deviations. It is $\mathbb{E}[\hat{\boldsymbol{r}}]$ when
muisnothing, $\boldsymbol{\mu}^\intercal \boldsymbol{w} - \bar{F}(\boldsymbol{w})$ whenmuis a vector $\boldsymbol{\mu}$, $\boldsymbol{v}^\intercal \boldsymbol{w} + s - \bar{F}(\boldsymbol{w})$ whenmuis aVecScalarwith fields $\boldsymbol{v}$ and $s$, andmuitself when it is a number.
The second form follows from $\lvert d \rvert = 2 \max(-d, 0) + d$. When $\tau$ is the observation mean of the net returns, the last two terms cancel, and the measure is twice the FirstLowerMoment of the same data. Against any other target, the measure differs from twice the first lower moment by $\mathbb{E}[\hat{r}_t] - \tau$.
Related
LowOrderMomentMeasureAlgorithmFirstLowerMoment: the one-sided deviation from the same target.LowOrderMomentMedianAbsoluteDeviation: a different risk measure, which centres at the median.
References
- [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 7.2.1.3, Equation 7.31. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
- [192] H. Konno and H. Yamazaki. Mean-absolute deviation portfolio optimization model and its applications to Tokyo stock market. Management Science 37, 519–531 (1991).
PortfolioOptimisers.SecondMoment — Type
struct SecondMoment{__T_ve, __T_alg1, __T_alg2} <: LowOrderMomentMeasureAlgorithmMeasures the second moment of the net portfolio returns about the Moment Target, or its square root.
alg1 selects the deviations. FullMoment reads all of them, and SemiMoment reads the deviations below the target alone. alg2 selects the units. SOCRiskExpr reports the square root, a standard deviation, and the three other formulations report the second moment itself.
With mu = nothing the measure is the variance or the semi-variance of the net portfolio returns. Against a stated target it is the second moment about that target, not a variance. ve reads the deviations at a mean of zero. So it supplies only its divisor and its observation weights, and its me has no effect. Page 81 of [32] states the variance. Pages 188 and 189 of [193] state the semi-variance about a target $b$ and about the mean $E$, with the divisor $T$.
Mathematical definition
\[\begin{align} R(\boldsymbol{w}) &= f \sum_{t=1}^{T} w_t\, d_t^{2}\,, \\ R(\boldsymbol{w}) &= f \sum_{t=1}^{T} w_t \left(d_t^{-}\right)^{2}\,. \end{align}\]
The first line is the full moment and the second line is the semi moment. SOCRiskExpr reports $\sqrt{R(\boldsymbol{w})}$.
Where:
- $R(\boldsymbol{w})$: Portfolio risk.
- $f$: Variance divisor of the estimator
ve,StatsBase.varcorrectionof $T$, or of the observation weights when the measure holds them, atve.corrected. With no observation weights it is $1/(T-1)$ whenve.correctedistrueand $1/T$ otherwise. - $w_{t}$: Observation weight of observation $t$. It is $1$ for every $t$ when the measure holds no observation weights.
- $d_t = \hat{r}_t - \tau$: Moment deviation of observation $t$.
- $d_t^{-} = \min(d_t, 0)$: Lower part of the moment deviation of observation $t$.
- $T$: Number of observations.
The default ve sets corrected = true, so the default divisor is $1/(T-1)$. Set ve = SimpleVariance(; me = nothing, corrected = false) for the divisor $1/T$ of [193].
Fields
ve: Variance estimator.
alg1: First algorithm variant.
alg2: Second algorithm variant.
Constructors
SecondMoment(; ve::AbstractVarianceEstimator = SimpleVariance(; me = nothing), alg1::AbstractMomentAlgorithm = FullMoment(), alg2::SecondMomentFormulation = SquaredSOCRiskExpr(),) -> SecondMomentKeywords correspond to the struct's fields.
Propagated parameters
factory passes its arguments on to these @fprop fields:
ve: Recursively updated throughfactory.
Examples
julia> SecondMoment()SecondMoment ve ┼ SimpleVariance │ me ┼ nothing │ w ┼ nothing │ corrected ┴ Bool: true alg1 ┼ FullMoment() alg2 ┴ SquaredSOCRiskExpr()Related
LowOrderMomentMeasureAlgorithmAbstractVarianceEstimatorAbstractMomentAlgorithmSecondMomentFormulation: each formulation states the cone or the quadratic form that the model builds on the deviations.factory
References
PortfolioOptimisers.EvenMoment — Type
struct EvenMoment{__T_p, __T_ddof, __T_alg} <: LowOrderMomentMeasureAlgorithmMeasures the $p$-th root of the even moment of order $2p$ of the net portfolio returns about the Moment Target.
The order is $2p$, and p is an integer of at least $2$, so the order is always even and at least $4$. An odd order cannot be stated. alg selects all the deviations, FullMoment, or the deviations below the target alone, SemiMoment. The $p$-th root is homogeneous of degree two in the weights, the degree of a variance. Equations 3 and 4 of [194] state the full and the lower moment about the mean, with the divisor $T$, and Formulations 5 and 8 state their power cone programmes. The divisor $T_d$, the observation weights and the other targets are the library's own.
Mathematical definition
\[\begin{align} R(\boldsymbol{w}) &= \left(\frac{1}{T_d} \sum_{t=1}^{T} w_t\, d_t^{2p}\right)^{1/p}\,, \\ R(\boldsymbol{w}) &= \left(\frac{1}{T_d} \sum_{t=1}^{T} w_t \left(d_t^{-}\right)^{2p}\right)^{1/p}\,, \\ T_d &= \frac{T - \mathrm{ddof}}{T} \sum_{t=1}^{T} w_t\,. \end{align}\]
The first line is the full moment and the second line is the semi moment.
Where:
- $R(\boldsymbol{w})$: Portfolio risk.
- $p$: Order parameter
p. The moment order is $2p$. - $T_d$: Effective sample size. It is $T - \mathrm{ddof}$ when the measure holds no observation weights.
- $\mathrm{ddof}$: Degrees of freedom
ddofthat the divisor subtracts. - $w_{t}$: Observation weight of observation $t$. It is $1$ for every $t$ when the measure holds no observation weights.
- $d_t = \hat{r}_t - \tau$: Moment deviation of observation $t$.
- $d_t^{-} = \min(d_t, 0)$: Lower part of the moment deviation of observation $t$.
- $T$: Number of observations.
$T_d$ is zero at $\mathrm{ddof} = T$, and the value is then Inf. A larger ddof makes $T_d$ negative, and the root raises a DomainError.
Fields
p: Power or order parameter.
ddof: Degrees-of-freedom correction, an integer that the library subtracts from the number of observations itself.
alg: Moment algorithm.
Constructors
EvenMoment(; p::Integer = 2, ddof::Integer = 0, alg::AbstractMomentAlgorithm = FullMoment(),) -> EvenMomentKeywords correspond to the struct's fields.
Validation
p >= 2, else aDomainError.ddof >= 0, else aDomainError.
Examples
julia> EvenMoment()EvenMoment p ┼ Int64: 2 ddof ┼ Int64: 0 alg ┴ FullMoment()Related
LowOrderMomentMeasureAlgorithmLowOrderMomentFullMomentSemiMomentFourthMoment: the fourth moment itself, with no root, on a hierarchical measure.
References
- [194] D. Cajas. Portfolio Optimization of Even Moments using Power Cone Programming. Available at SSRN 6518258 (2026). Equations 3 and 4, Formulations 5 and 8.
PortfolioOptimisers.LowOrderMoment — Type
struct LowOrderMoment{__T_settings, __T_w, __T_mu, __T_alg} <: RiskMeasureMeasures a low-order moment of the deviations of the net portfolio returns from the Moment Target.
alg selects the moment: FirstLowerMoment, the default, MeanAbsoluteDeviation, SecondMoment or EvenMoment. Each states its closed form. mu selects the target, and the target alone. A stated target shifts every deviation by one constant, and alg reduces the shifted deviations with the same formula. The measure is an optimisation risk measure, and set_risk_constraints! builds its model. Pages 188 and 189 of [193] measure a downside deviation from a target $b$ or from the mean $E$.
Mathematical definition
\[\begin{align} d_t &= \hat{r}_t - \tau\,,\quad t = 1, \ldots, T\,, \\ R(\boldsymbol{w}) &= \rho\left(d_1, \ldots, d_T\right)\,. \end{align}\]
Where:
- $d_t = \hat{r}_t - \tau$: Moment deviation of observation $t$.
- $\hat{r}_t$: Net portfolio return at observation $t$, $\boldsymbol{x}_t^\intercal \boldsymbol{w}$ less the fees charged at $t$.
- $\tau$: Moment Target, the value from which the measure measures the deviations. It is $\mathbb{E}[\hat{\boldsymbol{r}}]$ when
muisnothing, $\boldsymbol{\mu}^\intercal \boldsymbol{w} - \bar{F}(\boldsymbol{w})$ whenmuis a vector $\boldsymbol{\mu}$, $\boldsymbol{v}^\intercal \boldsymbol{w} + s - \bar{F}(\boldsymbol{w})$ whenmuis aVecScalarwith fields $\boldsymbol{v}$ and $s$, andmuitself when it is a number. - $\bar{F}(\boldsymbol{w})$: Mean fee per period of the portfolio, zero when
feesisnothing. Seemoment_target_fees. - $\mathbb{E}[z] = \sum_{t=1}^{T} w_t z_t / \sum_{t=1}^{T} w_t$: Observation mean of a series $z_t$, with $w_t = 1$ for every $t$ when the measure holds no observation weights.
- $T$: Number of observations.
- $R(\boldsymbol{w})$: Portfolio risk.
- $\rho$: The reduction that
algstates.
A number in mu is a threshold on the net series, so it takes no fee. A per-asset target is net of the mean fee per period, so a fee that every period pays in full cancels from every deviation.
Fields
settings: Risk measure settings.
w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.
mu: Optional centre the moment is taken about, a scalar or a vectorassets × 1. Also admits a Deferred Quantity — an expected returns estimator or a prior estimator that computes the centre against the optimisation's own prior, atfactorytime (seeMuSlotandresolve_deferred_quantities). Ifnothing, the prior supplies it.
alg: Moment algorithm.
Constructors
LowOrderMoment(; settings::RiskMeasureSettings = RiskMeasureSettings(), w::Option{<:ObsWeights} = nothing, mu::Option{<:MuSlot} = nothing, alg::LowOrderMomentMeasureAlgorithm = FirstLowerMoment(),) -> LowOrderMomentKeywords correspond to the struct's fields. The keyword constructor passes a w that is not nothing to alg with factory, so a variance estimator inside alg reads the same weights as the measure.
Validation
- If
muis a number,isfinite(mu), else anIsNonFiniteError. - If
muis a vector,!isempty(mu), else anIsEmptyError, andall(isfinite, mu), else anIsNonFiniteError. - If
wis aStatsBase.AbstractWeights, it is not empty, each entry is finite and>= 0, andsum(w) > 0, throughassert_observation_weights. ADynamicAbstractWeightsholds no weights until it reads the data, sochecked_observation_weightschecks it at evaluation, and also checks there that the weights have one entry for each observation.
A stated mu is fixed. It crosses a Cross-Validation fold or a subset view as the answer for the whole universe, so it does not follow the refit that the optimisation runs on. To make the target follow the fit, name a Deferred Quantity in mu, or leave the slot nothing and let the prior supply it.
Functor
(r::LowOrderMoment)(w::VecNum, X::MatNum, fees::Option{<:Fees} = nothing)(r::LowOrderMoment)(x::VecNum)Computes the risk of the portfolio w on the returns X net of fees, or the risk of the net portfolio returns x. A DynamicAbstractWeights in w first resolves against the data with resolve_observation_weights. calc_deviations_vec then gives the deviations from the Moment Target, and moment_risk reduces them. The second form reads x as a net series and charges no fee. It needs a target that does not read the asset weights, which supports_precomputed_returns reports. A mu that is nothing reads the observation mean of the series. So a measure that factory did not build against a prior measures the deviations from the mean of the data, not from the expected returns of a prior.
Arguments
w::VecNum: Asset weights.X::MatNum: Returns matrixobservations × assets.fees::Option{<:Fees}: Fees that the net returns pay, ornothing.x::VecNum: Net portfolio returnsobservations × 1.
Examples
julia> LowOrderMoment()LowOrderMoment settings ┼ RiskMeasureSettings │ scale ┼ Float64: 1.0 │ ub ┼ nothing │ rke ┴ Bool: true w ┼ nothing mu ┼ nothing alg ┴ FirstLowerMoment()julia> x = [0.02, -0.01, 0.03, -0.04, 0.01];julia> LowOrderMoment(; alg = FirstLowerMoment())(x)0.0108julia> LowOrderMoment(; alg = MeanAbsoluteDeviation())(x)0.0216julia> LowOrderMoment(; mu = 0.0, alg = MeanAbsoluteDeviation())(x)0.022The mean of x is 0.002. Against the mean, the mean absolute deviation is twice the first lower moment. Against the target 0.0, it is 0.0216 + 0.002 - 0.0.
Related
RiskMeasureSettingsLowOrderMomentMeasureAlgorithmFirstLowerMomentMeanAbsoluteDeviationSecondMomentEvenMomentcalc_moment_target: selects the Moment Target frommu.moment_riskset_risk_constraints!: builds the model of eachalg.HighOrderMoment: the hierarchical measure of the moments of order three and four.
References
- [193] H. M. Markowitz. Portfolio Selection: Efficient Diversification of Investments (John Wiley & Sons, New York, 1959). Chapter IX, pages 188 and 189.
PortfolioOptimisers.ThirdLowerMoment — Type
struct ThirdLowerMoment <: HighOrderMomentMeasureAlgorithmMeasures the negated third moment of the deviations below the Moment Target.
The cube of a deviation below the target is negative, so the measure negates the mean, and a larger value is more downside asymmetry. It is the lower partial moment of order three. Equation 7.45 of [12] states the lower partial moment, and it names [191] as the source. No copy of that work was found.
Mathematical definition
\[\begin{align} R(\boldsymbol{w}) &= -\mathbb{E}\left[\left(d_t^{-}\right)^{3}\right] = \mathbb{E}\left[\max(\tau - \hat{r}_t,\, 0)^{3}\right]\,. \end{align}\]
Where:
- $R(\boldsymbol{w})$: Portfolio risk.
- $\mathbb{E}[z] = \sum_{t=1}^{T} w_t z_t / \sum_{t=1}^{T} w_t$: Observation mean of a series $z_t$, with $w_t = 1$ for every $t$ when the measure holds no observation weights.
- $d_t^{-} = \min(d_t, 0)$: Lower part of the moment deviation of observation $t$.
- $\hat{r}_t$: Net portfolio return at observation $t$, $\boldsymbol{x}_t^\intercal \boldsymbol{w}$ less the fees charged at $t$.
- $\tau$: Moment Target, the value from which the measure measures the deviations. It is $\mathbb{E}[\hat{\boldsymbol{r}}]$ when
muisnothing, $\boldsymbol{\mu}^\intercal \boldsymbol{w} - \bar{F}(\boldsymbol{w})$ whenmuis a vector $\boldsymbol{\mu}$, $\boldsymbol{v}^\intercal \boldsymbol{w} + s - \bar{F}(\boldsymbol{w})$ whenmuis aVecScalarwith fields $\boldsymbol{v}$ and $s$, andmuitself when it is a number.
Related
HighOrderMomentMeasureAlgorithmHighOrderMoment: a variance estimator in itsvedivides the measure by the cube of the lower standard deviation.
References
- [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 7.2.2.2, Equation 7.45 with $q = 3$. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
- [191] P. C. Fishburn. Mean-risk analysis with risk associated with below-target returns. The American Economic Review 67, 116–126 (1977).
PortfolioOptimisers.FourthMoment — Type
struct FourthMoment{__T_alg} <: HighOrderMomentMeasureAlgorithmMeasures the fourth moment of the net portfolio returns about the Moment Target.
alg selects all the deviations, FullMoment, or the deviations below the target alone, SemiMoment. The value has no root and no division by a variance, so it is in the units of a return to the fourth power. The semi moment is the lower partial moment of order four. Equation 7.45 of [12] states the lower partial moment, and it names [191] as the source. No copy of that work was found.
Mathematical definition
\[\begin{align} R(\boldsymbol{w}) &= \mathbb{E}\left[d_t^{4}\right]\,, \\ R(\boldsymbol{w}) &= \mathbb{E}\left[\left(d_t^{-}\right)^{4}\right]\,. \end{align}\]
The first line is the full moment and the second line is the semi moment.
Where:
- $R(\boldsymbol{w})$: Portfolio risk.
- $\mathbb{E}[z] = \sum_{t=1}^{T} w_t z_t / \sum_{t=1}^{T} w_t$: Observation mean of a series $z_t$, with $w_t = 1$ for every $t$ when the measure holds no observation weights.
- $d_t = \hat{r}_t - \tau$: Moment deviation of observation $t$.
- $d_t^{-} = \min(d_t, 0)$: Lower part of the moment deviation of observation $t$.
Fields
alg: Moment algorithm.
Constructors
FourthMoment(; alg::AbstractMomentAlgorithm = FullMoment(),) -> FourthMomentKeywords correspond to the struct's fields.
Examples
julia> FourthMoment()FourthMoment alg ┴ FullMoment()Related
HighOrderMomentMeasureAlgorithmHighOrderMoment: a variance estimator in itsvedivides the measure by the square of the second moment of the same deviations.AbstractMomentAlgorithmEvenMoment: atp = 2andddof = 0, the square root of the same moment, on a measure that the optimiser can model.Kurtosis: the same moment read from a cokurtosis matrix.
References
- [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 7.2.2.2, Equation 7.45 with $q = 4$. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
- [191] P. C. Fishburn. Mean-risk analysis with risk associated with below-target returns. The American Economic Review 67, 116–126 (1977).
PortfolioOptimisers.HighOrderMoment — Type
struct HighOrderMoment{__T_settings, __T_w, __T_mu, __T_alg, __T_ve} <: HierarchicalRiskMeasureMeasures a moment of order three or four of the deviations of the net portfolio returns from the Moment Target, or that moment divided by a power of the second moment.
alg selects the moment of order $n$: ThirdLowerMoment, the default, or FourthMoment. Each states its closed form. mu selects the target, as it does for LowOrderMoment. When ve is nothing, the measure reports the moment as it is. When ve is a variance estimator, the measure divides the moment by the power $n/2$ of the second moment of the same deviations, so the value has no units. The measure is a hierarchical risk measure. The hierarchical optimisers and the value level read it, and the library builds no JuMP model for it.
A larger value is always more risk. The odd moment is the negated mean of negative cubes, and the even moments are non-negative. The second moment is positive, so the standardised value has the sign of the moment.
Mathematical definition
\[\begin{align} d_t &= \hat{r}_t - \tau\,,\quad t = 1, \ldots, T\,, \\ R_{n}(\boldsymbol{w}) &= \rho\left(d_1, \ldots, d_T\right)\,, \\ R(\boldsymbol{w}) &= \frac{R_{n}(\boldsymbol{w})}{\left(\sigma^{2}\right)^{n/2}}\,, \\ \sigma^{2} &= f \sum_{t=1}^{T} w_t\, \delta_t^{2}\,. \end{align}\]
When ve is nothing, the measure reports $R_{n}(\boldsymbol{w})$. The third and the fourth lines apply when ve is a variance estimator.
Where:
- $d_t = \hat{r}_t - \tau$: Moment deviation of observation $t$.
- $\hat{r}_t$: Net portfolio return at observation $t$, $\boldsymbol{x}_t^\intercal \boldsymbol{w}$ less the fees charged at $t$.
- $\tau$: Moment Target, the value from which the measure measures the deviations. It is $\mathbb{E}[\hat{\boldsymbol{r}}]$ when
muisnothing, $\boldsymbol{\mu}^\intercal \boldsymbol{w} - \bar{F}(\boldsymbol{w})$ whenmuis a vector $\boldsymbol{\mu}$, $\boldsymbol{v}^\intercal \boldsymbol{w} + s - \bar{F}(\boldsymbol{w})$ whenmuis aVecScalarwith fields $\boldsymbol{v}$ and $s$, andmuitself when it is a number. - $\bar{F}(\boldsymbol{w})$: Mean fee per period of the portfolio, zero when
feesisnothing. Seemoment_target_fees. - $\mathbb{E}[z] = \sum_{t=1}^{T} w_t z_t / \sum_{t=1}^{T} w_t$: Observation mean of a series $z_t$, with $w_t = 1$ for every $t$ when the measure holds no observation weights.
- $T$: Number of observations.
- $R(\boldsymbol{w})$: Portfolio risk.
- $R_{n}(\boldsymbol{w})$: The value of
alg, the moment of order $n$. - $\rho$: The reduction that
algstates. - $n$: Order of the moment, $3$ or $4$.
- $\sigma^{2}$: Second moment of the deviations that
algreads. - $\delta_t$: The deviation that
algreads, $d_t^{-}$ for a lower moment and $d_t$ for a full moment. - $f$: Variance divisor of the estimator
ve,StatsBase.varcorrectionof $T$, or of the observation weights when the measure holds them, atve.corrected. With no observation weights it is $1/(T-1)$ whenve.correctedistrueand $1/T$ otherwise. - $w_{t}$: Observation weight of observation $t$. It is $1$ for every $t$ when the measure holds no observation weights.
- $d_t^{-} = \min(d_t, 0)$: Lower part of the moment deviation of observation $t$.
The numerator is an observation mean, and the denominator takes the divisor of ve. SimpleVariance sets corrected = true by default, so its denominator divides by $T - 1$ and the numerator by $T$. Set ve = SimpleVariance(; me = nothing, corrected = false) for the ratio of two observation means.
Fields
settings: Risk measure settings.
w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.
mu: Optional centre the moment is taken about, a scalar or a vectorassets × 1. Also admits a Deferred Quantity — an expected returns estimator or a prior estimator that computes the centre against the optimisation's own prior, atfactorytime (seeMuSlotandresolve_deferred_quantities). Ifnothing, the prior supplies it.
alg: Moment algorithm.
ve: Variance estimator of the second moment that divides the moment, ornothingfor the moment as it is. The estimator reads the same deviations asalg: the deviations below the Moment Target for a lower moment,ThirdLowerMomentor aFourthMomentof aSemiMoment, and all the deviations for a full moment. It reads them about zero, so its ownmedoes not enter.
Constructors
HighOrderMoment(; settings::RiskMeasureSettings = RiskMeasureSettings(), w::Option{<:ObsWeights} = nothing, mu::Option{<:MuSlot} = nothing, alg::HighOrderMomentMeasureAlgorithm = ThirdLowerMoment(), ve::Option{<:AbstractVarianceEstimator} = nothing,) -> HighOrderMomentKeywords correspond to the struct's fields. A w that is not nothing is passed to ve with factory, so the variance estimator reads the same weights as the measure.
Validation
- If
muis a number,isfinite(mu), else anIsNonFiniteError. - If
muis a vector,!isempty(mu), else anIsEmptyError, andall(isfinite, mu), else anIsNonFiniteError. - If
wis aStatsBase.AbstractWeights, it is not empty, each entry is finite and>= 0, andsum(w) > 0, throughassert_observation_weights. ADynamicAbstractWeightsholds no weights until it reads the data, sochecked_observation_weightschecks it at evaluation, and also checks there that the weights have one entry for each observation.
A stated mu is fixed. It crosses a Cross-Validation fold or a subset view as the answer for the whole universe, so it does not follow the refit that the optimisation runs on. To make the target follow the fit, name a Deferred Quantity in mu, or leave the slot nothing and let the prior supply it.
Functor
(r::HighOrderMoment)(w::VecNum, X::MatNum, fees::Option{<:Fees} = nothing)(r::HighOrderMoment)(x::VecNum)Computes the risk of the portfolio w on the returns X net of fees, or the risk of the net portfolio returns x, as the functor of LowOrderMoment does. A DynamicAbstractWeights in w first resolves against the data with resolve_observation_weights. calc_deviations_vec then gives the deviations from the Moment Target, and moment_risk reduces them. The second form needs a target that does not read the asset weights, which supports_precomputed_returns reports.
Arguments
w::VecNum: Asset weights.X::MatNum: Returns matrixobservations × assets.fees::Option{<:Fees}: Fees that the net returns pay, ornothing.x::VecNum: Net portfolio returnsobservations × 1.
Examples
julia> HighOrderMoment()HighOrderMoment settings ┼ RiskMeasureSettings │ scale ┼ Float64: 1.0 │ ub ┼ nothing │ rke ┴ Bool: true w ┼ nothing mu ┼ nothing alg ┼ ThirdLowerMoment() ve ┴ nothingjulia> x = [0.02, -0.01, 0.03, -0.04, 0.01];julia> HighOrderMoment(; ve = SimpleVariance(; me = nothing))(x)1.4555036361053537julia> HighOrderMoment(; ve = SimpleVariance(; me = nothing, corrected = false))(x)2.034128169893555The two values differ in the divisor of the lower second moment alone, $T - 1$ under corrected = true, the default of SimpleVariance, and $T$ with corrected = false.
Related
RiskMeasureSettingsHighOrderMomentMeasureAlgorithmThirdLowerMomentFourthMomentAbstractVarianceEstimatorThirdCentralMoment: the same choice for the full third moment, through itsve.calc_moment_target: selects the Moment Target frommu.moment_riskLowOrderMoment: the optimisation measure of the moments of order one and two.
PortfolioOptimisers.factory — Method
factory(
r::LowOrderMoment,
pr::AbstractPriorResult,
args...;
kwargs...
) -> LowOrderMoment{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, <:LowOrderMomentMeasureAlgorithm} where {__T_scale, __T_ub, __T_rke, _A, _B}
Create a LowOrderMoment whose observation weights and mu come from the measure, or from the prior result pr where the measure states none.
A measure whose mu is nothing takes pr.mu, so after this method its Moment Target is the expected portfolio return of the prior, net of the mean fee per period. Before it, the target is the mean of the data that the functor reads. The two agree when pr.mu is the observation mean of pr.X under the same weights.
Algorithm
- Resolve a Deferred Quantity in
muwithresolve_deferred_quantities, givingr. - Select
w, the weights ofror elsepr.w, withnothing_scalar_array_selector. - Select
mu, the target ofror elsepr.mu, withnothing_scalar_array_selector. - Pass
wtor.algwithfactory, givingalg. - Build a new
LowOrderMomentfromr.settings,w,muandalg.
Related
PortfolioOptimisers.port_opt_view — Method
port_opt_view(
r::LowOrderMoment,
i,
args...
) -> LowOrderMoment{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, <:LowOrderMomentMeasureAlgorithm} where {__T_scale, __T_ub, __T_rke, _A, _B}
Return a LowOrderMoment restricted to the assets i.
The method slices a per-asset mu to the assets i with nothing_scalar_array_view. A number and nothing pass through unchanged, and so does a Deferred Quantity, which resolves on the subset. w weighs observations, not assets, so it passes through unchanged, and so do settings and alg.
Related
PortfolioOptimisers.factory — Method
factory(
r::HighOrderMoment,
pr::AbstractPriorResult,
args...;
kwargs...
) -> HighOrderMoment{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, <:HighOrderMomentMeasureAlgorithm} where {__T_scale, __T_ub, __T_rke, _A, _B}
Create a HighOrderMoment whose observation weights and mu come from the measure, or from the prior result pr where the measure states none.
A measure whose mu is nothing takes pr.mu, so after this method its Moment Target is the expected portfolio return of the prior, net of the mean fee per period.
Algorithm
- Resolve a Deferred Quantity in
muwithresolve_deferred_quantities, givingr. - Select
w, the weights ofror elsepr.w, withnothing_scalar_array_selector. - Select
mu, the target ofror elsepr.mu, withnothing_scalar_array_selector. - Rebuild
rwithwandmu, withrebuild_struct. It calls the keyword constructor, which passeswtovewithfactory.r.settings,r.algandr.vedo not change.
Related
PortfolioOptimisers.port_opt_view — Method
port_opt_view(
r::HighOrderMoment,
i,
args...
) -> HighOrderMoment{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, _A, _B, <:HighOrderMomentMeasureAlgorithm} where {__T_scale, __T_ub, __T_rke, _A, _B}
Return a HighOrderMoment restricted to the assets i.
The method slices a per-asset mu to the assets i with nothing_scalar_array_view. A number and nothing pass through unchanged, and so does a Deferred Quantity, which resolves on the subset. w weighs observations, not assets, so it passes through unchanged, and so do settings, alg and ve.
Related
PortfolioOptimisers.supports_precomputed_returns — Method
supports_precomputed_returns(
r::Union{LowOrderMoment{T1, T2, T3, T4}, HighOrderMoment{T1, T2, T3, T4}} where {T1, T2, T3, T4}
) -> Any
Return whether the functor r(x) of a LoHiOrderMoment can evaluate the net portfolio returns x alone.
The answer is weight_independent_target of r.mu. It is true when mu is nothing or a number, because such a target does not read the asset weights. It is false for a vector, a VecScalar and an unresolved Deferred Quantity.
Related
PortfolioOptimisers.obs_weights_view — Method
obs_weights_view(r::LowOrderMoment, i) -> LowOrderMoment
obs_weights_view(r::HighOrderMoment, i) -> HighOrderMomentReturn the measure with its observation weights, and the weights of its children, cut to the observations i.
The two measures are not @propagatable, so they need these methods of obs_weights_view. A cut of the observations of a fit, such as the drop of a Shared Series gap, then cuts the weights of the measure too, see shared_series_estimator.
Algorithm
- Index
r.wwithobs_weights_index. - Cut
r.algwithobs_weights_view, andr.vefor aHighOrderMoment. - Rebuild the measure with
rebuild_struct, which calls its keyword constructor.settingsandmukeep their values.
Arguments
r: The risk measure.i: The observations to keep: a mask of the full sample, or their positions.
Validation
- The rules of
obs_weights_index.
Returns
r: The measure at the kept observations.
Related
References
- [12]
- D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
- [32]
- H. Markowitz. Portfolio Selection. The Journal of Finance 7, 77–91 (1952).
- [191]
- P. C. Fishburn. Mean-risk analysis with risk associated with below-target returns. The American Economic Review 67, 116–126 (1977).
- [192]
- H. Konno and H. Yamazaki. Mean-absolute deviation portfolio optimization model and its applications to Tokyo stock market. Management Science 37, 519–531 (1991).
- [193]
- H. M. Markowitz. Portfolio Selection: Efficient Diversification of Investments. No. 16 of Cowles Foundation Monograph (John Wiley & Sons, New York, 1959).
- [194]
- D. Cajas. Portfolio Optimization of Even Moments using Power Cone Programming. Available at SSRN 6518258 (2026).