Tracking
Public
PortfolioOptimisers.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::NormError = L2Norm()
) -> 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 ┼ L2Norm
│ 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.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.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, 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: 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
sourcePortfolioOptimisers.narrow_optimiser_vector Function
narrow_optimiser_vector(opti::AbstractVector) -> AnyNarrow 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