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
- Read the carry state with
partial_fit_cache, givingstate. - Resolve the fill limit against the coverage floor of the members with
resolve_fill_limit, as the batch method does, givingfill_limit. - Drop the carried rows of a Shared Series gap with
shared_series_buffer, and read the rows that remain withsample_buffer, givingX. Under the horizon method, takelog1pof the rows, givingXl. - Read
muandsigmathroughread_member, which refits a member that did not fold overX, or overXlunder the horizon method. The mean comes frommean_with_count, with the countT_muthat its fit states. A member that it refits also takes the panel ofbuffer_asset_panel, and the implied volatilities andivpathatimplied_volatility_buffer_kwargsreads from the carried buffer, as the batch verb givesrd.pnl,rd.ivandrd.ivpato both members. A covariance that it refits is thelibrary_covariance_estimatorofpe.ce, as in the batch verb. AnImpliedVolatilityhas no fold, so it is such a member. - Under the horizon method, convert
muandsigmawithhorizon_moments!. - Cut the carried rows to
pe.max_scenarioswithscenario_window, and copy them into a new matrixXs, because the next fold writes into the storage of the buffer. - Fill
Xswithscenario_fill, and build aLowOrderPriorwhoseeocscenario_moment_countsreads fromT_muand the rows before the cut, the log-returns under a horizon. - Record the observations of the buffer that step 3 dropped with
shared_series_record, and return the prior.
Arguments
pe: Empirical prior estimator carrying aPriorCarryState.strict: Whether a zero-filled scenario raises rather than warns. It also reaches the covariance, where a peel of aCoveragePolicyrefuses understrictand warns otherwise.kwargs...: Additional keyword arguments, forwarded to the batch verb of a member that did not fold.
Validation
pe.cacheis notnothing. AnArgumentErroris thrown otherwise.- Under
strict, no investable column needs a fill. AnArgumentErroris thrown otherwise. - The rules of
shared_series_buffer.
Returns
pr::LowOrderPrior: Result object containing asset returns, mean vector, and covariance matrix.
Related
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 besideX, ornothing. The method forwards them to the embedded prior.kwargs...: Additional keyword arguments, forwarded to the embedded prior.
Validation
pe.pefolds. 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
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
- Read the embedded result
prior_modelout ofpe.pewithprior, passingstrict. - Check the asset axis of the views against
prior_model.Xwithassert_bl_views_axis. - 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
LinearConstraintEstimatorname one entry per asset ofprior_model.X. ADimensionMismatchis thrown otherwise.
Returns
pr::AbstractPriorResult: The embedded result with its two moments replaced by the posteriors.
Related