qis.generate_static_weights_schedule¶
- qis.generate_static_weights_schedule(prices, weights, rebalancing_freq='QE', is_rescale_to_live_universe=True, is_preserve_total_exposure=True, include_start_date=True, num_warmup_periods=None)[source]¶
turn a fixed allocation into a rebalancing weight frame over the live universe.
A static allocation stated once cannot be applied to a panel whose instruments start and stop at different dates: an instrument with no price on a rebalancing date is not traded, and
qis.backtest_model_portfolioleaves its weight in the cash balance, which is the correct contract and rarely the intended allocation. This reallocates that weight over the instruments that are priced on each rebalancing date, and returns the frame to pass back in asweights.The universe is read at the rebalancing date and nowhere else, so the construction is point in time: a price observed at t is information available at t. Instruments are reallocated at rebalancings only - an instrument going live between two rebalancings is admitted at the next one, not when it starts.
Rescaling preserves the total exposure of the specification rather than forcing the row to one, so a book that is 90% invested by design stays 90% invested when an instrument is missing instead of being silently levered to 100%. The two are the same whenever the specification sums to one.
- Parameters:
prices (DataFrame) – instrument prices, columns are tickers. A nan marks an instrument as not allocable on that date
weights (Dict[str, float] | List[float] | ndarray | Series) – target weights, aligned to
prices.columnsbyalign_weights_to_columns()rebalancing_freq (str) – calendar anchor for the rebalancing dates, passed to
generate_rebalancing_indicators(). The returned dates are the observation dates ofprices, so the frame can never rebalance more often than the price panelis_rescale_to_live_universe (bool) – reallocate the weight of a missing instrument over the live ones. False returns the specification with missing instruments set to zero, which is the cash-residual behaviour with an explicit 0.0 rather than a nan in the reported weights
is_preserve_total_exposure (bool) – scale the live weights to the total exposure of
weights. False forces every row to sum to oneinclude_start_date (bool) – mark the first price date as a rebalancing date, so the allocation is invested from inception. Note this defaults to True where the corresponding
is_rebalanced_at_first_dateofqis.backtest_model_portfoliodefaults to Falsenum_warmup_periods (int | None) – leading observations excluded from the schedule
- Returns:
weights indexed by the rebalancing dates that exist in
prices.index, columns asprices.columns. A date with no live instrument carries all zeros- Raises:
ValueError – if
pricesis not a pd.DataFrame, if the specification has no net exposure to preserve, or if the live weights cancel on a rebalancing date so that the rescaling is undefined- Return type: