A Result resumes an online run: private API
PortfolioOptimisers.OptimiserResume — Type
OptimiserResume = Resume{<:MultiPeriodPredictionResult{<:Any, <:Any, <:Any, <:NonFiniteAllocationOptimisationEstimator}}Alias for a Resume whose Result carries an optimiser: the declaration the optimiser doors take.
Related
PortfolioOptimisers.resume_fold_count — Function
resume_fold_count(opt, rd, train_idx) -> IntFinds 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 overrd.
Validation
- The carrier holds timestamps. An
ArgumentErroris thrown otherwise. - The state holds timestamps. An
ArgumentErroris thrown otherwise. - Some fold's training window ends at the state's last held timestamp. An
ArgumentErroris thrown otherwise. - The held timestamps equal the carrier's over the held span. An
ArgumentErroris thrown otherwise.
Returns
n_old::Int: The index of the last fold the run holds.
Related
PortfolioOptimisers.assert_resume_scheme — Function
assert_resume_scheme(cv::WFCVER)
assert_resume_scheme(cv::CVER)Refuses a scheme a Resume cannot re-enter, by name: one that is not a walk-forward, and a walk-forward with no Fold Fit.
Related
PortfolioOptimisers.assert_resume_folds — Function
assert_resume_folds(n_old::Integer, n::Integer)Refuses a carrier that adds no fold to the run a Resume continues.
Related
PortfolioOptimisers.assert_resume_full_fold — Function
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
PortfolioOptimisers.cv_resume_info — Function
cv_resume_info(n_old::Integer, n::Integer)Build the informational message emitted when a cross-validation run resumes from a Result, the counterpart of cv_online_info for the resumed arm of online_folds.
Returns
msg::String: The message.
Related
PortfolioOptimisers.copy_states — Function
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
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
PortfolioOptimisers.copy_state — Function
copy_state(state::AbstractPartialFitState)
copy_state(::Nothing)The cache arm of copy_states: a state is copied, and no state stays none.
Related
PortfolioOptimisers.carrier_timestamps — Function
carrier_timestamps(rd::ReturnsResult)
carrier_timestamps(pr::PricesResult)The timestamps of a carrier, or nothing when it holds none.
Related
PortfolioOptimisers.context_timestamps — Function
context_timestamps(cache::ReturnsBufferState)
context_timestamps(::Nothing)The timestamps a Fold Context holds; none before the first step.
Related
PortfolioOptimisers.is_time_dependent — Method
is_time_dependent(r::Resume)
needs_previous_weights(r::Resume)
assert_time_dependent_fold_count(r::Resume, n::Integer, all_binds::Bool = true)The fold loop reads its three traits off the root it is handed, and a Resume root answers for the estimator its Result carries: the loop resolves the declaration at entry, and the per-fold copy is made of that estimator.
Related
Base.vcat — Method
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 ofa.
Validation
- Both carry timestamps and
aends beforebstarts. AnArgumentErroris thrown otherwise.
Returns
res::MultiPeriodPredictionResult: The stacked Result.
Related