Entropy pooling Prior (c): private API

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

source
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.

  1. sets is nothing: no view resolves a name, so return nothing.
  2. sets is a UniverseSets: check that the length of sets.dict[sets.xkey] is equal to size(X, 2), and return nothing.

Arguments

  • sets: The universe sets of the estimator, pe.sets, or nothing.
  • X: Asset returns, observations × assets.

Validation

  • length(sets.dict[sets.xkey]) == size(X, 2) when sets is not nothing. Raises a DimensionMismatch.

Returns

  • nothing.

Related

source
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

  1. Fit the wrapped prior estimator with ep_wrapped_prior. The result is pr and the prior probabilities w0 on its rows. The fit sets the observation axis. T is size(pr.X, 1), which is smaller than size(X, 1) when a nested prior drops rows. The probabilities are pe.w when the caller gives one, pr.w when the fit returns one, and the uniform 1/T otherwise. prior_probability_factory puts the pe.w of the caller on the rows that each weighted field of the wrapped estimator reads, and the fit of pr uses it. Before that fit, scenario_count reads T with only the steps that drop rows, so most wrapped priors need no fit for it. When the fit under pe.w returns its own pr.w, a nested prior solved its views from pe.w. Then w0 is pr.w, the posterior of the nested prior.
  2. Pin each choice of pe.pe under a PinnedChoice at this fit with pin_prior_choice, so every refit reads the choice that the views read. Every refit goes through scenario_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.
  3. 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.
  4. Make the empty constraint dictionary epc, the empty tail view vector tvs, the matrix fixed of the pinned moments, and the Departure Ledger.
  5. Stage one, the mean, the value at risk and the three tail measures. Write the mu_views and var_views rows into epc. Lower the cvar_views, evar_views and rlvar_views into epc and tvs with ep_tail_views!. When epc or tvs is not empty, solve from w0 with entropy_pooling into w1, and refit pr under w1.
  6. Stage two, the variance and the covariance, when sigma_views or cov_views is set. Write the sigma_views and cov_views rows into epc. Pin the mean of every asset that those rows read with fix_mu!. Under the same test, solve into w1, and refit pr under w1.
  7. Stage three, the skewness, the kurtosis and the correlation, when sk_views, kt_views or rho_views is set. Write the sk_views, kt_views and rho_views rows into epc. Pin the mean and the variance of every asset that those rows read with fix_mu! and fix_sigma!. Under the same test, solve into w1, and refit pr under w1.
  8. Steps 6 and 7 solve from w0 under H1_EntropyPooling, and from the w1 of the stage before under H2_EntropyPooling.
  9. Report the departed assets and the views that they removed, with announce_ep_departures.
  10. Calculate the effective number of scenarios ens, the exponential of the entropy of w1. Calculate kld, the Kullback-Leibler divergence of w1 from w0.
  11. Return a LowOrderPrior that holds the moments of the last refit, w1, ens and kld. The factor block fpr comes 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, which prior reads from pe.alg.

    • ::H1_EntropyPooling: Each stage solves from the prior probabilities w0.
    • ::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: Optional AssetPanel, 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: If true, raise an error for an asset that the universe does not hold. If false, 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

source
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

  1. Fit the wrapped prior estimator with ep_wrapped_prior. The result is pr and the prior probabilities w0 on its rows. The fit sets the observation axis. T is size(pr.X, 1), which is smaller than size(X, 1) when a nested prior drops rows. The probabilities are pe.w when the caller gives one, pr.w when the fit returns one, and the uniform 1/T otherwise. prior_probability_factory puts the pe.w of the caller on the rows that each weighted field of the wrapped estimator reads, and the fit of pr uses it. Before that fit, scenario_count reads T with only the steps that drop rows, so most wrapped priors need no fit for it. When the fit under pe.w returns its own pr.w, a nested prior solved its views from pe.w. Then w0 is pr.w, the posterior of the nested prior.
  2. Pin each choice of pe.pe under a PinnedChoice at this fit with pin_prior_choice, so every refit reads the choice that the views read. Every refit goes through scenario_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.
  3. Get the Investable Mask of the fit and the universe of the views with investable_views. Every view row uses only the investable columns.
  4. Make the empty constraint dictionary epc, the empty tail view vector tvs and the Departure Ledger.
  5. Write the mu_views and var_views rows into epc. Lower the cvar_views, evar_views and rlvar_views into epc and tvs with ep_tail_views!.
  6. Write the sigma_views, cov_views, sk_views, kt_views and rho_views rows into epc. This route pins no moment, so it does not call fix_mu! or fix_sigma!.
  7. Report the departed assets and the views that they removed, with announce_ep_departures.
  8. When epc or tvs is not empty, solve the whole set one time from w0 with entropy_pooling into w1, and refit pr under w1. Under strict = false, every row of every family can drop, and the view set then states no view. Then w1 is w0, kld is zero, and no refit runs.
  9. Calculate the effective number of scenarios ens, the exponential of the entropy of w1. Calculate kld, the Kullback-Leibler divergence of w1 from w0.
  10. Return a LowOrderPrior that holds the moments of the refit, w1, ens and kld. The factor block fpr comes from that refit with no change.

Arguments

  • alg: Single-shot entropy pooling algorithm, which prior reads from pe.alg.
  • pe: Entropy pooling prior estimator.
  • X: Asset returns matrix, already oriented.
  • F: Optional factor returns matrix, already oriented.
  • pnl: Optional AssetPanel, 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: If true, raise an error for an asset that the universe does not hold. If false, 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

source
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.

  1. Any other prior: return w.
  2. An entropy pooling prior: return w when it is not nothing, and pe.w otherwise.

Arguments

  • pe: The prior that embeds a prior in pe.pe.
  • w: The observation weights under which the batch fit makes the choice that the method pins, or nothing when that fit is unweighted.

Returns

  • w::Option{<:AbstractWeights}: The weights of the fit of pe.pe, or nothing.

Related

source
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

  1. When pe.w is nothing, fit pe.pe. The result is pr. Read the prior probabilities w0 from pr with ep_prior_probabilities, and return pe, pr and w0.
  2. Otherwise, find the count T of the scenarios of pe.pe with scenario_count.
  3. Check pe.w against T with ep_prior_probabilities. The result is w0.
  4. Put w0 on the rows that each weighted field of pe.pe reads with prior_probability_factory. The result is a new pe. Fit its pe.pe, and the result is pr.
  5. Return the new pe, pr, and pr.w through scenario_probabilities when it is not nothing, or w0 otherwise. A wrapped prior that reweights its scenarios solved its own views from w0, 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: Optional AssetPanel, 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: If true, raise an error for an asset that the universe does not hold. If false, 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 of pe.pe answers the T rows that scenario_count counted. Otherwise the function throws a DimensionMismatch that names both counts.

Returns

  • pe::Union{EntropyPoolingPrior, MeucciEntropyPoolingPrior}: The estimator whose pe.pe answered pr.
  • pr::AbstractPriorResult: Prior result of the wrapped prior.
  • w0::ScenarioProbabilities: Prior probabilities, on the rows of pr.X.

Related

source
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.

  1. Any other prior: return factory of pe under w. Its rows are the returns, which no weight moves.
  2. A FactorPrior or a FactorBlackLittermanPrior: replace pe.pe with this function of pe.pe under w on the factor returns F alone and on the factor prior pr.fpr of the fit, as the fit of pe fits pe.pe, and keep every other field. The two factor priors keep re and ve.
  3. A BlackLittermanPrior or a BayesianBlackLittermanPrior: replace pe.pe with this function of pe.pe under w on pr, X, F and pnl. Their pe is their only weighted field, and their result forwards every field of the result of pe.pe.
  4. An AugmentedBlackLittermanPrior: replace the asset prior a_pe with this function of it on pr, X and pnl, and the factor prior f_pe with this function of it on pr.fpr and F alone, each under w. Keep re. Its result keeps the cache of the pool in a_pe, and its fpr the cache of the pool in f_pe.
  5. A nested entropy pooling prior: return this function of the estimator that fits its model, pe.pe, on pr, under prior_probability_factory of pe.w when the caller set one, which puts pe.w on the rows that each weighted field reads. Its result forwards the fields of the result of pe.pe that a cache reads. Its posterior is already the prior probabilities of the entropy pooling prior that embeds it, so its views are already in w. A call to factory gives it w as 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.
  6. An OpinionPoolingPrior: read the pooled weights wp from the cache of pr, or pool the opinions on X with opinion_pooling_weights when pr holds no cache. Its own fit fits pe.pe2 under wp. Return this function of factory of pe.pe2 under wp, under w, on pr. The posterior of the pool is already in the prior probabilities of the entropy pooling prior, so factory of the pool under w pooled its opinions again from w, and a FactorPrior around it read the factor moments of other weights.
  7. An EmpiricalPrior: return factory of pe under scenario_weights of w on the rows of X. A Scenario Cap keeps the last rows as scenarios, and w weighs 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 under w. Without a cap, w weighs every row and passes unchanged.
  8. A CrossSectionalFactorPrior: take the factor returns of pe.pe from the block of pr with cross_sectional_cached_scenarios when cross_sectional_cached_block finds a cache, and with cross_sectional_factor_scenarios on X, F and pnl otherwise. Replace pe.pe with this function of pe.pe under w on these factor returns alone, as the fit of pe fits pe.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 in pe.pe keeps 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 of pe that the views read, or nothing. A prior that stores a cache reads it from here.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • F: Optional factor returns matrix, already oriented.
  • pnl: Optional AssetPanel, 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: If true, raise an error for an asset that the universe does not hold. If false, warn. The default is false.
  • cache_reg: If true, a prior stores on its result the cache that its refit under new scenario weights reads: a CrossSectionalFactorPrior the active mask and the Return Forecast history on its block, and an OpinionPoolingPrior the rows of pe1, its pooled weights and the cache of pe2 in pc. 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 is false.
  • kwargs...: More keyword arguments, which go where the fit of pe sends them.

Returns

  • pe::AbstractPriorEstimator: The estimator to refit under w.

Related

source
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, or nothing.

Returns

  • fpr::Option{<:AbstractPriorResult}: pr.fpr of a LowOrderPrior, and nothing for no result or a result of any other type.

Related

source
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.

  1. Any other prior: fit scenario_factory of pe under w on pr, X, F and pnl.
  2. A nested entropy pooling prior: apply this function to the estimator that fits its model, on pr, as step 5 of scenario_factory does. This method exists because that model can be an OpinionPoolingPrior.
  3. A BlackLittermanPrior or a BayesianBlackLittermanPrior: refit pe.pe with this function under w on pr, and blend the views into its result, with bl_posterior or bbl_posterior. The result of the fit forwards every field of the result of pe.pe, so pr holds the cache of pe.pe. It is step 1 for this prior, with the refit of pe.pe through this function.
  4. An OpinionPoolingPrior: take the rows of pe.pe1 when it is set, and the returns otherwise, as its own fit does, and the pooled weights wp of the opinions with opinion_pooling_weights, under which its own fit fits pe.pe2. A pr whose cache holds the rows and the pooled weights gives both, so neither pe.pe1 nor an opinion runs again. Apply this function to factory of pe.pe2 under wp, under w, on those rows and on pr. The opinions run for wp alone, and their views do not reach the result.
  5. A CrossSectionalFactorPrior: when cross_sectional_cached_block finds a cache on pr, take the factor returns of the block with cross_sectional_cached_scenarios, fit scenario_factory of pe.pe under w on them with cross_sectional_factor_moments, split the Return Forecast of the block with cross_sectional_forecast_split, and build the result with cross_sectional_moment_prior on the block, the scenarios pr.X and the base-currency returns pr.o_X of the fit. It runs no regression. With no cache, fit the regression once with cross_sectional_factor_scenarios, fit the factor prior on its factor returns in the same way, and assemble the result from the stage with cross_sectional_assemble under cache_reg.

Arguments

  • pe: The prior that an entropy pooling prior embeds.
  • w: The posterior weights.
  • pr: The result of the fit of pe that the views read, or nothing. A prior that stores a cache reads it from here.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • F: Optional factor returns matrix, already oriented.
  • pnl: Optional AssetPanel, 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: If true, raise an error for an asset that the universe does not hold. If false, warn. The default is false.
  • cache_reg: If true, a prior stores on its result the cache that its refit under new scenario weights reads: a CrossSectionalFactorPrior the active mask and the Return Forecast history on its block, and an OpinionPoolingPrior the rows of pe1, its pooled weights and the cache of pe2 in pc. 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 is false.
  • kwargs...: More keyword arguments, which go to prior.

Returns

  • pr::AbstractPriorResult: The refitted prior result.

Related

source
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.

  1. Any other prior: return factory of pe under w. On the data, return this function of pe on the number of rows of X.
  2. An EmpiricalPrior: return factory of pe under scenario_weights of w on the n rows.
  3. A FactorPrior or a FactorBlackLittermanPrior: take factory of pe under scenario_weights of w on the rows of F, which the regression and the residual block read. Replace its pe with this function of pe.pe under w on the number of rows of F.
  4. A BlackLittermanPrior, a BayesianBlackLittermanPrior or a nested entropy pooling prior: take factory of pe under w, and replace its pe with this function of pe.pe under w on X, F and pnl, or on the n rows.
  5. An AugmentedBlackLittermanPrior: take factory of pe under scenario_weights of w on the rows of X. Replace a_pe with this function of it on X and pnl, and f_pe with this function of it on the number of rows of F.
  6. A CrossSectionalFactorPrior: take the rows rw after the Descriptor warm-up with cross_sectional_exposure_stage, and check them against the exposure lag with assert_cross_sectional_lag_rows. The regression answers n = length(rw) - pe.lag factor returns. Take factory of pe under scenario_weights of w on the n rows, which the regression, the residual block and every other weighted field read. Replace its pe with this function of pe.pe under w on the n rows.
  7. An OpinionPoolingPrior: take factory of pe under w, which gives w to the opinions and to pe2 on the scenarios of the pool. When pe1 is set, replace it with this function of pe1 under w on X, F and pnl, or on the n rows, because a Scenario Cap in pe1 keeps fewer rows than it reads.

Arguments

  • pe: The prior that an entropy pooling prior embeds.
  • w: The prior probabilities of the scenarios.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • F: Optional factor returns matrix, already oriented.
  • pnl: Optional AssetPanel, 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 of pe reads, in place of the data.
  • kwargs...: More keyword arguments of the fit of pe, which go to each nested prior that reads X and pnl.

Validation

Returns

  • pe::AbstractPriorEstimator: The estimator to refit under w.

Related

source
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.

  1. Any other prior: return nothing.
  2. A prior that scenario_factory rebuilds around pe.pe: apply this function to pe.pe.
  3. An AugmentedBlackLittermanPrior: apply this function to pe.a_pe and to pe.f_pe.
  4. An OpinionPoolingPrior: check that pe.pe1 is nothing, and apply this function to pe.pe2.
  5. A LowDimensionEnsemblePrior: throw.

Arguments

Validation

Returns

  • nothing.

Related

source
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.

  1. Any other prior: apply assert_scenario_model to pe.
  2. A nested entropy pooling prior: apply this function to pe.pe.
  3. An OpinionPoolingPrior: apply this function to pe.pe2.

Arguments

  • pe: The prior that an entropy pooling prior embeds.

Validation

Returns

  • nothing.

Related

source
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

source
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

  1. Lower each group of tail_views in turn, and pass args... and kwargs... to each call.
  2. Return nothing. Each call already wrote its constraints into epc and tvs.

Arguments

  • tail_views: The vector of tail view groups.
  • args...: More positional arguments, which go to ep_tail_views!.
  • kwargs...: More keyword arguments, which go to ep_tail_views!.

Returns

  • nothing: The function mutates epc and tvs in-place.

Related

source
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_args names the statistic to which a prior(...) 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

  1. Parse the view equations of tail_views.views.val. The result is one ParsingResult for each view.
  2. Replace every group name with the assets of the group. The result is one term for each member.
  3. Replace every prior(...) reference with the prior value of the measure, through replace_prior_views, under the tuple that ep_tail_view_prior_args gives.
  4. Expand the formulation setting to one formulation for each view with ep_view_formulations. The result is algs.
  5. For each view in turn, resolve its terms with ep_view_terms. Drop the view when the universe holds no name of the view.
  6. 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: If true, raise an error for an asset that the universe does not hold. If false, warn.
  • ledger: The Departure Ledger of the entry of the fit, or nothing when no caller collects the drops. The group expansion and ep_view_terms fill it.

Returns

  • nothing: The function mutates epc and tvs in-place.

Related

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.
source
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 mutates model in place.

Related

source

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).