quantlab.factor.predefined.residual_momentum.compound_onto_bars#
- quantlab.factor.predefined.residual_momentum.compound_onto_bars(table, timestamps)[source]#
Compound per-row returns onto a panel’s bars.
Bar
ireceivesprod(1 + r) - 1over the rows dated after bari - 1and up to bariinclusive; the first bar receives the last row dated at or before it. On daily bars stamped at midnight that is the same-day row; on weekly or coarser bars it is the compounded week or month. A bar with no row in its span is NaN.- Parameters:
- tablepd.DataFrame
Decimal returns, one column per series, on a sorted
DatetimeIndex(whatread_fama_french()returns).- timestampsnp.ndarray
The panel’s bar timestamps, ascending.
- Returns:
- pd.DataFrame
The same columns on
timestamps.
- Raises:
- ValueError
If
timestampsis not ascending.
Examples
>>> daily = pd.DataFrame({"x": [0.01, 0.02, -0.01]}, ... index=pd.to_datetime(["2024-01-02", "2024-01-03", "2024-01-04"])) >>> compound_onto_bars(daily, pd.to_datetime(["2024-01-02", "2024-01-04"]).values).round(6) x 2024-01-02 0.010000 2024-01-04 0.009800