Skip to content
6

Tracking

Public

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

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

julia
SOCTracking(; ddof::Integer = 1)

Validation

  • 0 <= ddof.

Examples

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

Related

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

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

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

Validation

  • 0 <= ddof.

Examples

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

Related

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

Norm-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
julia> NOCTracking()
NOCTracking()

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} <: AbstractTrackingAlgorithm
    fees::T1
    w::T2
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).

Constructor

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

Validation

  • !isempty(w).

Examples

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

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 = SOCTracking())

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]
  err ┼ Float64: 0.01
  alg ┼ SOCTracking
      │   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 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

source

Private

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

Abstract 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

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

Abstract 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

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

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

Abstract 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

source
PortfolioOptimisers.norm_tracking Function
julia
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, computes norm(a - b, 2) / sqrt(N - f.ddof) if N is provided, else unscaled.

  • For SquaredSOCTracking, computes norm(a - b, 2)^2 / (N - f.ddof) if N is provided, else unscaled.

  • For NOCTracking, computes norm(a - b, 1) / N if N is provided, else unscaled.

Examples

julia
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.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 provided, 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. This enables efficient subsetting and composability for tracking algorithms in portfolio analytics workflows.

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]

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. This enables efficient subsetting and composability for tracking error results in portfolio analytics workflows.

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]
  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: 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

  • tr: A WeightsTracking object 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 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]

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

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