Tracking: private API

PortfolioOptimisers.VariableTracking — Type
abstract type VariableTracking <: AbstractAlgorithm

Abstract 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

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

  1. Answer "" when est is a ReturnsTracking, and nothing when it is an AbstractPartialFitState.
  2. When est is a TimeDependent, answer the path in its default, after the name default.
  3. Walk every field of est in order, and find the path in each field with this function.
  4. Answer the first path found, with the field name before it, as tree_path joins them.
  5. Answer nothing when 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, "" when est is itself one, or nothing.

Related

source
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

  1. When n > 1, find the first returns series in the tree of est with returns_tracking_path.
  2. Refuse est when 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 of est holds a ReturnsTracking. The function throws an ArgumentError that names the field otherwise.

Returns

  • nothing.

Related

source
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_risk binds it on a ReturnsResult.
  • 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

  1. When x holds no data benchmark, or rd is not a ReturnsResult, return x unchanged. A data benchmark of a reader with no returns data stays unbound, and tracking_benchmark refuses it there.
  2. On a DataBenchmarkTracking, refuse an rd that carries no benchmark. Otherwise return a new DataBenchmarkTracking that holds rd.B.
  3. On a TrackingError, bind its tr field.
  4. 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

Returns

  • x': x with every data benchmark bound to rd.B, or x itself 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) === twtrue

Related

source