Prior partial fit (b)

PortfolioOptimisers.prior — Method
prior(pe::EmpiricalPrior{<:Any, <:Any, Nothing, <:Any, <:Any,
                         <:Option{<:PriorCarryState}}; strict::Bool = false, kwargs...)
prior(pe::EmpiricalPrior{<:Any, <:Any, <:Number, <:Any, <:Any,
                         <:Option{<:PriorCarryState}}; strict::Bool = false, kwargs...)

Reads an EmpiricalPrior out of its fold, with no data matrix.

mu comes from pe.me, sigma comes from pe.ce, and X is the matrix that the carry state already holds, less the observations that it marks with a Shared Series gap. The members never folded those observations, and shared_series_buffer drops them from the rows, so the result is the batch fit over the observations that the batch fit keeps. The method copies the rows, and does not refit a member that folded. The horizon method then applies the algebra of the batch method through horizon_moments!, which holds that algebra once.

pe.max_scenarios cuts the rows that the result carries, as it does in batch, and the fill runs over the rows that remain. eoc holds the effective number of observations of mu and of sigma over the buffered rows, through scenario_moment_counts. When the cap cuts, an unweighted moment counts the number of observations folded, so a consumer that prices a sample size reads $T$ and not the number of rows carried. The named-asset set of the carry state limits the notice of the fill, so a walk-forward names an asset at the first step whose fill reaches it, and at no later step.

A member that the method refits takes the AssetPanel that buffer_asset_panel rebuilds from the carried buffer, as the batch fit gives it rd.pnl. The buffer records the active mask of each step. So a member that the method refits answers on the Coverage Universe of a batch fit, on a gapped sample and under a time-varying panel. A member that folds read the active mask at each step of its fold, as the keyword form of its verb reads it.

Mathematical definition

\[\begin{align} \mathcal{P}_T &= \mathcal{P}(\mathbf{X})\,, \\ \mathbf{X} &= \begin{bmatrix} \boldsymbol{x}_1 & \cdots & \boldsymbol{x}_T \end{bmatrix}^\intercal\,. \end{align}\]

Where:

  • $\mathcal{P}_T$: Folded prior, the result that the estimator's batch verb gives with no data after the estimator folds the observations $\boldsymbol{x}_1, \ldots, \boldsymbol{x}_T$ in order, one at a time or in blocks of any size.
  • $\mathcal{P}(\cdot)$: Batch prior, the result that the estimator's batch verb gives on the matrices in the parentheses.
  • $\mathbf{X}$: Returns matrix $T \times N$.
  • $\boldsymbol{x}_t$: Asset returns for observation $t$, the $t$-th row of the returns matrix.
  • $T$: Number of observations.

The equality holds for mu, sigma, X and eoc, with and without a horizon, and under a Scenario Cap. In floating point, the moments of a member that folds differ from the batch moments by rounding, and every other entry is equal.

Algorithm

  1. Read the carry state with partial_fit_cache, giving state.
  2. Resolve the fill limit against the coverage floor of the members with resolve_fill_limit, as the batch method does, giving fill_limit.
  3. Drop the carried rows of a Shared Series gap with shared_series_buffer, and read the rows that remain with sample_buffer, giving X. Under the horizon method, take log1p of the rows, giving Xl.
  4. Read mu and sigma through read_member, which refits a member that did not fold over X, or over Xl under the horizon method. The mean comes from mean_with_count, with the count T_mu that its fit states. A member that it refits also takes the panel of buffer_asset_panel, and the implied volatilities and ivpa that implied_volatility_buffer_kwargs reads from the carried buffer, as the batch verb gives rd.pnl, rd.iv and rd.ivpa to both members. A covariance that it refits is the library_covariance_estimator of pe.ce, as in the batch verb. An ImpliedVolatility has no fold, so it is such a member.
  5. Under the horizon method, convert mu and sigma with horizon_moments!.
  6. Cut the carried rows to pe.max_scenarios with scenario_window, and copy them into a new matrix Xs, because the next fold writes into the storage of the buffer.
  7. Fill Xs with scenario_fill, and build a LowOrderPrior whose eoc scenario_moment_counts reads from T_mu and the rows before the cut, the log-returns under a horizon.
  8. Record the observations of the buffer that step 3 dropped with shared_series_record, and return the prior.

Arguments

  • pe: Empirical prior estimator carrying a PriorCarryState.
  • strict: Whether a zero-filled scenario raises rather than warns. It also reaches the covariance, where a peel of a CoveragePolicy refuses under strict and warns otherwise.
  • kwargs...: Additional keyword arguments, forwarded to the batch verb of a member that did not fold.

Validation

  • pe.cache is not nothing. An ArgumentError is thrown otherwise.
  • Under strict, no investable column needs a fill. An ArgumentError is thrown otherwise.
  • The rules of shared_series_buffer.

Returns

  • pr::LowOrderPrior: Result object containing asset returns, mean vector, and covariance matrix.

Related

source
PortfolioOptimisers.partial_fit! — Function
partial_fit!(pe::BlackLittermanPrior, X, F = nothing; kwargs...)

Folds observations into a BlackLittermanPrior by forwarding them to its embedded prior.

The estimator keeps no buffer, for the reason that HighOrderPriorEstimator keeps none. It returns forward_prior of the result of its embedded prior, so the rows it needs are one level down. The factor observations go down with the rows, as the batch verb passes F down. The views are configuration, and they fold nothing.

Arguments

  • pe: Black-Litterman prior estimator.
  • X: Observations to fold, a matrix of rows or one observation.
  • F: The factor observations beside X, or nothing. The method forwards them to the embedded prior.
  • kwargs...: Additional keyword arguments, forwarded to the embedded prior.

Validation

  • pe.pe folds. The embedded prior refuses the fold otherwise, with an error that names the wrapper that gives it a buffer.

Returns

  • pe: The estimator, with its embedded prior folded.

Related

source
PortfolioOptimisers.prior — Method
prior(pe::BlackLittermanPrior; strict::Bool = false, kwargs...)

Reads a BlackLittermanPrior out of its fold, with no data matrix.

The embedded prior answers first, and bl_posterior is the body of the batch method, unchanged. That body reads every number from the result and none from a returns matrix. These numbers are the number of observations behind tau, the asset axis, and the matrix that the processing runs over. So the fold and the batch fit run one body.

Mathematical definition

\[\begin{align} \mathcal{P}_T &= \mathcal{P}(\mathbf{X})\,. \end{align}\]

Where:

  • $\mathcal{P}_T$: Folded prior, the result that the estimator's batch verb gives with no data after the estimator folds the observations $\boldsymbol{x}_1, \ldots, \boldsymbol{x}_T$ in order, one at a time or in blocks of any size.
  • $\mathcal{P}(\cdot)$: Batch prior, the result that the estimator's batch verb gives on the matrices in the parentheses.
  • $\mathbf{X}$: Returns matrix $T \times N$.

Algorithm

  1. Read the embedded result prior_model out of pe.pe with prior, passing strict.
  2. Check the asset axis of the views against prior_model.X with assert_bl_views_axis.
  3. Compute the posterior with bl_posterior, and return it.

Arguments

  • pe: Black-Litterman prior estimator whose embedded prior carries a state.
  • strict: Whether an unresolved view raises rather than warns.
  • kwargs...: Additional keyword arguments, forwarded to the embedded prior and the processing.

Validation

  • Every condition that prior(pe.pe) with no data checks.
  • The views of a LinearConstraintEstimator name one entry per asset of prior_model.X. A DimensionMismatch is thrown otherwise.

Returns

  • pr::AbstractPriorResult: The embedded result with its two moments replaced by the posteriors.

Related

source