Entropy pooling Prior (c): private API
PortfolioOptimisers.VecEP — Type
const VecEP = AbstractVector{<:Union{EntropyPoolingPrior, MeucciEntropyPoolingPrior}}Alias for an abstract vector of entropy pooling prior estimators of either family.
Related
PortfolioOptimisers.show_fields — Method
show_fields(_::EntropyPoolingPrior) -> NTuple{17, Symbol}
Give every field of an EntropyPoolingPrior to print, except cache.
The state in cache changes at each step of an incremental fit, and it is not part of the configuration. Each site that prints the estimator also prints this state, unless this method leaves it out. Set set_show_nothing_fields!(:EntropyPoolingPrior, true) to print it.
Arguments
::EntropyPoolingPrior: Prior estimator, read for its type alone.
Returns
fields::Tuple: The field names to render, which is(:pe, :mu_views, :var_views, :cvar_views, :evar_views, :rlvar_views, :sigma_views, :sk_views, :kt_views, :cov_views, :rho_views, :sets, :opt, :diagnose, :w, :alg, :x_src).
Related
PortfolioOptimisers.assert_ep_views_axis — Function
assert_ep_views_axis(::Nothing, ::MatNum)
assert_ep_views_axis(sets::UniverseSets, X::MatNum)Refuse the asset universe of an entropy pooling prior when it does not match the returns matrix.
The views of an EntropyPoolingPrior and of a MeucciEntropyPoolingPrior resolve asset names against sets. Each name maps to the column of X at its position in the asset list. An asset list with a different length maps the names to the wrong columns, or to no column, and the fit then fails in a matrix product with an error that names no field. This guard refuses the input first, with a message that names sets. It is the entropy pooling twin of assert_bl_views_axis. The guard reads the asset list whenever sets is set, because each view of these estimators resolves names. The constructor refuses a view with no sets.
Algorithm
The method that Julia selects is the algorithm.
setsisnothing: no view resolves a name, so returnnothing.setsis aUniverseSets: check that the length ofsets.dict[sets.xkey]is equal tosize(X, 2), and returnnothing.
Arguments
sets: The universe sets of the estimator,pe.sets, ornothing.X: Asset returns,observations × assets.
Validation
length(sets.dict[sets.xkey]) == size(X, 2)whensetsis notnothing. Raises aDimensionMismatch.
Returns
nothing.
Related
PortfolioOptimisers.ep_prior — Function
ep_prior(alg::StagedEP, pe::EntropyPoolingPrior, X::MatNum, F::Option{<:MatNum},
pnl::Option{<:AssetPanel} = nothing; strict::Bool = false, kwargs...)Compute the entropy pooling prior moments of the asset returns, with the views applied in stages.
ep_prior calculates the mean and the covariance of the asset returns with entropy pooling, under the staged algorithms H1_EntropyPooling and H2_EntropyPooling. Each stage adds the views of one group of moments to one constraint set, solves, and refits the wrapped estimator under the new weights. So the views of a stage hold together with every view of the stages before it. A later stage fixes the moments that the earlier stages set, so a view on a higher moment does not move a lower moment.
Algorithm
- Fit the wrapped prior estimator with
ep_wrapped_prior. The result isprand the prior probabilitiesw0on its rows. The fit sets the observation axis.Tissize(pr.X, 1), which is smaller thansize(X, 1)when a nested prior drops rows. The probabilities arepe.wwhen the caller gives one,pr.wwhen the fit returns one, and the uniform1/Totherwise.prior_probability_factoryputs thepe.wof the caller on the rows that each weighted field of the wrapped estimator reads, and the fit ofpruses it. Before that fit,scenario_countreadsTwith only the steps that drop rows, so most wrapped priors need no fit for it. When the fit underpe.wreturns its ownpr.w, a nested prior solved its views frompe.w. Thenw0ispr.w, the posterior of the nested prior. - Pin each choice of
pe.peunder aPinnedChoiceat this fit withpin_prior_choice, so every refit reads the choice that the views read. Every refit goes throughscenario_prior, which holds the model of this fit, with its regression and its residual block. So the refit reads the scenarios that the views read. - Get the Investable Mask of the fit and the universe of the views with
investable_views. Every view row uses only the investable columns, and the mask is the same at each stage. - Make the empty constraint dictionary
epc, the empty tail view vectortvs, the matrixfixedof the pinned moments, and the Departure Ledger. - Stage one, the mean, the value at risk and the three tail measures. Write the
mu_viewsandvar_viewsrows intoepc. Lower thecvar_views,evar_viewsandrlvar_viewsintoepcandtvswithep_tail_views!. Whenepcortvsis not empty, solve fromw0withentropy_poolingintow1, and refitprunderw1. - Stage two, the variance and the covariance, when
sigma_viewsorcov_viewsis set. Write thesigma_viewsandcov_viewsrows intoepc. Pin the mean of every asset that those rows read withfix_mu!. Under the same test, solve intow1, and refitprunderw1. - Stage three, the skewness, the kurtosis and the correlation, when
sk_views,kt_viewsorrho_viewsis set. Write thesk_views,kt_viewsandrho_viewsrows intoepc. Pin the mean and the variance of every asset that those rows read withfix_mu!andfix_sigma!. Under the same test, solve intow1, and refitprunderw1. - Steps 6 and 7 solve from
w0underH1_EntropyPooling, and from thew1of the stage before underH2_EntropyPooling. - Report the departed assets and the views that they removed, with
announce_ep_departures. - Calculate the effective number of scenarios
ens, the exponential of the entropy ofw1. Calculatekld, the Kullback-Leibler divergence ofw1fromw0. - Return a
LowOrderPriorthat holds the moments of the last refit,w1,ensandkld. The factor blockfprcomes from that refit with no change.
Under strict = false, every row of every family can drop, and a stage then states no view. The test reads the rows that the stages hold, not the fields that the caller set. So such a fit returns the prior. Then w1 is w0, kld is zero, and no refit runs.
Arguments
alg: Staged entropy pooling algorithm, whichpriorreads frompe.alg.::H1_EntropyPooling: Each stage solves from the prior probabilitiesw0.::H2_EntropyPooling: Each stage solves from the weights of the stage before.
pe: Entropy pooling 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, raise an error for an asset that the universe does not hold. Iffalse, warn.kwargs...: More keyword arguments, which go to the wrapped prior estimator.
Returns
pr::LowOrderPrior: Prior result that holds the asset returns, the posterior mean and covariance, the posterior probability weights, the effective number of scenarios, the Kullback-Leibler divergence and the factor block of the last refit.
Related
PortfolioOptimisers.ep_prior — Function
ep_prior(alg::H0_EntropyPooling, pe::EntropyPoolingPrior, X::MatNum,
F::Option{<:MatNum}, pnl::Option{<:AssetPanel} = nothing;
strict::Bool = false, kwargs...)Compute the entropy pooling prior moments of the asset returns, with every view applied in one solve.
ep_prior calculates the mean and the covariance of the asset returns with entropy pooling, under the H0_EntropyPooling algorithm. It builds every view against the same prior, and solves the entropy pooling problem one time. No stage holds the lower moments fixed, so a view on a higher moment can move a lower moment.
Algorithm
- Fit the wrapped prior estimator with
ep_wrapped_prior. The result isprand the prior probabilitiesw0on its rows. The fit sets the observation axis.Tissize(pr.X, 1), which is smaller thansize(X, 1)when a nested prior drops rows. The probabilities arepe.wwhen the caller gives one,pr.wwhen the fit returns one, and the uniform1/Totherwise.prior_probability_factoryputs thepe.wof the caller on the rows that each weighted field of the wrapped estimator reads, and the fit ofpruses it. Before that fit,scenario_countreadsTwith only the steps that drop rows, so most wrapped priors need no fit for it. When the fit underpe.wreturns its ownpr.w, a nested prior solved its views frompe.w. Thenw0ispr.w, the posterior of the nested prior. - Pin each choice of
pe.peunder aPinnedChoiceat this fit withpin_prior_choice, so every refit reads the choice that the views read. Every refit goes throughscenario_prior, which holds the model of this fit, with its regression and its residual block. So the refit reads the scenarios that the views read. - Get the Investable Mask of the fit and the universe of the views with
investable_views. Every view row uses only the investable columns. - Make the empty constraint dictionary
epc, the empty tail view vectortvsand the Departure Ledger. - Write the
mu_viewsandvar_viewsrows intoepc. Lower thecvar_views,evar_viewsandrlvar_viewsintoepcandtvswithep_tail_views!. - Write the
sigma_views,cov_views,sk_views,kt_viewsandrho_viewsrows intoepc. This route pins no moment, so it does not callfix_mu!orfix_sigma!. - Report the departed assets and the views that they removed, with
announce_ep_departures. - When
epcortvsis not empty, solve the whole set one time fromw0withentropy_poolingintow1, and refitprunderw1. Understrict = false, every row of every family can drop, and the view set then states no view. Thenw1isw0,kldis zero, and no refit runs. - Calculate the effective number of scenarios
ens, the exponential of the entropy ofw1. Calculatekld, the Kullback-Leibler divergence ofw1fromw0. - Return a
LowOrderPriorthat holds the moments of the refit,w1,ensandkld. The factor blockfprcomes from that refit with no change.
Arguments
alg: Single-shot entropy pooling algorithm, whichpriorreads frompe.alg.pe: Entropy pooling 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, raise an error for an asset that the universe does not hold. Iffalse, warn.kwargs...: More keyword arguments, which go to the wrapped prior estimator.
Returns
pr::LowOrderPrior: Prior result that holds the asset returns, the posterior mean and covariance, the posterior probability weights, the effective number of scenarios, the Kullback-Leibler divergence and the factor block of the refit.
Related
PortfolioOptimisers.embedded_pin_weights — Function
embedded_pin_weights(pe::AbstractPriorEstimator, w)
embedded_pin_weights(pe::Union{EntropyPoolingPrior, MeucciEntropyPoolingPrior}, w)Return the observation weights of the fit of pe.pe, the prior that pe embeds, so that pin_prior_choice pins the choice of that fit.
A prior that embeds a prior fits it under the weights w that the prior around it gives it. An entropy pooling prior fits it under the caller's prior probabilities pe.w, builds its views on that fit, and refits under the posterior weights. Each refit reads the choice of that first fit. factory writes the weights of the outer prior into pe.w, so the weights of the first fit are w when w is set, and pe.w otherwise. They are not the w0 of ep_prior, which is the posterior of a nested prior that reweights its scenarios. When both are nothing, the fit is unweighted.
Algorithm
The method that Julia selects is the algorithm.
- Any other prior: return
w. - An entropy pooling prior: return
wwhen it is notnothing, andpe.wotherwise.
Arguments
pe: The prior that embeds a prior inpe.pe.w: The observation weights under which the batch fit makes the choice that the method pins, ornothingwhen that fit is unweighted.
Returns
w::Option{<:AbstractWeights}: The weights of the fit ofpe.pe, ornothing.
Related
PortfolioOptimisers.ep_wrapped_prior — Function
ep_wrapped_prior(pe::Union{EntropyPoolingPrior, MeucciEntropyPoolingPrior},
X::MatNum, F::Option{<:MatNum}, pnl::Option{<:AssetPanel};
strict::Bool = false, kwargs...)Fit the prior that an entropy pooling prior wraps, and read the prior probabilities that its solve starts from.
A caller's pe.w states the probabilities of the scenarios that the wrapped prior answers, and the wrapped prior is fitted under them. A wrapped prior can answer fewer rows than it receives, so this function reads the count of its scenarios with scenario_count before the fit under pe.w. That count runs only the steps of the fit that drop rows. It needs no fit for a prior that keeps_observations, a Scenario Cap, or a prior that wraps one of these, and it needs only the exposure stage of a CrossSectionalFactorPrior. A prior that states no count is fitted once to read it.
Algorithm
- When
pe.wisnothing, fitpe.pe. The result ispr. Read the prior probabilitiesw0fromprwithep_prior_probabilities, and returnpe,prandw0. - Otherwise, find the count
Tof the scenarios ofpe.pewithscenario_count. - Check
pe.wagainstTwithep_prior_probabilities. The result isw0. - Put
w0on the rows that each weighted field ofpe.pereads withprior_probability_factory. The result is a newpe. Fit itspe.pe, and the result ispr. - Return the new
pe,pr, andpr.wthroughscenario_probabilitieswhen it is notnothing, orw0otherwise. A wrapped prior that reweights its scenarios solved its own views fromw0, and its posterior is the prior of this estimator.
Each fit of pe.pe passes cache_reg = true, so a prior that stores a cache gives it to the refits of scenario_prior, which read it from pr.
Arguments
pe: Entropy pooling 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, raise an error for an asset that the universe does not hold. Iffalse, warn.kwargs...: More keyword arguments, which go to the wrapped prior estimator.
Validation
- The rules of
ep_prior_probabilities. - Under a caller's
pe.w, the fit ofpe.peanswers theTrows thatscenario_countcounted. Otherwise the function throws aDimensionMismatchthat names both counts.
Returns
pe::Union{EntropyPoolingPrior, MeucciEntropyPoolingPrior}: The estimator whosepe.peansweredpr.pr::AbstractPriorResult: Prior result of the wrapped prior.w0::ScenarioProbabilities: Prior probabilities, on the rows ofpr.X.
Related
PortfolioOptimisers.scenario_factory — Function
scenario_factory(pe::AbstractPriorEstimator, w, pr::Option{<:AbstractPriorResult},
X::MatNum, F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; kwargs...)
scenario_factory(pe::EmpiricalPrior, w, pr::Option{<:AbstractPriorResult}, X::MatNum,
F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; kwargs...)
scenario_factory(pe::Union{FactorPrior, FactorBlackLittermanPrior}, w,
pr::Option{<:AbstractPriorResult}, X::MatNum, F::MatNum,
pnl::Option{<:AssetPanel}; strict::Bool = false, kwargs...)
scenario_factory(pe::Union{BlackLittermanPrior, BayesianBlackLittermanPrior}, w,
pr::Option{<:AbstractPriorResult}, X::MatNum, F::Option{<:MatNum},
pnl::Option{<:AssetPanel}; kwargs...)
scenario_factory(pe::AugmentedBlackLittermanPrior, w, pr::Option{<:AbstractPriorResult},
X::MatNum, F::MatNum, pnl::Option{<:AssetPanel}; strict::Bool = false,
kwargs...)
scenario_factory(pe::Union{EntropyPoolingPrior, MeucciEntropyPoolingPrior}, w,
pr::Option{<:AbstractPriorResult}, X::MatNum, F::Option{<:MatNum},
pnl::Option{<:AssetPanel}; kwargs...)
scenario_factory(pe::OpinionPoolingPrior, w, pr::Option{<:AbstractPriorResult},
X::MatNum, F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; kwargs...)
scenario_factory(pe::CrossSectionalFactorPrior, w, pr::Option{<:AbstractPriorResult},
X::MatNum, F::Option{<:MatNum}, pnl::Option{<:AssetPanel};
strict::Bool = false, cache_reg::Bool = false, kwargs...)Return the estimator that an entropy pooling prior refits under its posterior weights w.
Entropy pooling holds the scenarios and changes only their probabilities, so the posterior moments are the moments of the same scenarios under w. EntropyPoolingPrior and MeucciEntropyPoolingPrior build their views on the rows pr.X of the fit of pe under the prior probabilities. A prior that fits a time-series regression makes those rows from the regression, F * transpose(M) .+ transpose(b). factory gives w to the regression too, so the refit fitted a new regression, and the rows that the views read moved under the posterior.
This function gives w to the estimators that read the scenarios, and holds the model that makes them. The regression re keeps the weights of the fit that the views read, so the refit reproduces the loadings, the intercepts and the rows of that fit. The variance estimator ve of the residual block keeps them too, so the residual block of the posterior is the block of that fit, which the views take off their targets with scenario_residual_variances. Then the posterior moments are the moments of the model of the prior under w, and every mean view holds on the posterior mean. The same model is what FactorPrior answers over an entropy pooling prior of the factors, whose regression and residual block read no posterior weights.
Mathematical definition
The rows of the fit under the prior probabilities are $\mathbf{X} = \mathbf{F} \mathbf{B}^\intercal + \mathbf{1} \boldsymbol{\alpha}^\intercal$. Under the posterior probabilities $\boldsymbol{p}$ the refit answers
\[\begin{align} \hat{\boldsymbol{\mu}} &= \mathbf{B} \hat{\boldsymbol{f}}_{\boldsymbol{p}} + \boldsymbol{\alpha}\,, \\ \hat{\mathbf{\Sigma}} &= \mathbf{B} \mathbf{\Sigma}_{f,\,\boldsymbol{p}} \mathbf{B}^\intercal + \mathbf{\Sigma}_\varepsilon\,, \end{align}\]
where $\mathbf{B}$, $\boldsymbol{\alpha}$ and $\mathbf{\Sigma}_\varepsilon$ are those of the fit under the prior probabilities, and $\hat{\boldsymbol{f}}_{\boldsymbol{p}}$ and $\mathbf{\Sigma}_{f,\,\boldsymbol{p}}$ are the factor moments under $\boldsymbol{p}$. When the factor prior reads the weighted sample mean, $\hat{\boldsymbol{\mu}} = \mathbf{X}^\intercal \boldsymbol{p}$, which is the mean that the views state.
The result pr of the fit that the views read travels down with pe, and each method gives a nested prior the part of pr that its fit answered. A prior that reads a cache from it skips the steps that the cache holds. A pr with no cache, or nothing, changes nothing, and the method then reads the data.
Algorithm
The method that Julia selects is the algorithm.
- Any other prior: return
factoryofpeunderw. Its rows are the returns, which no weight moves. - A
FactorPrioror aFactorBlackLittermanPrior: replacepe.pewith this function ofpe.peunderwon the factor returnsFalone and on the factor priorpr.fprof the fit, as the fit ofpefitspe.pe, and keep every other field. The two factor priors keepreandve. - A
BlackLittermanPrioror aBayesianBlackLittermanPrior: replacepe.pewith this function ofpe.peunderwonpr,X,Fandpnl. Theirpeis their only weighted field, and their result forwards every field of the result ofpe.pe. - An
AugmentedBlackLittermanPrior: replace the asset priora_pewith this function of it onpr,Xandpnl, and the factor priorf_pewith this function of it onpr.fprandFalone, each underw. Keepre. Its result keeps the cache of the pool ina_pe, and itsfprthe cache of the pool inf_pe. - A nested entropy pooling prior: return this function of the estimator that fits its model,
pe.pe, onpr, underprior_probability_factoryofpe.wwhen the caller set one, which putspe.won the rows that each weighted field reads. Its result forwards the fields of the result ofpe.pethat a cache reads. Its posterior is already the prior probabilities of the entropy pooling prior that embeds it, so its views are already inw. A call tofactorygives itwas its own prior probabilities, and it then solves its views again. This holds for an entropy pooling prior of the factors in step 2 too. - An
OpinionPoolingPrior: read the pooled weightswpfrom the cache ofpr, or pool the opinions onXwithopinion_pooling_weightswhenprholds no cache. Its own fit fitspe.pe2underwp. Return this function offactoryofpe.pe2underwp, underw, onpr. The posterior of the pool is already in the prior probabilities of the entropy pooling prior, sofactoryof the pool underwpooled its opinions again fromw, and aFactorPrioraround it read the factor moments of other weights. - An
EmpiricalPrior: returnfactoryofpeunderscenario_weightsofwon the rows ofX. A Scenario Cap keeps the last rows as scenarios, andwweighs these alone. Its moment estimators read every row, so the rows that the cap removed take a zero weight, and the posterior moments are those of the scenarios underw. Without a cap,wweighs every row and passes unchanged. - A
CrossSectionalFactorPrior: take the factor returns ofpe.pefrom the block ofprwithcross_sectional_cached_scenarioswhencross_sectional_cached_blockfinds a cache, and withcross_sectional_factor_scenariosonX,Fandpnlotherwise. Replacepe.pewith this function ofpe.peunderwon these factor returns alone, as the fit ofpefitspe.pe, and keep every other field. The regression, the weights of the cross-sectional fit, the residual block and the Return Forecast keep the weights of the fit that the views read, so the scenarios of the refit are the scenarios of that fit. A Scenario Cap inpe.pekeeps the last factor returns as scenarios, and step 7 gives a zero weight to the rows that it removed.
Every step recurses through this function and never through factory of a prior that reweights scenarios, so no entropy pooling constructor reads w and normalises it a second time. Each step gives a nested prior the rows that the fit of pe gives it, so a pool computes wp on the rows of the fit that the views read. A pool with pe1 refits on the rows of pe1, and no estimator that is fitted on X states that model. assert_scenario_model refuses such a pool when the entropy pooling prior is built, and scenario_prior refits a pool that the entropy pooling prior holds directly.
Arguments
pe: The prior that an entropy pooling prior embeds.w: The posterior weights.pr: The result of the fit ofpethat the views read, ornothing. A prior that stores a cache reads it from here.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.strict: Iftrue, raise an error for an asset that the universe does not hold. Iffalse, warn. The default isfalse.cache_reg: Iftrue, a prior stores on its result the cache that its refit under new scenario weights reads: aCrossSectionalFactorPriorthe active mask and the Return Forecast history on its block, and anOpinionPoolingPriorthe rows ofpe1, its pooled weights and the cache ofpe2inpc. The refit of an entropy pooling prior around it then runs no regression and no opinion. Every other prior forwards it to the prior that it wraps. Default isfalse.kwargs...: More keyword arguments, which go where the fit ofpesends them.
Returns
pe::AbstractPriorEstimator: The estimator to refit underw.
Related
PortfolioOptimisers.scenario_factor_result — Function
scenario_factor_result(pr::Option{<:AbstractPriorResult})
scenario_factor_result(pr::LowOrderPrior)Return the result of the factor prior of a fit, which a prior that holds a factor prior gives to scenario_factory of that factor prior.
A FactorPrior and a FactorBlackLittermanPrior fit their factor prior pe.pe on the factor returns, and their result carries the result of that fit in fpr. So a cache that the factor prior stores reaches the refit of the factor prior through fpr.
Arguments
pr: The result of the fit, ornothing.
Returns
fpr::Option{<:AbstractPriorResult}:pr.fprof aLowOrderPrior, andnothingfor no result or a result of any other type.
Related
PortfolioOptimisers.scenario_prior — Function
scenario_prior(pe::AbstractPriorEstimator, w, pr::Option{<:AbstractPriorResult},
X::MatNum, F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; kwargs...)
scenario_prior(pe::Union{EntropyPoolingPrior, MeucciEntropyPoolingPrior}, w,
pr::Option{<:AbstractPriorResult}, X::MatNum, F::Option{<:MatNum},
pnl::Option{<:AssetPanel}; kwargs...)
scenario_prior(pe::BlackLittermanPrior, w, pr::Option{<:AbstractPriorResult}, X::MatNum,
F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; strict::Bool = false,
kwargs...)
scenario_prior(pe::BayesianBlackLittermanPrior, w, pr::Option{<:AbstractPriorResult},
X::MatNum, F::MatNum, pnl::Option{<:AssetPanel}; strict::Bool = false,
kwargs...)
scenario_prior(pe::OpinionPoolingPrior, w, pr::Option{<:AbstractPriorResult},
X::MatNum, F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; kwargs...)
scenario_prior(pe::CrossSectionalFactorPrior, w, pr::Option{<:AbstractPriorResult},
X::MatNum, F::Option{<:MatNum}, pnl::Option{<:AssetPanel};
strict::Bool = false, cache_reg::Bool = false, kwargs...)Refit the prior that an entropy pooling prior embeds, with its scenarios under the posterior weights w.
EntropyPoolingPrior and MeucciEntropyPoolingPrior call this after each solve. Most priors are an estimator whose model scenario_factory holds, and the refit is that estimator under w. A prior that reweights scenarios itself has no such estimator. Its posterior is already the prior probabilities of the entropy pooling prior that embeds it, so its own views or opinions are already in w. A refit through factory gave w to it as its own prior probabilities, and it solved its views or pooled its opinions again from w. The weights then moved away from w, and the prior result reported the moments of other weights than the w that the result carries. This function refits the model of such a prior under w and runs no view and no opinion.
The result pr of the fit that the views read travels down with pe, as it does in scenario_factory. A prior that the entropy pooling prior fitted with cache_reg = true reads its cache from pr, and runs only the steps that read the new weights. A pr with no cache, or nothing, changes nothing.
Algorithm
The method that Julia selects is the algorithm.
- Any other prior: fit
scenario_factoryofpeunderwonpr,X,Fandpnl. - A nested entropy pooling prior: apply this function to the estimator that fits its model, on
pr, as step 5 ofscenario_factorydoes. This method exists because that model can be anOpinionPoolingPrior. - A
BlackLittermanPrioror aBayesianBlackLittermanPrior: refitpe.pewith this function underwonpr, and blend the views into its result, withbl_posteriororbbl_posterior. The result of the fit forwards every field of the result ofpe.pe, soprholds the cache ofpe.pe. It is step 1 for this prior, with the refit ofpe.pethrough this function. - An
OpinionPoolingPrior: take the rows ofpe.pe1when it is set, and the returns otherwise, as its own fit does, and the pooled weightswpof the opinions withopinion_pooling_weights, under which its own fit fitspe.pe2. Aprwhose cache holds the rows and the pooled weights gives both, so neitherpe.pe1nor an opinion runs again. Apply this function tofactoryofpe.pe2underwp, underw, on those rows and onpr. The opinions run forwpalone, and their views do not reach the result. - A
CrossSectionalFactorPrior: whencross_sectional_cached_blockfinds a cache onpr, take the factor returns of the block withcross_sectional_cached_scenarios, fitscenario_factoryofpe.peunderwon them withcross_sectional_factor_moments, split the Return Forecast of the block withcross_sectional_forecast_split, and build the result withcross_sectional_moment_prioron the block, the scenariospr.Xand the base-currency returnspr.o_Xof the fit. It runs no regression. With no cache, fit the regression once withcross_sectional_factor_scenarios, fit the factor prior on its factor returns in the same way, and assemble the result from the stage withcross_sectional_assembleundercache_reg.
Arguments
pe: The prior that an entropy pooling prior embeds.w: The posterior weights.pr: The result of the fit ofpethat the views read, ornothing. A prior that stores a cache reads it from here.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.strict: Iftrue, raise an error for an asset that the universe does not hold. Iffalse, warn. The default isfalse.cache_reg: Iftrue, a prior stores on its result the cache that its refit under new scenario weights reads: aCrossSectionalFactorPriorthe active mask and the Return Forecast history on its block, and anOpinionPoolingPriorthe rows ofpe1, its pooled weights and the cache ofpe2inpc. The refit of an entropy pooling prior around it then runs no regression and no opinion. Every other prior forwards it to the prior that it wraps. Default isfalse.kwargs...: More keyword arguments, which go toprior.
Returns
pr::AbstractPriorResult: The refitted prior result.
Related
PortfolioOptimisers.prior_probability_factory — Function
prior_probability_factory(pe::AbstractPriorEstimator, w, X::MatNum,
F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; kwargs...)
prior_probability_factory(pe::EmpiricalPrior, w, X::MatNum, F::Option{<:MatNum},
pnl::Option{<:AssetPanel}; kwargs...)
prior_probability_factory(pe::Union{FactorPrior, FactorBlackLittermanPrior}, w,
X::MatNum, F::MatNum, pnl::Option{<:AssetPanel}; kwargs...)
prior_probability_factory(pe::Union{BlackLittermanPrior,
BayesianBlackLittermanPrior,
EntropyPoolingPrior,
MeucciEntropyPoolingPrior}, w, X::MatNum,
F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; kwargs...)
prior_probability_factory(pe::AugmentedBlackLittermanPrior, w, X::MatNum, F::MatNum,
pnl::Option{<:AssetPanel}; kwargs...)
prior_probability_factory(pe::CrossSectionalFactorPrior, w, X::MatNum,
F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; kwargs...)
prior_probability_factory(pe::OpinionPoolingPrior, w, X::MatNum,
F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; kwargs...)
prior_probability_factory(pe::AbstractPriorEstimator, w, n::Integer)
prior_probability_factory(pe::EmpiricalPrior, w, n::Integer)
prior_probability_factory(pe::Union{BlackLittermanPrior,
BayesianBlackLittermanPrior,
EntropyPoolingPrior,
MeucciEntropyPoolingPrior}, w, n::Integer)
prior_probability_factory(pe::OpinionPoolingPrior, w, n::Integer)Return factory of pe under the prior probabilities w of the scenarios, with each weighted field on the rows that it reads.
EntropyPoolingPrior and MeucciEntropyPoolingPrior state a caller's w on the scenarios of the fit of the prior that they embed, and refit that prior under it. A Scenario Cap keeps the last rows of the observations as scenarios, and the moment estimators and the regression read every observation. factory gives the same w to every field, so these fields received fewer weights than rows. This function gives each such field scenario_weights of w on its rows, and every other field w as factory does. A nested entropy pooling prior keeps w as its own prior probabilities, on its scenarios.
A prior that reads no Asset Panel reads its data here only for the number of its rows. The methods that take the number of rows n in place of the data hold its rules, and every method on the data of such a prior answers through them. A factor prior is fitted on the factor returns alone, so a prior that holds one gives it the number of rows of its factor returns. A CrossSectionalFactorPrior reads that number off its exposure stage, so it runs no regression to count the rows.
Algorithm
The method that Julia selects is the algorithm.
- Any other prior: return
factoryofpeunderw. On the data, return this function ofpeon the number of rows ofX. - An
EmpiricalPrior: returnfactoryofpeunderscenario_weightsofwon thenrows. - A
FactorPrioror aFactorBlackLittermanPrior: takefactoryofpeunderscenario_weightsofwon the rows ofF, which the regression and the residual block read. Replace itspewith this function ofpe.peunderwon the number of rows ofF. - A
BlackLittermanPrior, aBayesianBlackLittermanPrioror a nested entropy pooling prior: takefactoryofpeunderw, and replace itspewith this function ofpe.peunderwonX,Fandpnl, or on thenrows. - An
AugmentedBlackLittermanPrior: takefactoryofpeunderscenario_weightsofwon the rows ofX. Replacea_pewith this function of it onXandpnl, andf_pewith this function of it on the number of rows ofF. - 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. Takefactoryofpeunderscenario_weightsofwon thenrows, which the regression, the residual block and every other weighted field read. Replace itspewith this function ofpe.peunderwon thenrows. - An
OpinionPoolingPrior: takefactoryofpeunderw, which giveswto the opinions and tope2on the scenarios of the pool. Whenpe1is set, replace it with this function ofpe1underwonX,Fandpnl, or on thenrows, because a Scenario Cap inpe1keeps fewer rows than it reads.
Arguments
pe: The prior that an entropy pooling prior embeds.w: The prior probabilities of the scenarios.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.n: The number of rows that the fit ofpereads, in place of the data.kwargs...: More keyword arguments of the fit ofpe, which go to each nested prior that readsXandpnl.
Validation
- Everything
scenario_weightsrefuses.
Returns
pe::AbstractPriorEstimator: The estimator to refit underw.
Related
PortfolioOptimisers.assert_scenario_model — Function
assert_scenario_model(pe::AbstractPriorEstimator)
assert_scenario_model(pe::Union{FactorPrior, FactorBlackLittermanPrior,
BlackLittermanPrior, BayesianBlackLittermanPrior,
EntropyPoolingPrior, MeucciEntropyPoolingPrior})
assert_scenario_model(pe::AugmentedBlackLittermanPrior)
assert_scenario_model(pe::OpinionPoolingPrior)
assert_scenario_model(pe::CrossSectionalFactorPrior)
assert_scenario_model(pe::LowDimensionEnsemblePrior)Check that scenario_factory can state the model of pe as one estimator.
scenario_factory returns the estimator that the refit of an entropy pooling prior fits on the rows of pe. An OpinionPoolingPrior with pe1 refits pe2 on the rows of pe1, which differ from the rows of pe, so no such estimator states its model. A LowDimensionEnsemblePrior reads no observation weights, so its refit under the posterior weights is the fit under the prior probabilities, and the views do not reach its moments. The check walks the priors that scenario_factory walks, and refuses each of the two, so the entropy pooling prior fails when it is built and not at the refit.
Algorithm
The method that Julia selects is the algorithm.
- Any other prior: return
nothing. - A prior that
scenario_factoryrebuilds aroundpe.pe: apply this function tope.pe. - An
AugmentedBlackLittermanPrior: apply this function tope.a_peand tope.f_pe. - An
OpinionPoolingPrior: check thatpe.pe1isnothing, and apply this function tope.pe2. - A
LowDimensionEnsemblePrior: throw.
Arguments
pe: The prior thatscenario_factoryrebuilds.
Validation
- Every
OpinionPoolingPriorthat the walk meets has nope1. Otherwise the function throws anArgumentError. - The walk meets no
LowDimensionEnsemblePrior. Otherwise the function throws anArgumentError.
Returns
nothing.
Related
PortfolioOptimisers.assert_scenario_refit — Function
assert_scenario_refit(pe::AbstractPriorEstimator)
assert_scenario_refit(pe::Union{EntropyPoolingPrior, MeucciEntropyPoolingPrior})
assert_scenario_refit(pe::OpinionPoolingPrior)Check that scenario_prior can refit pe, the prior that an entropy pooling prior embeds, under its posterior weights.
The constructors of EntropyPoolingPrior and MeucciEntropyPoolingPrior call this on their pe. The check walks the priors that scenario_prior walks, and applies assert_scenario_model where scenario_prior calls scenario_factory. scenario_prior refits a pool that the entropy pooling prior holds directly on the rows of its pe1, so this function lets such a pool keep its pe1.
Algorithm
The method that Julia selects is the algorithm.
- Any other prior: apply
assert_scenario_modeltope. - A nested entropy pooling prior: apply this function to
pe.pe. - An
OpinionPoolingPrior: apply this function tope.pe2.
Arguments
pe: The prior that an entropy pooling prior embeds.
Validation
- The rules of
assert_scenario_model.
Returns
nothing.
Related
PortfolioOptimisers.ep_tail_views! — Function
ep_tail_views!(tail_views::Nothing, args...; kwargs...)Do nothing when a problem states no tail view.
ep_tail_views! is the function that lowers a group of tail views into entropy pooling constraints. This method is the branch for an absent group. It adds no constraint, so a caller can call the function with tail_views = nothing and needs no special case.
Arguments
tail_views::Nothing: Shows that the problem states no tail view.args...: More positional arguments, which the method does not read.kwargs...: More keyword arguments, which the method does not read.
Returns
nothing.
Related
ep_tail_views!(tail_views::AbstractVector{<:AbstractEntropyPoolingTailViewEstimator},
args...; kwargs...)Lower each group of tail views under its own settings.
The function lowers each AbstractEntropyPoolingTailViewEstimator of the vector in turn. All the groups add their constraints to the same constraint set, so one entropy pooling solve meets all of them.
Algorithm
- Lower each group of
tail_viewsin turn, and passargs...andkwargs...to each call. - Return
nothing. Each call already wrote its constraints intoepcandtvs.
Arguments
tail_views: The vector of tail view groups.args...: More positional arguments, which go toep_tail_views!.kwargs...: More keyword arguments, which go toep_tail_views!.
Returns
nothing: The function mutatesepcandtvsin-place.
Related
ep_tail_views!(tail_views::AbstractEntropyPoolingTailViewEstimator, epc::AbstractDict,
tvs::AbstractVector, pr::AbstractPriorResult, sets::UniverseSets,
w::VecNum; strict::Bool = false,
ledger::Option{<:AbstractVector} = nothing)Parse a group of tail views and lower them into entropy pooling constraints.
ep_tail_views! lowers every tail view family. It parses the view equations of a LinearConstraintEstimator, and replaces the prior references with their values. It resolves the asset names against the universe, selects a formulation for each view, and appends the constraints that the formulation needs. This function solves nothing, as against the recursive algorithm of MeucciEntropyPoolingPrior. The views become part of the one entropy pooling problem that entropy_pooling solves.
The function accepts ==, >= and <=. A group name expands to its members, and each member takes the coefficient of the group. So a view on a group constrains the sum of the risk measures of the members, not their average. A view whose coefficients have one sign is a positive combination of measures, and its lower-bound form is convex. A view whose coefficients have both signs is a relative view, and its lower-bound form is not convex in general.
These two functions hold every difference between the conditional, the entropic and the relativistic value at risk. So a fourth measure needs two methods, and no fourth copy of this function:
ep_tail_view_prior_argsnames the statistic to which aprior(...)reference resolves, and the settings of its search.ep_add_tail_view!checks the shape of the view, reads its prior value, selects its formulation, and appends its constraints.
Algorithm
- Parse the view equations of
tail_views.views.val. The result is oneParsingResultfor each view. - Replace every group name with the assets of the group. The result is one term for each member.
- Replace every
prior(...)reference with the prior value of the measure, throughreplace_prior_views, under the tuple thatep_tail_view_prior_argsgives. - Expand the formulation setting to one formulation for each view with
ep_view_formulations. The result isalgs. - For each view in turn, resolve its terms with
ep_view_terms. Drop the view when the universe holds no name of the view. - Lower the view with
ep_add_tail_view!.
Arguments
tail_views: The tail view group.epc: The dictionary of entropy pooling constraints, from keys to(lhs, rhs)pairs.tvs: The vector of tail view constraints, to which the function appends.pr: The prior result. The function reads its returns matrix.sets: The universe sets that map the asset names to indices.w: The prior probability weights.strict: Iftrue, raise an error for an asset that the universe does not hold. Iffalse, warn.ledger: The Departure Ledger of the entry of the fit, ornothingwhen no caller collects the drops. The group expansion andep_view_termsfill it.
Returns
nothing: The function mutatesepcandtvsin-place.
Related
ep_tail_view_prior_argsep_add_tail_view!ConditionalValueatRiskViewEntropicValueatRiskViewRelativisticValueatRiskViewEntropyPoolingPrior
References
- [1] D. Cajas. Entropy Pooling with CVaR and EVaR Views. Available at SSRN 7120258 (2026). Section 2.2, Equations 2 to 6, and Section 2.3, Equations 7 to 11.
- [2] D. Cajas. Entropy Pooling with Relativistic Value at Risk Views. Available at SSRN 7329718 (2026). Section 2, Equations 1 to 5, and Section 3.2, Equation 7.
PortfolioOptimisers.ep_diagnose_tail_view! — Method
ep_diagnose_tail_view!(model::JuMP.Model, p,
tv::Union{LinearConditionalValueatRiskViewConstraint,
ConicEntropicValueatRiskViewConstraint,
ConicRelativisticValueatRiskViewConstraint})Add an exact tail view constraint to the feasibility programme of ep_diagnose_views.
The three dual tail view constraints state a lower bound on a positive combination of concave measures. The bound is a convex set of the posterior probabilities, and the dual blocks of ep_tail_dual_block! state it exactly. So the method adds the rows of add_ep_tail_view!, with the scale one. The solvers of the programme must then take the cones of those blocks: the exponential cone for an entropic view, and the power cone for a relativistic view.
Arguments
model: The JuMP model of the feasibility programme.p: The posterior probability variables of the model.tv: Dual tail view constraint.
Returns
nothing: The function mutatesmodelin place.
Related
References
- [1]
- D. Cajas. Entropy Pooling with CVaR and EVaR Views. Available at SSRN 7120258 (2026).
- [2]
- D. Cajas. Entropy Pooling with Relativistic Value at Risk Views. Available at SSRN 7329718 (2026).