Black-Litterman Views Generation
PortfolioOptimisers.BlackLittermanViews — Type
struct BlackLittermanViews{__T_P, __T_Q, __T_excl} <: AbstractResultContainer for Black-Litterman investor views in canonical matrix form.
BlackLittermanViews stores the views matrix P and the expected returns vector Q for use in Black-Litterman prior construction and related portfolio optimisation routines. The matrix P encodes the linear relationships between assets for each view, while Q specifies the expected value for each view.
Mathematical definition
This type stores the pair $(\mathbf{P}, \boldsymbol{q})$ of the view creation model:
\[\begin{align} \mathbf{P}\,\boldsymbol{\mu}_{e} &= \boldsymbol{q} + \boldsymbol{\nu}\,. \end{align}\]
Where:
- $\mathbf{P}$: $K \times N$ views matrix (each row encodes one view).
- $\boldsymbol{\mu}_{e}$: $N \times 1$ prior expected excess returns vector.
- $\boldsymbol{q}$: $K \times 1$ vector of view expected returns.
- $\boldsymbol{\nu}$: $K \times 1$ estimation error of the views.
The view uncertainty matrix $\boldsymbol{\Omega}$ is not stored here. It is derived from $\mathbf{P}$ and the covariance of the distribution the views update, by calc_omega and bl_preroll.
Fields
P: Views loading matrixviews × assets.
Q: Views values vectorviews × 1.
excl: Indices of views to exclude.
Constructors
BlackLittermanViews(; P::MatNum, Q::VecNum, excl::Option{<:VecInt} = nothing) -> BlackLittermanViewsKeywords correspond to the struct's fields.
Validation
!isempty(P)and!isempty(Q).size(P, 1) == length(Q).- If
exclis provided,!isempty(excl)andlength(excl) <= length(Q).
Examples
julia> BlackLittermanViews(; P = [1 2 3 4; 5 6 7 8], Q = [9; 10])BlackLittermanViews P ┼ 2×4 Matrix{Int64} Q ┼ Vector{Int64}: [9, 10] excl ┴ nothingRelated
References
PortfolioOptimisers.black_litterman_views — Function
black_litterman_views(views::Option{<:BlackLittermanViews}, args...; kwargs...)
black_litterman_views(views::EqnType, sets::UniverseSets,
key::Option{<:AbstractString} = nothing;
datatype::DataType = Float64, strict::Bool = false)
black_litterman_views(views::LinearConstraintEstimator, sets::UniverseSets,
key::Option{<:AbstractString} = nothing;
datatype::DataType = Float64, strict::Bool = false)Unified interface for constructing or passing through Black-Litterman investor views.
black_litterman_views provides a composable API for handling Black-Litterman views in portfolio optimisation workflows. It supports passing through an existing BlackLittermanViews object, constructing views from equations or constraint estimators, and converting parsed view equations into canonical matrix form.
The two routes agree. A LinearConstraintEstimator assembled here and the BlackLittermanViews result of that same assembly, passed back in, give the same P and the same Q, so a caller who precomputes the pair loses nothing but the name resolution.
Algorithm
- When
viewsisnothingor aBlackLittermanViews, return it unchanged. The pair was assembled against whatever universe the caller held, sosets,key,datatypeandstrictare all ignored. - When
viewsis aLinearConstraintEstimator, pick the key:views.keywhen the estimator carries one, and thekeyargument otherwise. Call step 3 onviews.valwith that key. - When
viewsis anEqnType, parse it withparse_equationunder the==operator alone, giving the parsed viewslcs. A Black-Litterman view is an equality, so no inequality operator is admitted. - Expand every group name in
lcsinto its member assets withreplace_group_by_assets, undersets. A group sheds its departed members there, before its coefficient is spread, so a Black-Litterman mean divides by the surviving count. - Assemble the canonical pair from
lcswithget_black_litterman_views, under the key of step 2, and return what it gives.
Arguments
views:nothingorBlackLittermanViews: it is returned unchanged,keyand all — a precomputedPwas assembled against whatever universe the caller had, and nothing here can re-check it.EqnType: The view(s) are parsed, groups are replaced by their constituent members usingsets, callsget_black_litterman_viewsand constructs aBlackLittermanViewsobject is constructed.LinearConstraintEstimator: calls the method described above using thevalfield of the estimator. Its ownkeywins over the one the estimator passes, which is the same precedencerebase_linear_constraintsuses: the argument is the axis the caller is written against, the field is the user overriding it.
sets: AUniverseSetsobject specifying the universes and groupings.key: Key to specify the universe insets.dictthat names resolve against. Ifnothing, the key is taken fromsets.xkey— or, where the caller is written against another declared axis, from that axis' key.datatype: Numeric type for coefficients and expected returns.strict: Iftrue, throws an error if a variable or group is not found insets; iffalse, issues a warning.ledger: The door's ledger of departure casualties, ornothingwhen nobody is collecting. It is threaded into bothreplace_group_by_assetsandget_black_litterman_views, so a shed group and a dropped row are both recorded.
Returns
blv::BlackLittermanViews: An object containing the assembled views matrixPand expected returns vectorQ, ornothingif no views are present.
Examples
julia> sets = UniverseSets(; xkey = "nx", dict = Dict("nx" => ["A", "B", "C"]));julia> black_litterman_views(["A + B == 0.05", "C == 0.02"], sets)BlackLittermanViews P ┼ 2×3 LinearAlgebra.Transpose{Float64, Matrix{Float64}} Q ┼ Vector{Float64}: [0.05, 0.02] excl ┴ nothingjulia> lce = LinearConstraintEstimator(; val = ["A == 0.03", "B + C == 0.04"]);julia> black_litterman_views(lce, sets)BlackLittermanViews P ┼ 2×3 LinearAlgebra.Transpose{Float64, Matrix{Float64}} Q ┼ Vector{Float64}: [0.03, 0.04] excl ┴ nothingRelated
BlackLittermanViewsget_black_litterman_viewsparse_equationreplace_group_by_assetsExpands a group name into its member assets.UniverseSetsLinearConstraintEstimatorLc_BLVThe union of the two shapes this function admits.
References
- [5]
- D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
- [29]
- F. Black and R. Litterman. Global portfolio optimization. Financial Analysts Journal 48, 28–43 (1992).