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_FBayesian 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.
views: The views, aLinearConstraintEstimatorof view equations or a precomputedBlackLittermanViews.
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 ofFin order.UniverseSetsalso needs the asset axis, and a view slices that axis. The factor entries come back fromport_opt_viewwith no change.
views_conf: The confidence of the views, in(0, 1), ornothing. A number is one confidence for all the views, and a vector holds one confidence for each view that the caller wrote. Ifnothing, the view uncertainty has no confidence scale, seecalc_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. Ifnothing, the estimator uses1/T, whereTis the number of observations.
cache: Optional partial-fit state. It isnothinguntilpartial_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.factorykeeps it unchanged, because a factory call resolves the configuration, not the sample.port_opt_viewcopies the entries of the selected assets into a new state, so the viewed estimator holds the state of those assets alone.obs_weights_viewremoves 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,nothingor anAbstractReturnsSource.nothingandDataSourceread the asset returnsrd.X.ExcessSourcereads the returns in excess of the benchmark,rd.X - rd.B, the Excess Frame, and refuses returns data with no benchmark.nothingmeans that the caller stated no source, so an optimiser that holds a reader of the Excess Frame warns about a prior atnothing, and not about a prior atDataSource(). A prior reads no prior, so it refusesPriorSource. A prior inside another estimator, such as thepeof aFactorPrior, keepsnothing, 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) -> BayesianBlackLittermanPriorKeywords 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:
muandsigmaare the asset posterior. The estimator dropschol, because the posterior covariance replaces the covariance thatcholfactorises.- The factor block
fprholds the posterior factor moments,mu_hatand the inverse of the posterior precision, processed byf_mp. The estimator drops itscholfor the same reason. Itswand the diagnostics of that weighting forward with no change, because the views do not change the observation axis. - All other fields forward.
Xis theXof the wrapped prior with no change, sow,ens,kldandowstill describe the axis of their fit.rris 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.
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
- If
viewsis aLinearConstraintEstimator,!isnothing(sets). - If
views_confis notnothing,assert_bl_views_confchecksviews_conf. - If
tauis notnothing,tau > 0. x_srcisnothing,DataSource()orExcessSource(), seeassert_returns_source.- The
x_srcofpeisnothing, because the prior picks the returns that it reads, seeassert_inner_reader.
Propagated parameters
factory passes its arguments on to these @fprop fields:
View parameters
port_opt_view takes the view of these @vprop fields at the selected indices:
pe: Recursively viewed throughport_opt_view.sets: Sliced to the selected indices throughport_opt_view.cache: Sliced to the selected assets throughport_opt_view.
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 ┴ nothingThe 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
AbstractLowOrderPriorEstimator_FFactorPriorBlackLittermanViewsUniverseSetsLowOrderPriorpriorfactoryport_opt_view
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.
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_omegaandbl_preroll. - $\tau$: Scaling parameter,
1/Tby 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
- Orient
XandFwithdims_oriented, toobservations × assetsandobservations × factors. - When
pe.viewsresolves names, check the declared factor axis against the width ofFwithfactor_universe, throughassert_bbl_views_axis. A precomputedBlackLittermanViewsresolves no name, so step 6 checks its width instead. - Fit the wrapped prior
pe.peon(X, F). The result isprior_result.bbl_posteriordoes the rest of this step and steps 4 to 16. So the refit ofscenario_priorunder new scenario weights uses the same code to blend the views into the refitprior_result. Check thatprior_resultcarries a regression withassert_prior_regression. - Find the Investable Mask with
investable_mask, and view the fitted prior at the mask withinvestable_prior. This step uses the mask alone, notinvestable_views. The views apply to the factors, so this member needs no Non-Investable Axis and reads no asset universe. - Read
posterior_X,prior_sigma,fprandrrfrom the reduced prior. Refuse anrrthat states a re-based Factor Family throughhas_family_rebasis. - Make the views and their uncertainty with
bl_preroll, over the factor prior covariance and the count of the factor mean frommoment_observation_count. ReadP,Qandomegafrom the result withbl_view_block. The axis is:tfkey, because these views apply to the factors. A view set with no row left gives a0 × Kblock. 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 underbl_view_block. - Build the posterior factor precision $\mathbf{H}$ as
sigma_hat. - Solve
sigma_hatagainst the sum of the two precision-weighted means. The result ismu_hat, the posterior factor mean $\bar{\boldsymbol{\Pi}}_f$. - Build the posterior asset covariance
posterior_sigmafrom $\mathbf{H}$, the loadings andprior_sigma. - Build the posterior asset mean from the same quantities, add
rr.b, and addpe.rfwithapply_rf. This is the one site that adds the rate. - Process
posterior_sigmain place withsample_matrix_processing!, underpe.mp,posterior_Xand the count of the covariance of the prior frommoment_observation_count. This step comes after step 10, sope.mpdoes not change the mean. - Invert
sigma_hatfor the posterior factor covariance $\bar{\mathbf{\Sigma}}_f$, and process it in place underpe.f_mp,Fand the count of the factor covariance. - Forward the factor block with
forward_prior. Replacemuandsigmawith the posterior factor pair, and dropchol. Do not expand the block, because the reduction did not change the factor axis. - Announce the departures once with
announce_bl_departures.investable_universe_namesgives their names. - Write both asset posteriors back onto the full asset universe with
expand_moment. A non-investable asset then carriesNaNinmuand on the diagonal ofsigma. - Forward all of
prior_resultwithforward_prior. Replacemuandsigmawith the expanded asset pair, dropchol, and replacefprwith the block of step 13.
Arguments
pe: Bayesian Black-Litterman prior estimator.X: Asset returns matrix (observations × assets).F: Factor matrix (observations × factors).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.dims: Dimension along which the computation runs.strict: Iftrue, enforce strict validation of views and sets. Default isfalse.kwargs...: More keyword arguments, for the wrapped prior and for matrix processing.
Validation
dims in (1, 2).- If
pe.viewsis aLinearConstraintEstimator,haskey(pe.sets.dict, pe.sets.tfkey)andlength(pe.sets.dict[pe.sets.tfkey]) == size(F, 2), both throughfactor_universe. - The prior result of
pe.pemust carry a regression result, throughassert_prior_regression. - That regression result must state no re-based Factor Family, through
has_family_rebasis. A re-basis makesfpr.sigmasingular, 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 blockfprholds the posterior factor moments. Both blocks are posterior, sopr.mu == pr.rr.M * pr.fpr.mu + pr.rr.b + pe.rfholds.cholisnothingon both blocks.
Related
BayesianBlackLittermanPriorLowOrderPriorpriorbl_preroll: AssemblesP,Qandomegaatpe.sets.tfkey, and resolvespe.tauto1/Twhen the estimator carries none.calc_omegaapply_rfforward_priorvanilla_posteriors: The master equations that this estimator does not use. The three other members use them.
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).