0a6f367fbf
Weights formed from close[t] now earn the t→t+1 return: forward returns are computed on the full market calendar before selecting signal dates, so a sparse signal grid earns the next available return rather than the next signal date, and the final signal date (no forward return) is dropped. Signal pct_change uses fill_method=None so suspended names do not inherit stale prices. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
19 lines
490 B
Python
19 lines
490 B
Python
"""Short-horizon momentum alpha."""
|
|
import pandas as pd
|
|
|
|
from pipeline.alpha.base import BaseAlpha
|
|
from pipeline.alpha.registry import register_alpha
|
|
|
|
|
|
@register_alpha
|
|
class MomentumAlpha(BaseAlpha):
|
|
"""Positive trailing return: stocks that rose score high."""
|
|
|
|
name = "momentum"
|
|
|
|
def __init__(self, lookback: int = 5):
|
|
self.lookback = lookback
|
|
|
|
def signal(self, close: pd.DataFrame) -> pd.DataFrame:
|
|
return close.pct_change(self.lookback, fill_method=None)
|