Black-Litterman Views Generation
PortfolioOptimisers.BlackLittermanViews Type
struct BlackLittermanViews{T1, T2} <: AbstractResult
P::T1
Q::T2
endContainer 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.
Fields
P: Matrix of view coefficients, where each row represents a view and each column corresponds to an asset.Q: Vector of expected returns or values for each view.
Constructor
BlackLittermanViews(; P::AbstractMatrix, Q::AbstractVector)Keyword arguments correspond to the fields above.
Validation
!isempty(P)and!isempty(Q).size(P, 1) == 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]Related
sourcePortfolioOptimisers.black_litterman_views Function
black_litterman_views(views::Union{Nothing, <:BlackLittermanViews}, args...; kwargs...)
black_litterman_views(views::Union{<:AbstractString, Expr,
<:AbstractVector{<:Union{<:AbstractString, Expr}}},
sets::AssetSets; datatype::DataType = Float64, strict::Bool = false)
black_litterman_views(views::LinearConstraintEstimator, sets::AssetSets;
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.
Arguments
views:nothingorBlackLittermanViews: it is returned unchanged.Union{<:AbstractString, Expr, <:AbstractVector{<:Union{<:AbstractString, Expr}}}: the view(s) are parsed, groups are replaced by their constituent assets usingsets, callsget_black_litterman_viewsand constructs aBlackLittermanViewsobject is constructed.LinearConstraintEstimator: calls the method described above using thevalfield of the estimator.
sets: AnAssetSetsobject specifying the asset universe and groupings.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.
Returns
blv::BlackLittermanViews: An object containing the assembled views matrixPand expected returns vectorQ, ornothingif no views are present.
Examples
julia> sets = AssetSets(; key = "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]
julia> 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]Related
sourcePortfolioOptimisers.get_black_litterman_views Function
get_black_litterman_views(lcs::Union{<:ParsingResult, <:AbstractVector{<:ParsingResult}},
sets::AssetSets; datatype::DataType = Float64,
strict::Bool = false)Convert parsed Black-Litterman view equations into a BlackLittermanViews object.
get_black_litterman_views takes one or more ParsingResult objects (as produced by parse_equation), expands variable names using the provided AssetSets, and assembles the canonical views matrix P and expected returns vector Q for Black-Litterman prior construction. The result is a BlackLittermanViews object suitable for use in portfolio optimisation routines.
Arguments
lcs: A singleParsingResultor a vector of such objects, representing parsed Black-Litterman view equations.sets: AnAssetSetsobject specifying the asset universe and groupings.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.
Details
For each view, variable names are matched to the asset universe in
sets.Coefficient vectors are assembled for each view, with entries corresponding to the order of assets in
sets.The function validates that all views reference valid assets or groups, using
@argcheckfor defensive programming.Returns
nothingif no valid views are found after processing.
Returns
BlackLittermanViews: An object containing the assembled views matrixPand expected returns vectorQ, ornothingif no views are present.
Examples
julia> sets = AssetSets(; key = "nx", dict = Dict("nx" => ["A", "B", "C"]));
julia> lcs = parse_equation(["A + B == 0.05", "C == 0.02"]);
julia> PortfolioOptimisers.get_black_litterman_views(lcs, sets)
BlackLittermanViews
P ┼ 2×3 LinearAlgebra.Transpose{Float64, Matrix{Float64}}
Q ┴ Vector{Float64}: [0.05, 0.02]Related
sourcePortfolioOptimisers.assert_bl_views_conf Function
assert_bl_views_conf(::Nothing, args...)
assert_bl_views_conf(views_conf::Union{Nothing, <:Real, <:AbstractVector{<:Real}},
views::Union{<:AbstractString, Expr,
<:AbstractVector{<:Union{<:AbstractString, Expr}},
<:LinearConstraintEstimator, <:BlackLittermanViews})Validate Black-Litterman view confidence specification.
assert_bl_views_conf checks that the view confidence parameter(s) provided for Black-Litterman prior construction are valid. It supports scalar and vector confidence values, and works with views specified as equations, constraint estimators, or canonical views objects. The function enforces that confidence values are strictly between 0 and 1, and that the number of confidence values matches the number of views when a vector is provided.
Arguments
views_conf: Scalar or vector of confidence values.views: Black-Litterman views, which may be equations.
Returns
nothing: Returns nothing if validation passes; throws an error otherwise.
Validation
views_conf:::Nothing, no-op.::Real,0 < views_conf < 1.::AbstractVector{<:Real},all(x -> 0 < x < 1, views_conf), and must have the same length as the number of views.
views:::Union{<:AbstractString, Expr},length(views_conf) == 1.::AbstractVector{<:Union{<:AbstractString, Expr}},length(views_conf) == length(views).::LinearConstraintEstimator, callsassert_bl_views_conf(views_conf, views.val).::BlackLittermanViews,length(views_conf) == length(views.Q).
Related
source