quantlab.portfolio.predefined.black_litterman.ReturnView#

class quantlab.portfolio.predefined.black_litterman.ReturnView(config)[source]#

Bases: _Configured, ABC

Base class of the user’s views of a BlackLittermanOptimizer: one portfolio’s return.

A view says p' f = q, f the risk model’s factor returns: a subclass says what p is (row) and which risk-model factors it names (risk_factors). The value and its uncertainty are shared: an annualised return, a constant (annual_return) or a series read point-in-time from a zarr store (store, variable), whose value at a bar is the last finite one dated at or before the bar, each read logged to the open DataRecorder; the uncertainty is Idzorek’s confidence or a standard deviation std.

Parameters:
configReturnViewConfig

An instance of the subclass’s config_cls.

Raises:
ValueError

If not exactly one of annual_return and store is set, annual_return is not finite, variable is missing with store or set without it, not exactly one of confidence and std is set, confidence is outside (0, 1] or std is not positive.

Examples

>>> from quantlab.portfolio.config import MarketReturnViewConfig
>>> view = MarketReturnView(MarketReturnViewConfig(annual_return=0.06, confidence=0.5))
>>> view.annual_return_at(pd.Timestamp("2024-03-01"))
0.06
>>> view.variance(prior=4e-4, tau=0.05, span=5)
2e-05
annual_return_at(timestamp)[source]#

Return the view’s annualised return known at timestamp, NaN before the first.

Parameters:
timestamppd.Timestamp or np.datetime64

The bar.

Returns:
float

The constant, or the series’ last finite value dated at or before timestamp.

Examples

With view reading a series whose first value is dated 2024-03-04:

>>> view.annual_return_at(pd.Timestamp("2024-03-01"))
nan
property risk_factors#

The risk-model factors the view names, checked against the risk model; none by default.

Examples

>>> view.risk_factors
()
abstractmethod row(factor_names, market_exposures)[source]#

Return the view’s row p on the bar’s factor returns, None when the bar cannot price it.

Parameters:
factor_namesSequence[str]

The factors of the bar’s forecast.

market_exposuresnp.ndarray

The market’s exposure to each of them.

Returns:
np.ndarray or None

p with the view p' f = q; None when the bar’s forecast cannot price it.

Examples

>>> view.row(("market", "value"), np.array([1.0, 0.2]))
array([1. , 0.2])
property store_path#

The store the series is read from, None for a constant view.

Examples

>>> view.store_path is None
True
variance(prior, tau, span)[source]#

Return the view’s variance over the span.

Parameters:
priorfloat

p' F p, the viewed return’s variance over the span.

taufloat

The rule’s tau.

spanint

The span in bars.

Returns:
float

tau (1 - C)/C prior with a confidence C, else (std * span / 252) ** 2.

Examples

>>> view.variance(prior=4e-4, tau=0.05, span=5)
2e-05