quantlab.portfolio.predefined.black_litterman.ReturnView#
- class quantlab.portfolio.predefined.black_litterman.ReturnView(config)[source]#
Bases:
_Configured,ABCBase class of the user’s views of a
BlackLittermanOptimizer: one portfolio’s return.A view says
p' f = q,fthe risk model’s factor returns: a subclass says whatpis (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 openDataRecorder; the uncertainty is Idzorek’sconfidenceor a standard deviationstd.- Parameters:
- configReturnViewConfig
An instance of the subclass’s
config_cls.
- Raises:
- ValueError
If not exactly one of
annual_returnandstoreis set,annual_returnis not finite,variableis missing withstoreor set without it, not exactly one ofconfidenceandstdis set,confidenceis outside(0, 1]orstdis 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
viewreading 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
pon the bar’s factor returns,Nonewhen 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
pwith the viewp' f = q;Nonewhen 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,
Nonefor 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 priorwith a confidenceC, else(std * span / 252) ** 2.
Examples
>>> view.variance(prior=4e-4, tau=0.05, span=5) 2e-05