Turnover risk measure
PortfolioOptimisers.TurnoverRiskMeasure — Type
struct TurnoverRiskMeasure{__T_settings, __T_w, __T_fixed} <: RiskMeasureMeasures the turnover of a portfolio, the $L^1$ distance of its weights from a vector of reference weights.
The measure reads no returns. It reads the portfolio weights and the reference weights w, and nothing else. As a risk term it penalises the trades of a rebalance, and with settings.ub it bounds their sum. Turnover bounds the change of each asset, and this measure bounds or penalises the sum of the changes.
The measure is the full sum of the absolute changes, the two-way turnover. A purchase and the sale that pays for it both count. So a move of a weight of 0.25 from one asset to another has a turnover of 0.5. The one-way convention halves this sum, and the measure does not.
fixed sets the source of the reference weights. With fixed = false, factory replaces w with the weights that it receives, so in a sequence of rebalances w holds the weights of the last rebalance. needs_previous_weights then returns true. With fixed = true, w is a fixed target, and factory keeps it. The constructor has no default for w, so a measure always holds reference weights. A factory call that receives no weights keeps them.
In an optimisation the model is exact. The risk that the model reports, divided by the budget variable $k$ of a ratio problem, is equal to the functor at the optimal weights.
Mathematical definition
\[\begin{align} \mathrm{Turnover}(\boldsymbol{w}) &= \lVert \boldsymbol{w} - \boldsymbol{w}_{0} \rVert_1 = \sum_{i=1}^{N} \lvert w_i - w_{0,i} \rvert\,. \end{align}\]
Where:
- $\mathrm{Turnover}(\boldsymbol{w})$: Turnover of the portfolio, the sum over the assets of the absolute change of weight from the reference weights.
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $\boldsymbol{w}_{0}$: Reference portfolio weights vector $N \times 1$, the weights from which the turnover is measured.
- $w_i$: Weight of asset $i$.
- $w_{0,i}$: Reference weight of asset $i$.
- $N$: Number of assets.
Equation 9.10 of [12] bounds the absolute change of each asset, $\lvert \boldsymbol{w} - \boldsymbol{w}_{0} \rvert$. This measure is the sum of that vector.
Fields
settings: Risk measure settings.
w: Reference portfolio weights vector.
fixed: Iftrue,factorykeeps the reference weightswand ignores the new weights. Iffalse,factoryreplaceswwith the new weights.
Constructors
TurnoverRiskMeasure(; settings::RiskMeasureSettings = RiskMeasureSettings(), w::VecNum, fixed::Bool = false) -> TurnoverRiskMeasureKeywords correspond to the struct's fields.
Validation
w, throughassert_nonempty_finite_val:!isempty(w)andall(isfinite, w). Every entry must be finite, so the constructor refuses[0.5, NaN].
Functor
(r::TurnoverRiskMeasure)(w::VecNum)Computes the turnover of the portfolio weights w from the reference weights r.w.
Arguments
w::VecNum: Portfolio weights vector. It has the length ofr.w. A vector of a different length raises aDimensionMismatch.
The measure holds no Fees, so fee amortisation cannot reach it. Each fold evaluates it against the reference weights that factory gives.
View parameters
port_opt_view takes the view of these @vprop fields at the selected indices:
w: Sliced to the selected indices throughport_opt_view.
Examples
julia> TurnoverRiskMeasure(; w = [0.5, 0.5])TurnoverRiskMeasure settings ┼ RiskMeasureSettings │ scale ┼ Float64: 1.0 │ ub ┼ nothing │ rke ┴ Bool: true w ┼ Vector{Float64}: [0.5, 0.5] fixed ┴ Bool: falsejulia> TurnoverRiskMeasure(; w = [0.5, 0.25, 0.25])([0.25, 0.5, 0.25])0.5Related
References
- [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 9.1, Equation 9.10. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
PortfolioOptimisers.port_opt_view — Method
port_opt_view(x, i, args...; kwargs...) -> nothing_scalar_array_view(x, i)Select the assets i of an estimator, a result or an algorithm.
port_opt_view is the index-selection counterpart of factory. factory passes runtime values down a tree of composed structs, and port_opt_view passes an index selection down the same tree. It restricts every field that holds data, and every composed child, to the subset i. The meta-optimisers, such as NestedClustered and SubsetResampling, and the cross-validation variants use it to solve sub-problems with structs of the same shape.
A caller does not usually call port_opt_view. The meta-optimisers and the cross-validation internals call it. It is public and not exported, because the author of a new composed estimator can need to define a method. Tag each field that holds data with @vprop, and @propagatable makes the method.
This universal fallback handles leaf values. It views an array through nothing_scalar_array_view. It returns a scalar, nothing, an estimator with no data fields and an algorithm with no change. A composed struct that recurses into its children has its own, more specific method, which @propagatable makes from the @vprop tags or which the author writes by hand.
This method accepts and drops the threaded tail args... and all kwargs. The tail is usually the returns matrix X of the JuMP families. With this method, a call port_opt_view(child, i, X) that a macro makes never raises a MethodError on a leaf field.
Algorithm
- Drop
args...andkwargs.... This method is the leaf of the recursion, so it passes nothing further. - Return
nothing_scalar_array_viewofxati. The algorithm of that function gives the rule for each leaf type.
Related
PortfolioOptimisers.factory — Method
factory(
r::TurnoverRiskMeasure,
w::AbstractVector{<:Union{Number, AbstractJuMPScalar}}
) -> TurnoverRiskMeasure
Return a TurnoverRiskMeasure whose reference weights are w.
When r.fixed is true, the function returns r and does not read w. Otherwise it rebuilds r with w as the reference weights, with rebuild_struct, and r.settings and r.fixed pass through unchanged.
Validation
- When
r.fixedisfalse, the constructor checkswthroughassert_nonempty_finite_val:!isempty(w)andall(isfinite, w).
Related
PortfolioOptimisers.factory — Method
factory(
r::TurnoverRiskMeasure,
,
,
,
w::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
args...;
kwargs...
) -> TurnoverRiskMeasure
Return the TurnoverRiskMeasure whose reference weights are w, as factory(r, w) does.
The measure reads no moment, so the prior result, the solver and the uncertainty set in the second to fourth positions are not read. When w is nothing, the method on ::Nothing returns r unchanged. The method on a vector holds the rule of factory(r, w), and the two give one measure.
Related
PortfolioOptimisers.needs_previous_weights — Method
needs_previous_weights(r::TurnoverRiskMeasure) -> Any
Return true when TurnoverRiskMeasure r reads the previous portfolio weights.
The measure reads them when r.fixed is false, because factory then replaces the reference weights with the weights that it receives. When r.fixed is true, the reference weights are a fixed target, and the function returns false.
Related
References
- [12]
- D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).