Opinion pooling Prior: private API
PortfolioOptimisers.robust_probabilities — Function
robust_probabilities(ow::VecNum, args...)
robust_probabilities(ow::VecNum, pw::MatNum, p::Number)Penalise each opinion probability by the divergence of its opinion from the consensus.
The three-argument method multiplies the probability of each opinion by $\exp(-\rho D_k)$, where $D_k$ is the Kullback-Leibler divergence of the opinion from the linear pool, and renormalises. An opinion far from the consensus loses probability. When p is nothing, the args... method returns ow as it is.
Mathematical definition
\[\begin{align} D_k &= \sum_{t=1}^{T} p_{tk} \log\!\frac{p_{tk}}{c_t}\,, \quad c_t = \sum_{k=1}^{K} \alpha_k p_{tk}\,, \\ \tilde{\alpha}_k &= \frac{\alpha_k \exp(-\rho D_k)}{\sum_{j=1}^{K} \alpha_j \exp(-\rho D_j)}\,. \end{align}\]
Where:
- $\alpha_k$: Opinion probability of expert $k$, the input
ow. - $p_{tk}$: Scenario weight for scenario $t$ from expert $k$, column $k$ of
pw. - $c_t$: Consensus scenario weight.
- $D_k$: Kullback-Leibler divergence from expert $k$ to the consensus.
- $\rho$: Penalty parameter, the argument
p. - $T$: Number of observations.
The consensus $\boldsymbol{c}$ is always the linear pool, whatever OpinionPoolingAlgorithm the caller selected. The divergence has a direction. It is $D_k = \mathrm{KL}(\boldsymbol{p}_k \,\|\, \boldsymbol{c})$, from each opinion to the consensus. The kld field of the result of prior has the other direction, from the consensus to each opinion, so the two vectors hold different numbers.
$\exp(-\rho D_k)$ decreases in $D_k$, so a larger $\rho$ moves the mass to the opinions nearest the consensus. As $\rho$ increases without bound, all the mass goes to the opinion of smallest divergence.
Algorithm
The steps below are those of the three-argument method. The args... method takes no step and returns ow.
- Pool the opinions linearly into the consensus
c. - Compute
kldivs, the Kullback-Leibler divergence of each column ofpwfromc. - Multiply each entry of
owbyexp(-p * kldivs), into a new vector. - Divide that vector by its sum, and return it.
Arguments
ow: Opinion probabilities, one entry per opinion.pw: Scenario weights of the opinions,observations × opinions, one column per opinion.p: Penalty, above zero.
Returns
ow::VecNum: The opinion probabilities to pool with, summing to 1. The three-argument method returns a new vector, and theargs...method returns the argument itself. Neither method writes to the argument, because it can be the estimator's ownwfield, or the immutablerangethatopinion_pooling_weightsmakes whenwisnothing.
Related
OpinionPoolingPrior: the estimator that calls this function, throughopinion_pooling_weights.compute_pooling
PortfolioOptimisers.opinion_pooling_weights — Function
opinion_pooling_weights(pe::OpinionPoolingPrior, X::MatNum, F::Option{<:MatNum},
pnl::Option{<:AssetPanel}; strict::Bool = false, kwargs...)Pools the opinions of an OpinionPoolingPrior into the consensus weights of the observations.
prior refits pe.pe2 under these weights. The online step of the refit route reads them too, because pin_prior_choice pins the regression of pe.pe2 under the weights of its first fit.
Algorithm
- Read the opinion probabilities
ow, frompe.wwhen it is set and from a uniformrangeoverlength(pe.pes)when it isnothing. - Compute the remainder
rw = 1 - sum(ow). Whenrwis more thaneps, append it toow, and fill a last column ofpwwith1/T, the uniform prior over the observations. - Fit every estimator of
pe.peswith the executorpe.ex. Check that each one answered on the observation axis of the pool, and write its weights into a column ofpw. - Penalise
owthroughrobust_probabilities, which returnsowas it is whenpe.pisnothing. - Pool the columns of
pwunderpe.algthroughcompute_poolinginto the consensus weightsw.
Arguments
pe: Opinion pooling prior estimator.X: The returns that the opinions read,observations × assets. These are the returns ofpe.pe1when it is set.F: Optional factor returns matrix.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: Passed to every opinion. Iftrue, an opinion with a view that names an asset that itssetsdoes not hold raises an error. Iffalse, the opinion drops that view with a warning. Default isfalse.kwargs...: More keyword arguments, passed to every opinion.
Validation
- Every opinion answers on the observation axis of
X. If an opinion does not, the function raises aDimensionMismatchthat names the opinion.
Returns
w::StatsBase.AnalyticWeights: The consensus weights of the observations.ow::VecNum: The penalised opinion probabilities, one entry per column ofpw.pw::MatNum: The weights of each opinion, one column per opinion.
Related
PortfolioOptimisers.opinion_pooling_cache — Function
opinion_pooling_cache(pr::Option{<:AbstractPriorResult})
opinion_pooling_cache(pr::LowOrderPrior)
opinion_pooling_cache(res::Option{<:AbstractPriorResult}, pc::Option{<:NamedTuple})
opinion_pooling_cache(res::LowOrderPrior, pc::Option{<:NamedTuple})Read the cache of the opinion pool that answered pr, or write a cache onto a result.
A fit of an OpinionPoolingPrior with cache_reg = true stores the rows that its opinions read, its pooled weights and the cache of its pe2 in pr.pc. Its refits through scenario_prior and scenario_factory read them with the one-argument methods, so they run no opinion and no pe1. A result with no cache gives nothing, and the refit then pools the opinions again.
The two-argument methods write a cache onto a result that can carry one. Only a LowOrderPrior has a field pc, so every other result gives res unchanged. A LowOrderPrior takes pc as it is, so nothing clears its cache. The refit writes the cache twice, and only when the result of the fit holds the cache of the pool:
- The result of a pool carries the fields of the result of
pe2, and its own cache inpc. The refit ofpe2reads its cache from that result. Ape2that is a pool, or an entropy pooling prior over one, would then read the pooled weights of the outer pool as its own. So the cache of the pool keeps the cache ofpe2inpc.pe2, and the refit writespc.pe2onto the result before the refit ofpe2. Ape2that stored no cache gets a result with no cache, and then pools its own opinions again. - The refit returns the result of
pe2, which carries no cache of the pool. The refit writes the cache of the pool onto it, so an entropy pooling prior around a nested one reads it too.
Algorithm
The method that Julia selects is the algorithm.
- Read
pr.pcof aLowOrderPrior, andnothingfor no result or a result of any other type. - When the type of
reshas no fieldpc, returnres. - When
resis aLowOrderPrior, rebuildreswithpcthroughforward_prior, also whenpcisnothing.
Arguments
pr: The result of the fit that the views read, ornothing.res: The result to write the cache onto, ornothing.pc: The cache to write, ornothing.
Returns
pc::Option{<:NamedTuple}: For the one-argument methods,pr.pcof aLowOrderPrior, andnothingfor no result or a result of any other type.res::Option{<:AbstractPriorResult}: For the two-argument methods, the result with the cache where it can carry one.
Related
PortfolioOptimisers.opinion_pooling_scenarios — Function
opinion_pooling_scenarios(pe::OpinionPoolingPrior, pc::Nothing, X::MatNum,
F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; kwargs...)
opinion_pooling_scenarios(pe::OpinionPoolingPrior, pc::NamedTuple, X::MatNum,
F::Option{<:MatNum}, pnl::Option{<:AssetPanel}; kwargs...)Return the rows that the opinions of a pool read and its pooled weights, for its refit under new scenario weights.
The refit of scenario_prior and scenario_factory fits pe.pe2 under the pooled weights, on the rows of pe.pe1 when it is set. A fit with cache_reg = true stores both in pc, so the refit reads them and runs no opinion and no pe.pe1.
Algorithm
The method that Julia selects is the algorithm.
- When
pcisnothing, take the rows ofpe.pe1when it is set, andXwhen it is not, as the fit of the pool does. Pool the opinions on those rows withopinion_pooling_weights. - When
pcis a cache, takepc.X, orXwhenpc.Xisnothing, and takepc.w.
Arguments
pe: Opinion pooling prior estimator.pc: The cache of the fit, ornothing.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.F: Optional factor returns matrix.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.kwargs...: More keyword arguments, passed tope.pe1and to the opinions when no cache is given.
Returns
(X, w)::Tuple: The rows that the opinions read,X::MatNum, and the pooled weights,w::StatsBase.AbstractWeights.
Related
PortfolioOptimisers.show_fields — Method
show_fields(_::OpinionPoolingPrior) -> NTuple{8, Symbol}
Renders every field of a OpinionPoolingPrior except cache.
The state a cache holds is the running detail of an incremental fit, not the configuration a reader looks the type up for, and it prints under the estimator at every site that renders one. Set set_show_nothing_fields!(:OpinionPoolingPrior, true) to render it.
Arguments
::OpinionPoolingPrior: Prior estimator, read for its type alone.
Returns
fields::Tuple: The field names to render, which is(:pes, :pe1, :pe2, :p, :w, :alg, :ex, :x_src).
Related