Online selection rules: the forecast-reading arm: private API
PortfolioOptimisers.copy_forecaster — Function
copy_forecaster(me::AbstractExpectedReturnsEstimator)
copy_forecaster(me::PriorExpectedReturns)Copies a folded forecaster, so that its state shares no array with the original.
The first method copies the cache field through the Base.copy of the state, and returns an estimator with no cache unchanged. The second method copies the prior of the adapter with copy_forecaster_prior.
Related
PortfolioOptimisers.copy_forecaster_prior — Function
copy_forecaster_prior(pe::AbstractPriorEstimator) -> Any
Copies a folded prior, so that its state shares no array with the original.
copy_forecaster calls it for the prior of a PriorExpectedReturns. It copies the cache field through the Base.copy of the state, and returns a prior with no cache unchanged.
Related
PortfolioOptimisers.assert_forecaster — Function
assert_forecaster(me::AbstractExpectedReturnsEstimator)
Refuses an Online wrapper in the forecaster slot of a rule.
The rows buffer of the head already holds the rows that the forecaster reads. A second buffer would hold them twice.
Validation
meis not anOnline, and holds none at any depth. AnArgumentErroris thrown otherwise, and it names the path to the wrapper.
Returns
nothing.
Related
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
ArgumentErroris 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
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_momentdecides it. - $n_{\mathrm{fit}}$: Least number of rows that the estimator states through
fit_min_rows.
Related
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
- When
estis a covariance, variance or prior estimator, or aStatsBase.CovarianceEstimator, returntrue. Stop. - When
estis another estimator, call the function on each field thatestimator_fieldsnames, and returntruewhen any call returnstrue. - Return
falsefor a value that is not an estimator.
Related
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
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
PortfolioOptimisers.last_active_mask — Function
last_active_mask(pnl::Nothing)
last_active_mask(pnl::AssetPanel)Returns the active mask of the last row of an Asset Panel, or nothing when there is no panel or the panel is static.
The fold arm of forecast_relative folds the current row under this mask.
Related
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
PortfolioOptimisers.scale_rows — Function
scale_rows(scale::Nothing)
scale_rows(scale::AbstractPriceLevelStatistic)Returns the number of rows that a scale statistic reads at a step, and 0 when there is no statistic.
Related