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 i receives prod(1 + r) - 1 over the rows dated after bar i - 1 and up to bar i inclusive; 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 (what read_fama_french() returns).

timestampsnp.ndarray

The panel’s bar timestamps, ascending.

Returns:
pd.DataFrame

The same columns on timestamps.

Raises:
ValueError

If timestamps is 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