Tracking: private API
PortfolioOptimisers.AbstractTracking — Type
abstract type AbstractTracking <: AbstractResultAbstract supertype of the tracking Results.
A tracking Result holds a benchmark and a bound on the distance of the portfolio from it. TrackingError bounds a norm of the difference of the return series, and RiskTrackingError bounds a difference of risks.
Related
PortfolioOptimisers.VecTr — Type
PortfolioOptimisers.Tr_VecTr — Type
const Tr_VecTr = Union{AbstractTracking, VecTr}Alias for one tracking Result or a vector of tracking Results.
Related
PortfolioOptimisers.VariableTracking — Type
abstract type VariableTracking <: AbstractAlgorithmAbstract supertype of the variable tracking algorithms.
A variable tracking algorithm states the quantity that a risk tracking measure compares with its benchmark. The quantity is the weights that the risk measure reads, or the risk that the risk measure returns. The norm that measures the difference is a separate choice. A tracking measure holds the norm in a different field, as a NormError.
Related
PortfolioOptimisers.returns_tracking_path — Function
returns_tracking_path(est)
returns_tracking_path(::ReturnsTracking)
returns_tracking_path(v::AbstractVector)
returns_tracking_path(p::Pair)
returns_tracking_path(td::TimeDependent)
returns_tracking_path(::AbstractPartialFitState)
returns_tracking_path(::Any)Names the first field of an estimator tree that holds a ReturnsTracking, or answers nothing.
A returns series is constant after construction, and it aligns only with the rows of one batch fit. These callers use this walk to refuse it:
- The online step of an optimiser.
- A batch cross-validation with more than one fold, through
assert_folds_track_no_series. - The two row readers of an online portfolio selection head, the risk ceiling of a
ProgrammeAllocationSetand aRiskLoss.
The walk reads every field of an estimator, of a Result and of an algorithm. A TrackingError is a Result, a TrackingRiskMeasure is an estimator, and a ProgrammeAllocationSet is an algorithm that holds tracking errors. A vector answers with the index of its element in brackets, and a Pair answers through its value, as element_path joins them. A series at the root answers "", the empty path. A numeric array and every other value answer nothing.
A partial-fit state answers nothing without a walk. It holds observations and folded copies of the members of its estimator, and never a configuration that a caller writes. The walk already reads each member through the estimator. The online step of an optimiser calls the walk at every step, so a walk into the buffers costs one dispatch for each of their fields at each step.
A TimeDependent schedule answers through its default only. Entry i of the schedule is the value of fold i alone, so the caller can give each fold a series of its own rows. The default is one value that every solve with no fold reads, so it can misalign as a field can.
Algorithm
- Answer
""whenestis aReturnsTracking, andnothingwhen it is anAbstractPartialFitState. - When
estis aTimeDependent, answer the path in itsdefault, after the namedefault. - Walk every field of
estin order, and find the path in each field with this function. - Answer the first path found, with the field name before it, as
tree_pathjoins them. - Answer
nothingwhen no field gives a path.
Arguments
est: The estimator, the Result, the algorithm, or any value a field holds.v: A vector that a field holds.p: A Pair that a vector holds.td: A schedule that a field holds.
Returns
path::Option{<:String}: The path of the first returns series found,""whenestis itself one, ornothing.
Related
PortfolioOptimisers.assert_folds_track_no_series — Function
assert_folds_track_no_series(est, n::Integer)Refuses a ReturnsTracking in the tree of est when a batch cross-validation runs more than one fold.
Each fold of a batch cross-validation refits on its own training rows. A returns series is constant after construction, so it covers the rows of one fold at most. The length check of tracking_benchmark cannot see the misalignment when the folds share one training length. The folds of a rolling walk-forward and of a KFold share one length, and the series then passes the check at every fold. So fold_loop calls this function once before the folds run, and the function refuses the series by the name of its field. The walk is returns_tracking_path, so the function also refuses the series of an online portfolio selection head. That head cuts the series to its first rows, which align only with a fold that starts at the first row.
One fold is one batch fit, so a series of its training rows aligns, and the function accepts it. An entry of a TimeDependent schedule is the value of one fold only, so the walk does not read it.
Algorithm
- When
n > 1, find the first returns series in the tree ofestwithreturns_tracking_path. - Refuse
estwhen there is one.
Arguments
est: The estimator that the fold loop takes.n: The number of folds.
Validation
- When
n > 1, no field in the tree ofestholds aReturnsTracking. The function throws anArgumentErrorthat names the field otherwise.
Returns
nothing.
Related
ReturnsTrackingDataBenchmarkTracking: The form that follows the rows, because each fold binds it to the benchmark of its training rows.returns_tracking_pathfold_loop
PortfolioOptimisers.bind_data_benchmark — Method
bind_data_benchmark(x, rd)
bind_data_benchmark(tr::DataBenchmarkTracking, rd::ReturnsResult)
bind_data_benchmark(tr::TrackingError, rd)
bind_data_benchmark(v::AbstractVector, rd)Bind every DataBenchmarkTracking that x holds to the benchmark B of the returns data rd.
A data benchmark has no series of its own, so each reader that holds the returns data binds it to the rows that the reader reads:
- An optimiser binds it at its entry.
- The value-level
expected_riskbinds it on aReturnsResult. - An online portfolio selection head binds it on the rows of its window.
The bind replaces a B bound earlier, so a benchmark never reads the rows of another reader.
The bind does not read the source of the prior. A data benchmark with a prior that states x_src = ExcessSource() subtracts the benchmark two times. The configuration alone shows this, so the constructor of the holder refuses the pair before any data arrives. See the table of combinations of AbstractTrackingAlgorithm.
The function rebuilds an object through its keyword constructor only when a part changes. The function returns an object that holds no data benchmark as itself, so === holds. The risk measures and the optimisers that hold a tracking object add their own methods.
Algorithm
- When
xholds no data benchmark, orrdis not aReturnsResult, returnxunchanged. A data benchmark of a reader with no returns data stays unbound, andtracking_benchmarkrefuses it there. - On a
DataBenchmarkTracking, refuse anrdthat carries no benchmark. Otherwise return a newDataBenchmarkTrackingthat holdsrd.B. - On a
TrackingError, bind itstrfield. - Bind each element of a vector, and return the vector itself when no element changes.
Arguments
x: The value to bind: a tracking algorithm, a tracking error, a risk measure, an optimiser, or a vector of them.rd: The returns data of the rows that the reader holds.
Validation
rd.Bis notnothingwhenxis aDataBenchmarkTracking. The function throws anArgumentErrorotherwise.
Returns
x':xwith every data benchmark bound tord.B, orxitself when it holds none.
Examples
julia> rd = ReturnsResult(; nx = ["A", "B"], X = [0.01 0.03; 0.02 -0.01], nb = ["BM"], B = [0.02, 0.0]);julia> te = TrackingError(; tr = DataBenchmarkTracking(), err = 0.01);julia> PortfolioOptimisers.bind_data_benchmark(te, rd).tr.B === rd.Btruejulia> tw = TrackingError(; tr = WeightsTracking(; w = [0.5, 0.5]));julia> PortfolioOptimisers.bind_data_benchmark(tw, rd) === twtrueRelated