Empirical Prior: private API
PortfolioOptimisers.show_fields — Method
show_fields(
pe::EmpiricalPrior
) -> Union{NTuple{5, Symbol}, NTuple{6, Symbol}}
Renders every field of an EmpiricalPrior except cache, and max_scenarios only where it is set.
The state in cache belongs to an incremental fit and is not part of the configuration, and it would print under the estimator at every site that renders one. Most callers leave max_scenarios at nothing, and a nothing row would change the rendering of every estimator that holds a prior. The row appears only when a caller sets a cap. Set set_show_nothing_fields!(:EmpiricalPrior, true) to render both.
Arguments
pe: Empirical prior estimator.
Returns
fields::Tuple: The field names to render, which is(:ce, :me, :horizon, :fill_limit, :x_src)with no scenario cap and(:ce, :me, :horizon, :fill_limit, :max_scenarios, :x_src)with one.
Related
PortfolioOptimisers.horizon_moments! — Function
horizon_moments!(
mu::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
sigma::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
horizon::Number
)
Scales a pair of log-return moments to an investment horizon and converts them to arithmetic returns, in place.
This is the one copy of the horizon conversion of EmpiricalPrior. The batch method calls it after it fits pe.me and pe.ce on log1p.(X). prior(pe) with no data calls it after it reads the same two moments off their states. The two routes then run the same arithmetic.
Mathematical definition
\[\begin{align} \tilde{\boldsymbol{\mu}} &= h \cdot \hat{\boldsymbol{\mu}}_{\log}\,, & \tilde{\mathbf{\Sigma}} &= h \cdot \hat{\mathbf{\Sigma}}_{\log}\,, \\ \hat{\mu}_i &= \exp\!\left(\tilde{\mu}_i + \tfrac{1}{2}\tilde{\sigma}_{ii}\right) - 1\,, & \hat{\sigma}_{ij} &= (\hat{\mu}_i + 1)(\hat{\mu}_j + 1)\left(\exp(\tilde{\sigma}_{ij}) - 1\right)\,. \end{align}\]
Where:
- $h$: Investment horizon.
- $\hat{\boldsymbol{\mu}}_{\log}$, $\hat{\mathbf{\Sigma}}_{\log}$: Mean and covariance of the log-returns.
- $\hat{\mu}_i$, $\hat{\sigma}_{ij}$: Arithmetic mean return and covariance.
Algorithm
Steps 3 to 5 must run in this order. Step 4 reads the mu that step 3 left, which is $\hat{\mu}_i + 1$, because step 5 has not yet subtracted the one. The second closed form needs that factor. If step 5 runs before step 4, each $\hat{\mu}_i + 1$ becomes $\hat{\mu}_i$. Entry $(i,\, j)$ of the covariance then falls by the factor $\hat{\mu}_i \hat{\mu}_j / ((\hat{\mu}_i + 1)(\hat{\mu}_j + 1))$, which is about six orders of magnitude on a daily return series.
- Scale
mubyhorizon. - Scale
sigmabyhorizon. - Overwrite
muwith the exponential term of the first closed form. This is the arithmetic mean plus one. - Overwrite
sigmawith the second closed form, whose $\hat{\mu}_i + 1$ factors are themuof step 3. - Subtract one from
mu.
Arguments
mu: The log-return mean, overwritten with the arithmetic mean.sigma: The log-return covariance, overwritten with the arithmetic covariance.horizon: The investment horizon.
Returns
nothing. The function changes both arguments in place.
Related
PortfolioOptimisers.buffer_refit_member — Function
buffer_refit_member(est, state::SampleBufferState) -> typeof(est)Return a member of a carrying prior as the prior reads it after a Shared Series gap.
A member that folds reads its own state, which never folded a marked observation, so it comes back with no change. A member that refits on the buffer reads the buffer with the marked observations dropped, so its fixed observation weights must drop them too. It comes back cut with shared_series_buffer_estimator. The prior then reads both kinds through read_member, and states their counts from the same members.
Arguments
est: The member of the prior.state: The buffer of the prior.
Returns
est: The member that the prior reads.
Related
PortfolioOptimisers.buffer_refit_members — Function
buffer_refit_members(pe::EmpiricalPrior, state::SampleBufferState)
-> Tuple{EmpiricalPrior, SampleBufferState}Return the carrying EmpiricalPrior with each member as buffer_refit_member reads it after a Shared Series gap, and the buffer that prior reads.
The method of prior on a carrying prior reads pe.me and pe.ce, and it states their counts with scenario_moment_counts, so one rebuilt prior serves both. The state of the prior stays in cache.
Algorithm
- Drop the marked observations from the buffer with
shared_series_buffer. - Return
pewith the buffer when the buffer marks no observation of its valid region, seebuffer_gap_marks. - Otherwise rebuild
pewithmeandcefrombuffer_refit_member, throughrebuild_struct.
Arguments
pe: The carrying prior.state: The buffer of its carry state.
Returns
pe::EmpiricalPrior: The prior whose memberspriorreads.buf::SampleBufferState: The buffer at the kept observations.
Related