Tracking
Public
PortfolioOptimisers.L2Tracking Type
struct L2Tracking{__T_ddof} <: NormTrackingSecond-order cone (SOC) norm-based tracking formulation.
L2Tracking implements a norm-based tracking error formulation using the Euclidean (L2) norm, scaled by the square root of the number of assets minus the degrees of freedom (ddof). This is commonly used for tracking error constraints and objectives in portfolio optimisation.
Mathematical definition
Where:
: L2-norm tracking error. : Portfolio weight or return vector . : Benchmark vector . : Number of observations. : Degrees of freedom, ddof. Whenis not provided the denominator is 1.
Fields
ddof: Degrees-of-freedom correction.
Constructors
L2Tracking(;
ddof::Integer = 1
) -> L2TrackingValidation
0 <= ddof.
Examples
julia> L2Tracking()
L2Tracking
ddof ┴ Int64: 1Related
sourcePortfolioOptimisers.SquaredL2Tracking Type
struct SquaredL2Tracking{__T_ddof} <: NormTrackingSecond-order cone (SOC) squared norm-based tracking formulation.
SquaredL2Tracking implements a norm-based tracking error formulation using the squared Euclidean (L2) norm, scaled by the number of assets minus the degrees of freedom (ddof). This is commonly used for tracking error constraints and objectives in portfolio optimisation where squared error is preferred.
Mathematical definition
Where:
: Squared L2-norm tracking error. : Portfolio weight or return vector . : Benchmark vector . : Number of observations. : Degrees of freedom, ddof. Whenis not provided the denominator is 1.
Fields
ddof: Degrees-of-freedom correction.
Constructors
SquaredL2Tracking(;
ddof::Integer = 1,
) -> SquaredL2TrackingValidation
0 <= ddof.
Examples
julia> SquaredL2Tracking()
SquaredL2Tracking
ddof ┴ Int64: 1Related
sourcePortfolioOptimisers.L1Tracking Type
struct L1Tracking <: NormTrackingNorm-one (NOC) tracking formulation.
L1Tracking implements a norm-based tracking error formulation using the L1 (norm-one) distance between portfolio and benchmark weights. This is commonly used for tracking error constraints and objectives in portfolio optimisation where sparsity or absolute deviations are preferred.
Mathematical definition
Where:
: L1-norm tracking error. : Portfolio weight or return vector . : Benchmark vector . : Number of observations. When is not provided the denominator is 1.
Constructors
L1Tracking() -> L1TrackingExamples
julia> L1Tracking()
L1Tracking()Related
sourcePortfolioOptimisers.LpTracking Type
struct LpTracking{__T_p, __T_ddof} <: NormTrackingL-p norm tracking error estimator.
Computes the Lp-norm of the difference between portfolio and benchmark returns:
Mathematical definition
Where:
: Lp-norm tracking error. : Portfolio weight or return vector . : Benchmark vector . : Number of observations. : Degrees of freedom, ddof. Whenis not provided the denominator is 1. : Norm order.
Fields
p: Power or order parameter.ddof: Degrees-of-freedom correction.
Constructors
LpTracking(; p::Number = 3, ddof::Integer = 0) -> LpTrackingKeywords correspond to the struct's fields.
Validation
0 <= ddof.
Examples
julia> LpTracking()
LpTracking
p ┼ Int64: 3
ddof ┴ Int64: 0Related
sourcePortfolioOptimisers.LInfTracking Type
struct LInfTracking{__T_ddof, __T_pos} <: NormTrackingL-infinity norm (maximum absolute deviation) tracking error estimator.
Computes the L∞-norm (maximum absolute deviation) of the difference between portfolio and benchmark returns.
Mathematical definition
Where:
: L∞-norm tracking error. pos = trueuses, pos = falseuses. : Portfolio weight or return vector . : Benchmark vector . : Number of observations. : Degrees of freedom, ddof. Whenis not provided the denominator is 1.
Fields
ddof: Degrees-of-freedom correction.pos: Whether to consider only positive deviations.
Constructors
LInfTracking(; ddof::Integer = 0, pos::Bool = true) -> LInfTrackingKeywords correspond to the struct's fields.
Validation
0 <= ddof.
Examples
julia> LInfTracking()
LInfTracking
ddof ┼ Int64: 0
pos ┴ Bool: trueRelated
sourcePortfolioOptimisers.IndependentVariableTracking Type
struct IndependentVariableTracking <: VariableTrackingIndependent variable-based tracking formulation.
IndependentVariableTracking tracks the independent variables of a measurement.
Constructors
IndependentVariableTracking() -> IndependentVariableTrackingExamples
julia> IndependentVariableTracking()
IndependentVariableTracking()Related
sourcePortfolioOptimisers.DependentVariableTracking Type
struct DependentVariableTracking <: VariableTrackingDependent variable-based tracking formulation.
DependentVariableTracking tracks the measurement.
Constructors
DependentVariableTracking() -> DependentVariableTrackingExamples
julia> DependentVariableTracking()
DependentVariableTracking()Related
sourcePortfolioOptimisers.WeightsTracking Type
struct WeightsTracking{__T_fees, __T_w, __T_fixed} <: AbstractTrackingAlgorithmAsset weights-based tracking algorithm.
WeightsTracking represents a tracking algorithm that operates directly on portfolio weights, optionally incorporating transaction fees. This is used for tracking error measurement and constraint generation where the comparison is made between portfolio weights and benchmark weights, with optional adjustment for fees.
Fields
fees: Fees estimator or result.w: Current portfolio weights vector.fixed: Whether the estimator is fixed and does not update with new weights.
Constructors
WeightsTracking(;
fees::Option{<:Fees} = nothing,
w::VecNum,
fixed::Bool = false
) -> WeightsTrackingValidation
!isempty(w).
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
fees: Recursively viewed viaport_opt_view.w: Sliced to the selected indices viaport_opt_view.
Examples
julia> WeightsTracking(; w = [0.5, 0.5])
WeightsTracking
fees ┼ nothing
w ┼ Vector{Float64}: [0.5, 0.5]
fixed ┴ Bool: falseRelated
sourcePortfolioOptimisers.ReturnsTracking Type
struct ReturnsTracking{__T_w} <: AbstractTrackingAlgorithmReturns-based tracking algorithm.
ReturnsTracking represents a tracking algorithm that operates directly on portfolio returns, rather than asset weights. This is used for tracking error measurement and constraint generation where the comparison is made between portfolio returns and benchmark returns.
Fields
w: Benchmark portfolio returns vector.
Constructors
ReturnsTracking(;
w::VecNum
) -> ReturnsTrackingValidation
!isempty(w).
Examples
julia> ReturnsTracking(; w = [0.01, 0.02, 0.03])
ReturnsTracking
w ┴ Vector{Float64}: [0.01, 0.02, 0.03]Related
sourcePortfolioOptimisers.TrackingError Type
struct TrackingError{__T_tr, __T_err, __T_alg} <: AbstractTrackingTracking error result type.
TrackingError represents the result of a tracking error computation, including the tracking algorithm used, the computed error value, and the tracking formulation algorithm. This type is used to store and propagate tracking error results in portfolio analytics and optimisation workflows.
Fields
tr: Tracking error constraint estimator.err: Tracking error tolerance.alg: Tracking formulation algorithm.
Constructors
TrackingError(;
tr::AbstractTrackingAlgorithm,
err::Number = 0.0,
alg::NormTracking = L2Tracking()
) -> TrackingErrorValidation
isfinite(err)anderr >= 0.
Propagated parameters
When factory is called on this type, the following @fprop-tagged fields are automatically propagated:
tr: Recursively updated viafactory.
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
tr: Recursively viewed viaport_opt_view.
Examples
julia> tr = WeightsTracking(; w = [0.5, 0.5]);
julia> TrackingError(; tr = tr, err = 0.01)
TrackingError
tr ┼ WeightsTracking
│ fees ┼ nothing
│ w ┼ Vector{Float64}: [0.5, 0.5]
│ fixed ┴ Bool: false
err ┼ Float64: 0.01
alg ┼ L2Tracking
│ ddof ┴ Int64: 1Related
PortfolioOptimisers.TrackingFormulation Type
abstract type TrackingFormulation <: AbstractAlgorithmAbstract supertype for all tracking formulation algorithm types in PortfolioOptimisers.jl.
All concrete and/or abstract types representing tracking formulation algorithms (such as norm-based or variable-based tracking) should be subtypes of TrackingFormulation.
Related
sourcePrivate
PortfolioOptimisers.AbstractTracking Type
abstract type AbstractTracking <: AbstractResultAbstract supertype for all tracking result types in PortfolioOptimisers.jl.
All concrete and/or abstract types representing tracking error or tracking constraint results should be subtypes of AbstractTracking.
Related
sourcePortfolioOptimisers.AbstractTrackingAlgorithm Type
abstract type AbstractTrackingAlgorithm <: AbstractAlgorithmAbstract supertype for all tracking algorithm types in PortfolioOptimisers.jl.
All concrete and/or abstract types representing tracking algorithms (such as weights or returns tracking) should be subtypes of AbstractTrackingAlgorithm.
Interfaces
In order to implement a new tracking algorithm that works seamlessly with the library, subtype AbstractTrackingAlgorithm and implement the following methods:
tracking_benchmark(tr::AbstractTrackingAlgorithm, X::MatNum) -> VecNum: Compute benchmark returns from the asset return matrixX.factory(tr::AbstractTrackingAlgorithm, w::VecNum) -> AbstractTrackingAlgorithm: Construct a new instance with updated portfolio weightsw.port_opt_view(tr::AbstractTrackingAlgorithm, i) -> AbstractTrackingAlgorithm: Create a view of the tracking algorithm for the subset of assets at indicesi.
Arguments
tr: The concrete tracking algorithm instance.X: Covariance-like or correlation-like matrixfeatures × features.w: New portfolio weights.i: Index or indices for asset subset.
Returns
b::VecNum: Benchmark returns (fortracking_benchmark).tr::AbstractTrackingAlgorithm: Updated or viewed tracking algorithm (forfactory,port_opt_view).
Examples
julia> struct MyTracking <: PortfolioOptimisers.AbstractTrackingAlgorithm
w::Vector{Float64}
end
julia> function PortfolioOptimisers.tracking_benchmark(tr::MyTracking,
X::PortfolioOptimisers.MatNum)
return X * tr.w
end
julia> PortfolioOptimisers.factory(tr::MyTracking, w) = MyTracking(w)
julia> PortfolioOptimisers.port_opt_view(tr::MyTracking, i) = MyTracking(tr.w[i])
julia> tr = MyTracking([0.5, 0.5]);
julia> X = [0.01 0.02; 0.03 0.04];
julia> PortfolioOptimisers.tracking_benchmark(tr, X)
2-element Vector{Float64}:
0.015
0.035Related
sourcePortfolioOptimisers.VecTr Type
const VecTr = AbstractVector{<:AbstractTracking}Alias for a vector of tracking result types.
Related
sourcePortfolioOptimisers.Tr_VecTr Type
const Tr_VecTr = Union{<:AbstractTracking, <:VecTr}Union type for a single tracking result or a vector of tracking results.
Related
sourcePortfolioOptimisers.NormTracking Type
abstract type NormTracking <: TrackingFormulationAbstract supertype for all norm-based tracking formulation algorithms in PortfolioOptimisers.jl.
All concrete and/or abstract types representing norm-based tracking algorithms (such as second-order cone or norm-one tracking) should be subtypes of NormTracking.
Related
sourcePortfolioOptimisers.VariableTracking Type
abstract type VariableTracking <: TrackingFormulationAbstract supertype for all variable-based tracking formulation algorithms in PortfolioOptimisers.jl.
All concrete and/or abstract types representing variable-based tracking algorithms (such as independent or dependent variable tracking) should be subtypes of VariableTracking.
Related
sourcePortfolioOptimisers.norm_tracking Function
norm_tracking(f::L2Tracking, a, b, T::Option{<:Number} = nothing)
norm_tracking(f::SquaredL2Tracking, a, b, T::Option{<:Number} = nothing)
norm_tracking(::L1Tracking, a, b, T::Option{<:Number} = nothing)
norm_tracking(f::LpTracking, a, b, T::Option{<:Number} = nothing)
norm_tracking(f::LInfTracking, a, b, T::Option{<:Number} = nothing)Compute the norm-based tracking error between portfolio and benchmark weights.
norm_tracking computes the tracking error using either the Euclidean (L2) norm for L2Tracking, squared Euclidean (L2) norm for SquaredL2Tracking, or the L1 (norm-one) distance for L1Tracking. The error is optionally scaled by the number of assets and degrees of freedom for SOC, or by the number of assets for NOC.
Mathematical definition
Where:
: Portfolio weight or return vector . : Benchmark vector . : Number of observations. : Degrees of freedom, ddof.: Norm order.
Arguments
f: Tracking formulation algorithm.a: Portfolio weights.b: Benchmark weights.T: Optional number of observations.
Returns
err::Number: Norm-based tracking error.
Details
For
L2Tracking, computesLinearAlgebra.norm(a - b, 2) / sqrt(T - f.ddof)ifTis notnothing, else unscaled.For
SquaredL2Tracking, computesLinearAlgebra.norm(a - b, 2)^2 / (T - f.ddof)ifTis notnothing, else unscaled.For
L1Tracking, computesLinearAlgebra.norm(a - b, 1) / TifTis notnothing, else unscaled.
Examples
julia> PortfolioOptimisers.norm_tracking(L2Tracking(), [0.5, 0.5], [0.6, 0.4], 2)
0.14142135623730948
julia> PortfolioOptimisers.norm_tracking(L1Tracking(), [0.5, 0.5], [0.6, 0.4], 2)
0.09999999999999998Related
sourcePortfolioOptimisers.tracking_benchmark Function
tracking_benchmark(tr::WeightsTracking, X::MatNum)Compute the benchmark portfolio returns for a weights-based tracking algorithm.
tracking_benchmark computes the net portfolio returns for the benchmark weights stored in a WeightsTracking object, optionally adjusting for transaction fees if specified. The asset return matrix X is multiplied by the benchmark weights, and fees are deducted if present.
Arguments
tr:WeightsTrackingtracking algorithm containing benchmark weights and optional fees.X: Asset return matrix (assets × periods).
Returns
b::VecNum: Net benchmark portfolio returns.
Details
If
tr.feesis notnothing, net returns are computed usingcalc_net_returns.Otherwise, returns are computed as
X * tr.w.
Examples
julia> tr = WeightsTracking(; w = [0.5, 0.5]);
julia> X = [0.01 0.02; 0.03 0.04];
julia> PortfolioOptimisers.tracking_benchmark(tr, X)
2-element Vector{Float64}:
0.015
0.035Related
sourcetracking_benchmark(tr::ReturnsTracking, args...)Return the benchmark portfolio returns for a returns-based tracking algorithm.
tracking_benchmark extracts the benchmark portfolio returns stored in a ReturnsTracking object. This is used for tracking error measurement and constraint generation where the comparison is made directly between portfolio returns and benchmark returns.
Arguments
tr:ReturnsTrackingtracking algorithm containing benchmark returns.args...: For interface compatibility (ignored).
Returns
b::VecNum: Benchmark portfolio returns.
Examples
julia> tr = ReturnsTracking(; w = [0.01, 0.02, 0.03]);
julia> PortfolioOptimisers.tracking_benchmark(tr)
3-element Vector{Float64}:
0.01
0.02
0.03Related
sourcePortfolioOptimisers.port_opt_view Method
port_opt_view(tr::VecTr, args...)Return a vector of tracking views for each element in a vector of tracking results.
This function applies port_opt_view to each element of the input vector of tracking results, passing any additional arguments. It enables efficient subsetting and composability for collections of tracking error or tracking constraint results.
Arguments
tr: A vector of tracking result objects (VecTr).args...: Additional arguments to pass to eachport_opt_viewcall.
Returns
tres::Vector{<:AbstractTracking}: Vector of tracking view results.
Details
Applies
port_opt_viewto each element in the input vector.Passes all additional arguments to each call.
Returns a vector of the results.
Examples
julia> tr = TrackingError(; tr = WeightsTracking(; w = [0.5, 0.5, 0.5]), err = 0.01);
julia> PortfolioOptimisers.port_opt_view([tr], 1:2)
1-element Vector{TrackingError{WeightsTracking{Nothing, SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}, Bool}, Float64, L2Tracking{Int64}}}:
TrackingError
tr ┼ WeightsTracking
│ fees ┼ nothing
│ w ┼ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.5, 0.5]
│ fixed ┴ Bool: false
err ┼ Float64: 0.01
alg ┼ L2Tracking
│ ddof ┴ Int64: 1Related
sourcePortfolioOptimisers.factory Method
factory(tr::WeightsTracking, w::VecNum)Construct a new WeightsTracking object with updated portfolio weights.
This function creates a new WeightsTracking instance by copying the fees from the input tr object and replacing the portfolio weights with w. The fees field is updated using the factory function on the existing fees and weights.
Arguments
tr: AWeightsTrackingobject to copy fees from.w: Portfolio weights.
Returns
tr::WeightsTracking: New tracking algorithm object with updated weights.
Details
Copies and updates the
feesfield usingfactory(tr.fees, tr.w).Replaces the
wfield with the provided weights.
Examples
julia> tr = WeightsTracking(; fees = Fees(; l = 0.002), w = [0.5, 0.5])
WeightsTracking
fees ┼ Fees
│ tn ┼ nothing
│ l ┼ Float64: 0.002
│ s ┼ nothing
│ fl ┼ nothing
│ fs ┼ nothing
│ kwargs ┴ @NamedTuple{atol::Float64}: (atol = 1.0e-8,)
w ┼ Vector{Float64}: [0.5, 0.5]
fixed ┴ Bool: false
julia> PortfolioOptimisers.factory(tr, [0.6, 0.4])
WeightsTracking
fees ┼ Fees
│ tn ┼ nothing
│ l ┼ Float64: 0.002
│ s ┼ nothing
│ fl ┼ nothing
│ fs ┼ nothing
│ kwargs ┴ @NamedTuple{atol::Float64}: (atol = 1.0e-8,)
w ┼ Vector{Float64}: [0.6, 0.4]
fixed ┴ Bool: false
julia> tr = WeightsTracking(; fees = Fees(; l = 0.002), w = [0.5, 0.5], fixed = true)
WeightsTracking
fees ┼ Fees
│ tn ┼ nothing
│ l ┼ Float64: 0.002
│ s ┼ nothing
│ fl ┼ nothing
│ fs ┼ nothing
│ kwargs ┴ @NamedTuple{atol::Float64}: (atol = 1.0e-8,)
w ┼ Vector{Float64}: [0.5, 0.5]
fixed ┴ Bool: true
julia> PortfolioOptimisers.factory(tr, [0.1, 0.1])
WeightsTracking
fees ┼ Fees
│ tn ┼ nothing
│ l ┼ Float64: 0.002
│ s ┼ nothing
│ fl ┼ nothing
│ fs ┼ nothing
│ kwargs ┴ @NamedTuple{atol::Float64}: (atol = 1.0e-8,)
w ┼ Vector{Float64}: [0.5, 0.5]
fixed ┴ Bool: trueRelated
source