skfolio.prior.BlackLitterman#

class skfolio.prior.BlackLitterman(views, groups=None, prior_estimator=None, tau=0.05, view_confidences=None, risk_free_rate=0)[source]#

Black & Litterman Prior Model estimator.

The Black & Litterman model [1] takes a Bayesian approach by using a prior estimate of the assets expected returns and covariance matrix, which are updated using the analyst views to get a posterior estimate.

Parameters:
viewsarray-like of floats of shape (n_views,)

The analyst views about the assets expected returns. The views must match the following patterns:

  • Absolute view: “asset_i = a”

  • Relative view: “asset_i - asset_j = b”

With “asset_i” and “asset_j” the assets names and “a” and “b” the analyst views about the assets expected returns expressed in the same frequency as the returns X.

Examples:

  • “SPX = 0.00015” –> the SPX will have a daily expected return of 0.015%

  • “SX5E - TLT = 0.00039” –> the SX5E will outperform the TLT by a daily expected return of 0.039%

  • “SX5E - SPX = -0.0002” –> the SX5E will underperform the SPX by a daily expected return of 0.02%

  • “Equity = 0.00010” –> the sum of Equity assets will have a daily expected return of 0.01%

  • “Europe - US = 0.0004” –> the sum of European assets will outperform the sum of US assets by a daily expected return of 0.04%

groupsdict[str, list[str]] or array-like of strings of shape (n_groups, n_assets), optional

The assets groups to be referenced in views. If a dictionary is provided, its (key/value) pair must be the (asset name/asset groups) and the input X of the fit method must be a DataFrame with the assets names in columns.

Examples:

  • groups = {“SX5E”: [“Equity”, “Europe”], “SPX”: [“Equity”, “US”], “TLT”: [“Bond”, “US”]}

  • groups = [[“Equity”, “Equity”, “Bond”], [“Europe”, “US”, “US”]]

prior_estimatorBasePrior, optional

The assets’ prior model estimator. It is used to estimate the PriorModel containing the estimation of the assets expected returns, covariance matrix, returns and Cholesky decomposition. The default (None) is to use EmpiricalPrior(mu_estimator=EquilibriumMu()).

taufloat, default=0.05

Tau controls the degree of uncertainty given to the analyst views. A low value means high uncertainty and will put less weight on the analyst views compared to the prior returns. The default value is 0.05. Other common values used in the literature are 1.0 or the inverse of the number of observations.

view_confidencesarray-like of floats of shape (n_views,), optional

Instead of using a diagonal uncertainty matrix (Omega) proportional to the prior covariance matrix, you can provide the vector of view confidences (between 0 and 1) as describe by the Idzorek’s method [2].

risk_free_ratefloat, default=0.0

The risk-free rate.

Attributes:
prior_model_PriorModel

The PriorModel.

groups_ndarray of shape(n_groups, n_assets)

Assets names and groups converted to an 2D array.

views_ndarray of shape (n_views,)

The analyst views converted to a ndarray of floats.

picking_matrix_ndarray of shape (n_views, n_assets)

Picking matrix computed from the views and assets names/groups.

prior_estimator_BasePrior

Fitted prior_estimator.

n_features_in_int

Number of assets seen during fit.

feature_names_in_ndarray of shape (n_features_in_,)

Names of features seen during fit. Defined only when X has feature names that are all strings.

References

[1]

“Combining investor views with market equilibrium”, The Journal of Fixed Income, Fischer Black and Robert Litterman, 1991.

[2]

“A step-by-step guide to the Black-Litterman model : Incorporating user-specified confidence”, Forecasting Expected Returns in the Financial Markets, Idzorek T, 2007.

Methods

fit(X[, y])

Fit the Black & Litterman estimator.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_params(**params)

Set the parameters of this estimator.

fit(X, y=None, **fit_params)[source]#

Fit the Black & Litterman estimator.

Parameters:
Xarray-like of shape (n_observations, n_assets)

Price returns of the assets.

yIgnored

Not used, present for API consistency by convention.

**fit_paramsdict

Parameters to pass to the underlying estimators. Only available if enable_metadata_routing=True, which can be set by using sklearn.set_config(enable_metadata_routing=True). See Metadata Routing User Guide for more details.

Returns:
selfBlackLitterman

Fitted estimator.

get_metadata_routing()[source]#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.