Skip to content
18

Tracking

Public

PortfolioOptimisers.IndependentVariableTracking Type
julia
struct IndependentVariableTracking <: VariableTracking

Independent variable-based tracking formulation.

IndependentVariableTracking tracks the independent variables of a measurement.

Constructors

julia
IndependentVariableTracking() -> IndependentVariableTracking

Examples

julia
julia> IndependentVariableTracking()
IndependentVariableTracking()

Related

source
PortfolioOptimisers.DependentVariableTracking Type
julia
struct DependentVariableTracking <: VariableTracking

Dependent variable-based tracking formulation.

DependentVariableTracking tracks the measurement.

Constructors

julia
DependentVariableTracking() -> DependentVariableTracking

Examples

julia
julia> DependentVariableTracking()
DependentVariableTracking()

Related

source
PortfolioOptimisers.WeightsTracking Type
julia
struct WeightsTracking{__T_fees, __T_w, __T_fixed} <: AbstractTrackingAlgorithm

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: Fees estimator or result.

  • w: Current portfolio weights vector.

  • fixed: Whether the estimator is fixed and does not update with new weights.

Constructors

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

Validation

  • !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:

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{__T_w} <: AbstractTrackingAlgorithm

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.

Constructors

julia
ReturnsTracking(;
    w::VecNum
) -> ReturnsTracking

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{__T_tr, __T_err, __T_alg} <: AbstractTracking

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 error constraint estimator.

  • err: Tracking error tolerance.

  • alg: Tracking formulation algorithm.

Constructors

julia
TrackingError(;
    tr::AbstractTrackingAlgorithm,
    err::Number = 0.0,
    alg::NormError = L2Norm()
) -> TrackingError

Validation

  • isfinite(err) and err >= 0.

Propagated parameters

When factory is called on this type, the following @fprop-tagged fields are automatically propagated:

  • tr: Recursively updated via factory.

View parameters

When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:

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 ┼ L2Norm
      │   ddof ┴ Int64: 1

Related

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

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

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

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.

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 matrix X.

  • factory(tr::AbstractTrackingAlgorithm, w::VecNum) -> AbstractTrackingAlgorithm: Construct a new instance with updated portfolio weights w.

  • port_opt_view(tr::AbstractTrackingAlgorithm, i) -> AbstractTrackingAlgorithm: Create a view of the tracking algorithm for the subset of assets at indices i.

Arguments

  • tr: The concrete tracking algorithm instance.

  • X: Covariance-like or correlation-like matrix features × features.

  • w: New portfolio weights.

  • i: Index or indices for asset subset.

Returns

  • b::VecNum: Benchmark returns (for tracking_benchmark).

  • tr::AbstractTrackingAlgorithm: Updated or viewed tracking algorithm (for factory, port_opt_view).

Examples

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

Related

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

Alias for a vector of tracking result types.

Related

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

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

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.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.port_opt_view Method
julia
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 each port_opt_view call.

Returns

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

Details

  • Applies port_opt_view to each element in the input vector.

  • Passes all additional arguments to each call.

  • Returns a vector of the results.

Examples

julia
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, L2Norm{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 ┼ L2Norm
      │   ddof ┴ Int64: 1

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.narrow_optimiser_vector Function
julia
narrow_optimiser_vector(opti::AbstractVector) -> Any

Narrow a vector of optimisers so element-level TimeDependent schedules type-check.

A literal like [MeanRisk(), TimeDependent(…)] infers eltype AbstractEstimator, which the VecOptE_Opt_TD bound rejects even though every element is admissible. Vectors already matching the bound pass through unchanged; otherwise every element is checked against OptE_Opt_TD and the vector is rebuilt with the tightest element-type union. A field-level schedule passes through untouched.

Related

source