Skip to content
11

Tracking

Public

PortfolioOptimisers.L2Tracking Type
julia
struct L2Tracking{T1} <: NormTracking
    ddof::T1
end

Second-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.

Fields

  • ddof: Degrees of freedom adjustment.

Constructor

julia
L2Tracking(; ddof::Integer = 1)

Validation

  • 0 <= ddof.

Examples

julia
julia> L2Tracking()
L2Tracking
  ddof ┴ Int64: 1

Related

source
PortfolioOptimisers.SquaredL2Tracking Type
julia
struct SquaredL2Tracking{T1} <: NormTracking
    ddof::T1
end

Second-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.

Fields

  • ddof: Degrees of freedom adjustment for scaling.

Constructors

julia
SquaredL2Tracking(; ddof::Integer = 1)
  • ddof: Sets the degrees of freedom adjustment.

Validation

  • 0 <= ddof.

Examples

julia
julia> SquaredL2Tracking()
SquaredL2Tracking
  ddof ┴ Int64: 1

Related

source
PortfolioOptimisers.L1Tracking Type
julia
struct L1Tracking <: NormTracking end

Norm-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.

Examples

julia
julia> L1Tracking()
L1Tracking()

Related

source
PortfolioOptimisers.IndependentVariableTracking Type
julia
struct IndependentVariableTracking <: VariableTracking end

Independent variable-based tracking formulation.

IndependentVariableTracking tracks the independent variables of a measurement.

Related

source
PortfolioOptimisers.DependentVariableTracking Type
julia
struct DependentVariableTracking <: VariableTracking end

Dependent variable-based tracking formulation.

DependentVariableTracking tracks the measurement.

Related

source
PortfolioOptimisers.WeightsTracking Type
julia
struct WeightsTracking{T1, T2, T3} <: AbstractTrackingAlgorithm
    fees::T1
    w::T2
    fixed::T3
end

Asset 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).

  • fixed: Boolean indicating whether the algorithm is fixed (does not update with new weights) or variable (updates with new weights).

Constructor

julia
WeightsTracking(; fees::Option{<:Fees} = nothing, w::VecNum, fixed::Bool = false)

Validation

  • !isempty(w).

Examples

julia
julia> WeightsTracking(; w = [0.5, 0.5])
WeightsTracking
   fees ┼ nothing
      w ┼ Vector{Float64}: [0.5, 0.5]
  fixed ┴ Bool: false

Related

source
PortfolioOptimisers.ReturnsTracking Type
julia
struct ReturnsTracking{T1} <: AbstractTrackingAlgorithm
    w::T1
end

Returns-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

julia
ReturnsTracking(; w::VecNum)

Validation

  • !isempty(w).

Examples

julia
julia> ReturnsTracking(; w = [0.01, 0.02, 0.03])
ReturnsTracking
  w ┴ Vector{Float64}: [0.01, 0.02, 0.03]

Related

source
PortfolioOptimisers.TrackingError Type
julia
struct TrackingError{T1, T2, T3} <: AbstractTracking
    tr::T1
    err::T2
    alg::T3
end

Tracking 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

julia
TrackingError(; tr::AbstractTrackingAlgorithm, err::Number = 0.0,
              alg::NormTracking = L2Tracking())

Validation

  • isfinite(err) and err >= 0.

Examples

julia
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: 1

Related

source
PortfolioOptimisers.TrackingFormulation Type
julia
abstract type TrackingFormulation <: AbstractAlgorithm end

Abstract 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

source

Private

PortfolioOptimisers.AbstractTracking Type
julia
abstract type AbstractTracking <: AbstractResult end

Abstract 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

source
PortfolioOptimisers.AbstractTrackingAlgorithm Type
julia
abstract type AbstractTrackingAlgorithm <: AbstractAlgorithm end

Abstract 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.

Related

source
PortfolioOptimisers.VecTr Type
julia
const VecTr = AbstractVector{<:AbstractTracking}

Alias for a vector of tracking result types.

Related Types

source
PortfolioOptimisers.Tr_VecTr Type
julia
const Tr_VecTr = Union{<:AbstractTracking, <:VecTr}

Union type for a single tracking result or a vector of tracking results.

Related Types

source
PortfolioOptimisers.NormTracking Type
julia
abstract type NormTracking <: TrackingFormulation end

Abstract 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

source
PortfolioOptimisers.VariableTracking Type
julia
abstract type VariableTracking <: TrackingFormulation end

Abstract 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

source
PortfolioOptimisers.norm_tracking Function
julia
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.

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, computes LinearAlgebra.norm(a - b, 2) / sqrt(T - f.ddof) if T is not nothing, else unscaled.

  • For SquaredL2Tracking, computes LinearAlgebra.norm(a - b, 2)^2 / (T - f.ddof) if T is not nothing, else unscaled.

  • For L1Tracking, computes LinearAlgebra.norm(a - b, 1) / T if T is not nothing, else unscaled.

Examples

julia
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.09999999999999998

Related

source
PortfolioOptimisers.tracking_benchmark Function
julia
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: WeightsTracking tracking algorithm containing benchmark weights and optional fees.

  • X: Asset return matrix (assets × periods).

Returns

  • b::VecNum: Net benchmark portfolio returns.

Details

  • If tr.fees is not nothing, net returns are computed using calc_net_returns.

  • Otherwise, returns are computed as X * tr.w.

Examples

julia
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.035

Related

source
julia
tracking_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: ReturnsTracking tracking algorithm containing benchmark returns.

  • args...: For interface compatibility (ignored).

Returns

  • b::VecNum: Benchmark portfolio returns.

Examples

julia
julia> tr = ReturnsTracking(; w = [0.01, 0.02, 0.03]);

julia> PortfolioOptimisers.tracking_benchmark(tr)
3-element Vector{Float64}:
 0.01
 0.02
 0.03

Related

source
PortfolioOptimisers.tracking_view Function
julia
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 nothing in tracking view operations.

  • Ensures interface consistency for missing tracking objects.

Related

source
julia
tracking_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.

Arguments

  • tr: A WeightsTracking object 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 at i.

Details

  • Uses fees_view to subset the fees field.

  • Uses view to subset the w field.

  • Returns a new WeightsTracking object with the subsetted fields.

Examples

julia
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]
  fixed ┴ Bool: false

julia> tr = WeightsTracking(; w = [0.5, 0.5, 0.6], fixed = true);

julia> PortfolioOptimisers.tracking_view(tr, 2:3)
WeightsTracking
   fees ┼ nothing
      w ┼ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.5, 0.6]
  fixed ┴ Bool: true

Related

source
julia
tracking_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: A ReturnsTracking object 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

source
julia
tracking_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.

Arguments

  • tr: A TrackingError object 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 at i.

Details

  • Uses tracking_view to subset the tr field.

  • Preserves the err and alg fields.

  • Returns a new TrackingError object with the subsetted tracking algorithm.

Examples

julia
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]
      │   fixed ┴ Bool: false
  err ┼ Float64: 0.01
  alg ┼ L2Tracking
      │   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]
      │   fixed ┴ Bool: false
  err ┼ Float64: 0.01
  alg ┼ L2Tracking
      │   ddof ┴ Int64: 1

Related

source
julia
tracking_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 each tracking_view call.

Returns

  • tres::Vector{<:AbstractTracking}: Vector of tracking view results.

Details

  • Applies tracking_view to each element in the input vector.

  • Passes all additional arguments to each call.

  • Returns a vector of the results.

Related

source
PortfolioOptimisers.factory Method
julia
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

Returns

  • tr::WeightsTracking: New tracking algorithm object with updated weights.

Details

  • Copies and updates the fees field using factory(tr.fees, tr.w).

  • Replaces the w field with the provided weights.

Examples

julia
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: true

Related

source
PortfolioOptimisers.factory Method
julia
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: A ReturnsTracking object 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