Resume

The MultiPeriodPredictionResult of an online walk-forward stores the estimator as it was after the last training window. To continue the run, pass Resume(res) to cross_val_predict in place of the estimator, with the same walk-forward and the full history with the new rows at its end. The walk-forward skips every fold up to the one whose training window ends at the last row of the stored state. It adds the rows after that point to a copy of the state, and continues from the next fold. Each fold then gets the same weights that one run over the longer history gives. The result holds the new folds only, and vcat stacks a run and its resumes, so you can score them together.

PortfolioOptimisers.Resume — Type
struct Resume{__T_res, __T_opt} <: AbstractResult

Continues an online walk-forward from the folds that its Result holds, over a longer history.

Resume is a transient declaration in the estimator slot, like Online and TimeDependent. The MultiPeriodPredictionResult of an online run carries in opt the estimator that the fold loop threaded, folded through the last training end. Resume(res) hands that Result back to cross_val_predict, with the same scheme and the full history extended, which is the old returns data with the new rows appended. The loop skips the folds that the Result holds, folds the new rows into a copy of res.opt, and runs the folds after them. No warm-up runs. The resumed Result holds the new folds only and carries opt again, so it can be resumed in turn, and vcat stacks the two Results for scoring.

The oracle is the one-shot run. For an online scheme cv, a history rd_T and its extension rd_{T+k},

res  = cross_val_predict(mr, rd_T, cv)res2 = cross_val_predict(Resume(res), rd_{T+k}, cv)vcat(res.pred, res2.pred) ≈ cross_val_predict(mr, rd_{T+k}, cv).pred   # fold for fold

The weights agree to the tolerance of the moment layer and of the solver. The training returns that the call with no data rebuilds from the state agree exactly, under a cap too. Resume copies every state at entry, so res is never written. One Result can be resumed any number of times, and a terminal view does not change a later continuation.

cross_val_predict refuses a resume in five cases, each with an ArgumentError that names the cause.

  • The scheme is not an Online Scheme.
  • rd adds no fold.
  • rd or the state holds no timestamps, or the timestamps that the state holds differ from their rows of rd. An index-only caller attaches a synthetic calendar, ts = Date(1) .+ Day.(0:(T - 1)).
  • The last fold of the Result was partial. With reduce_test = true that fold predicted the rows left at the end of the old history, and in the longer history those rows are the first part of a full window. The fold can be neither skipped nor completed. Resume the same Result with reduce_test = true for the live view of the leftover rows, and resume it again with reduce_test = false when the rows arrive.
  • The head is an OnlinePortfolioSelection whose fees carry a turnover term, and the scheme has no Previous-Weights Source. The one-shot online arm refuses the same head.

The timestamp check reads the training ends of the scheme. It refuses a scheme with a different window, step or purge, because such a scheme moves the training ends. A change of the Weight Drift or of the Previous-Weights Source moves no training end, so the check does not see it. The new folds then run under the scheme handed, and the identity above does not hold. Under a cap the state holds its last rows only, and the check pins those rows and nothing before them.

The previous weights come from the Result alone. When no fold of res passes its weights on, for example because every fold of a short resumed Result failed, the first new fold gets no previous weights. The one-shot run hands it the last threadable fold of the earlier run instead. Resume vcat(old, res) in that case, because the stacked Result holds the earlier folds too.

Every state is an immutable struct of arrays, names, integers and a timestamp vector. The Result of an online run therefore round-trips through the stdlib Serialization as it stands, and the deserialised Result resumes to the same weights. That format is bound to the Julia version that wrote it, and the package gives no other format.

The constructor refuses a batch Result and a PopulationPredictionResult from a MultipleRandomised run. cross_val_predict refuses a scheme that is not a walk-forward, a walk-forward that is not an Online Scheme, and a search. A Pipeline resumes on the same terms, through the state that its row owner keeps.

Fields

  • res: The Result of the online run to continue, carrying the threaded estimator in opt.
  • opt: The estimator that res carries in opt, the same object. The Result does not carry the type of its estimator in a type parameter, so Resume carries it here, and the methods for an optimiser and for a Pipeline dispatch on it.

Constructors

Resume(res::MultiPeriodPredictionResult)Resume(; res::MultiPeriodPredictionResult)

opt is a derived field, so Accessors.set reads it again from the new res, and it refuses a patch of opt.

Validation

  • res.opt is not nothing. An ArgumentError is thrown otherwise, because a batch run threads no estimator.
  • res is not a PopulationPredictionResult. An ArgumentError is thrown otherwise.

Related

source
PortfolioOptimisers.cross_val_predict — Method
cross_val_predict(r::OptimiserResume, rd::ReturnsResult, cv::CVER; cols = :, ex = FLoops.ThreadedEx())
fit_and_predict(r::OptimiserResume, rd::ReturnsResult, cv::CVER, cv_res = split(cv, rd); cols = :, ex = FLoops.ThreadedEx(), id = nothing)

Continues an online walk-forward from a Result, over the full history extended.

The methods that take an optimiser in the estimator slot take a Resume too. cross_val_predict views rd by cols as the one-shot method views it, but it leaves the estimator of the Result as it is. That estimator was threaded over the view of the old run already, and its state refuses a different view at the first step. The Result that the methods return holds the new folds only.

Algorithm

  1. For cross_val_predict only, run assert_internal_optimiser and assert_external_optimiser on r.opt, and view rd by cols when cols is not :.
  2. Refuse a scheme that a Resume cannot re-enter, through assert_resume_scheme.
  3. Read train_idx and test_idx from the split of rd by cv, which fit_and_predict takes as cv_res, and refuse shuffled folds through assert_unshuffled_folds.
  4. Read the evaluation settings of cv through fold_evaluation, giving wd, pws, fa, store_weight_path and strict, and the drift of the held weights through held_weights_drift, giving hwd.
  5. Run fold_loop on r, which takes the resumed arm of online_folds. Each fold calls the one-fold fit_and_predict with its estimator, its test window, its previous weights and the settings of step 4, giving predictions and the threaded est.
  6. Return a MultiPeriodPredictionResult of predictions, with id, and with est as opt.

Arguments

  • r: The declaration, holding the Result to continue.
  • rd: The returns result to use.
  • cv: The scheme that the Result came from, an Online Scheme.
  • cv_res: The split of the data by cv, a CrossValidationResult. The default splits the data argument by cv. A caller that runs many estimators over one scheme splits once and passes the split to each call. Then every estimator scores the same folds, and a scheme that draws at random draws once. The method still reads the evaluation settings and the fold predicates of cv. cross_val_predict takes no cv_res, because it views rd by cols before the split.
  • cols: The asset view. cross_val_predict views rd by it. fit_and_predict hands it to every fold, which views its estimator and its prediction by it.
  • ex: Not read, because the resumed arm runs the folds in order.
  • id: The identifier that the Result carries.

Validation

Returns

  • res::MultiPeriodPredictionResult: The new folds, carrying the threaded estimator.

Related

source
PortfolioOptimisers.search_cross_validation — Method
search_cross_validation(::Resume, ::AbstractSearchCrossValidationEstimator, ::Any)

Refuses a Resume in a search, by name.

A search scores every candidate through one fold loop. A resumed search would need one Result per candidate, and the Result of a search does not carry them. The message names the resume of the walk-forward of the chosen candidate instead.

Validation

  • A search never takes a Resume. An ArgumentError is always thrown.

Related

source
Base.vcat — Method
Base.vcat(a::MultiPeriodPredictionResult, b::MultiPeriodPredictionResult)

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

The stacked Result carries the id of a and the opt of b, which is the estimator that the later run threaded, so it can be resumed too. The two Results must abut in time. The check reads the timestamps of the stacked return series, so a pair that overlaps and a pair from runs without timestamps are refused with an error that names the cause.

Algorithm

  1. Read the timestamps of the stacked return series, giving ta = a.mrd.ts and tb = b.mrd.ts. Refuse when either is nothing.
  2. Refuse unless the last entry of ta is before the first entry of tb.
  3. Build a MultiPeriodPredictionResult from vcat(a.pred, b.pred), the id of a and the opt of b. Its constructor stacks mrd again from the folds.

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