A Result resumes an online run: private API

PortfolioOptimisers.resume_fold_countFunction
resume_fold_count(opt, rd, train_idx) -> Int

Finds the fold a Resume continues from, by the timestamps, and refuses a carrier whose rows do not carry the state.

The state's last held timestamp names the row it folded through, and the fold whose training window ends at that row is the last fold the run holds: n_old is that fold's index in the scheme's enumeration over the extended carrier, and the loop continues from n_old + 1. The count is read off the state and not off length(res.pred), because a resumed Result holds the new folds only, and the chain Resume(res2) must skip every fold before it. Both the carrier and the state must hold timestamps, and every timestamp the state holds must equal its row of the carrier: held == carrier_timestamps(rd)[(r - h + 1):r] for r = last(train_idx[n_old]) and h the held count. That is exact over the held span at O(h), and it is the one check that pins a prefix — a row dropped or inserted before r moves the carrier's row r, and a changed scheme moves every training end — under a cap, where the state holds no total, as much as without one.

Arguments

  • opt: The stepped estimator the Result carries.
  • rd: The carrier of the full history extended.
  • train_idx: The training windows of every fold the scheme enumerates over rd.

Validation

  • The carrier holds timestamps. An ArgumentError is thrown otherwise.
  • The state holds timestamps. An ArgumentError is thrown otherwise.
  • Some fold's training window ends at the state's last held timestamp. An ArgumentError is thrown otherwise.
  • The held timestamps equal the carrier's over the held span. An ArgumentError is thrown otherwise.

Returns

  • n_old::Int: The index of the last fold the run holds.

Related

source
PortfolioOptimisers.assert_resume_full_foldFunction
assert_resume_full_fold(test_idx::VecInt, pred::PredictionResult, ts)

Refuses a Resume whose last held fold was partial: its test window under the longer history runs past the last row the fold predicted.

With reduce_test = true the last fold of the old run predicted the rows left over at the end of the carrier, which under the longer history are the first part of a full window — the same training end, the same weights, too short a span. Skipping it loses rows and completing it needs a mid-window entry, so it is terminal. The check compares timestamps, not counts — the fold's last predicted timestamp against the carrier's at the window's last row — because a price-level window of L rows predicts L - 1 returns, and the timestamp of the last one is the last price's either way. The message names the two-resume workaround.

Arguments

  • test_idx: The test window of the last held fold, over the extended carrier.
  • pred: The last held fold's prediction.
  • ts: The extended carrier's timestamps.

Related

source
PortfolioOptimisers.copy_statesFunction
copy_states(est)
copy_states(td::TimeDependent)

Copies every partial-fit state an estimator tree carries, and returns the tree rebuilt around the copies.

The walk of online_entry_state with a rebuild in place of a report: it copies est's own cache when it holds a state, descends into every estimator-valued field (estimator_fields), and rebuilds each host whose fields moved through rebuild_estimator. A host nothing under changed is returned as it is. A TimeDependent schedule is returned unchanged, because its entries are batch configuration resolved per fold and the loop threads no state through them, and so is anything that is not an estimator.

Two callers take it. Resume calls it once at entry, so the Result it holds is never written: partial_fit! promises nothing about a kept estimator, a buffer appends into its backing array, and every state answers Base.copy. The generic method of partial_fit calls it before every fold, so the value form holds the same promise on a host that folds through the states of its members — a HighOrderPriorEstimator, a hierarchical optimiser — as on a leaf that carries its own cache.

Arguments

  • est: The estimator, or any value a field holds.

Returns

  • est: The tree, with every state copied.

Related

source
copy_states(p::Pipeline)

Copies every partial-fit state a Pipeline carries — its own cache, and the states under every step through copy_step_states — and rebuilds the pipeline around the copies, for Resume.

Related

source
Base.vcatMethod
Base.vcat(a::MultiPeriodPredictionResult, b::MultiPeriodPredictionResult)

Stacks the folds of a run and of its resume into one Result, for scoring.

pred is concatenated and mrd re-stacked by the constructor; the Result carries a's id and b's opt, the estimator the later run threaded. The two must abut in time: the last row of a is before the first row of b, both read off the stacked carriers' timestamps, so two Results that overlap, or that come from carriers without timestamps, are refused by name.

Arguments

  • a: The earlier Result.
  • b: The later Result, a resume of a.

Validation

  • Both carry timestamps and a ends before b starts. An ArgumentError is thrown otherwise.

Returns

  • res::MultiPeriodPredictionResult: The stacked Result.

Related

source