Prior Scenarios (a): private API
A prior result carries its scenarios in X. A cap on the number of scenarios keeps the last rows of the observations. The scenario fill writes zero into each gap of an investable asset, so that a risk measure that reads the scenarios reads a complete matrix. The functions below find the entries to fill, resolve the limit on the filled share, keep the rows under the cap, cut a nested prior result to the rows that a wrapping prior keeps, put the probabilities of the scenarios on the rows that the moments read, and report the filled entries. The function that fills them is on the page of part (b). A Cross-Sectional Factor Prior reads its scenarios from the factor returns of its regression, so two functions fit that regression and give those rows to an entropy pooling prior around it. A fit with cache_reg = true stores a cache, and six functions store it or read it, so the refit of an entropy pooling prior runs no regression. They store the cache on the block, find the block of the cache, and read its factor returns. They split the return forecast of the block, and run the steps of the assembly that read the factor moments. The last one keeps the cache of a pool in the factor slot.
Five more functions give the scenarios and the return forecast of a Cross-Sectional Factor Prior. They split a forecast into the part that the factors explain and an alpha, fit the return forecast of the block, blend the forecast into the factor means, divide the scenario weights of the factors by their sum, and give the return scenarios of the assets. Three more functions count the scenarios of a prior with only the steps that drop rows, and check the rows that the exposure lag leaves. Two functions state the effective count of the moments of an empirical prior, and fit its mean together with the count that the fit states.
Types
PortfolioOptimisers.RegressionStage — Type
struct RegressionStage{__T_ca, __T_lv, __T_fit, __T_rde}The cross-sectional regression of a CrossSectionalFactorPrior, up to the factor returns that its factor prior reads.
This type is an implementation detail and is not intended for direct use. cross_sectional_regression_stage makes it. The returns-matrix method of prior, cross_sectional_factor_scenarios and the refit of scenario_prior read it.
Fields
ca:ca: The estimated factors with the observed factors appended, anAppendedFactorModel.ca.fholds the factor returns, one row per fitted observation.
lv:lv:trueat each factor ofca.fthat is not empty.
fit:fit: The regression, the weights, the variance history and the rows thatcross_sectional_assemblereads.
rde:rde: The returns data that the estimated members read.
Related
PortfolioOptimisers.CachedFactorReturns — Type
struct CachedFactorReturns{__T_fa, __T_f, __T_lv}The factor returns that the factor prior of a CrossSectionalFactorPrior is fitted on, read from the block of a fit that stores the cache.
This type is an implementation detail and is not intended for direct use. cross_sectional_cached_scenarios makes it. scenario_prior and scenario_factory read it. fa and f are matrices of one type, so a positional swap would be silent.
Fields
fa:fa: The factor returns on the combined reduced factor axis.
f:f: The factor returns of the factors that are not empty, which the factor prior reads.
lv:lv:trueat each factor offathat is not empty.
Related
Functions
PortfolioOptimisers.scenario_fill_pairs — Function
scenario_fill_pairs(
X::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
imsk::BitVector
) -> Vector
Find the entries a mask-aware prior fills: the non-finite returns of an investable asset.
A non-investable asset keeps its whole NaN column, because the Investable Mask is derived from that gap and filling it would erase the mask. Only a column whose moments came back finite is filled.
Arguments
X: Asset returns,observations × assets.imsk: The Investable Mask,trueat every asset whose prior moments were finite.
Returns
filled::Vector{Tuple{Int, Int}}: The(observation, asset)pairs to fill, asset-major.
Related
PortfolioOptimisers.scenario_fill_msg — Function
scenario_fill_msg(
filled::AbstractVector{<:Tuple{Integer, Integer}},
wi::Integer,
worst::Real,
frac::Real,
fill_limit::Union{Nothing, Real}
) -> String
Write the message a scenario fill raises.
The message names the assets, the count of filled pairs and the first observation, so a caller can find the listing that made them. It then names the worst investable column, the share of its own observations the fill invented, and the limit that share was measured against — that share is the one the fill tests, because a matrix-wide denominator scales with the universe and hides the column the notice exists to catch. The matrix-wide share is reported beside it as context, and it trips nothing.
It states the consequence at each of the four consumers that a census of the readers of pr.X found, because a caller told only about the tail will not look for the other three, and it states the tail's cost as the identity rather than the adjective: the invented zeros do not enter the tail, they inflate the denominator, so a measure at level alpha over an admitted column of coverage c reads that column's observed alpha / c level.
The limit it names is the estimator's own, after resolve_fill_limit. A fill_limit of nothing demands every observation of every investable asset, so the message says so rather than printing a share no caller chose.
Arguments
filled: The(observation, asset)pairsscenario_fill_pairsfound.wi: The index of the worst investable column, the one with the most filled entries.worst: The share of its own observations that column's fill invented.frac: The share of the entries of the returns matrix every filled pair is, as context.fill_limit: The share of a column the fit allowed in silence, ornothingwhen it allowed none.
Returns
msg::String: The message.
Related
PortfolioOptimisers.resolve_fill_limit — Function
resolve_fill_limit(fill_limit::Nothing, floor::Nothing)
resolve_fill_limit(fill_limit::Nothing, floor::Real)
resolve_fill_limit(fill_limit::Real, floor::Nothing)
resolve_fill_limit(fill_limit::Real, floor::Real)Resolve the share of an investable column a scenario_fill may invent in silence, at the fit.
fill_limit and a CoveragePolicy's min_coverage are two spellings of one number. admits reads an asset's coverage share as its own observation count over the number of observations folded, and the fill counts that column's non-finite entries over the same denominator, so filled_share == 1 - coverage_share identically and the admission test is the fill test. A limit that did not know this would fire on nearly every fold of an available-case walk-forward, naming the caller for doing precisely what they configured.
So nothing derives. Where any arm of the fitting estimator states a floor, nothing means 1 - floor, and it never fires: every admitted column satisfies it by construction. Where no arm states one — the exponentially weighted family is mask-aware without a policy, gating on min_obs, a count that says nothing about the share of a long window — nothing keeps its original meaning and names every fill, because a caller who set no floor has weighed no trade.
An explicit fill_limit overrides the derivation and must be tighter than admission. A value above 1 - floor is refused, because it is dead by construction: nothing that reaches the fill could trip it, and a knob that cannot fire is worse than no knob. What an explicit value buys is the one configuration the derivation cannot express — admit broadly and be told anyway, min_coverage = 0.3 with fill_limit = 0.5.
The four methods are dispatch rather than a branch, so a call site holding two Options finds a method for every arm of its union split.
Arguments
fill_limit: The estimator's ownfill_limitfield, ornothingto derive one.floor: The binding coverage floor of the estimator's arms, ornothingwhen no arm states one.
Validation
fill_limit <= 1 - floorwhere both are stated, else aDomainErrornaming both is thrown.
Returns
fill_limit::Option{<:Real}: The share of an investable column the fill may invent in silence, ornothingwhen it may invent none.
Related
PortfolioOptimisers.scenario_window — Function
scenario_window(::Nothing, X::MatNum)
scenario_window(max_scenarios::Integer, X::MatNum)Cut the returns matrix a Prior Result carries down to the last max_scenarios observations.
The Scenario Cap, applied. A prior that carries X carries it for the scenario risk measures, and a caller who wants a long window of moments and a short window of scenarios says so with one field rather than with two fits. The cap therefore touches X alone: mu and sigma are already computed when this runs, over every observation the fit read, and nothing here can or does move them.
It is deliberately the same verb in batch and online. A cap is a property of the result, not of the fold, so prior(pe, X) and prior(pe) with no data on a folded pe cut the same rows off the same tail.
A window at or above the number of observations is the matrix itself, and no copy is taken: the cut is a view, so a cap that does nothing costs nothing.
Arguments
max_scenarios: The number of observations to carry, ornothingto carry every one.X: Asset returns,observations × assets.
Returns
X::MatNum: The lastmax_scenariosrows ofX, orXitself.
Related
PortfolioOptimisers.scenario_tail — Function
scenario_tail(pr::LowOrderPrior, n::Integer, name::Symbol)Cut a nested Prior Result to the last n scenarios that it carries.
AugmentedBlackLittermanPrior fits two nested priors, one on the asset returns and one on the factor returns. A Scenario Cap in one of them keeps the last rows of its own returns alone. The two blocks of the result describe the same observations, so the result keeps the rows that both nested priors keep, and this function cuts the nested prior that carries more rows. The moments of pr are fitted over every observation, so the cut changes no moment.
An entry of nothing in the eoc of a Prior Result states size(pr.X, 1) as the count of the observations that its moment reads. The cut makes X shorter, so it writes that count in each such entry, as scenario_moment_counts does for the cap itself.
Algorithm
- Take
t = size(pr.X, 1). Whenn >= t, returnpr. - Refuse a
prthat carries weights, per# Validation. - Forward
prwithforward_prior, withXando_Xcut byscenario_window, and with each entry ofeocset totwhen it isnothing.
Arguments
pr: The Prior Result of a nested prior.n: The number of scenarios to keep.name: The field of the wrapping prior that holds the nested prior, for the error message.
Validation
- When the cut removes a row,
pr.wisnothing. A weight vector states a probability for each row thatprcarries, so it has no meaning on fewer rows. ADimensionMismatchthat namesname, both counts and the fix is thrown otherwise.
Returns
pr::LowOrderPrior:prwith the lastnrows ofX, orpritself.
Related
PortfolioOptimisers.scenario_weights — Function
scenario_weights(w::Nothing, t::Integer)
scenario_weights(w::ObsWeights, t::Integer)Put the probabilities w of the scenarios of a capped Prior Result on the t observations that its moments read.
scenario_window keeps the last rows of the observations as scenarios, and the moment estimators read every observation. A prior that reweights scenarios, such as EntropyPoolingPrior, states a probability for each scenario and none for the observations that the cap removed. Its posterior gives those observations no probability, so this function gives them a zero weight. A weighted moment over the t observations is then the moment of the scenarios under w, and the posterior mean is pr.X' * w, the mean that a view states.
Algorithm
- A
nothingwreturnsnothing. - Otherwise take
s = length(w), and refuses > t. - When
s == t, the cap removed no row: returnw. - Otherwise return
t - szeros followed byw, throughscenario_probabilities: in the kind ofwwhen it is aScenarioProbabilities, and asStatsBase.AnalyticWeightsotherwise.
Arguments
w: The probabilities of the scenarios, ornothing.t: The number of observations that the moments read.
Validation
length(w) <= t. ADimensionMismatchis thrown otherwise.
Returns
w′::Option{<:ObsWeights}: The weights over thetobservations, ornothing.
Related
PortfolioOptimisers.cross_sectional_regression_stage — Function
cross_sectional_regression_stage(pe::CrossSectionalFactorPrior, X::MatNum,
F::Option{<:MatNum}, pnl::Option{<:AssetPanel};
ne = nothing, E = nothing, iv = nothing,
ivpa = nothing, ts = nothing) -> RegressionStageFit the cross-sectional regression of a CrossSectionalFactorPrior, up to the factor returns that its factor prior reads.
The returns-matrix method of prior fits pe.pe on the factor returns of this stage and assembles the result. scenario_factory and prior_probability_factory read the same factor returns, because an entropy pooling prior around pe states its probabilities on the scenarios of pe.pe. The stage reads no weight of pe.pe, so a change of pe.pe alone leaves its answer the same.
Algorithm
- Run the steps 1 to 9 of the returns-matrix method of
prior: the exposure stage, the Neutralisation, the Factor Family Basis, the lag, the eligibility, the regression and the idiosyncratic variance history. - Append the observed factors with
cross_sectional_observed_append, givingca. - Mark the factors that are not empty in
lv, on the axis ofca.f. An Observed Factor is never empty.
Arguments
pe: Cross-Sectional Factor Prior estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.F: Optional factor returns matrix, already oriented. The stage does not read it.pnl: OptionalAssetPanel, the panel that the returns data held. A wrapping prior forwards it unchanged, so that it can compose an estimator that is fitted on a panel. An estimator that reads no panel ignores it. This estimator reads it, and refuses without it.ne,E,iv,ivpa,ts: As in the returns-matrix method ofprior, withEalready oriented.
Validation
- The rules of the returns-matrix method of
prior, up to the factor prior.
Returns
rs::RegressionStage: The outputcaofcross_sectional_observed_append, whoseca.fholds the factor returns, one row per fitted observation; the marklv,trueat each factor ofca.fthat is not empty; the bundlefitof the regression, the weights, the variance history and the rows thatcross_sectional_assemblereads; and the returns datardethat the estimated members read.
Related
PortfolioOptimisers.cross_sectional_factor_scenarios — Function
cross_sectional_factor_scenarios(pe::CrossSectionalFactorPrior, X::MatNum,
F::Option{<:MatNum}, pnl::Option{<:AssetPanel};
ne = nothing, E = nothing, iv = nothing,
ivpa = nothing, ts = nothing, kwargs...)Return the factor returns that the factor prior pe.pe of a CrossSectionalFactorPrior is fitted on, with the regression stage that gives them.
An entropy pooling prior around pe states its probabilities on the scenarios of pe, and these are the last rows of the factor returns of pe.pe. The Descriptor warm-up and the exposure lag drop rows, so the number of factor returns is known only after the regression. scenario_factory and prior_probability_factory read these rows, to put the probabilities on the observations that pe.pe reads. scenario_prior also reads the stage, so the refit runs the regression once.
Algorithm
- Fit the regression of
pewithcross_sectional_regression_stage, giving the stagers, with the factor returnsrs.ca.fand the maskrs.lvof the factors that are not empty. - Take the columns of
rs.ca.fthatrs.lvmarks, as the fit ofpe.pereads them. - Return them with
rs, and with the keyword arguments that the stage did not read.
Arguments
pe: Cross-Sectional Factor Prior estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.F: Optional factor returns matrix, already oriented.pnl: OptionalAssetPanel, the panel that the returns data held. A wrapping prior forwards it unchanged, so that it can compose an estimator that is fitted on a panel. An estimator that reads no panel ignores it.ne,E,iv,ivpa,ts: As in the returns-matrix method ofprior, withEalready oriented.kwargs...: The other keyword arguments of the fit. The regression reads none of them.
Validation
- The rules of
cross_sectional_regression_stage.
Returns
(f, rs, kw)::Tuple:f::Matrix, the factor returns ofpe.pe, one row per fitted observation;rs::RegressionStage, the output ofcross_sectional_regression_stage; andkw, the keyword arguments inkwargs..., which the rest of the fit reads.
Related
PortfolioOptimisers.cross_sectional_cached_block — Function
cross_sectional_cached_block(pe::CrossSectionalFactorPrior, pr::Nothing, X::MatNum)
cross_sectional_cached_block(pe::CrossSectionalFactorPrior, pr::AbstractPriorResult,
X::MatNum)
cross_sectional_cached_block(pe::CrossSectionalFactorPrior, pr::LowOrderPrior, X::MatNum)Return the block of the fit pr of a CrossSectionalFactorPrior when it holds the cache that a refit under new scenario weights reads, and nothing otherwise.
A fit of prior with cache_reg = true stores the cache. EntropyPoolingPrior and MeucciEntropyPoolingPrior fit the prior that they wrap with it, and give the result of that fit to scenario_prior and scenario_factory. The regression, the cross-sectional weights, the residual block and the Return Forecast of a refit are those of the fit, so the refit reads them from the block and runs no regression. A result with no cache gives nothing, and the refit then runs the whole fit.
Algorithm
The method that Julia selects is the algorithm.
- No result, or a result of any other type: return
nothing. - A
LowOrderPrior: return its blockrrwhen every condition holds, andnothingotherwise:rris aCrossSectionalFactorModelwith a regressioncsr, a recorded live-factor maskcsr.lvand an active-mask historyamr.rrhas one row ofMfor each column ofX, so the cache describes the asset universe of the refit.- When a Calibration Slot of
pereads the Return Forecast history, asreads_forecast_historyanswers, andpestates a Return Forecast Estimator,rrcarries that history inhist.
Arguments
pe: Cross-Sectional Factor Prior estimator.pr: The result of the fit that the views read, ornothing.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.
Returns
rr::Option{<:CrossSectionalFactorModel}: The block that holds the cache, ornothing.
Related
PortfolioOptimisers.cross_sectional_cached_scenarios — Function
cross_sectional_cached_scenarios(rr::CrossSectionalFactorModel) -> CachedFactorReturnsReturn the factor returns that the factor prior of a CrossSectionalFactorPrior is fitted on, from the block of a fit that stores the cache.
The regression stage gives these factor returns to the fit, as cross_sectional_factor_scenarios states. The block of a fit with cache_reg = true holds the regression and its live-factor mask, so scenario_prior and scenario_factory read the same factor returns from it and run no regression.
Algorithm
- Take the factor returns of the block with
cross_sectional_factor_returns, the estimated factors and then the observed ones, givingfa. - Extend the live-factor mask
rr.csr.lvof the estimated factors withtruefor each observed factor, givinglv. An Observed Factor carries the return the caller observed, so it is never empty. - Take the columns of
fathatlvmarks, givingf.
Arguments
rr: The block of a fit that stores the cache, ascross_sectional_cached_blockanswers.
Returns
cf::CachedFactorReturns: The factor returnsfaon the combined reduced factor axis, the factor returnsfof the factors that are not empty, which the factor prior reads, and the marklv,trueat each factor offathat is not empty.
Related
PortfolioOptimisers.cross_sectional_forecast_split — Function
cross_sectional_forecast_split(ofit::AbstractOrthogonalForecastFit, rf::Nothing,
csfm::CrossSectionalFactorModel,
cre::AbstractCrossSectionalRegressionEstimator)
-> ForecastSplitResult
cross_sectional_forecast_split(ofit::AbstractOrthogonalForecastFit,
rf::AbstractReturnForecastResult,
csfm::CrossSectionalFactorModel,
cre::AbstractCrossSectionalRegressionEstimator)
-> ForecastSplitResultSplit a Return Forecast Result against the latest Factor Exposures of the estimated factors of a CrossSectionalFactorModel, giving its spanned coefficients and its orthogonal part before the Orthogonal Forecast Scale.
cross_sectional_return_forecast fits the forecast and splits it here. The refit of scenario_prior reads the forecast that the block carries, and splits it here, so it fits no member.
Algorithm
- No Return Forecast Result: return
nothingfor both parts. - Split
rf.muagainst the latest exposures of the estimated factors withcross_sectional_alpha_split, under the weights of the latest row ofcsfm.rw, givinggandap. The observed factors are the trailing columns ofL, and the split leaves them out, soghas one entry per column ofcsr.f. - Scale
apwithorthogonal_forecast_rescale, which changes it underOrthogonalPartCalibrationalone.
Arguments
ofit: The Orthogonal Forecast Fit of the prior.rf: The Return Forecast Result, ornothing.csfm: The factor-model block.cre: Cross-Sectional Regression Estimator of the split.
Validation
- The rules of
cross_sectional_alpha_split.
Returns
res::ForecastSplitResult:g, the spanned coefficients, andap, the orthogonal part before the Orthogonal Forecast Scale, one entry per asset. Both arenothingwith no Return Forecast Result.
Related
PortfolioOptimisers.cross_sectional_alpha_split — Function
cross_sectional_alpha_split(cre::AbstractCrossSectionalRegressionEstimator, mu::VecNum,
L::MatNum, w::VecNum) -> ForecastSplitResultSplit a Return Forecast into the part the latest Factor Exposures span and the part they do not.
Mathematical definition
Under CrossSectionalLinearRegression, the spanned coefficients solve a weighted least squares over the valid assets. Another Cross-Sectional Regression Estimator fits $\boldsymbol{g}$ by its own rule over the same assets and weights.
\[\begin{align} \mathcal{V} &= \left\{i : \alpha_{i} \in \mathbb{R},\ B_{Tik} \in \mathbb{R} \ \forall k,\ u_{i} > 0\right\}\,, \\ (c, \boldsymbol{g}) &= \underset{c,\,\boldsymbol{g}}{\arg\min} \sum_{i \in \mathcal{V}} u_{i} \left(\alpha_{i} - c - \sum_{k=1}^{K} B_{Tik} \, g_{k}\right)^{2}\,, \\ \boldsymbol{\alpha}^{\perp} &= \boldsymbol{\alpha} - \mathbf{B}_{T} \, \boldsymbol{g}\,. \end{align}\]
Where:
- $\mathcal{V}$: Valid assets of the split.
- $\alpha_{i}$: Return Forecast of asset $i$.
- $u_{i}$: Regression weight of asset $i$ in the latest fit.
- $c$: Intercept of the regression, held at $0$ when the estimator fits none.
- $\boldsymbol{\alpha}^{\perp}$: Orthogonal part of a Return Forecast, one entry per asset,
NaNat an asset whose forecast or whose latest exposures are not finite. - $\boldsymbol{g}$: Spanned coefficients of a Return Forecast, $K \times 1$, the coefficients of its regression on the latest Factor Exposures.
- $\mathbf{B}_{T}$: Latest Factor Exposures, $N \times K$, with entry $B_{Tik}$ for asset $i$ and factor $k$.
- $K$: Number of factors.
The orthogonal part is $\boldsymbol{\alpha} - \mathbf{B}_{T} \boldsymbol{g}$ and not the residual of the regression, so the intercept stays in it: the weighted mean of $\alpha^{\perp}_{i}$ over $\mathcal{V}$ is $c$. The split then adds up. The prior's expected return is $\mathbf{B}_{T} (\lambda \boldsymbol{\mu}_{f} + (1 - \lambda) \boldsymbol{g}) + c_{\alpha} \boldsymbol{\alpha}^{\perp}$, which is $\boldsymbol{\alpha}$ at $\lambda = 0$ and $c_{\alpha} = 1$, whatever the intercept. Without an intercept, $\mathbf{B}_{T,\,\mathcal{V}}^{\intercal} \mathbf{U} \boldsymbol{\alpha}^{\perp}_{\mathcal{V}} = \boldsymbol{0}$, with $\mathbf{U}$ the diagonal matrix of the weights $u_{i}$. The symbols $\lambda$, $c_{\alpha}$ and $\boldsymbol{\mu}_{f}$ are the Spanned Shrinkage, the Orthogonal Forecast Scale and the factor mean of CrossSectionalFactorPrior.
Algorithm
- If
muis zero at every asset, return a zerogand a zeroap. No regression runs. - Copy
wintowv, and set to zero the weight of every asset whose forecast, or whose row of exposures, is not finite. The weights come from the lagged fit, so a positive weight says nothing about the finiteness of the latest forecast. If no weight inwvis positive, return the zero split of step 1. - Regress
muonLacross the assets underwv, throughcre, givingg. - Subtract
L * gfrommu, givingap.
Arguments
cre: Cross-Sectional Regression Estimator of the split.mu: The Return Forecast, one entry per asset of the coverage universe.L: The latest Factor Exposures,assets × factors, in the basis the fit ran in.w: The regression weights of the latest fit, one entry per asset.
Validation
- The rules of
cross_sectional_regression.
Returns
res::ForecastSplitResult:g, the spanned coefficients, one per factor ofL, andap, the orthogonal part of the forecast, one entry per asset.
Related
PortfolioOptimisers.cross_sectional_return_forecast — Function
cross_sectional_return_forecast(ofit::AbstractOrthogonalForecastFit, rfe::Nothing,
rd::ReturnsResult, csfm::CrossSectionalFactorModel,
cre::AbstractCrossSectionalRegressionEstimator,
reads::Bool, H::Option{<:MatNum},
rf0::Nothing = nothing) -> SplitReturnForecast
cross_sectional_return_forecast(ofit::AbstractOrthogonalForecastFit,
rfe::AbstractReturnForecastEstimator, rd::ReturnsResult,
csfm::CrossSectionalFactorModel,
cre::AbstractCrossSectionalRegressionEstimator,
reads::Bool, H::Option{<:MatNum},
rf0::Option{<:AbstractReturnForecastResult} = nothing)
-> SplitReturnForecastFit the Return Forecast of a CrossSectionalFactorPrior under its Orthogonal Forecast Fit, and split it against the latest Factor Exposures.
The split is unscaled by c. The Orthogonal Forecast Scale c can be a rule that reads the orthogonal part, so cross_sectional_calibration resolves c after this function, and cross_sectional_forecast_block then scales the part. A prior that states no Return Forecast Estimator takes the method over Nothing, which returns nothing in each entry, so the factor mean and the zero b do not change. The batch fit, the online refit and the carry fold all reach the forecast through this function, so the Orthogonal Forecast Fit holds on each of them.
Algorithm
- Take the member that the prior fits with
orthogonal_forecast_member, givingrfo. UnderScoreNeutralisationa fitted member neutralises its scores against the estimated factors ofcsfm. - Take
rf0asrfwhen the carry fold gives it. Otherwise fitrfoon the coverage universe withreturn_forecast, with the regression thatorthogonal_forecast_regressiongives, givingrf.rdholds every observation, so the Descriptors of the forecast warm up over every observation of the panel.return_forecast_rowsfinds the block as a suffix ofrdby its size. - Split
rf.muagainst the latest exposures of the estimated factors withcross_sectional_forecast_split, givinggandap. The observed factors are the trailing columns ofL, and the split leaves them out, soghas one entry per column ofcsr.f. The split scalesapwithorthogonal_forecast_rescale, which changes it underOrthogonalPartCalibrationalone. - When
readsistrue, take the Return Forecast history ofrfoonce withcross_sectional_forecast_historyfromrf, givinghist. Otherwisehistisnothing.
Arguments
ofit: The Orthogonal Forecast Fit of the prior.rfe: Return Forecast Estimator, ornothing.rd: The returns result to use. It is the full returns data that the estimated members of the prior read, and the block is a suffix of it. Under observed factors itsXholds the returns net of them.csfm: The factor-model block, built with a zeroband no Return Forecast.cre: Cross-Sectional Regression Estimator of the split.reads: Whether a slot of the prior reads the Return Forecast history, asreads_forecast_historyanswers.H: The rows of the Return Forecast history that the carry fold carries, ornothingwhen the history is made here.rf0: The Return Forecast Result that the carry fold of a forecast that folds carries, asfolds_forecast_rowsanswers, ornothingto fit the member here.
Validation
- The rules of
return_forecast, ofcross_sectional_alpha_splitand, whenreadsistrue, ofcross_sectional_forecast_history. - The rules of
DescriptorScoreson the rebuilt scores underScoreNeutralisation.
Returns
sp::SplitReturnForecast: The Return Forecast Resultrf, the spanned coefficientsg, the orthogonal partapbefore the Orthogonal Forecast Scale, one entry per asset, and the Return Forecast historyhist,observations × assets. Each isnothingwhen the fit gives none.
Related
PortfolioOptimisers.cross_sectional_forecast_mu — Function
cross_sectional_forecast_mu(lambda::Real, mu::VecNum, g::Nothing) -> VecNum
cross_sectional_forecast_mu(lambda::Real, mu::VecNum, g::VecNum) -> VecNumBlend the expected factor returns with the spanned part of a Return Forecast.
A prior that states no Return Forecast Estimator has a spanned part of zero, and the method over Nothing takes it. There lambda shrinks the factor mean towards zero, and lambda = 0 gives an expected return of zero. At lambda = 0 the blend reads no factor mean, so a factor mean that the factor prior does not state gives a finite blend there, and NaN at every other lambda.
Mathematical definition
\[\begin{align} \tilde{\boldsymbol{\mu}}_{f} &= \lambda \, \boldsymbol{\mu}_{f} + (1 - \lambda) \, \boldsymbol{g}\,. \end{align}\]
Where:
- $\tilde{\boldsymbol{\mu}}_{f}$: Blended expected factor returns.
- $\lambda$: Shrinkage of the factor mean towards the spanned forecast. At $\lambda = 1$ the blend is the factor mean, and at $\lambda = 0$ it is the spanned forecast.
- $\boldsymbol{\mu}_{f}$: Expected factor returns, $K \times 1$, the mean of the factor distribution that the prior result carries.
- $\boldsymbol{g}$: Spanned coefficients of a Return Forecast, $K \times 1$, the coefficients of its regression on the latest Factor Exposures. It is $\boldsymbol{0}$ when the prior states no Return Forecast Estimator.
Arguments
lambda: Shrinkage of the factor mean towards the spanned forecast.mu: The expected factor returns of the nested factor prior, on the reduced axis.g: The spanned coefficients of the Return Forecast, ornothing.
Returns
mu::VecNum: The blended expected factor returns, on the reduced axis.
Related
PortfolioOptimisers.cross_sectional_scenario_weights — Function
cross_sectional_scenario_weights(_::Nothing)
Divide the scenario weights of the factor prior of a Cross-Sectional Factor Prior by their sum.
A scenario weight vector states a probability measure over the scenarios only when it sums to one. A ratio estimator, such as the weighted mean $\sum_t w_t x_t / \sum_t w_t$, gives the same answer at every scale of $w$. A consumer that reads the weights as probabilities, such as a scenario risk measure that forms $\sum_t w_t L_t$ and divides by nothing, gives a wrong answer at every other scale. So the prior stores the weights divided by their sum, which every consumer reads correctly. A sum that is zero states no measure, so the function refuses it.
The function keeps the kind of StatsBase.Weights, AnalyticWeights and ProbabilityWeights, as nothing_scalar_array_getindex does. The corrected variance of each of these kinds is the same at every scale of the weights. FrequencyWeights are counts, so their corrected variance divides by $\sum_t w_t - 1$, which is zero after the division. So FrequencyWeights, and a kind the function cannot rebuild such as StatsBase.UnitWeights, become StatsBase.AnalyticWeights, as the prior probabilities of EntropyPoolingPrior do by default. ScenarioProbabilities states the bias correction of that kind.
Mathematical definition
\[\begin{aligned} p_t &= \frac{w_t}{\sum_{s = 1}^{T} w_s}\,. \end{aligned}\]
Where:
- $p_t$: The scenario weight that the prior stores for scenario $t$.
- $w_t$: The scenario weight of the factor prior for scenario $t$.
- $T$: Number of observations.
Algorithm
wisnothing: returnnothing, because no weights means unweighted.wis aStatsBase.Weights,AnalyticWeightsorProbabilityWeights: refuse a sum that is not positive, and return weights of the same kind overw.valuesdivided by the sum.wis any otherStatsBase.AbstractWeights,FrequencyWeightsamong them: wrap its values inStatsBase.AnalyticWeights, and apply step 2.
Arguments
w: The scenario weights of the factor prior, ornothing.
Validation
- The sum of
wis positive. Raises aDomainErrorthat holds the sum. StatsBase refuses a weight vector whose sum is not finite when it builds the vector, so a sum that reaches this function is finite.
Returns
p::Option{<:StatsBase.AbstractWeights}: The weightswdivided by their sum, ornothing.
Related
PortfolioOptimisers.cross_sectional_scenarios — Function
cross_sectional_scenarios(
Fs::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
L::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
S::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
ev::AbstractVector{<:Union{Number, AbstractJuMPScalar}}
) -> Any
Rebuild the asset return scenarios of a Cross-Sectional Factor Prior.
The function maps the scenarios of the factor prior onto the assets through the latest loadings, rescales the standardised idiosyncratic returns by the latest idiosyncratic volatilities, and adds the two. So a scenario carries the factor risk and the idiosyncratic risk of the latest observation, whatever the risk of the observation it comes from. The two histories can differ in length, and the last rows of each pair up.
Mathematical definition
\[\begin{align} n &= \min(S, T)\,, \\ \hat{x}_{si} &= \sum_{k=1}^{K} B_{Tik} \, f_{S - n + s,\,k} + \sqrt{v_{Ti}} \, \tilde{z}_{T - n + s,\,i}\,, \quad s = 1, \ldots, n\,. \end{align}\]
Where:
- $n$: Number of asset return scenarios.
- $S$: Number of factor return scenarios.
- $\hat{x}_{si}$: Return of asset $i$ in scenario $s$.
- $f_{sk}$: Return of factor $k$ in factor return scenario $s$.
- $T$: Number of observations of the standardised idiosyncratic returns.
- $\mathbf{B}_{T}$: Latest Factor Exposures, $N \times K$, with entry $B_{Tik}$ for asset $i$ and factor $k$.
- $v_{ti}$: Idiosyncratic variance of asset $i$ that the fit estimated from the observations up to $t$, so it is the forecast for observation $t + 1$.
- $\tilde{z}_{ti}$: Filled standardised idiosyncratic return of asset $i$ at observation $t$. It is $z_{ti}$ where that is finite, $\bar{z}_{t}$ where the asset is active and $z_{ti}$ is not finite, and
NaNwhere the asset is inactive. - $K$: Number of factors.
A non-investable asset has a non-finite latest variance or a non-finite row of $\mathbf{B}_{T}$, so its column is NaN in every scenario. The contract of factor_exposure writes NaN at every inactive cell, so this also holds for an asset that is inactive at the latest observation.
Arguments
Fs: Factor return scenarios on the reduced axis,scenarios × factors.L: The reduced loadings of the latest observation,assets × factors.S: The standardised idiosyncratic returns,observations × assets.ev: The latest idiosyncratic variances, one per asset.
Validation
LmatchesFson the factor axis, andSandevmatchLon the asset axis. Raises aDimensionMismatch.
Returns
Xs::Matrix{<:Real}: The asset return scenarios,scenarios × assets.
Related
PortfolioOptimisers.cross_sectional_moment_prior — Function
cross_sectional_moment_prior(pe::CrossSectionalFactorPrior, f_pr::FactorPriorMoments,
csfm::CrossSectionalFactorModel, sp::SplitReturnForecast,
L::MatNum,
am::AbstractVector{Bool}, Xs::MatNum, oX::Option{<:MatNum};
kwargs...) -> LowOrderPriorBuild the Prior Result of a CrossSectionalFactorPrior from its block and its factor moments, with the steps of cross_sectional_assemble that read the factor moments.
The fit and the call with no data of the carry fold reach it through cross_sectional_assemble. The refit of scenario_prior under new scenario weights reaches it with the block of the fit that the views read. The block, the scenarios and the Return Forecast read no scenario weight of the factor prior, so the refit takes them from that fit, and only the steps that this function runs read the new weights.
Algorithm
- Take the ready factors of
f_prwithcross_sectional_ready_factorsand the determined assets withcross_sectional_determined. Refuse a fit that determines no asset withassert_cross_sectional_factor_moments. - Resolve the Spanned Shrinkage
lambdaand the Orthogonal Forecast Scalecwithcross_sectional_calibration, against the factor momentsf_prand the blockcsfm. - Write
b = c ap, the Return Forecast Result and the resolvedlambdaandconto the block withcross_sectional_forecast_block, givingrr. Blend the spanned part into the mean of the estimated factors withcross_sectional_forecast_muunder the resolvedlambda, and keep the mean of the observed factors, givingf_mu. - Expand the blended factor moments onto the raw factor axis with
cross_sectional_expand, with the basis of the block. - Take the investable assets
idxwithcross_sectional_investable, from the active assetsamof the latest observation, the latest idiosyncratic variances ofcsfm.vs, and the assets that the ready factors of the blended mean determine. - Lift the reduced factor distribution onto the assets with
cross_sectional_lift, and addbto the expected return it answers. - Assemble a
LowOrderPrioroverXs, withoXundero_X, the three lifted moments, the factor prior'swdivided by its sum, itsens,kldandow, the block underrr, and the expanded factor prior underfpr. The factor prior keeps the cachepcof a pool that answered it, so the refit of the pool reads it fromfpr. The factor prior holds the factor returns of the block on the raw axis, on the last rows that the scenarios keep.
Arguments
pe: Cross-Sectional Factor Prior estimator.f_pr: The factor moments thatcross_sectional_factor_momentsstates over the combined reduced factor returns.csfm: The factor-model block, with the regression, the variance history, the idiosyncratic covariance, the basis and the factor returns of the fit.sp: The split of the Return Forecast, aSplitReturnForecast.L: The loadings of the latest observation on the combined reduced factor axis.am: The active mask of the latest observation, one entry per asset.Xs: The asset return scenarios.oX: The base-currency returns of the scenario rows, ornothing.kwargs...: Additional keyword arguments passed tocross_sectional_lift.
Validation
- The factor prior determines the factor moments of at least one asset. Raises an
IsNonFiniteError. - At least one asset is investable at the latest observation. Raises an
IsEmptyError. - The rules of every verb the algorithm names. A resolved
lambdalies in[0, 1], and a resolvedcis finite and>= 0.
Returns
pr::LowOrderPrior: The prior on the full asset universe, aspriorstates it.
Related
PortfolioOptimisers.cross_sectional_kept_cache — Function
cross_sectional_kept_cache(f_pr::FactorPriorMoments, pf::Option{<:AbstractPriorResult})
-> FactorPriorMomentsKeep the cache of a pool in the factor slot of a CrossSectionalFactorPrior on the factor moments of its refit.
The refit of scenario_prior fits the model of the pool under the new weights, which is pe2 of the pool and keeps no cache. So the factor prior fpr of the refit would carry no cache, and an entropy pooling prior around a nested one would run the opinions of the pool again. The fit that the views read gives the cache in pf, the factor prior of its result, and the refit keeps it.
Arguments
f_pr: The factor moments of the refit, ascross_sectional_factor_momentsstates them.pf: The factor prior of the result of the fit that the views read, ornothing.
Returns
f_pr::FactorPriorMoments:f_pr, withpcfrompfwhenf_prcarries none.
Related
PortfolioOptimisers.cross_sectional_stored_cache — Function
cross_sectional_stored_cache(csfm::CrossSectionalFactorModel, cache_reg::Bool,
amr::AbstractMatrix{Bool}, hist::Option{<:MatNum})
-> CrossSectionalFactorModelStore the cache that the refit of an entropy pooling prior reads on the block of a CrossSectionalFactorPrior.
cross_sectional_assemble calls it after the Return Forecast. A plain fit stores nothing, and a fit with cache_reg = true stores the active mask of the fitted rows in amr and the Return Forecast history in hist, which is nothing when no Calibration Slot reads it.
Arguments
csfm: The factor-model block.cache_reg: Iftrue, store the cache.amr: The active mask of the fitted rows.hist: The Return Forecast history, ornothing.
Returns
csfm::CrossSectionalFactorModel: The block, with the cache whencache_registrue.
Related
PortfolioOptimisers.kept_scenarios — Function
kept_scenarios(pe::AbstractPriorEstimator, T::Integer)
kept_scenarios(pe::EmpiricalPrior, T::Integer)
kept_scenarios(pe::Union{FactorPrior, FactorBlackLittermanPrior,
BlackLittermanPrior, BayesianBlackLittermanPrior,
EntropyPoolingPrior, MeucciEntropyPoolingPrior,
HighOrderPriorEstimator, HighOrderFactorPriorEstimator},
T::Integer)
kept_scenarios(pe::AugmentedBlackLittermanPrior, T::Integer)
kept_scenarios(pe::OpinionPoolingPrior, T::Integer)Return the number of scenarios that a fit of pe on T observations carries, when the configuration of pe alone states it, and nothing when the data decides it.
scenario_count reads this function first, so a prior whose count the configuration states needs no data to count its scenarios. A Scenario Cap keeps the last pe.max_scenarios rows, and a prior that wraps another carries the rows of the prior that it wraps. A CrossSectionalFactorPrior drops the rows that its Descriptors warm up over, which the data decides, so it answers nothing.
Algorithm
The method that Julia selects is the algorithm.
- Any other prior: return
Twhenkeeps_observationsreturnstrueforpe, andnothingotherwise. - An
EmpiricalPrior: returnT, orpe.max_scenarioswhen it is set and smaller, becausescenario_windowkeeps the lastpe.max_scenariosrows. - A prior whose result carries the scenarios of the prior in its
pefield: return this function ofpe.pe. A factor prior fitspe.peon the factor returns, which have the rows of the asset returns. - An
AugmentedBlackLittermanPrior: return the smaller of this function ofpe.a_peand ofpe.f_pe, because the result keeps the rows that both nested priors keep. Returnnothingwhen either one isnothing. - An
OpinionPoolingPrior: returnTwhenpe.pe1isnothing, and this function ofpe.pe1otherwise.
Arguments
pe: Prior estimator.T: The number of observations that the fit ofpereceives.
Returns
n::Option{Int}: The number of scenarios of the fit, ornothingwhen the data decides it.
Related
PortfolioOptimisers.scenario_count — Function
scenario_count(pe::AbstractPriorEstimator, X::MatNum, F::Option{<:MatNum},
pnl::Option{<:AssetPanel}; strict::Bool = false, kwargs...)
scenario_count(pe::Union{FactorPrior, FactorBlackLittermanPrior}, X::MatNum,
F::MatNum, pnl::Option{<:AssetPanel}; strict::Bool = false, kwargs...)
scenario_count(pe::Union{BlackLittermanPrior, BayesianBlackLittermanPrior,
EntropyPoolingPrior, MeucciEntropyPoolingPrior,
HighOrderPriorEstimator, HighOrderFactorPriorEstimator},
X::MatNum, F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; kwargs...)
scenario_count(pe::AugmentedBlackLittermanPrior, X::MatNum, F::MatNum,
pnl::Option{<:AssetPanel}; strict::Bool = false, kwargs...)
scenario_count(pe::OpinionPoolingPrior, X::MatNum, F::Option{<:MatNum},
pnl::Option{<:AssetPanel}; kwargs...)
scenario_count(pe::CrossSectionalFactorPrior, X::MatNum, F::Option{<:MatNum},
pnl::AssetPanel; strict::Bool = false, ne::Option{<:VecStr} = nothing,
E::Option{<:MatNum} = nothing, iv::Option{<:MatNum} = nothing,
ivpa::Option{<:Num_VecNum} = nothing, kwargs...)Return the number of scenarios that the fit of pe on X, F and pnl carries, with the least work that states it.
A prior that reweights observations, such as EntropyPoolingPrior, checks a caller's prior probabilities against the scenarios of the prior that it wraps, before it fits that prior under them. A fit states the count, but the count needs only the steps that drop rows. When the configuration states the count, kept_scenarios gives it with no fit. A CrossSectionalFactorPrior drops the rows that its Descriptors warm up over, which the data decides, so its count runs its exposure stage, and not its regression, its factor moments or its assembly.
Algorithm
The method that Julia selects is the algorithm.
- Any other prior: return
kept_scenariosofpeonsize(X, 1)observations when it is notnothing. Otherwise fitpeand return the row count of its scenarios. - A
FactorPrioror aFactorBlackLittermanPrior: return this function ofpe.peonFalone, as the fit ofpefitspe.pe. The asset rows are cut to the rows of the factor prior. - A prior whose result carries the scenarios of the prior in its
pefield: return this function ofpe.peonX,Fandpnl. - An
AugmentedBlackLittermanPrior: return the smaller of this function ofpe.a_peonXandpnl, and ofpe.f_peonFalone, because the result keeps the rows that both nested priors keep. - An
OpinionPoolingPrior: returnsize(X, 1)whenpe.pe1isnothing, and this function ofpe.pe1otherwise. - A
CrossSectionalFactorPrior: take the rowsrwafter the Descriptor warm-up withcross_sectional_exposure_stage, and check them against the exposure lag withassert_cross_sectional_lag_rows. The regression answersn = length(rw) - pe.lagfactor returns. Returnkept_scenariosofpe.peonnobservations when it is notnothing. Otherwise take the factor returns withcross_sectional_factor_scenarios, and return this function ofpe.peon them alone.
Arguments
pe: Prior estimator.X: Asset returns matrix, already oriented.F: Optional factor returns matrix, already oriented.pnl: OptionalAssetPanel, the panel that the returns data held. A wrapping prior forwards it unchanged, so that it can compose an estimator that is fitted on a panel. An estimator that reads no panel ignores it.strict: Iftrue, throws error for missing assets; otherwise, issue warnings.ne,E,iv,ivpa: As in the returns-matrix method ofprior, withEalready oriented.kwargs...: Additional keyword arguments of the fit ofpe.
Validation
- The rules of every step of the fit that the method runs.
Returns
T::Int: The number of scenarios that the fit ofpecarries.
Related
PortfolioOptimisers.assert_cross_sectional_lag_rows — Function
assert_cross_sectional_lag_rows(t::Integer, lag::Integer)Check that the t rows after the Descriptor warm-up of a CrossSectionalFactorPrior leave at least two factor returns after the exposure lag lag.
The regression reads the exposures of the row lag observations before each return, so it answers t - lag factor returns. The factor prior states a covariance of them, and a covariance of one observation is not a number. cross_sectional_regression_stage and scenario_count both read this check, so a count refuses the rows that the fit refuses.
Arguments
t: The number of rows after the Descriptor warm-up.lag: The exposure lag,pe.lag.
Validation
t > lag. Raises anArgumentError.t - lag >= 2. Raises anArgumentError.
Returns
nothing.
Related
PortfolioOptimisers.scenario_moment_counts — Function
scenario_moment_counts(pe::EmpiricalPrior, X::MatNum, t::Integer,
T_mu::Option{<:Real} = nothing; kwargs...)
-> Tuple{Option{<:Real}, Option{<:Real}}State the effective number of observations of the mean and of the covariance of an empirical Prior Result, in the form of its field eoc.
pe.me fits mu and pe.ce fits sigma over every row of X. Each estimator states the number of observations that its moment is worth with effective_observation_count. That is size(X, 1) for an unweighted estimator, and the count of its weights for a weighted one, such as the Kish count of an exponentially weighted covariance. The two estimators can carry different weights, so each moment has its own count.
T_mu is the count of the mean that the fit of mu stated, from mean_with_count. A PriorExpectedReturns states it, because its count is known only after the fit of its prior. When T_mu is nothing, the function reads the count of pe.me with effective_observation_count.
A Scenario Cap cuts the rows that the result carries to the last t, and leaves the moments fitted over every row. scenario_window makes the cut. A consumer that reads size(pr.X, 1) then reads t rows for moments fitted over size(X, 1). So an entry of eoc states the count whenever it is not t, and nothing otherwise, through moment_count_entry. A fit with no cap and no weights states (nothing, nothing).
It is the same function in batch and in prior(pe) with no data after a fold, as scenario_window is. The fold keeps the rows in its buffer, so both routes read the same counts over the same rows.
Arguments
pe: Empirical prior estimator.X: The returns that the moments were fitted over,observations × assets, before the cut. Under a horizon they are the log-returns.t: The number of rows that the result carries, after the cut.T_mu: The count of the mean that the fit ofmustated, ornothing.kwargs...: The keywords that the prior gives to the fits ofmuandsigma. The function gives them toeffective_observation_count, so a count reads the same values as its fit.
Returns
eoc::Tuple: The entries(T_mu, T_sigma)of the fieldeoc.
Related
PortfolioOptimisers.mean_with_count — Function
mean_with_count(me::AbstractExpectedReturnsEstimator, X::MatNum,
pnl::Option{<:AssetPanel}; dims::Int = 1, kwargs...)
mean_with_count(me::AbstractExpectedReturnsEstimator; kwargs...)Fit the mean of me as a vector, and return it with the count of the mean that the fit states.
An EmpiricalPrior reads its mean through this function, and gives the count to scenario_moment_counts. Most mean estimators state their count before the fit, with effective_observation_count, so the function returns nothing as their count. A PriorExpectedReturns reads the mu of a prior that it fits, and a pooling prior knows its count only after its fit. So its method returns entry 1 of the eoc of that prior result, and the prior is fitted once.
The form with no data reads a folded estimator, as Statistics.mean(me) does.
Algorithm
The method that Julia selects is the algorithm.
- On a mean estimator with no method of its own, fit
muwithStatistics.mean, and returnvec(mu)with the countnothing. - On
PriorExpectedReturns, fit the prior resultprwithprior, with no factor returns. Returnvec(pr.mu)with the count of the mean ofpr, frommoment_observation_count. The form with no data readsprior(me.pe).
Arguments
me: The expected returns estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.pnl: OptionalAssetPanel. The Coverage Universe of the fit comes from its active mask. If it isnothing, the rule reads only the finiteness of the returns.dims: Dimension along which the computation runs.kwargs...: Forwarded to the fit of the mean.
Validation
- Everything the fit of the mean refuses.
Returns
(mu, T_mu)::Tuple: The mean vectormu, and its countT_mu, aRealornothing.
Related
PortfolioOptimisers.scenario_fill_report — Function
scenario_fill_report(filled, ::Nothing)
scenario_fill_report(filled, named::AbstractSet{<:Integer})Narrow the filled pairs a scenario_fill reports to the assets it has not named before.
A batch fit calls scenario_fill once, so it reports everything it finds and keeps no memory: that is the nothing method. A walk-forward reading out at every step calls it once per step over a growing window, and every step would otherwise name the same assets again, so a caller who read the first notice learns to ignore the channel and misses the asset that lists at step 500.
So a carry state holds the set of assets it has already named, and this verb narrows the report to the pairs of assets outside it. The set is the state's memory, and scenario_fill_remember! is what writes to it — only for a notice that actually fired, so an asset whose share was under the limit at one step is still named at the step where it goes over.
Arguments
filled: The(observation, asset)pairsscenario_fill_pairsfound.named: The assets already named, ornothingwhen nothing remembers.
Returns
report::AbstractVector{<:Tuple{Integer, Integer}}: The pairs to name, which isfilleditself when nothing remembers.
Related
PortfolioOptimisers.scenario_fill_remember! — Function
scenario_fill_remember!(::Nothing, report)
scenario_fill_remember!(named::AbstractSet{<:Integer}, report)Record the assets a scenario_fill has just named, so a later call of prior(pe) with no data does not name them again.
The write side of scenario_fill_report. It runs after the notice, not before it, so an asset is remembered exactly when a caller was told about it: under strict the notice throws and nothing is remembered, and under a limit the notice did not trip nothing is remembered either.
The set is a field of a PriorCarryState and is written in place, because prior(pe) with no data returns a Prior Result rather than the estimator, so there is no other channel by which the memory could survive the call.
Arguments
named: The assets already named, ornothingwhen nothing remembers.report: The(observation, asset)pairs just named.
Returns
nothing.
Related