Online selection rules: the forecast-reading arm: private API

PortfolioOptimisers.forecaster_seed — Function
forecaster_seed(
    me::AbstractExpectedReturnsEstimator
) -> Union{Nothing, ForecasterState{__T_me} where __T_me<:AbstractExpectedReturnsEstimator}

Returns the carrier that a forecast-reading rule seeds.

The carrier is a ForecasterState over a forecaster that folds, and nothing for a forecaster that the rule fits again from the rows of the head.

Validation

  • A forecaster that folds carries no partial-fit state at the seed. An ArgumentError is thrown otherwise. The head starts cold, and a state folded elsewhere would make the forecast of the first row read rows that the head never saw.

Related

source
PortfolioOptimisers.forecast_min_rows — Function
forecast_min_rows(
    me::AbstractExpectedReturnsEstimator
) -> Any

Returns the number of rows that a forecaster needs before the refit arm of forecast_relative reads it.

Below this number the refit arm gives a flat forecast.

Mathematical definition

\[\begin{align} n_{\min} &= \max\left(n_2,\, n_{\mathrm{fit}}\right)\,. \end{align}\]

Where:

  • $n_{\min}$: Least number of rows of the refit arm.
  • $n_2$: Two when the estimator tree holds a covariance, variance or prior estimator, whose second moment is undefined on one row, and one otherwise. holds_second_moment decides it.
  • $n_{\mathrm{fit}}$: Least number of rows that the estimator states through fit_min_rows.

Related

source
PortfolioOptimisers.holds_second_moment — Function
holds_second_moment(est)

Returns whether an estimator tree holds a covariance, variance or prior estimator at any depth.

Algorithm

  1. When est is a covariance, variance or prior estimator, or a StatsBase.CovarianceEstimator, return true. Stop.
  2. When est is another estimator, call the function on each field that estimator_fields names, and return true when any call returns true.
  3. Return false for a value that is not an estimator.

Related

source
PortfolioOptimisers.flat_where_undefined — Function
flat_where_undefined(xhat::AbstractVector) -> Any

Reads each non-finite entry of a Price Relative Forecast as one, so the step holds that asset.

A forecaster whose estimate is undefined over the first rows, such as a variance over one observation, therefore holds until the estimate is defined.

Related

source
PortfolioOptimisers.refit_rows — Function
refit_rows(rows::ReturnsResult, x::AbstractVector)
refit_rows(rows::Nothing, x::AbstractVector)

Returns the returns that the refit arm fits a forecaster on, and the Asset Panel that explains them.

With a rows carrier these are its X and its pnl. Without one, they are the current row as a matrix of one row, and no panel.

Related

source
PortfolioOptimisers.scale_relative — Function
scale_relative(scale::Nothing, x::AbstractVector, rows)
scale_relative(scale::AbstractPriceLevelStatistic, x::AbstractVector, rows)

Returns the diagonal of the preconditioner of a ForecastReversion step, or nothing for the identity.

The diagonal is the Price Relative Forecast of the scale statistic, fit on the rows that the head holds, or on the current row alone without a rows carrier. An entry that the statistic cannot give is one, through flat_where_undefined, so the step on that asset is not scaled.

Related

source