Tracking risk measure

PortfolioOptimisers.RiskTrackingError — Type
struct RiskTrackingError{__T_tr, __T_r, __T_err, __T_alg} <: AbstractTracking

Bounds how far the risk of a portfolio can move from the risk of a benchmark portfolio.

RiskTrackingRiskMeasure measures the same quantity in the same two modes, and this type bounds it. Put it in the tr slot of a JuMPOptimiser. The distance is a difference of risks, not a norm of the difference of the return series, and that is how it differs from TrackingError.

In an optimisation the independent bound is exact, and the dependent bound holds from above only. The model states the portfolio risk through an upper bound that the solver can raise. So a portfolio whose risk is below the benchmark risk by more than err also satisfies the dependent bound. This is true of every measure whose model is an upper bound, among them ConditionalValueatRisk, StandardDeviation and a Variance in the semidefinite form. A Variance outside the semidefinite form does not solve in the dependent mode.

The model charges the fee of the portfolio on the returns that the tracked measure reads, in both modes, and it never reads tr.fees. The functor of RiskTrackingRiskMeasure charges the same fee, so it reads back the value that the model bounds. In the independent mode the tracked series is $\mathbf{X}(\boldsymbol{w} - \boldsymbol{w}_b) - F(\boldsymbol{w})$, the net return of the portfolio minus the gross return of the benchmark.

Warning

The default err = 0.0 bounds the tracked quantity at zero. In the independent mode with a positive-definite measure, the bound pins the portfolio weights to the benchmark weights. Give an err unless you want that result.

Mathematical definition

The alg field selects which of two quantities err bounds. The independent mode, IndependentVariableTracking, bounds the risk of the weight difference. The dependent mode, DependentVariableTracking, bounds the absolute difference of the two risks.

\[\begin{align} \rho(\boldsymbol{w} - \boldsymbol{w}_b) &\leq \varepsilon\,, \\ \lvert \rho(\boldsymbol{w}) - \rho(\boldsymbol{w}_b) \rvert &\leq \varepsilon\,. \end{align}\]

Where:

  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $\boldsymbol{w}_b$: Benchmark portfolio weights vector $N \times 1$, the w of the tracking specification tr.
  • $\rho$: Tracked risk measure, the r field. Its value at a weight vector is the risk of that vector as expected_risk reports it.
  • $\varepsilon$: Tolerance, the err field.

Page 15 of [187] states the independent mode for the variance, $(\boldsymbol{w} - \boldsymbol{w}_b)^\intercal \mathbf{\Sigma} (\boldsymbol{w} - \boldsymbol{w}_b)$, and Equation 9.18 of [12] states its square root, the case of a StandardDeviation. The independent mode under any other measure, and the dependent mode, are the library's own.

Fields

  • tr: Benchmark tracking specification.
  • r: Risk measure instance.
  • err: Tracking error tolerance.
  • alg: Tracking formulation algorithm.

Constructors

RiskTrackingError(;    tr::WeightsTracking,    r::AbstractBaseRiskMeasure = StandardDeviation(),    err::Number = 0.0,    alg::VariableTracking = IndependentVariableTracking()) -> RiskTrackingError

Keywords correspond to the struct's fields.

The constructor passes r through no_bounds_no_risk_expr_risk_measure, which drops the settings.ub and the settings.rke of the tracked measure. The tracked measure only measures the distance. It does not bound the portfolio and it adds no term to the objective, so err is the only bound of the constraint.

Validation

View parameters

RiskTrackingError defines its own port_opt_view method rather than deriving one from field tags.

  • tr recurses through port_opt_view with the asset indices alone, which slices the benchmark weights.
  • r recurses through port_opt_view with the asset indices and the returns matrix, because a measure can slice a moment that it holds.
  • err and alg pass through unchanged.

Examples

julia> RiskTrackingError(; tr = WeightsTracking(; w = [0.5, 0.5]), err = 0.05)RiskTrackingError   tr ┼ WeightsTracking      │    fees ┼ nothing      │       w ┼ Vector{Float64}: [0.5, 0.5]      │   fixed ┴ Bool: false    r ┼ StandardDeviation      │   settings ┼ RiskMeasureSettings      │            │   scale ┼ Float64: 1.0      │            │      ub ┼ nothing      │            │     rke ┴ Bool: false      │      sigma ┼ nothing      │       chol ┼ nothing      │   mtx_sqrt ┴ EigenFallbackSquareRoot()  err ┼ Float64: 0.05  alg ┴ IndependentVariableTracking()

Related

References

  • [187] R. Roll. A mean/variance analysis of tracking error. The Journal of Portfolio Management 18, 13–22 (1992). Page 15.
  • [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 9.2, Equation 9.18.
source
PortfolioOptimisers.TrackingRiskMeasure — Type
struct TrackingRiskMeasure{__T_settings, __T_tr, __T_alg} <: RiskMeasure

Measures the tracking error, a scaled norm of the gap between the net portfolio returns and a benchmark return series.

The benchmark is a return series in a ReturnsTracking, and a weight vector in a WeightsTracking, which builds the series from the returns matrix. TrackingError bounds the same quantity in an optimisation, and RiskTrackingRiskMeasure measures a difference of risks in its place.

Mathematical definition

The alg field selects the norm and the divisor that scales it.

\[\begin{align} \boldsymbol{x} &= \mathbf{X}\boldsymbol{w} - F(\boldsymbol{w})\,, \\ \mathrm{TE}_{L_2}(\boldsymbol{w}) &= \frac{\lVert \boldsymbol{x} - \boldsymbol{b} \rVert_2}{\sqrt{T - d}}\,, \\ \mathrm{TE}_{L_2^2}(\boldsymbol{w}) &= \frac{\lVert \boldsymbol{x} - \boldsymbol{b} \rVert_2^2}{T - d}\,, \\ \mathrm{TE}_{L_1}(\boldsymbol{w}) &= \frac{\lVert \boldsymbol{x} - \boldsymbol{b} \rVert_1}{T - d}\,, \\ \mathrm{TE}_{L_p}(\boldsymbol{w}) &= \frac{\lVert \boldsymbol{x} - \boldsymbol{b} \rVert_p}{(T - d)^{1/p}}\,, \\ \mathrm{TE}_{L_\infty}(\boldsymbol{w}) &= \lVert \boldsymbol{x} - \boldsymbol{b} \rVert_\infty\,. \end{align}\]

Where:

  • $\boldsymbol{x}$: Net portfolio return series $T \times 1$.
  • $\mathbf{X}$: Returns matrix $T \times N$.
  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $F(\boldsymbol{w})$: Fee series $T \times 1$ of the portfolio, zero when fees is nothing. See calc_net_returns.
  • $\boldsymbol{b}$: Benchmark return series $T \times 1$, from tracking_benchmark on tr. A WeightsTracking gives $\boldsymbol{b} = \mathbf{X}\boldsymbol{w}_b - F_b(\boldsymbol{w}_b)$, with the fee $F_b$ of its own fees field. A DataBenchmarkTracking gives the benchmark $\mathbf{B}$ of the rows, or $\mathbf{B}\boldsymbol{w}$ when $\mathbf{B}$ holds one benchmark per asset.
  • $\boldsymbol{w}_b$: Benchmark portfolio weights vector $N \times 1$, the w of the tracking specification tr.
  • $\mathrm{TE}_{L_2}$, $\mathrm{TE}_{L_2^2}$, $\mathrm{TE}_{L_1}$, $\mathrm{TE}_{L_p}$, $\mathrm{TE}_{L_\infty}$: Tracking error under L2Norm, SquaredL2Norm, L1Norm, LpNorm and LInfNorm.
  • $T$: Number of observations.
  • $d$: Degrees of freedom, ddof. When the caller gives no $T$, the denominator is 1.
  • $p$: Norm order.

Page 15 of [187] takes the variance of the difference of the two returns as the tracking error. Equation 2 of [10] minimises the sum of the squared differences of the two series, and its Equations 5 and 6 state the $L_1$ and $L_\infty$ forms without a divisor. Equation 9 of [11] states the $L_p$ form, but it divides by $T$ for every $p$, where the form above divides by $T^{1/p}$ at $d = 0$. With $d = 0$, the $L_2$ and $L_1$ forms are Equations 9.16 and 9.17 of [12], and the squared $L_2$ form is the empirical tracking error of Equation 13.5 of [217] and of [218]. The divisor $T - d$ is the library's own.

Fields

  • settings: Risk measure settings.
  • tr: Benchmark tracking specification.
  • alg: Tracking formulation algorithm.

Constructors

TrackingRiskMeasure(;    settings::RiskMeasureSettings = RiskMeasureSettings(),    tr::AbstractTrackingAlgorithm,    alg::NormError = L2Norm()) -> TrackingRiskMeasure

Keywords correspond to the struct's fields.

View parameters

port_opt_view takes the view of these @vprop fields at the selected indices:

Observation weight parameters

obs_weights_view indexes these fields to the selected observations:

  • tr: Recursively indexed through obs_weights_view. A ReturnsTracking holds one benchmark return for each observation, so a Shared Series gap drops the benchmark return of the dropped observation with it.

Functor

(r::TrackingRiskMeasure)(w::VecNum, X::MatNum, fees = nothing)

Computes the tracking error of the portfolio weights w on the returns matrix X.

Arguments

  • w::VecNum: Portfolio weights vector.
  • X::MatNum: Asset returns matrix ($T \times N$).
  • fees: Optional fee of the portfolio.

calc_net_returns charges fees on the portfolio series, and tracking_benchmark charges r.tr.fees on the benchmark series. Both charge over the same X, and neither divides by a fold. A bare AmortisedFees on either fee charges its fixed amounts in full. Give a horizon to both fees to spread both of them.

Precomputed portfolio returns

(r::TrackingRiskMeasure{<:Any, <:ReturnsTracking})(x::VecNum)(r::TrackingRiskMeasure{<:Any, <:DataBenchmarkTracking})(x::VecNum)

Computes the tracking error of a portfolio return series x ($T \times 1$) that the caller already holds. A ReturnsTracking measure supports this, and so does a DataBenchmarkTracking measure bound to a vector benchmark, because each benchmark is a return series. A WeightsTracking measure builds its benchmark from the asset returns, and a DataBenchmarkTracking bound to a matrix forms it against the weights, so both need the portfolio weights. On a series they throw an ArgumentError, and so does an unbound DataBenchmarkTracking. See supports_precomputed_returns.

Examples

julia> TrackingRiskMeasure(; tr = ReturnsTracking(; w = [0.1, -0.2, 0.3]))TrackingRiskMeasure  settings ┼ RiskMeasureSettings           │   scale ┼ Float64: 1.0           │      ub ┼ nothing           │     rke ┴ Bool: true        tr ┼ ReturnsTracking           │   w ┴ Vector{Float64}: [0.1, -0.2, 0.3]       alg ┼ L2Norm           │   ddof ┴ Int64: 1

Related

References

  • [187] R. Roll. A mean/variance analysis of tracking error. The Journal of Portfolio Management 18, 13–22 (1992). Page 15.
  • [10] M. Rudolf, H.-J. Wolter and H. Zimmermann. A linear model for tracking error minimization. Journal of Banking & Finance 23, 85–103 (1999). Pages 87 and 88, Equations 2, 5 and 6.
  • [11] J. E. Beasley, N. Meade and T.-J. Chang. An evolutionary heuristic for the index tracking problem. European Journal of Operational Research 148, 621–643 (2003). Page 629, Equation 9.
  • [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 9.2, Equations 9.16 and 9.17.
  • [217] D. P. Palomar. Portfolio Optimization: Theory and Application (Cambridge University Press, 2025). Section 13.3.1, Equation 13.5.
  • [218] K. Benidis, Y. Feng and D. P. Palomar. Optimization Methods for Financial Index Tracking: From Theory to Practice. Foundations and Trends in Optimization 3, 171–279 (2018).
source
PortfolioOptimisers.RiskTrackingRiskMeasure — Type
struct RiskTrackingRiskMeasure{__T_settings, __T_tr, __T_r, __T_alg} <: RiskMeasure

Measures how far the risk of a portfolio is from the risk of a benchmark portfolio, under any risk measure.

The alg field selects the mode. The independent mode, IndependentVariableTracking, takes the risk of the weight difference. The dependent mode, DependentVariableTracking, takes the absolute difference of the two risks. RiskTrackingError bounds the same quantity in an optimisation, and TrackingRiskMeasure measures a norm of the gap between two return series in its place.

In an optimisation the independent mode is exact, and the dependent mode holds from one side only. The model states the portfolio risk through an upper bound that the solver can raise. So the model penalises a portfolio that is riskier than the benchmark, and it can report zero for a portfolio that is less risky. This is true of every measure whose model is an upper bound, among them ConditionalValueatRisk, StandardDeviation and a Variance in the semidefinite form. The constructor warns for a measure whose model is a quadratic expression, and a Variance outside the semidefinite form does not solve in the dependent mode.

The functor never reads tr.fees, and it charges the fee of the portfolio as the model does. In the independent mode the tracked measure reads the series $\mathbf{X}(\boldsymbol{w} - \boldsymbol{w}_b) - F(\boldsymbol{w})$, the net return of the portfolio minus the gross return of the benchmark. difference_risk computes it. The benchmark pays no fee there, because the difference $\boldsymbol{w} - \boldsymbol{w}_b$ is not a portfolio that anyone holds. In the dependent mode each weight vector pays its own fee on its own risk, in the functor and in the model.

Mathematical definition

\[\begin{align} \mathrm{RT}_{\mathrm{ind}}(\boldsymbol{w}) &= \rho(\boldsymbol{w} - \boldsymbol{w}_b)\,, \\ \mathrm{RT}_{\mathrm{dep}}(\boldsymbol{w}) &= \lvert \rho(\boldsymbol{w}) - \rho(\boldsymbol{w}_b) \rvert\,. \end{align}\]

Where:

  • $\mathrm{RT}_{\mathrm{ind}}(\boldsymbol{w})$: Risk tracking in the independent mode, the risk of the weight difference.
  • $\mathrm{RT}_{\mathrm{dep}}(\boldsymbol{w})$: Risk tracking in the dependent mode, the absolute difference of the two risks.
  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $\boldsymbol{w}_b$: Benchmark portfolio weights vector $N \times 1$, the w of the tracking specification tr.
  • $\rho$: Tracked risk measure, the r field. Its value at a weight vector is the risk of that vector as expected_risk reports it.
  • $\mathbf{\Sigma}$: Covariance matrix of a StandardDeviation tracked measure.

With a StandardDeviation, the independent mode is $\sqrt{(\boldsymbol{w} - \boldsymbol{w}_b)^\intercal \mathbf{\Sigma} (\boldsymbol{w} - \boldsymbol{w}_b)}$, Equation 9.18 of [12]. Page 15 of [187] states its square, the variance of the weight difference. The independent mode under any other measure, and the dependent mode, are the library's own.

Fields

  • settings: Risk measure settings.
  • tr: Benchmark tracking specification.
  • r: Risk measure instance.
  • alg: Tracking formulation algorithm.

Constructors

RiskTrackingRiskMeasure(;    settings::RiskMeasureSettings = RiskMeasureSettings(),    tr::WeightsTracking,    r::AbstractBaseRiskMeasure = Variance(),    alg::VariableTracking = IndependentVariableTracking()) -> RiskTrackingRiskMeasure

Keywords correspond to the struct's fields.

The constructor passes r through no_bounds_no_risk_expr_risk_measure, which drops the settings.ub and the settings.rke of the tracked measure. The tracked measure only measures the distance, and settings of this measure holds its bound and its objective flag. In the dependent mode, the constructor logs a warning when r is a measure whose model is a quadratic expression, such as a Variance.

View parameters

RiskTrackingRiskMeasure defines its own port_opt_view method rather than deriving one from field tags.

  • tr recurses through port_opt_view with the asset indices alone, which slices the benchmark weights.
  • r recurses through port_opt_view with the asset indices and the returns matrix, because a measure can slice a moment that it holds.
  • settings and alg pass through unchanged.

Functor

(r::RiskTrackingRiskMeasure)(w::VecNum, X::MatNum, fees = nothing)

Computes the risk tracking of the portfolio weights w on the returns matrix X, in the mode that r.alg selects.

Arguments

  • w::VecNum: Portfolio weights vector.
  • X::MatNum: Asset returns matrix ($T \times N$).
  • fees: Optional fee of the portfolio w. In the dependent mode the benchmark weights also pay it, on their own risk.

Examples

julia> RiskTrackingRiskMeasure(; tr = WeightsTracking(; w = [0.5, 0.5]))RiskTrackingRiskMeasure  settings ┼ RiskMeasureSettings           │   scale ┼ Float64: 1.0           │      ub ┼ nothing           │     rke ┴ Bool: true        tr ┼ WeightsTracking           │    fees ┼ nothing           │       w ┼ Vector{Float64}: [0.5, 0.5]           │   fixed ┴ Bool: false         r ┼ Variance           │    settings ┼ RiskMeasureSettings           │             │   scale ┼ Float64: 1.0           │             │      ub ┼ nothing           │             │     rke ┴ Bool: false           │       sigma ┼ nothing           │        chol ┼ nothing           │          rc ┼ nothing           │         alg ┼ SquaredSOCRiskExpr()           │    mtx_sqrt ┼ EigenFallbackSquareRoot()           │   ratio_alg ┼ SquareRootRatio()           │      corner ┴ nothing       alg ┴ IndependentVariableTracking()

Related

References

  • [187] R. Roll. A mean/variance analysis of tracking error. The Journal of Portfolio Management 18, 13–22 (1992). Page 15.
  • [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 9.2, Equation 9.18.
source
PortfolioOptimisers.port_opt_view — Method
port_opt_view(::Nothing, ::Any; kwargs...) -> nothing
port_opt_view(::Nothing, ::Any, args...; kwargs...) -> nothing

Fallback of port_opt_view for an absent value. The index view of a nothing estimator, algorithm, result or constraint is nothing.

Every propagation family uses these methods. Many optional fields have the type Option{T} = Union{Nothing, T}. A nothing argument matches both the Option{T} passthrough of a family and the universal leaf fallback, and the ::Nothing methods resolve that ambiguity. Both methods have a fixed second positional argument, so they are more specific than the universal port_opt_view(x, i, args...) method.

Algorithm

  1. Return nothing. Neither method reads its index, its tail or its keywords.

The two methods differ only in the tail, and both are necessary. A call site that threads no tail resolves on the first method. A call site that threads a returns matrix resolves on the second method.

Examples

julia> PortfolioOptimisers.port_opt_view(nothing, 1)
source
PortfolioOptimisers.port_opt_view — Method
port_opt_view(
    tr::RiskTrackingError,
    i,
    X::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
    args...
) -> RiskTrackingError{WeightsTracking{__T_fees, __T_w, __T_fixed}, _A, <:Number, <:VariableTracking} where {__T_fees, __T_w, __T_fixed, _A}

Return a RiskTrackingError restricted to the assets at the indices i.

A hierarchical or clustering optimiser calls it to build the constraint of one cluster. The benchmark weights of the result are the entries i of tr.tr.w, so they no longer sum to the budget of the whole benchmark.

Algorithm

  1. Slice the benchmark with port_opt_view(tr.tr, i).
  2. Slice the tracked measure with port_opt_view(tr.r, i, X).
  3. Rebuild tr with the two slices, with rebuild_struct. tr.err and tr.alg do not change.

Related

source
PortfolioOptimisers.factory — Function
factory(
    tr::RiskTrackingError,
    pr::AbstractPriorResult,
    slv,
    ucs;
    ...
) -> RiskTrackingError{WeightsTracking{__T_fees, __T_w, __T_fixed}, _A, <:Number, <:VariableTracking} where {__T_fees, __T_w, __T_fixed, _A}
factory(
    tr::RiskTrackingError,
    pr::AbstractPriorResult,
    slv,
    ucs,
    w::Union{Nothing, AbstractVector{<:Union{Number, AbstractJuMPScalar}}},
    args...;
    kwargs...
) -> RiskTrackingError{WeightsTracking{__T_fees, __T_w, __T_fixed}, _A, <:Number, <:VariableTracking} where {__T_fees, __T_w, __T_fixed, _A}

Return a RiskTrackingError whose tracked measure is resolved against a prior result, and whose benchmark takes the weights w.

Algorithm

  1. Advance the benchmark with factory(tr.tr, w). The benchmark stays as it is when w is nothing, or when its fixed flag is true.
  2. Resolve the tracked measure with factory(tr.r, pr, slv, ucs, w, args...; kwargs...), which fills the moments that it reads from pr.
  3. Rebuild tr with the two results, with rebuild_struct. tr.err and tr.alg do not change.

Related

source
PortfolioOptimisers.factory — Method
factory(
    tr::RiskTrackingError,
    w::AbstractVector{<:Union{Number, AbstractJuMPScalar}}
) -> RiskTrackingError{WeightsTracking{__T_fees, __T_w, __T_fixed}, _A, <:Number, <:VariableTracking} where {__T_fees, __T_w, __T_fixed, _A}

Return a RiskTrackingError whose benchmark and tracked measure take the portfolio weights w.

Algorithm

  1. Advance the benchmark with factory(tr.tr, w). A WeightsTracking whose fixed flag is true stays as it is.
  2. Advance the tracked measure with factory(tr.r, w).
  3. Rebuild tr with the two results, with rebuild_struct. tr.err and tr.alg do not change.

Related

source
PortfolioOptimisers.factory — Method
factory(
    r::TrackingRiskMeasure,
    w::AbstractVector{<:Union{Number, AbstractJuMPScalar}}
) -> TrackingRiskMeasure{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, <:AbstractTrackingAlgorithm, <:NormError} where {__T_scale, __T_ub, __T_rke}

Return a TrackingRiskMeasure whose benchmark takes the portfolio weights w.

factory(r.tr, w) advances the benchmark. A WeightsTracking whose fixed flag is false takes w as its new benchmark weights, and any other benchmark stays as it is. rebuild_struct rebuilds r with the benchmark, and r.settings and r.alg pass through unchanged.

Related

source
PortfolioOptimisers.factory — Method
factory(
    r::TrackingRiskMeasure,
    ,
    ,
    ,
    w::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
    args...;
    kwargs...
) -> TrackingRiskMeasure{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, <:AbstractTrackingAlgorithm, <:NormError} where {__T_scale, __T_ub, __T_rke}

Return the TrackingRiskMeasure whose benchmark takes the portfolio weights 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. The method holds the one-line body of factory(r, w), and the two give one measure.

Related

source
PortfolioOptimisers.port_opt_view — Method
port_opt_view(
    r::RiskTrackingRiskMeasure,
    i,
    X::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
    args...
) -> RiskTrackingRiskMeasure{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, WeightsTracking{__T_fees, __T_w, __T_fixed}, _A, <:VariableTracking} where {__T_scale, __T_ub, __T_rke, __T_fees, __T_w, __T_fixed, _A}

Return a RiskTrackingRiskMeasure restricted to the assets at the indices i.

A hierarchical or clustering optimiser calls it to build the measure of one cluster. The benchmark weights of the result are the entries i of r.tr.w, so they no longer sum to the budget of the whole benchmark.

Algorithm

  1. Slice the benchmark with port_opt_view(r.tr, i).
  2. Slice the tracked measure with port_opt_view(r.r, i, X).
  3. Rebuild r with the two slices, with rebuild_struct. r.settings and r.alg do not change.

Related

source
PortfolioOptimisers.factory — Method
factory(
    r::RiskTrackingRiskMeasure,
    w::AbstractVector{<:Union{Number, AbstractJuMPScalar}}
) -> RiskTrackingRiskMeasure{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, WeightsTracking{__T_fees, __T_w, __T_fixed}, _A, <:VariableTracking} where {__T_scale, __T_ub, __T_rke, __T_fees, __T_w, __T_fixed, _A}

Return a RiskTrackingRiskMeasure whose benchmark and tracked measure take the portfolio weights w.

Algorithm

  1. Advance the benchmark with factory(r.tr, w). A WeightsTracking whose fixed flag is true stays as it is.
  2. Advance the tracked measure with factory(r.r, w).
  3. Rebuild r with the two results, with rebuild_struct. r.settings and r.alg do not change.

Related

source
PortfolioOptimisers.factory — Method
factory(
    r::RiskTrackingRiskMeasure,
    pr::AbstractPriorResult,
    args...;
    kwargs...
) -> RiskTrackingRiskMeasure{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, WeightsTracking{__T_fees, __T_w, __T_fixed}, _A, <:VariableTracking} where {__T_scale, __T_ub, __T_rke, __T_fees, __T_w, __T_fixed, _A}

Return a RiskTrackingRiskMeasure whose tracked measure is resolved against the prior result pr.

factory(r.r, pr, args...; kwargs...) fills the moments that the tracked measure reads from pr. The benchmark stays as it is, even when args carries portfolio weights. The method factory(r, w) advances it.

Related

source
PortfolioOptimisers.supports_precomputed_returns — Method
supports_precomputed_returns(
    r::TrackingRiskMeasure{<:Any, <:DataBenchmarkTracking}
) -> Bool

Return true for a TrackingRiskMeasure whose DataBenchmarkTracking benchmark is bound to a vector.

A vector benchmark is a return series, so the tracking error is a function of the net portfolio return series alone. A matrix benchmark forms the series $\mathbf{B}\boldsymbol{w}$ against the portfolio weights, and an unbound benchmark has no series, so both return false.

Related

source
PortfolioOptimisers.supports_precomputed_returns — Method
supports_precomputed_returns(
    _::RiskTrackingRiskMeasure
) -> Bool

Return false for every RiskTrackingRiskMeasure, because the measure needs the portfolio weights.

Its tr field is a WeightsTracking, and both functors read the benchmark weights from it. The independent mode takes the tracked risk of w - r.tr.w, and the dependent mode takes the difference of the tracked risk at w and at r.tr.w. A net return series carries no weights, so neither difference exists for it.

Related

source
PortfolioOptimisers.obs_weights_view — Method
obs_weights_view(r::Union{RiskTrackingError, RiskTrackingRiskMeasure}, i)

Return the tracking measure with the observation weights of the measure that it tracks cut to the observations i, through obs_weights_fields.

The two types are not @propagatable, so they need this method of obs_weights_view. The tracked measure r can hold fixed observation weights, so a cut of the returns of the solve, such as the drop of a Shared Series gap, must reach them, see shared_series_estimator. The benchmark weights of tr are portfolio weights, and they keep their value.

Related

source

References

[10]
M. Rudolf, H.-J. Wolter and H. Zimmermann. A linear model for tracking error minimization. Journal of Banking & Finance 23, 85–103 (1999).
[11]
J. E. Beasley, N. Meade and T.-J. Chang. An evolutionary heuristic for the index tracking problem. European Journal of Operational Research 148, 621–643 (2003).
[12]
D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
[187]
R. Roll. A mean/variance analysis of tracking error. The Journal of Portfolio Management 18, 13–22 (1992).
[217]
D. P. Palomar. Portfolio Optimization: Theory and Application (Cambridge University Press, 2025).
[218]
K. Benidis, Y. Feng and D. P. Palomar. Optimization Methods for Financial Index Tracking: From Theory to Practice. Foundations and Trends in Optimization 3, 171–279 (2018).