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.

  1. Pool the opinions linearly into the consensus c.
  2. Compute kldivs, the Kullback-Leibler divergence of each column of pw from c.
  3. Multiply each entry of ow by exp(-p * kldivs), into a new vector.
  4. 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 the args... method returns the argument itself. Neither method writes to the argument, because it can be the estimator's own w field, or the immutable range that opinion_pooling_weights makes when w is nothing.

Related

source
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

  1. Read the opinion probabilities ow, from pe.w when it is set and from a uniform range over length(pe.pes) when it is nothing.
  2. Compute the remainder rw = 1 - sum(ow). When rw is more than eps, append it to ow, and fill a last column of pw with 1/T, the uniform prior over the observations.
  3. Fit every estimator of pe.pes with the executor pe.ex. Check that each one answered on the observation axis of the pool, and write its weights into a column of pw.
  4. Penalise ow through robust_probabilities, which returns ow as it is when pe.p is nothing.
  5. Pool the columns of pw under pe.alg through compute_pooling into the consensus weights w.

Arguments

  • pe: Opinion pooling prior estimator.
  • X: The returns that the opinions read, observations × assets. These are the returns of pe.pe1 when it is set.
  • F: Optional factor returns matrix.
  • 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: Passed to every opinion. If true, an opinion with a view that names an asset that its sets does not hold raises an error. If false, the opinion drops that view with a warning. Default is false.
  • 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 a DimensionMismatch that names the opinion.

Returns

  • w::StatsBase.AnalyticWeights: The consensus weights of the observations.
  • ow::VecNum: The penalised opinion probabilities, one entry per column of pw.
  • pw::MatNum: The weights of each opinion, one column per opinion.

Related

source
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 in pc. The refit of pe2 reads its cache from that result. A pe2 that 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 of pe2 in pc.pe2, and the refit writes pc.pe2 onto the result before the refit of pe2. A pe2 that 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.

  1. Read pr.pc of a LowOrderPrior, and nothing for no result or a result of any other type.
  2. When the type of res has no field pc, return res.
  3. When res is a LowOrderPrior, rebuild res with pc through forward_prior, also when pc is nothing.

Arguments

  • pr: The result of the fit that the views read, or nothing.
  • res: The result to write the cache onto, or nothing.
  • pc: The cache to write, or nothing.

Returns

  • pc::Option{<:NamedTuple}: For the one-argument methods, pr.pc of a LowOrderPrior, and nothing for 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

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

  1. When pc is nothing, take the rows of pe.pe1 when it is set, and X when it is not, as the fit of the pool does. Pool the opinions on those rows with opinion_pooling_weights.
  2. When pc is a cache, take pc.X, or X when pc.X is nothing, and take pc.w.

Arguments

  • pe: Opinion pooling prior estimator.
  • pc: The cache of the fit, or nothing.
  • 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.
  • 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.
  • kwargs...: More keyword arguments, passed to pe.pe1 and 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

source
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

source