Black-Litterman Views Generation

PortfolioOptimisers.BlackLittermanViewsType
struct BlackLittermanViews{__T_P, __T_Q, __T_excl} <: AbstractResult

Container 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 matrix views × assets.
  • Q: Views values vector views × 1.
  • excl: Indices of views to exclude.

Constructors

BlackLittermanViews(;    P::MatNum,    Q::VecNum,    excl::Option{<:VecInt} = nothing) -> BlackLittermanViews

Keywords correspond to the struct's fields.

Validation

  • !isempty(P) and !isempty(Q).
  • size(P, 1) == length(Q).
  • If excl is provided, !isempty(excl) and length(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 ┴ nothing

Related

References

  • [29] F. Black and R. Litterman. Global portfolio optimization. Financial Analysts Journal 48, 28–43 (1992).
  • [5] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 5.1.3, Equations 5.5 and 5.7.
source
PortfolioOptimisers.black_litterman_viewsFunction
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

  1. When views is nothing or a BlackLittermanViews, return it unchanged. The pair was assembled against whatever universe the caller held, so sets, key, datatype and strict are all ignored.
  2. When views is a LinearConstraintEstimator, pick the key: views.key when the estimator carries one, and the key argument otherwise. Call step 3 on views.val with that key.
  3. When views is an EqnType, parse it with parse_equation under the == operator alone, giving the parsed views lcs. A Black-Litterman view is an equality, so no inequality operator is admitted.
  4. Expand every group name in lcs into its member assets with replace_group_by_assets, under sets. A group sheds its departed members there, before its coefficient is spread, so a Black-Litterman mean divides by the surviving count.
  5. Assemble the canonical pair from lcs with get_black_litterman_views, under the key of step 2, and return what it gives.

Arguments

  • views:

    • nothing or BlackLittermanViews: it is returned unchanged, key and all — a precomputed P was 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 using sets, calls get_black_litterman_views and constructs a BlackLittermanViews object is constructed.
    • LinearConstraintEstimator: calls the method described above using the val field of the estimator. Its own key wins over the one the estimator passes, which is the same precedence rebase_linear_constraints uses: the argument is the axis the caller is written against, the field is the user overriding it.
  • sets: A UniverseSets object specifying the universes and groupings.

  • key: Key to specify the universe in sets.dict that names resolve against. If nothing, the key is taken from sets.xkey — or, where the caller is written against another declared axis, from that axis' key.

  • datatype: Numeric type for coefficients and expected returns.

  • strict: If true, throws an error if a variable or group is not found in sets; if false, issues a warning.

  • ledger: The door's ledger of departure casualties, or nothing when nobody is collecting. It is threaded into both replace_group_by_assets and get_black_litterman_views, so a shed group and a dropped row are both recorded.

Returns

  • blv::BlackLittermanViews: An object containing the assembled views matrix P and expected returns vector Q, or nothing if 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 ┴ nothing

Related

source

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