Bayesian Black-Litterman Prior

PortfolioOptimisers.BayesianBlackLittermanPrior — Type
struct BayesianBlackLittermanPrior{__T_pe, __T_f_mp, __T_mp, __T_views, __T_sets, __T_views_conf, __T_rf, __T_tau, __T_cache, __T_x_src} <: AbstractLowOrderPriorEstimator_F

Bayesian Black-Litterman prior estimator for asset returns.

BayesianBlackLittermanPrior is a low order prior estimator. It applies views to the factors of a factor prior, and it updates the factor distribution by Bayes' rule. The asset moments are the posterior predictive distribution that the factor model gives.

The model and the posterior equations follow Cajas [12], who follows Kolm and Ritter [155]. Cajas [12] writes the view error covariance as $\tau\mathbf{\Sigma}_f$. The library uses $\tau\,\mathrm{Diag}(\mathbf{P}\mathbf{\Sigma}_f\mathbf{P}^\intercal)$, which has one row per view. Cajas [12] has no regression intercept. The library adds the intercept $\boldsymbol{b}$ to the posterior asset mean.

Fields

  • pe: Prior estimator.
  • f_mp: Factor matrix processing estimator.
  • mp: Matrix processing estimator.
  • sets: Universe sets. This estimator reads the time-series factor axis, sets.dict[sets.tfkey]. The views are written in the names of this axis, and the axis must name the columns of F in order. UniverseSets also needs the asset axis, and a view slices that axis. The factor entries come back from port_opt_view with no change.
  • views_conf: The confidence of the views, in (0, 1), or nothing. A number is one confidence for all the views, and a vector holds one confidence for each view that the caller wrote. If nothing, the view uncertainty has no confidence scale, see calc_omega.
  • rf: Risk-free rate. The Black-Litterman update compares the prior mean with the view returns, so it uses the total-return scale of the views. A mean from a wrapped prior estimator has that scale. An equilibrium mean is only a risk premium, and the rate converts it before the update. A member with no equilibrium branch has no mean to convert, and it adds the rate to the posterior asset expected returns. In both cases the estimator adds the rate once. It does not change the wrapped prior estimators, so a risk-free rate that one of them applied stays in its mean.
  • tau: The scale of the uncertainty of the prior mean, tau > 0. If nothing, the estimator uses 1/T, where T is the number of observations.
  • cache: Optional partial-fit state. It is nothing until partial_fit! writes one. When the caller gives no data matrix, the batch verb of the estimator reads it. Each propagation channel does one thing with it. factory keeps it unchanged, because a factory call resolves the configuration, not the sample. port_opt_view copies the entries of the selected assets into a new state, so the viewed estimator holds the state of those assets alone. obs_weights_view removes it, because a state has no slice on the observation axis. Only a type with an observation-weights field has that channel. A type with no such field falls through to the identity method, so it keeps its state. A family whose state has no exact asset slice removes it on both axes and names the reason.
  • x_src: The source of the returns that the prior fits on, nothing or an AbstractReturnsSource. nothing and DataSource read the asset returns rd.X. ExcessSource reads the returns in excess of the benchmark, rd.X - rd.B, the Excess Frame, and refuses returns data with no benchmark. nothing means that the caller stated no source, so an optimiser that holds a reader of the Excess Frame warns about a prior at nothing, and not about a prior at DataSource(). A prior reads no prior, so it refuses PriorSource. A prior inside another estimator, such as the pe of a FactorPrior, keeps nothing, and the outer estimator states the source.

Constructors

BayesianBlackLittermanPrior(;    pe::AbstractLowOrderPriorEstimator_F_AF = FactorPrior(;        pe = EmpiricalPrior(;            me = EquilibriumExpectedReturns()        )    ),    f_mp::AbstractMatrixProcessingEstimator = MatrixProcessing(),    mp::AbstractMatrixProcessingEstimator = MatrixProcessing(),    views::Lc_BLV,    sets::Option{<:UniverseSets} = nothing,    views_conf::Option{<:Num_VecNum} = nothing,    rf::Number = 0.0,    tau::Option{<:Number} = nothing,    cache::Option{<:AbstractPartialFitState} = nothing,    x_src::Option{<:AbstractReturnsSource} = nothing) -> BayesianBlackLittermanPrior

Keywords correspond to the struct's fields.

Composition: what this estimator forwards

The estimator applies the views to the factors, and the views reach the assets through the regression loadings. So the estimator gives a posterior for both blocks. It forwards the wrapped prior whole, with these changes:

  • mu and sigma are the asset posterior. The estimator drops chol, because the posterior covariance replaces the covariance that chol factorises.
  • The factor block fpr holds the posterior factor moments, mu_hat and the inverse of the posterior precision, processed by f_mp. The estimator drops its chol for the same reason. Its w and the diagnostics of that weighting forward with no change, because the views do not change the observation axis.
  • All other fields forward. X is the X of the wrapped prior with no change, so w, ens, kld and ow still describe the axis of their fit. rr is a regression over data that the views do not change.

Both blocks are posterior, so the returned prior result is internally consistent: mu == rr.M * fpr.mu + rr.b + rf holds. At the default rf = 0.0, this is the plain identity. On a 250 × 5 sample over three factors at rf = 0.03, the largest difference between the two sides is 1.4e-17. FactorBlackLittermanPrior satisfies the identity too, for the same reason. The other two members do not. See the warnings on BlackLittermanPrior and AugmentedBlackLittermanPrior.

Warning

The returned mu and sigma are the Black-Litterman posterior, but w is the observation weighting of the wrapped prior, forwarded with no change. Black-Litterman gives no posterior over the observations, so no weighting that agrees with the posterior exists. If the estimator drops w, the unweighted empirical distribution takes its place, and that is further from the weights that the caller computed. So pr.w, pr.ens, pr.kld and pr.ow describe the prior, not the posterior.

What this estimator refuses

The update inverts the factor covariance of the wrapped prior twice, so it needs a factor axis of full rank. A factor model that states a re-based Factor Family through has_family_rebasis carries fpr on the raw axis. The re-basis makes that axis a linear image of a smaller axis, so the covariance on it is singular. The estimator refuses such a prior result with an ArgumentError that names the wrapped estimator.

The inversion raises no error on such a matrix. It returns entries of the order of 1e18, and the update continues to a posterior with the same scale as the prior. A caller who reads the result sees no sign that it is meaningless. For this reason, the refusal reads what the result states and does not test its rank, and it raises an error, not a warning.

HighOrderFactorPriorEstimator accepts the same prior result, because it projects through rr.M and does not invert the factor covariance.

The views are written on the factor axis

views resolves against sets.dict[sets.tfkey], the factor axis that UniverseSets declares. The Bayesian update changes the factor distribution, and the assets get the update through the loadings. The asset axis is still necessary, because every UniverseSets carries one, and port_opt_view slices it. The factor entries come back with no change, so this field is @vprop and needs no exemption.

sets.dict[sets.tfkey] must name the columns of F in order. factor_universe checks it. When the axis is missing or has the wrong length, the error names the factor axis, not the asset axis.

Validation

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • pe: Recursively updated through factory.
  • cache: Carried unchanged through factory.

View parameters

port_opt_view takes the view of these @vprop fields at the selected indices:

Examples

julia> BayesianBlackLittermanPrior(;                                   sets = UniverseSets(;                                                       dict = Dict("nx" => ["A", "B", "C"],                                                                   "nf" => ["F1", "F2"])),                                   views = LinearConstraintEstimator(;                                                                     val = ["F1 == 0.03",                                                                            "F2 == 0.04"]))BayesianBlackLittermanPrior          pe ┼ FactorPrior             │         pe ┼ EmpiricalPrior             │            │           ce ┼ PortfolioOptimisersCovariance             │            │              │   ce ┼ Covariance             │            │              │      │    me ┼ SimpleExpectedReturns             │            │              │      │       │   w ┴ nothing             │            │              │      │    ce ┼ GeneralCovariance             │            │              │      │       │   ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)             │            │              │      │       │    w ┴ nothing             │            │              │      │   alg ┼ FullMoment()             │            │              │      │     w ┴ nothing             │            │              │   mp ┼ MatrixProcessing             │            │              │      │     pdm ┼ Posdef             │            │              │      │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton             │            │              │      │         │   kwargs ┴ @NamedTuple{}: NamedTuple()             │            │              │      │      dn ┼ nothing             │            │              │      │      dt ┼ nothing             │            │              │      │     alg ┼ nothing             │            │              │      │   order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)             │            │           me ┼ EquilibriumExpectedReturns             │            │              │   ce ┼ PortfolioOptimisersCovariance             │            │              │      │   ce ┼ Covariance             │            │              │      │      │    me ┼ SimpleExpectedReturns             │            │              │      │      │       │   w ┴ nothing             │            │              │      │      │    ce ┼ GeneralCovariance             │            │              │      │      │       │   ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)             │            │              │      │      │       │    w ┴ nothing             │            │              │      │      │   alg ┼ FullMoment()             │            │              │      │      │     w ┴ nothing             │            │              │      │   mp ┼ MatrixProcessing             │            │              │      │      │     pdm ┼ Posdef             │            │              │      │      │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton             │            │              │      │      │         │   kwargs ┴ @NamedTuple{}: NamedTuple()             │            │              │      │      │      dn ┼ nothing             │            │              │      │      │      dt ┼ nothing             │            │              │      │      │     alg ┼ nothing             │            │              │      │      │   order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)             │            │              │    w ┼ nothing             │            │              │    l ┴ Int64: 1             │            │      horizon ┼ nothing             │            │   fill_limit ┼ nothing             │            │        x_src ┴ nothing             │         mp ┼ MatrixProcessing             │            │     pdm ┼ Posdef             │            │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton             │            │         │   kwargs ┴ @NamedTuple{}: NamedTuple()             │            │      dn ┼ nothing             │            │      dt ┼ nothing             │            │     alg ┼ nothing             │            │   order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)             │         re ┼ StepwiseRegression             │            │       crit ┼ PValue             │            │            │   t ┴ Float64: 0.05             │            │        alg ┼ ForwardSelection()             │            │        tgt ┼ LinearModel             │            │            │   kwargs ┴ @NamedTuple{}: NamedTuple()             │            │     choice ┼ BatchChoice()             │            │   included ┼ nothing             │            │      x_src ┴ nothing             │         ve ┼ SimpleVariance             │            │          me ┼ SimpleExpectedReturns             │            │             │   w ┴ nothing             │            │           w ┼ nothing             │            │   corrected ┴ Bool: true             │        rsd ┼ Bool: true             │   mtx_sqrt ┼ EigenFallbackSquareRoot()             │      x_src ┴ nothing        f_mp ┼ MatrixProcessing             │     pdm ┼ Posdef             │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton             │         │   kwargs ┴ @NamedTuple{}: NamedTuple()             │      dn ┼ nothing             │      dt ┼ nothing             │     alg ┼ nothing             │   order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)          mp ┼ MatrixProcessing             │     pdm ┼ Posdef             │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton             │         │   kwargs ┴ @NamedTuple{}: NamedTuple()             │      dn ┼ nothing             │      dt ┼ nothing             │     alg ┼ nothing             │   order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)       views ┼ LinearConstraintEstimator             │   val ┼ Vector{String}: ["F1 == 0.03", "F2 == 0.04"]             │   key ┴ nothing        sets ┼ UniverseSets             │     xkey ┼ String: "nx"             │    uxkey ┼ String: "ux"             │    tfkey ┼ String: "nf"             │   utfkey ┼ String: "uf"             │    cfkey ┼ String: "ncf"             │   ucfkey ┼ String: "ucf"             │    nikey ┼ String: "ni"             │     dict ┴ Dict{String, Vector{String}}: Dict("nf" => ["F1", "F2"], "nx" => ["A", "B", "C"])  views_conf ┼ nothing          rf ┼ Float64: 0.0         tau ┼ nothing       x_src ┴ nothing

The incremental fit

This prior has no exact incremental recursion, and it takes the online step by a refit from a sample buffer. Online seeds cache, and partial_fit! adds each observation to it with no change. The prior method with one argument then runs the batch verb of this estimator over the rows that the buffer kept. The result is the batch fit over those rows, and a max_history on the wrapper sets the window of the whole fit.

cache goes through the three propagation channels as every partial-fit state does. factory carries it with no change, and port_opt_view cuts it to the selected assets. obs_weights_view drops it, because a state has no cut on the observation axis. The show method does not print cache, because a buffer that changes at each step is not part of the configuration.

Related

References

  • [155] P. N. Kolm and G. Ritter. On the Bayesian interpretation of Black-Litterman. European Journal of Operational Research 258, 564–572 (2017).
  • [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 5.3, Equations 5.23, 5.34 and 5.35. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
source
PortfolioOptimisers.prior — Function
prior(pe::BayesianBlackLittermanPrior, X::MatNum, F::MatNum,
      pnl::Option{<:AssetPanel} = nothing; dims::Int = 1, strict::Bool = false,
      kwargs...)

Compute Bayesian Black-Litterman prior moments for asset returns.

prior fits the wrapped factor prior, and it updates the factor distribution with the factor views by Bayes' rule. The asset moments are the posterior predictive distribution of the factor model.

When pe.tau is nothing, the blending parameter is 1/T, where T is the effective number of observations of the factor mean, pr.fpr.eoc[1] of the wrapped prior. It is the number of observations of the oriented F when the factor prior states no count. pe.rf reaches the result once, on the posterior asset expected returns. apply_rf owns that rule, and the factor block never carries the rate. This is the one Black-Litterman member that does not call vanilla_posteriors. Its update is the conditional posterior of the factor parameter. The asset moments are a posterior predictive distribution, not a second run of the master equations.

Mathematical definition

This is not the classic Black-Litterman update on the assets. The views apply to the factor parameter $\boldsymbol{\theta}$, and the asset moments are the posterior predictive distribution of the factor model. The model is:

\[\begin{align} \boldsymbol{r} &\sim \mathcal{N}(\mathbf{M}\boldsymbol{\theta} + \boldsymbol{b},\ \mathbf{\Sigma})\,, \\ \boldsymbol{\theta} &\sim \mathcal{N}(\boldsymbol{\Pi}_f,\ \mathbf{\Sigma}_f)\,, \\ \mathbf{P}\boldsymbol{\theta} &\sim \mathcal{N}(\boldsymbol{q},\ \mathbf{\Omega})\,. \end{align}\]

The conditional posterior of $\boldsymbol{\theta}$ given the views is Gaussian, with precision $\mathbf{H}$:

\[\begin{align} \mathbf{H} &= \mathbf{\Sigma}_f^{-1} + \mathbf{P}^\intercal \mathbf{\Omega}^{-1} \mathbf{P}\,, \\ \bar{\mathbf{\Sigma}}_f &= \mathbf{H}^{-1}\,, \\ \bar{\boldsymbol{\Pi}}_f &= \mathbf{H}^{-1}\left(\mathbf{\Sigma}_f^{-1}\boldsymbol{\Pi}_f + \mathbf{P}^\intercal \mathbf{\Omega}^{-1} \boldsymbol{q}\right)\,. \end{align}\]

With $\mathbf{V} = \left(\mathbf{H} + \mathbf{M}^\intercal \mathbf{\Sigma}^{-1} \mathbf{M}\right)^{-1}$, the posterior predictive asset moments are:

\[\begin{align} \hat{\mathbf{\Sigma}}_{BBL} &= \left(\mathbf{\Sigma}^{-1} - \mathbf{\Sigma}^{-1}\mathbf{M}\,\mathbf{V}\,\mathbf{M}^\intercal \mathbf{\Sigma}^{-1}\right)^{-1}\,, \\ \hat{\boldsymbol{\mu}}_{BBL} &= \hat{\mathbf{\Sigma}}_{BBL}\,\mathbf{\Sigma}^{-1}\mathbf{M}\,\mathbf{V}\,\mathbf{H}\,\bar{\boldsymbol{\Pi}}_f + \boldsymbol{b} + r_{f}\,. \end{align}\]

Where:

  • $N$, $K$, $K_v$, $T$: The number of assets, of factors, of views, and of observations.
  • $\boldsymbol{r}$: $N \times 1$ asset return vector of the model.
  • $\boldsymbol{\theta}$: $K \times 1$ factor parameter that the views apply to.
  • $\hat{\boldsymbol{\mu}}_{BBL}$: $N \times 1$ Bayesian Black-Litterman posterior asset mean, pr.mu.
  • $\hat{\mathbf{\Sigma}}_{BBL}$: $N \times N$ Bayesian Black-Litterman posterior asset covariance, pr.sigma.
  • $\boldsymbol{\Pi}_f$, $\mathbf{\Sigma}_f$: $K \times 1$ and $K \times K$ prior factor moments, from pe.pe.
  • $\mathbf{H}$: $K \times K$ posterior factor precision, the sum of the prior precision and the view precision.
  • $\bar{\boldsymbol{\Pi}}_f$, $\bar{\mathbf{\Sigma}}_f$: $K \times 1$ and $K \times K$ posterior factor moments, reported in pr.fpr.
  • $\mathbf{\Sigma}$: $N \times N$ prior asset covariance matrix, from pe.pe.
  • $\mathbf{V}$: $K \times K$ inverse of the sum of $\mathbf{H}$ and the factor precision $\mathbf{M}^\intercal \mathbf{\Sigma}^{-1} \mathbf{M}$ of the asset model.
  • $\mathbf{M}$: $N \times K$ factor loadings matrix, pr.rr.M.
  • $\boldsymbol{b}$: $N \times 1$ regression intercept vector, pr.rr.b.
  • $\mathbf{P}$: $K_v \times K$ views matrix, over the factor axis.
  • $\boldsymbol{q}$: $K_v \times 1$ views vector.
  • $\mathbf{\Omega}$: $K_v \times K_v$ view uncertainty matrix, $\mathrm{Diag}(\mathbf{P}(\tau\mathbf{\Sigma}_f)\mathbf{P}^\intercal)$ from calc_omega and bl_preroll.
  • $\tau$: Scaling parameter, 1/T by default.
  • $r_{f}$: Risk-free rate, added once by apply_rf.

Two facts change what a caller can do. First, $\mathbf{P}$ is over the factor axis, so it has $K$ columns and not $N$. The quantities of this estimator cannot give the classic master equation on the asset axis. Second, $\hat{\boldsymbol{\mu}}_{BBL}$ equals $\mathbf{M}\bar{\boldsymbol{\Pi}}_f + \boldsymbol{b} + r_{f}$. This is the identity of the Composition section above.

The estimator checks the width of $\mathbf{P}$. A precomputed BlackLittermanViews with a P of five columns, against a prior of three factors, raises a DimensionMismatch from bl_preroll. The error gives size(P, 2) => 5 and size(prior_sigma, 1) => 3. Views in asset names raise an IsNothingError, because no name resolves against the factor universe.

Algorithm

  1. Orient X and F with dims_oriented, to observations × assets and observations × factors.
  2. When pe.views resolves names, check the declared factor axis against the width of F with factor_universe, through assert_bbl_views_axis. A precomputed BlackLittermanViews resolves no name, so step 6 checks its width instead.
  3. Fit the wrapped prior pe.pe on (X, F). The result is prior_result. bbl_posterior does the rest of this step and steps 4 to 16. So the refit of scenario_prior under new scenario weights uses the same code to blend the views into the refit prior_result. Check that prior_result carries a regression with assert_prior_regression.
  4. Find the Investable Mask with investable_mask, and view the fitted prior at the mask with investable_prior. This step uses the mask alone, not investable_views. The views apply to the factors, so this member needs no Non-Investable Axis and reads no asset universe.
  5. Read posterior_X, prior_sigma, fpr and rr from the reduced prior. Refuse an rr that states a re-based Factor Family through has_family_rebasis.
  6. Make the views and their uncertainty with bl_preroll, over the factor prior covariance and the count of the factor mean from moment_observation_count. Read P, Q and omega from the result with bl_view_block. The axis is :tfkey, because these views apply to the factors. A view set with no row left gives a 0 × K block. The steps below then give the moments of the factor model of this member, and these are not the moments of the wrapped prior. See the note under bl_view_block.
  7. Build the posterior factor precision $\mathbf{H}$ as sigma_hat.
  8. Solve sigma_hat against the sum of the two precision-weighted means. The result is mu_hat, the posterior factor mean $\bar{\boldsymbol{\Pi}}_f$.
  9. Build the posterior asset covariance posterior_sigma from $\mathbf{H}$, the loadings and prior_sigma.
  10. Build the posterior asset mean from the same quantities, add rr.b, and add pe.rf with apply_rf. This is the one site that adds the rate.
  11. Process posterior_sigma in place with sample_matrix_processing!, under pe.mp, posterior_X and the count of the covariance of the prior from moment_observation_count. This step comes after step 10, so pe.mp does not change the mean.
  12. Invert sigma_hat for the posterior factor covariance $\bar{\mathbf{\Sigma}}_f$, and process it in place under pe.f_mp, F and the count of the factor covariance.
  13. Forward the factor block with forward_prior. Replace mu and sigma with the posterior factor pair, and drop chol. Do not expand the block, because the reduction did not change the factor axis.
  14. Announce the departures once with announce_bl_departures. investable_universe_names gives their names.
  15. Write both asset posteriors back onto the full asset universe with expand_moment. A non-investable asset then carries NaN in mu and on the diagonal of sigma.
  16. Forward all of prior_result with forward_prior. Replace mu and sigma with the expanded asset pair, drop chol, and replace fpr with the block of step 13.

Arguments

  • pe: Bayesian Black-Litterman prior estimator.
  • X: Asset returns matrix (observations × assets).
  • F: Factor matrix (observations × factors).
  • 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.
  • dims: Dimension along which the computation runs.
  • strict: If true, enforce strict validation of views and sets. Default is false.
  • kwargs...: More keyword arguments, for the wrapped prior and for matrix processing.

Validation

  • dims in (1, 2).
  • If pe.views is a LinearConstraintEstimator, haskey(pe.sets.dict, pe.sets.tfkey) and length(pe.sets.dict[pe.sets.tfkey]) == size(F, 2), both through factor_universe.
  • The prior result of pe.pe must carry a regression result, through assert_prior_regression.
  • That regression result must state no re-based Factor Family, through has_family_rebasis. A re-basis makes fpr.sigma singular, and steps 7 and 8 invert it.

Returns

  • pr::LowOrderPrior: Result object with the asset returns, the posterior asset mean vector and the posterior asset covariance matrix. Its factor block fpr holds the posterior factor moments. Both blocks are posterior, so pr.mu == pr.rr.M * pr.fpr.mu + pr.rr.b + pe.rf holds. chol is nothing on both blocks.

Related

source

References

[12]
D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
[155]
P. N. Kolm and G. Ritter. On the Bayesian interpretation of Black-Litterman. European Journal of Operational Research 258, 564–572 (2017).