Norm error
PortfolioOptimisers.NormError — Type
abstract type NormError <: AbstractEstimatorAbstract supertype for all norm-based error algorithms.
All concrete and abstract types of norm-based error algorithms, such as the second-order cone error or the norm-one error, must subtype NormError.
Interfaces
To implement a new norm-based error algorithm, subtype NormError with a struct that holds its parameters, and implement the method below.
norm_factor(f::NormError, T::Number) -> Number: Returns the divisor that scales the norm. A generic method already returns1forT === nothing.
norm_error computes the error for a value. In the JuMP model, set_risk_constraints! for TrackingRiskMeasure and set_tracking_error_constraints! for TrackingError build the error. All three read norm_factor, so a new norm declares its factor once.
Related
PortfolioOptimisers.L2Norm — Type
struct L2Norm{__T_ddof} <: NormErrorSecond-order cone (SOC) norm-based error formulation.
L2Norm takes the Euclidean norm of the difference between the portfolio returns and the benchmark returns. It divides the norm by the square root of the number of observations minus the degrees of freedom ddof.
Mathematical definition
\[\begin{align} \mathrm{TE}_{L_2}(\boldsymbol{a},\boldsymbol{b}) &= \frac{\lVert \boldsymbol{a} - \boldsymbol{b} \rVert_2}{\sqrt{T - d}}\,. \end{align}\]
Where:
- $\mathrm{TE}_{L_2}(\boldsymbol{a},\boldsymbol{b})$: L2-norm error.
- $\boldsymbol{a}$: Portfolio weight or return vector $T \times 1$.
- $\boldsymbol{b}$: Benchmark vector $T \times 1$.
- $T$: Number of observations.
- $d$: Degrees of freedom,
ddof. When the caller gives no $T$, the denominator is 1.
[10] minimises the sum of the squared differences, $(\boldsymbol{a} - \boldsymbol{b})^{\intercal} (\boldsymbol{a} - \boldsymbol{b})$, and does not centre them. [11] takes the $\alpha$-th root of the sum of the $\alpha$-th powers, divides it by $T$, and names the case $\alpha = 2$ the root mean squared error. The root mean square divides by $\sqrt{T}$, as [12] does, and this error also does. The two values differ by the factor $\sqrt{T}$ and have the same minimiser, but a bound on the error must use the denominator of this error. The default ddof = 1 gives the sample denominator $\sqrt{T-1}$. Set ddof = 0 to recover the root mean square.
Fields
ddof: Degrees-of-freedom correction, an integer that the library subtracts from the number of observations itself.
Constructors
L2Norm(; ddof::Integer = 1) -> L2NormKeywords correspond to the struct's fields.
Validation
0 <= ddof.
Examples
julia> L2Norm()L2Norm ddof ┴ Int64: 1Related
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). Section 2, Equation 2.
- [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). Section 3.5.1, Equation 9.
- [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 9.2, Equation 9.16.
PortfolioOptimisers.SquaredL2Norm — Type
struct SquaredL2Norm{__T_ddof} <: NormErrorSecond-order cone (SOC) squared norm-based error formulation.
SquaredL2Norm takes the squared Euclidean norm of the difference between the portfolio returns and the benchmark returns. It divides the squared norm by the number of observations minus the degrees of freedom ddof.
The value is the square of the L2Norm error, so a settings.ub on a TrackingRiskMeasure has squared units. The JuMP model converts the bound with a square root, so the two encodings accept the same bound.
[10] minimises the sum of the squared differences, which is this error times $T - d$, and does not centre the differences. The division by $T - d$ squares the root mean square of [12].
Mathematical definition
\[\begin{align} \mathrm{TE}_{L_2^2}(\boldsymbol{a},\boldsymbol{b}) &= \frac{\lVert \boldsymbol{a} - \boldsymbol{b} \rVert_2^2}{T - d}\,. \end{align}\]
Where:
- $\mathrm{TE}_{L_2^2}(\boldsymbol{a},\boldsymbol{b})$: Squared L2-norm error.
- $\boldsymbol{a}$: Portfolio weight or return vector $T \times 1$.
- $\boldsymbol{b}$: Benchmark vector $T \times 1$.
- $T$: Number of observations.
- $d$: Degrees of freedom,
ddof. When the caller gives no $T$, the denominator is 1.
Fields
ddof: Degrees-of-freedom correction, an integer that the library subtracts from the number of observations itself.
Constructors
SquaredL2Norm(; ddof::Integer = 1,) -> SquaredL2NormKeywords correspond to the struct's fields.
Validation
0 <= ddof.
Examples
julia> SquaredL2Norm()SquaredL2Norm ddof ┴ Int64: 1Related
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). Section 2, Equation 2.
- [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 9.2, Equation 9.16.
PortfolioOptimisers.L1Norm — Type
struct L1Norm{__T_ddof} <: NormErrorNorm-one (NOC) error formulation.
L1Norm takes the L1 distance between the portfolio returns and the benchmark returns. It divides the distance by the number of observations minus the degrees of freedom ddof.
Mathematical definition
\[\begin{align} \mathrm{TE}_{L_1}(\boldsymbol{a},\boldsymbol{b}) &= \frac{\lVert \boldsymbol{a} - \boldsymbol{b} \rVert_1}{T - d}\,. \end{align}\]
Where:
- $\mathrm{TE}_{L_1}(\boldsymbol{a},\boldsymbol{b})$: L1-norm error.
- $\boldsymbol{a}$: Portfolio weight or return vector $T \times 1$.
- $\boldsymbol{b}$: Benchmark vector $T \times 1$.
- $T$: Number of observations.
- $d$: Degrees of freedom,
ddof. When the caller gives no $T$, the denominator is 1.
[10] states the error as the sum of the absolute differences, $\boldsymbol{1}^{\intercal} \lvert \boldsymbol{a} - \boldsymbol{b} \rvert$, and names it the mean absolute deviation. [12] divides the sum by $T$, which gives the mean that the name states and does not move the minimiser. The default ddof = 0 gives that denominator $T$, so the error is the mean absolute difference. LpNorm defaults to ddof = 1, so LpNorm(; p = 1) and L1Norm() differ by a factor of $T / (T - 1)$.
Fields
ddof: Degrees-of-freedom correction, an integer that the library subtracts from the number of observations itself.
Constructors
L1Norm(; ddof::Integer = 0) -> L1NormKeywords correspond to the struct's fields.
Validation
0 <= ddof.
Examples
julia> L1Norm()L1Norm ddof ┴ Int64: 0Related
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). Section 3, Equations 5 and 7a.
- [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 9.2, Equation 9.17.
PortfolioOptimisers.LpNorm — Type
struct LpNorm{__T_p, __T_ddof} <: NormErrorL-p norm error estimator.
LpNorm takes the Lp-norm of the difference between the portfolio returns and the benchmark returns, and divides it by $(T - d)^{1/p}$. It extends L1Norm and L2Norm to any norm order.
[11] states this family with the divisor $T$ outside the root, $\lVert \boldsymbol{a} - \boldsymbol{b} \rVert_p / T$. The divisor here is $(T - d)^{1/p}$, so the error is the $p$-th root of a mean and keeps the scale of one period as $T$ changes. At a fixed $T$ the two values differ by a constant factor and have the same minimiser.
Mathematical definition
\[\begin{align} \mathrm{TE}_{L_p}(\boldsymbol{a},\boldsymbol{b}) &= \frac{\lVert \boldsymbol{a} - \boldsymbol{b} \rVert_p}{(T - d)^{1/p}}\,. \end{align}\]
Where:
- $\mathrm{TE}_{L_p}(\boldsymbol{a},\boldsymbol{b})$: Lp-norm error.
- $\boldsymbol{a}$: Portfolio weight or return vector $T \times 1$.
- $\boldsymbol{b}$: Benchmark vector $T \times 1$.
- $T$: Number of observations.
- $d$: Degrees of freedom,
ddof. When the caller gives no $T$, the denominator is 1. - $p$: Norm order.
The default ddof = 1 matches L2Norm, so LpNorm(; p = 2) and L2Norm() give the same error. L1Norm defaults to ddof = 0, so LpNorm(; p = 1) and L1Norm() differ by a factor of $T / (T - 1)$. As $p$ grows the factor goes to $1$, which is the factor of LInfNorm.
Fields
p: Power or order parameter.
ddof: Degrees-of-freedom correction, an integer that the library subtracts from the number of observations itself.
Constructors
LpNorm(; p::Number = 3, ddof::Integer = 1) -> LpNormKeywords correspond to the struct's fields.
Validation
0 <= ddof. The constructor does not boundp, and the JuMP model does. Bothset_risk_constraints!andset_tracking_error_constraints!need1 < pfor the power cone, and raise aDomainErrorfor each otherp.norm_erroraccepts eachpthatLinearAlgebra.normaccepts.
Examples
julia> LpNorm()LpNorm p ┼ Int64: 3 ddof ┴ Int64: 1Related
References
- [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). Section 3.5.1, Equation 9.
PortfolioOptimisers.LInfNorm — Type
struct LInfNorm <: NormErrorL-infinity norm error estimator, which is the maximum absolute deviation.
LInfNorm takes the largest absolute deviation between the portfolio returns and the benchmark returns, and does not scale it. The factor of LpNorm is $(T - d)^{1/p}$, which goes to $1$ as $p$ increases. The error is thus the largest difference in one period, and it has no degrees of freedom. It is the MinMax tracking error of [10].
Mathematical definition
\[\begin{align} \mathrm{TE}_{L_\infty}(\boldsymbol{a},\boldsymbol{b}) &= \lVert \boldsymbol{a} - \boldsymbol{b} \rVert_\infty\,. \end{align}\]
Where:
- $\mathrm{TE}_{L_\infty}(\boldsymbol{a},\boldsymbol{b})$: L∞-norm error, the largest absolute deviation.
- $\boldsymbol{a}$: Portfolio weight or return vector $T \times 1$.
- $\boldsymbol{b}$: Benchmark vector $T \times 1$.
Constructors
LInfNorm() -> LInfNormExamples
julia> LInfNorm()LInfNorm()Related
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). Section 3, Equations 6 and 7c.
PortfolioOptimisers.norm_factor — Function
norm_factor(f::Union{Nothing, NormError}, T::Option{<:Number})Compute the denominator that scales a norm in norm_error.
This function is the one place that turns the optional observation count T into a divisor. norm_error and both JuMP models read it. Each NormError declares its own factor. The case T === nothing is a method, and not a branch inside a method. An earlier branch let ifelse evaluate T - f.ddof when T was nothing.
Algorithm
The method that Julia selects on the types of f and T is the algorithm. A T of nothing selects the method that returns 1.
f === nothinggivessqrt(T), the unweighted L2 factor.L2Normgivessqrt(T - f.ddof).SquaredL2NormgivesT - f.ddof.L1NormgivesT - f.ddof.LpNormgives(T - f.ddof)^(1/f.p). The method usescbrtwhenf.pis3, the default.LInfNormgives1, the limit of theLpNormfactor asf.pincreases.
Arguments
f: The norm-based error algorithm, aNormErrorsubtype.nothingmeans an unweighted L2 norm.T: The optional number of observations.
Returns
factor::Number: The divisor of the norm. It is1whenTisnothing.
Examples
julia> PortfolioOptimisers.norm_factor(L2Norm(), 4)1.7320508075688772julia> PortfolioOptimisers.norm_factor(LInfNorm(), nothing)1Related
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).