Black-Litterman Prior: private API
Types
PortfolioOptimisers.BlackLittermanViewSystem — Type
struct BlackLittermanViewSystem{__T_P, __T_Q, __T_tau, __T_omega}The views of a Black-Litterman system, tau and the view uncertainty.
This type is an implementation detail and is not intended for direct use. bl_preroll makes it. vanilla_posteriors and bl_view_block read it.
Fields
P:P: The view matrix,views × n.
Q:Q: The view returns,views × 1.
tau:tau: The value oftauthat the system used.
omega:omega: The view uncertainty matrix, multiplied bytau.
Related
Functions
PortfolioOptimisers.calc_omega — Function
calc_omega(::Nothing, P::MatNum, sigma::MatNum) -> LinearAlgebra.Diagonal
calc_omega(views_conf::Number, P::MatNum, sigma::MatNum) -> LinearAlgebra.Diagonal
calc_omega(views_conf::VecNum, P::MatNum, sigma::MatNum) -> LinearAlgebra.DiagonalCompute the Black-Litterman view uncertainty matrix Ω.
Each method selects one shape of views_conf and computes one branch of the closed forms below. ::Nothing gives the diagonal with no scale, ::Number gives the same diagonal with one scale for all the views, and ::VecNum gives the same diagonal with one scale for each view.
Mathematical definition
Let $\mathbf{P}$ be the $K \times N$ view matrix and $\mathbf{\Sigma}$ the $N \times N$ prior covariance matrix. The view uncertainty matrix $\mathbf{\Omega}$ for each views_conf variant is:
\[\begin{align} \mathbf{\Omega} &= \mathrm{Diag}(\mathbf{P} \mathbf{\Sigma} \mathbf{P}^\intercal) \quad (\text{no confidence})\,. \end{align}\]
\[\begin{align} \mathbf{\Omega} &= \left(\frac{1}{v} - 1\right) \mathrm{Diag}(\mathbf{P} \mathbf{\Sigma} \mathbf{P}^\intercal) \quad (\text{scalar confidence } v)\,. \end{align}\]
\[\begin{align} \mathbf{\Omega} &= \mathrm{Diag}\!\left(\left(\frac{1}{\boldsymbol{v}} - \boldsymbol{1}\right) \odot \mathrm{diag}(\mathbf{P} \mathbf{\Sigma} \mathbf{P}^\intercal)\right) \quad (\text{vector confidence } \boldsymbol{v})\,. \end{align}\]
Where:
- $\mathbf{\Omega}$: $K \times K$ diagonal view uncertainty matrix.
- $\mathbf{P}$: $K \times N$ views matrix.
- $\mathbf{\Sigma}$: $N \times N$ prior covariance matrix.
- $v$: Scalar view confidence level.
- $\boldsymbol{v}$: $K \times 1$ vector of view confidence levels.
- $\odot$: Element-wise multiplication.
The branch with no confidence is the diagonal uncertainty of the view creation model. bl_preroll multiplies the result by $\tau$, so the two functions together return $\mathrm{Diag}(\mathbf{P}(\tau\mathbf{\Sigma})\mathbf{P}^\intercal)$.
A confidence $v$ scales that diagonal by $1/v - 1$. This is the method of Idzorek in the closed form of Walters. A high confidence makes the view uncertainty smaller, and a low confidence makes it larger. The scale is negative for each $v$ outside $(0, 1)$, and assert_bl_views_conf refuses such a value.
A scalar $v$ gives the same $\mathbf{\Omega}$ as the constant vector of $v$, to the last bit. The two shapes are two forms of one input, and assert_bl_views_conf counts only the vector against the views.
The bound is strict, and it also refuses the two endpoints. $v = 1$ gives $\mathbf{\Omega} = \mathbf{0}$, a view with no uncertainty. Then $\mathbf{P}\tau\mathbf{\Sigma}\mathbf{P}^\intercal + \mathbf{\Omega}$ is singular when $\mathbf{P}$ is rank-deficient. Two identical views over a sample of three assets give a $\mathbf{P}$ of rank one. At $v = 1$ the sum is the constant matrix 1.0021e-6, its determinant is 0.0 and its rank is 1, and the solve raises SingularException. Near the bound the sum is ill-conditioned but not singular: at $v = 1 - 10^{-8}$ the condition number is 2.0e8, and at $v = 0.99$ it is 199. $v = 0$ gives an infinite uncertainty, which has the same effect as no view.
Arguments
views_conf:::Nothing: No confidence.Ω = Diag(P * sigma * P').::Number: One confidencevfor all the views.Ω = (1/v - 1) * Diag(P * sigma * P').::VecNum: One confidence for each view, the vectorv.Ω = Diag((1 ./ v .- 1) .* diag(P * sigma * P')).
P: Views matrix,views × n, with one column for each name of the axis that the views update.sigma: Covariance matrixassets × assets.
Returns
omega::LinearAlgebra.Diagonal: Diagonal view uncertainty matrixviews × views.
Related
PortfolioOptimisers.bl_preroll — Function
bl_preroll(
views,
sets,
views_conf,
prior_sigma,
pe_tau,
T,
datatype,
strict;
...
) -> Union{Nothing, BlackLittermanViewSystem}
bl_preroll(
views,
sets,
views_conf,
prior_sigma,
pe_tau,
T,
datatype,
strict,
axis::Symbol;
ledger
) -> Union{Nothing, BlackLittermanViewSystem}
Assemble the views, tau and the view uncertainty that the Black-Litterman members share.
axis names the declared axis of the distribution that the views update. Each caller knows it from its own type, not from the views. BlackLittermanPrior uses the default :xkey, the asset axis. A member whose views update the factor distribution passes :tfkey or :cfkey. axis is the last positional argument, because a caller on the asset axis never gives it.
UniverseSets declares two factor axes, so the function accepts three symbols. Each member of the library that updates a factor distribution reads the columns of F, and passes :tfkey. The function accepts :cfkey because the axis exists and a view can update it. No member passes :cfkey now.
axis is the name of a field of UniverseSets, not a key, so a caller states its axis and nothing more. This function reads the key, and only when sets is not nothing. To read sets.tfkey when there is no universe is the same error as to read the universe. A precomputed BlackLittermanViews is the one shape of views that can come with no sets. It resolves no names, and it ignores the sets and the axis.
This function is also where P meets the distribution that it updates, so it checks that their widths agree. A P assembled from names has the correct width. A precomputed BlackLittermanViews resolves no names, and no other site checks its width.
When no view is left, the function returns nothing, for each cause. get_black_litterman_views drops a row that it cannot assemble, and it does not fit the row without the term. Thus a set of views can lose all its rows for different causes:
- A departure removed the last row.
- The fit uses a sub-universe that does not hold the names, such as a cluster of a nested optimisation or a subset of a resampling.
- The caller wrote a typo.
No cause changes the data that is left for the update, so no cause changes the result. The fit continues as if the caller stated no view. Each member states what that means for it through vanilla_posteriors or bl_view_block.
strict_diagnostic still reports each name that resolves against neither axis, at the site where the assembly reads it. It raises an ArgumentError under strict = true and warns otherwise, and the message names the name and the universe that it failed against. That report names the cause. A refusal here can only name the result, and it cannot tell a typo from a correct name that is outside a sub-universe. The ledger keeps the two cases apart for the report: only a departed name writes into it, and announce_bl_departures reads it to say which case happened.
The returned omega includes $\tau$, so a caller passes it to vanilla_posteriors with no change. calc_omega is homogeneous of degree one in the covariance that it reads. Thus $\tau$ multiplies $\mathbf{P}\tau\mathbf{\Sigma}\mathbf{P}^\intercal$ and $\mathbf{\Omega}$, and it cancels from the posterior mean on each confidence branch. It does not cancel from the posterior covariance. vanilla_posteriors gives the measurement.
Algorithm
- Check that
axisnames a declared axis that a view can update. - Read the universe key from the field
axisofsets. Whensetsisnothing, the key isnothing, because a precomputed views object resolves no name. - Assemble the views with
black_litterman_viewsunder that key. The result isblv. - When no view is left, return
nothing. The caller decides what a fit with no view gives. - Read
P,Qandexclfromblv. - Check that the number of columns of
Pis equal to the number of rows ofprior_sigma. - Set
tautope_tauwhen it is notnothing, and to1/Totherwise. - Remove the confidences of the views that step 3 dropped, with
remove_excl_views. - Make the view uncertainty matrix from the remaining confidences with
calc_omega, and multiply it bytau. Return it asomega, withP,Qandtau.
Validation
axis in (:xkey, :tfkey, :cfkey). Raises aDomainError.size(P, 2) == size(prior_sigma, 1), when a view is left. Raises aDimensionMismatch.
Arguments
views: The views, aLinearConstraintEstimatorof view equations or a precomputedBlackLittermanViews.sets: Sets used to map estimator values to assets.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.prior_sigma::MatNum: The prior covariance matrix of the distribution that the views update,n × nover that axis.pe_tau::Option{<:Number}: Thetauof the estimator, ornothing. Ifnothing, the function uses1/T.T::Real: The effective number of observations of the prior mean, for the defaulttau = 1/T.datatype: Data type of the result whenvalisnothing.strict: Whether to throw an error ifsetsdoes not contain the desired value insets.dict[key].axis: The field ofsetsthat names the declared axis that the views resolve against::xkeyfor the asset axis,:tfkeyfor the time-series factor axis,:cfkeyfor the cross-sectional factor axis. The function reads the key fromsets, and only whensetsis notnothing.ledger: The Departure Ledger of the entry of the fit, ornothingwhen no caller collects the drops. The function passes it toblack_litterman_views. The ledger tells a set of views that a departure emptied from a set that another cause emptied. Only the report uses this difference, and the result does not.
Returns
blp::BlackLittermanViewSystem: The views and their uncertainty:P::MatNum: The view matrix,views × n.Q::VecNum: The view returns,views × 1.tau::Number: The value oftauthat the function used.omega::LinearAlgebra.Diagonal: The view uncertainty matrix, multiplied bytau.
nothing: The function dropped every view, so the fit continues with no view.
Related
PortfolioOptimisers.announce_bl_departures — Function
announce_bl_departures(ni::VecStr, ledger::VecStr, viewless::Bool) -> NothingReport, once for each Black-Litterman fit, the assets that left the investable universe and the views that they removed.
This is the call of announce_non_investable for the Black-Litterman members. It is written once, so each of the four prior methods calls it in one line, and the four use the same words. It names the process "Black-Litterman fit". The default message names an optimisation, which is wrong for a call of prior(pe, X) outside an optimisation.
The message is one sentence for the four members, and it is true for each. Two members write their views on the factor axis, where no asset name occurs, so the clause about view rows does not apply to them. The first clause applies to each member, because the four estimate their posterior over the assets that remain.
viewless is true when the fit has no view left. The function reports this in two ways, because it has two causes.
- When the ledger is not empty, a departure removed the last view. The function raises the message to a warning, and the message states the departure.
- When the ledger is empty, no departure removed a view, and the departure message cannot explain the empty set.
announce_non_investablesays nothing about the views, so the function gives its own warning for the fit with no view. This is the case of a sub-universe: a cluster of a nested optimisation or a subset of a resampling holds none of the names that the caller wrote. The fit drops each row, and the caller receives a result with no update and no other report.
A drop that removes only some of the views stays at the @info level.
Arguments
ni: The names that the Investable Mask leaves out, frominvestable_views.ledger: The views that the departures removed, as the view assembly recorded them. When it is not empty andviewlessistrue, a departure removed the last view.viewless:truewhen the fit has no view left.
Returns
nothing.
Related
PortfolioOptimisers.bl_view_block — Function
bl_view_block(::Nothing, n::Integer, datatype::DataType) -> Tuple
bl_view_block(blp::BlackLittermanViewSystem, ::Integer, ::DataType) -> TupleReturn the P, Q and omega of a view system, or a block with no row when the system has no view left.
Two members use this function and not vanilla_posteriors, for two different reasons.
AugmentedBlackLittermanPrior puts a block of asset views above a block of factor views, and each half can become empty alone. An empty half adds no row, and the stack does not change to the prior. The other half still holds views that the caller stated and that resolve, so the joint posterior still uses them. The prior stack discards those views. Only when both halves are empty is no view left, and that member then reads the two results itself and takes the prior stack. The empty block is 0 × n and not a row of zeros, so the stack holds no false view, and aug_Q has one entry less, not an entry of zero.
BayesianBlackLittermanPrior has one view system and no stack. It uses an empty block because, for it, the algebra of an empty block is the result with no view. Its update is a sum of precisions, $\hat{\mathbf{\Sigma}}^{-1} = \mathbf{\Sigma}_f^{-1} + \mathbf{P}^\intercal\mathbf{\Omega}^{-1}\mathbf{P}$, so a 0 × n $\mathbf{P}$ adds zero, and there is no term of estimation error $\tau\mathbf{\Sigma}$ to widen the covariance. The master equations of vanilla_posteriors have that term, and that is why the members that run them take its nothing method when no view is left. The result is not the wrapped prior of that member but $\mathbf{\Sigma}_a + \mathbf{M}\mathbf{\Sigma}_f\mathbf{M}^\intercal$, the moments that its factor model gives, and the member has no unchanged prior to return.
Arguments
blp: The result ofbl_prerollfor this system, ornothing.n: The width of the axis of this system, for the emptyP.datatype: The numeric type of the block.
Returns
(P, Q, omega)::Tuple: The view matrix, the view returns and the view uncertainty, with no row when the system has no view left.
Related
PortfolioOptimisers.assert_bl_precomputed_universe — Function
assert_bl_precomputed_universe(sets::UniverseSets, pr::AbstractPriorResult) -> Nothing
assert_bl_precomputed_universe(sets::Nothing, pr::AbstractPriorResult) -> NothingRefuse a precomputed view matrix over a universe that an asset left. This is the one configuration where the estimator cannot reduce the asset views.
The reduction resolves the view names of the caller against the universe that remains. With the names, the estimator can drop a row that names a departed asset, and build each other row again over the investable columns. A precomputed BlackLittermanViews resolves no name. black_litterman_views returns it unchanged, because the caller assembled it over its own universe and no later step can check it. Thus the estimator cannot reduce its P, and it has no names to reduce it with: an estimator with precomputed views can have no sets.
Without this check, the configuration fails with no clear report. calc_omega forms P * sigma * transpose(P) over the full universe, 0 * NaN is NaN, and each entry of the posterior is NaN. Under the default mp, posdef! then raises ArgumentError: matrix contains Infs or NaNs, which names the wrong cause. Under a matrix processing estimator that does nothing, the fit gives no error, and the next layer finds no investable asset. This function refuses the configuration with an error that names it.
The two methods split by dispatch on the type of sets. sets is a field of a @concrete estimator, so its type is known when the method compiles. The UniverseSets method is the usual path, and it does nothing. Only the method for nothing derives the mask, and only to refuse.
Arguments
sets: Sets used to map estimator values to assets.pr: Prior result.
Validation
- When
setsisnothing, each asset ofpris investable. Raises anArgumentError.
Returns
nothing.
Related
PortfolioOptimisers.vanilla_posteriors — Function
vanilla_posteriors(::Nothing, prior_mu::VecNum, prior_sigma::MatNum) -> Tuple
vanilla_posteriors(blp::BlackLittermanViewSystem, prior_mu::VecNum, prior_sigma::MatNum) -> TupleRun the master equations, or return the prior pair when no view is left.
bl_preroll returns nothing when no view row is left. The fit continues and does not refuse. A Black-Litterman posterior with no view is the distribution that the views were to update, so this function returns that distribution.
The function returns the prior pair, not the result of the master equations with an empty $\mathbf{P}$. The difference is not a rounding error. vanilla_posteriors adds the term of estimation error $[(\tau\mathbf{\Sigma})^{-1}]^{-1} = \tau\mathbf{\Sigma}$ to the covariance. With an empty $\mathbf{P}$ it gives $(1 + \tau)\mathbf{\Sigma}$, a covariance wider than the prior, from views that do not exist. With the prior pair, the caller loses the views and nothing more.
BayesianBlackLittermanPrior does not use this function. Its update is a sum of precisions, $\hat{\mathbf{\Sigma}}^{-1} = \mathbf{\Sigma}_f^{-1} + \mathbf{P}^\intercal\mathbf{\Omega}^{-1}\mathbf{P}$, so an empty $\mathbf{P}$ adds zero, and there is no $\tau\mathbf{\Sigma}$ term to widen the covariance. Its result with no view is thus the algebra of an empty block from bl_view_block. That result is not its wrapped prior. By Woodbury, it is $\mathbf{\Sigma}_a + \mathbf{M}\mathbf{\Sigma}_f\mathbf{M}^\intercal$ and $\mathbf{M}\boldsymbol{\mu}_f + \mathbf{b}$, the moments that the factor model gives. That member has no unchanged prior to return, because it changes its wrapped prior with or without views.
The function copies the covariance. Each caller passes the result to matrix_processing!, which writes in place, and the function must not change a prior result that a caller still holds.
The two methods split by dispatch. The result of bl_preroll is nothing or one concrete BlackLittermanViewSystem, so the compiler splits that small union at the call.
Arguments
blp: The result ofbl_preroll, ornothing.prior_mu: The prior mean of the distribution the views update.prior_sigma: The prior covariance of that distribution.
Returns
(posterior_mu, posterior_sigma)::Tuple{VecNum, MatNum}: The posterior pair, or the prior pair when there is no view.
Related
vanilla_posteriors(tau::Number, prior_mu::VecNum, prior_sigma::MatNum,
omega::MatNum, P::MatNum, Q::VecNum)Compute the Black-Litterman posterior mean and covariance.
The function does not add a risk-free rate. Each Black-Litterman prior estimator adds its own rf once, through apply_rf, which states where each member adds it.
The two equations below are the inverse-free form of the master equations. They are algebraically equal to the form on prior: the covariance term is the Woodbury expansion of $\left[(\tau\mathbf{\Sigma})^{-1} + \mathbf{P}^\intercal\mathbf{\Omega}^{-1}\mathbf{P}\right]^{-1}$. The function uses this form because it solves against one $K \times K$ matrix, and the other form inverts three $N \times N$ matrices.
Mathematical definition
Let $\boldsymbol{\Pi}$ be the prior mean, $\mathbf{\Sigma}$ the prior covariance, $\tau$ the scaling parameter, $\mathbf{P}$ the view matrix, $\boldsymbol{q}$ the view vector, and $\mathbf{\Omega}$ the view uncertainty matrix:
\[\begin{align} \hat{\boldsymbol{\mu}}_{BL} &= \boldsymbol{\Pi} + \tau\mathbf{\Sigma}\mathbf{P}^\intercal \left(\mathbf{P}\tau\mathbf{\Sigma}\mathbf{P}^\intercal + \mathbf{\Omega}\right)^{-1} (\boldsymbol{q} - \mathbf{P}\boldsymbol{\Pi})\,. \end{align}\]
\[\begin{align} \hat{\mathbf{\Sigma}}_{BL} &= \mathbf{\Sigma} + \tau\mathbf{\Sigma} - \tau\mathbf{\Sigma}\mathbf{P}^\intercal \left(\mathbf{P}\tau\mathbf{\Sigma}\mathbf{P}^\intercal + \mathbf{\Omega}\right)^{-1} \mathbf{P}\tau\mathbf{\Sigma}\,. \end{align}\]
Where:
- $\hat{\boldsymbol{\mu}}_{BL}$: Black-Litterman posterior mean vector.
- $\hat{\mathbf{\Sigma}}_{BL}$: Black-Litterman posterior covariance matrix.
- $\boldsymbol{\Pi}$: $N \times 1$ prior (equilibrium) expected returns.
- $\mathbf{\Sigma}$: $N \times N$ prior covariance matrix.
- $\tau$: Scaling parameter for the uncertainty in the prior.
- $\mathbf{P}$: $K \times N$ views matrix.
- $\boldsymbol{q}$: $K \times 1$ views vector.
- $\mathbf{\Omega}$: $K \times K$ view uncertainty matrix.
$\tau$ occurs in both equations, but it does not move the posterior mean when $\mathbf{\Omega}$ comes from bl_preroll. calc_omega is homogeneous of degree one in the covariance that it reads, and bl_preroll multiplies its result by $\tau$. Thus the gain $\tau\mathbf{\Sigma}\mathbf{P}^\intercal(\mathbf{P}\tau\mathbf{\Sigma}\mathbf{P}^\intercal + \mathbf{\Omega})^{-1}$ has one $\tau$ outside the inverse and one inside it, and the two cancel. On a $200 \times 3$ sample with two views, over $\tau \in \{1/200, 0.05, 0.5\}$, the posterior mean moves by at most 3.3e-19 on each confidence branch: no confidence, the scalar 0.4, and the vector [0.25, 0.75]. The posterior covariance does move, because $\mathbf{\Sigma} + \tau\mathbf{\Sigma} - \ldots$ holds a $\tau$ that does not cancel. Its excess over $\mathbf{\Sigma}$ has trace 2.013e-7, 2.013e-6 and 2.013e-5 at $\tau = 0.001$, 0.01 and 0.1, which is linear in $\tau$ to three figures.
A view that repeats the prior changes nothing. With $\boldsymbol{q} = \mathbf{P}\boldsymbol{\Pi}$ the residual $\boldsymbol{q} - \mathbf{P}\boldsymbol{\Pi}$ is zero, so the posterior mean is equal to the prior mean. On the same sample the difference is 0.0.
Algorithm
- Multiply the prior covariance by
tauand by the transpose ofP. The result isv1, the $N \times K$ matrix $\tau\mathbf{\Sigma}\mathbf{P}^\intercal$. - Multiply
Pbyv1, and add the view uncertainty. The result isv2, the $K \times K$ matrix $\mathbf{P}\tau\mathbf{\Sigma}\mathbf{P}^\intercal + \mathbf{\Omega}$. This is the only matrix that the function solves against. - Subtract
P * prior_mufromQ. The result is the view residualv3. - Solve
v2againstv3, multiply the solution byv1, and add it toprior_mu. The result isposterior_mu. - Solve
v2against the transpose ofv1, multiply the solution byv1, and subtract it fromprior_sigma + tau * prior_sigma. The result isposterior_sigma.
Arguments
tau: The scale of the uncertainty of the prior mean.prior_mu: The prior mean of the distribution that the views update.prior_sigma: The prior covariance of that distribution.omega: The view uncertainty matrix, multiplied bytau.P: The view matrix,views × n.Q: The view returns, one for each view.
Returns
posterior_mu::VecNum: The posterior mean.posterior_sigma::Matrix{<:Number}: The posterior covariance matrix.
Related
PortfolioOptimisers.apply_rf — Function
apply_rf(rf::Number, mu::VecNum)Add the risk-free rate to a Black-Litterman mean.
apply_rf is the one site that reads the rf field of a Black-Litterman prior estimator. Each of the four members, BlackLittermanPrior, BayesianBlackLittermanPrior, FactorBlackLittermanPrior and AugmentedBlackLittermanPrior, calls it once. No function subtracts the rate.
The four members keep three rules:
- The estimator adds the rate once. No method adds it twice.
- The update uses the scale of the views. The update forms the residual
Q - P * mu, so the prior mean must have the scale ofQ, which is a total return. A mean from a wrapped prior estimator has that scale, and it goes to the update with no change. The equilibrium mean ofequilibrium_muis only a risk premium. Thus the two members that can make one add the rate to it before the update, on the axis of that mean. If the prior mean has no rate, the update compares the views with the wrong level, so these members add the rate first and not last. - The wrapped prior does not change. The estimator does not fit a wrapped prior again and does not scale its mean, so a risk-free rate that a wrapped prior applied stays in its mean.
Each member calls it at one site:
BlackLittermanPriorandBayesianBlackLittermanPriorhave no equilibrium branch, so they have no mean to convert. They add the rate to the posterior asset mean as the last step, andrfshifts the result.FactorBlackLittermanPriorandAugmentedBlackLittermanPriorcall it on the equilibrium mean, and only whenlis notnothing. Whenlisnothing, they do not readrf, and it has no effect on the result.
A measurement shows that the estimator adds the rate once. Two BlackLittermanPrior fits over one $200 \times 3$ sample, with different rf and no other difference, give posterior means whose difference is rf in each entry, to the last bit. At rf = 0.03 the difference is [0.03, 0.03, 0.03], and max|diff - rf| is 0.0.
Algorithm
- Add
rfto every entry ofmu, and return the result. The input is not modified.
Arguments
rf: Risk-free rate.mu: Expected returns vector. It is a posterior asset mean for the two members with no equilibrium branch, and a prior equilibrium mean for the two members that have one.
Returns
mu::VecNum:mushifted byrf.
Related
PortfolioOptimisers.remove_excl_views — Function
remove_excl_views(
views_conf::Union{Nothing, Number},
args...
) -> Union{Nothing, Number}
Remove excluded views from views_conf.
This method is for a confidence that is nothing or a scalar. Neither has one entry for each view, because a scalar is one confidence for all the views. A dropped view changes nothing for them, and the method ignores each argument after the first.
Algorithm
- Return
views_confunchanged.
Arguments
views_conf:nothing, or one confidence for all the views.args...: The indices of the dropped views. The method ignores them.
Returns
views_conf::Option{<:Number}: The input, unchanged.
Related
remove_excl_views(
views_conf::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
_::Nothing
) -> AbstractVector{<:Union{Number, AbstractJuMPScalar}}
Remove excluded views from views_conf.
This method is for a vector of confidences when no view was dropped. When get_black_litterman_views drops no view, it writes excl = nothing and not an empty vector, so this method is the usual case.
Algorithm
- Return
views_confunchanged.
Arguments
views_conf: One confidence for each view.::Nothing: No view was dropped.
Returns
views_conf::VecNum: The input, unchanged.
Related
remove_excl_views(
views_conf::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
excl::AbstractVector{<:Integer}
) -> Any
Remove excluded views from views_conf.
This method removes entries. It takes a vector with one confidence for each view that the caller wrote, and the indices of the views that get_black_litterman_views dropped. The remaining entries keep the order of the caller, so entry k of the result belongs to row k of the P of the same assembly. When excl holds every view, the result is an empty vector.
Algorithm
- Take the indices of
views_confthat are not inexcl, in ascending order. - Return the entries at those indices as a lazy view, with
nothing_scalar_array_view.
Arguments
views_conf: One confidence for each view that the caller wrote.excl: The indices of the dropped views, over the views that the caller wrote.
Returns
views_conf::VecNum: A view of the input, with one confidence for each kept view.
Related
PortfolioOptimisers.assert_bl_views_axis — Function
assert_bl_views_axis(
pe::BlackLittermanPrior,
X::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}}
)
Refuse a BlackLittermanPrior whose asset universe does not match the returns matrix.
The function checks the axis only for views that resolve names against it. A precomputed BlackLittermanViews holds its own P and does not read sets. A check of the universe would refuse that valid configuration, which assert_bl lets have no sets.
Arguments
pe: Black-Litterman prior estimator.X: Asset returns,observations × assets.
Validation
length(pe.sets.dict[pe.sets.xkey]) == size(X, 2)when the views resolve names. Raises aDimensionMismatch.
Returns
nothing.
Related
PortfolioOptimisers.bl_posterior — Function
bl_posterior(
pe::BlackLittermanPrior,
prior_model::AbstractPriorResult,
strict::Bool;
kwargs...
) -> Union{HighOrderPrior, LowOrderPrior}
Update the result of the wrapped prior of a BlackLittermanPrior with the views of the estimator.
This function holds each step of the estimator after the wrapped prior gives its result. The batch method calls it with the result of a fit over the matrix of the caller. prior(pe) with no data calls it with the result of the fold of the wrapped prior. The function reads no returns matrix that the result does not hold: T, the axis and the matrix for the processing all come from prior_model. Both routes use this one body, so they cannot become different.
Algorithm
- Derive the Investable Mask and the reduced view universe with
investable_views. A view is a dense linear form over the asset axis, so one departed asset makes each entry ofomegaNaN. - Refuse a precomputed view matrix over a universe with a departed asset, with
assert_bl_precomputed_universe. - View the prior result at the mask with
investable_prior, and readposterior_X,prior_muandprior_sigmafrom it. - Assemble
P,Q,tauandomegawithbl_preroll. ItsTis the number of rows ofprior_model.X. - Run the update with
vanilla_posteriors, and addpe.rfonce withapply_rf. - Process the reduced covariance with
sample_matrix_processing!, at the count of the covariance of the wrapped prior, before the expansion, because a frame withNaNentries has no factorisation. - Report the departures once with
announce_bl_departures. - Expand both moments to the universe of the caller with
expand_moment. - Forward each field of the wrapped result with
forward_prior, and drop onlychol.
Arguments
pe: Black-Litterman prior estimator.prior_model: The result of the wrapped prior.strict: Iftrue, a view name that does not resolve raises an error. Iffalse, it warns.kwargs...: More keyword arguments, for the matrix processing.
Returns
pr::AbstractPriorResult: The wrapped result, with the posteriors in place of its two moments.
Related
PortfolioOptimisers.fold_prior_step — Method
fold_prior_step(pe::BlackLittermanPrior, rd::ReturnsResult,
gaps::Option{<:AbstractVector{Bool}})Fold the observations of a ReturnsResult into a BlackLittermanPrior. The function forwards rd and its marks to the wrapped prior.
This is the forwarding form of fold_prior_step, the fold that partial_fit! uses for each prior over a ReturnsResult. The outer prior keeps no rows. The wrapped prior keeps them, so the route of the wrapped prior decides what the step uses. The estimation mask and the Panel Fields reach it with no change, and it refuses what its route cannot use.
Arguments
pe: The Black-Litterman prior estimator.rd: The returns result to use.gaps: One mark for each observation ofrd,trueat an observation with a Shared Series gap, ornothing.
Validation
- Each condition that the fold of
pe.peoverrdchecks.
Returns
pe: A new estimator, with the folded wrapped prior.
Related