quantlab.portfolio.predefined.approximate.topk_dropout.decide#
- quantlab.portfolio.predefined.approximate.topk_dropout.decide(rule, panel, prices=None, stopping=Stopping(tolerance=1e-05, max_iterations=20000))[source]#
Return every bar’s TopkDropout book, the bars decided forward from
prices.previous.- Parameters:
- ruleTopkDropoutConstructor
The rule: its config’s
direction,topkandn_drop, and the label it ranks by (ranking_label).- panelDecisionPanel
The bars’ predictions and tradability.
- pricesPanelPrices, optional
The book before the bars and the prices it drifts with; without them the book starts empty and does not drift.
- stoppingStopping
Not read.
- Returns:
- PanelSolution
[bars, symbols]weights, no iterations, every bar converged.
Examples
>>> import numpy as np, pandas as pd, xarray as xr >>> from quantlab.portfolio.base import DecisionPanel >>> from quantlab.portfolio.config import TopkDropoutConfig >>> from quantlab.portfolio.predefined.topk_dropout import TopkDropoutConstructor >>> bars, symbols = pd.DatetimeIndex(["2024-01-02", "2024-01-03"]), ["AAA", "BBB", "CCC", "DDD"] >>> panel = DecisionPanel( ... timestamps=bars, ... symbols=np.array(symbols), ... predictions=xr.Dataset( ... {"ret": (("timestamp", "symbol"), [[0.3, 0.2, 0.1, 0.0], [0.0, 0.2, 0.1, 0.4]])}, ... coords={"timestamp": bars, "symbol": symbols}, ... ), ... tradable=np.ones((2, 4), dtype=bool), ... ) >>> decide(TopkDropoutConstructor(TopkDropoutConfig("long_only", topk=2, n_drop=1)), panel).weights array([[0.5, 0.5, 0. , 0. ], [0. , 0.5, 0. , 0.5]])