Tracking
Public
PortfolioOptimisers.SOCTracking Type
struct SOCTracking{T1} <: NormTracking
ddof::T1
endSecond-order cone (SOC) norm-based tracking formulation.
SOCTracking 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.
Fields
ddof: Degrees of freedom adjustment.
Constructor
SOCTracking(; ddof::Integer = 1)Validation
0 <= ddof.
Examples
julia> SOCTracking()
SOCTracking
ddof ┴ Int64: 1Related
sourcePortfolioOptimisers.SquaredSOCTracking Type
struct SquaredSOCTracking{T1} <: NormTracking
ddof::T1
endSecond-order cone (SOC) squared norm-based tracking formulation.
SquaredSOCTracking 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.
Fields
ddof: Degrees of freedom adjustment for scaling.
Constructors
SquaredSOCTracking(; ddof::Integer = 1)ddof: Sets the degrees of freedom adjustment.
Validation
0 <= ddof.
Examples
julia> SquaredSOCTracking()
SquaredSOCTracking
ddof ┴ Int64: 1Related
sourcePortfolioOptimisers.NOCTracking Type
struct NOCTracking <: NormTracking endNorm-one (NOC) tracking formulation.
NOCTracking 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.
Examples
julia> NOCTracking()
NOCTracking()Related
sourcePortfolioOptimisers.IndependentVariableTracking Type
struct IndependentVariableTracking <: VariableTracking endIndependent variable-based tracking formulation.
IndependentVariableTracking tracks the independent variables of a measurement.
Related
sourcePortfolioOptimisers.DependentVariableTracking Type
struct DependentVariableTracking <: VariableTracking endDependent variable-based tracking formulation.
DependentVariableTracking tracks the measurement.
Related
sourcePortfolioOptimisers.WeightsTracking Type
struct WeightsTracking{T1, T2} <: AbstractTrackingAlgorithm
fees::T1
w::T2
endAsset 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: Optional fees estimator or result to apply to the weights tracking.w: Portfolio weights (vector of real numbers).
Constructor
WeightsTracking(; fees::Option{<:Fees} = nothing, w::VecNum)Validation
!isempty(w).
Examples
julia> WeightsTracking(; w = [0.5, 0.5])
WeightsTracking
fees ┼ nothing
w ┴ Vector{Float64}: [0.5, 0.5]Related
sourcePortfolioOptimisers.ReturnsTracking Type
struct ReturnsTracking{T1} <: AbstractTrackingAlgorithm
w::T1
endReturns-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 of real numbers).
Constructor
ReturnsTracking(; w::VecNum)Validation
!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{T1, T2, T3} <: AbstractTracking
tr::T1
err::T2
alg::T3
endTracking 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 algorithm object.err: Tracking error value.alg: Tracking formulation algorithm.
Constructor
TrackingError(; tr::AbstractTrackingAlgorithm, err::Number = 0.0,
alg::NormTracking = SOCTracking())Validation
isfinite(err)anderr >= 0.
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]
err ┼ Float64: 0.01
alg ┼ SOCTracking
│ ddof ┴ Int64: 1Related
sourcePortfolioOptimisers.TrackingFormulation Type
abstract type TrackingFormulation <: AbstractAlgorithm endAbstract supertype for all tracking formulation algorithm types in PortfolioOptimisers.jl.
All concrete types representing tracking formulation algorithms (such as norm-based or variable-based tracking) should subtype TrackingFormulation. This enables a consistent, composable interface for tracking error computation, constraint generation, and related portfolio analytics.
Related
sourcePrivate
PortfolioOptimisers.AbstractTracking Type
abstract type AbstractTracking <: AbstractResult endAbstract supertype for all tracking result types in PortfolioOptimisers.jl.
All concrete types representing tracking error or tracking constraint results should subtype AbstractTracking. This enables a consistent, composable interface for tracking error measurement, tracking constraint generation, and related portfolio analytics.
Related
sourcePortfolioOptimisers.AbstractTrackingAlgorithm Type
abstract type AbstractTrackingAlgorithm <: AbstractAlgorithm endAbstract supertype for all tracking algorithm types in PortfolioOptimisers.jl.
All concrete types representing tracking algorithms (such as weights or returns tracking) should subtype AbstractTrackingAlgorithm. This enables a consistent, composable interface for tracking error computation, tracking constraint generation, and related portfolio analytics.
Related
sourcePortfolioOptimisers.VecTr Type
const VecTr = AbstractVector{<:AbstractTracking}Alias for a vector of tracking result types.
Related Types
sourcePortfolioOptimisers.Tr_VecTr Type
const Tr_VecTr = Union{<:AbstractTracking, <:VecTr}Union type for a single tracking result or a vector of tracking results.
Related Types
sourcePortfolioOptimisers.NormTracking Type
abstract type NormTracking <: TrackingFormulation endAbstract supertype for all norm-based tracking formulation algorithms in PortfolioOptimisers.jl.
All concrete types representing norm-based tracking algorithms (such as second-order cone or norm-one tracking) should subtype NormTracking. This enables a consistent, composable interface for tracking error computation and constraint generation using norm-based formulations.
Related
sourcePortfolioOptimisers.VariableTracking Type
abstract type VariableTracking <: TrackingFormulation endAbstract supertype for all variable-based tracking formulation algorithms in PortfolioOptimisers.jl.
All concrete types representing variable-based tracking algorithms (such as independent or dependent variable tracking) should subtype VariableTracking. This enables a consistent, composable interface for tracking error computation and constraint generation using variable-based formulations.
Related
sourcePortfolioOptimisers.norm_tracking Function
norm_tracking(f::SOCTracking, a, b; N::Option{<:Number} = nothing)
norm_tracking(f::SquaredSOCTracking, a, b; N::Option{<:Number} = nothing)
norm_tracking(::NOCTracking, a, b; N::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 SOCTracking, squared Euclidean (L2) norm for SquaredSOCTracking, or the L1 (norm-one) distance for NOCTracking. The error is optionally scaled by the number of assets and degrees of freedom for SOC, or by the number of assets for NOC.
Arguments
f: Tracking formulation algorithm.a: Portfolio weights.b: Benchmark weights.N: Optional number of assets.
Returns
err::Number: Norm-based tracking error.
Details
For
SOCTracking, computesnorm(a - b, 2) / sqrt(N - f.ddof)ifNis provided, else unscaled.For
SquaredSOCTracking, computesnorm(a - b, 2)^2 / (N - f.ddof)ifNis provided, else unscaled.For
NOCTracking, computesnorm(a - b, 1) / NifNis provided, else unscaled.
Examples
julia> PortfolioOptimisers.norm_tracking(SOCTracking(), [0.5, 0.5], [0.6, 0.4], 2)
0.14142135623730948
julia> PortfolioOptimisers.norm_tracking(NOCTracking(), [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 provided, 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.tracking_view Function
tracking_view(::Nothing, ::Any)Return a nothing value for tracking view when the input tracking object is nothing.
Used as a fallback method for missing tracking constraints or estimators, ensuring composability and uniform interface handling in constraint processing workflows.
Arguments
::Nothing: Indicates absence of a tracking object.::Any: Index or argument (ignored).
Returns
nothing.
Details
Used to propagate
nothingin tracking view operations.Ensures interface consistency for missing tracking objects.
Related
sourcetracking_view(tr::WeightsTracking, i)Return a view of a WeightsTracking object for the given index or indices.
This function creates a new WeightsTracking instance by extracting a view of the fees and portfolio weights fields at the specified index or indices. This enables efficient subsetting and composability for tracking algorithms in portfolio analytics workflows.
Arguments
tr: AWeightsTrackingobject containing fees and portfolio weights.i: Index or indices to subset the fees and weights.
Returns
tr::WeightsTracking: New tracking algorithm object with fees and weights viewed ati.
Details
Uses
fees_viewto subset thefeesfield.Uses
viewto subset thewfield.Returns a new
WeightsTrackingobject with the subsetted fields.
Examples
julia> tr = WeightsTracking(; w = [0.5, 0.5, 0.6]);
julia> PortfolioOptimisers.tracking_view(tr, 2:3)
WeightsTracking
fees ┼ nothing
w ┴ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.5, 0.6]Related
sourcetracking_view(tr::ReturnsTracking, ::Any)Return a view of a ReturnsTracking object.
This function returns the input ReturnsTracking object unchanged. It is used to provide a consistent interface for tracking view operations on returns-based tracking algorithms.
Arguments
tr: AReturnsTrackingobject containing benchmark portfolio returns.::Any: Index or argument (ignored).
Returns
tr::ReturnsTracking: The input tracking algorithm object.
Details
Returns the input object unchanged.
Ensures interface consistency for tracking view operations.
Related
sourcetracking_view(tr::TrackingError, i)Return a view of a TrackingError object for the given index or indices.
This function creates a new TrackingError instance by extracting a view of the underlying tracking algorithm at the specified index or indices. The error value and formulation algorithm are preserved. This enables efficient subsetting and composability for tracking error results in portfolio analytics workflows.
Arguments
tr: ATrackingErrorobject containing a tracking algorithm, error value, and formulation algorithm.i: Index or indices to subset the underlying tracking algorithm.
Returns
tre::TrackingError: New tracking error result object with the underlying tracking algorithm viewed ati.
Details
Uses
tracking_viewto subset thetrfield.Preserves the
errandalgfields.Returns a new
TrackingErrorobject with the subsetted tracking algorithm.
Examples
julia> tr = WeightsTracking(; w = [0.5, 0.5, 0.6]);
julia> err = TrackingError(; tr = tr, err = 0.01)
TrackingError
tr ┼ WeightsTracking
│ fees ┼ nothing
│ w ┴ Vector{Float64}: [0.5, 0.5, 0.6]
err ┼ Float64: 0.01
alg ┼ SOCTracking
│ ddof ┴ Int64: 1
julia> PortfolioOptimisers.tracking_view(err, 2:3)
TrackingError
tr ┼ WeightsTracking
│ fees ┼ nothing
│ w ┴ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.5, 0.6]
err ┼ Float64: 0.01
alg ┼ SOCTracking
│ ddof ┴ Int64: 1Related
sourcetracking_view(tr::VecTr, args...)Return a vector of tracking views for each element in a vector of tracking results.
This function applies tracking_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 eachtracking_viewcall.
Returns
tres::Vector{<:AbstractTracking}: Vector of tracking view results.
Details
Applies
tracking_viewto each element in the input vector.Passes all additional arguments to each call.
Returns a vector of the results.
Related
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 (vector of real numbers).
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]
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]Related
sourcePortfolioOptimisers.factory Method
factory(tr::ReturnsTracking, ::Any)Return the input ReturnsTracking object unchanged.
This function provides a consistent interface for updating or copying returns-based tracking algorithms. It is used for composability in portfolio analytics workflows where the tracking object does not require modification.
Arguments
tr: AReturnsTrackingobject containing benchmark portfolio returns.::Any: Index or argument (ignored).
Returns
tr::ReturnsTracking: The input tracking algorithm object.
Details
Returns the input object unchanged.
Ensures interface consistency for factory operations.
Related
source