23 lines
608 B
Python
23 lines
608 B
Python
"""Short-horizon reversal signal."""
|
|
import pandas as pd
|
|
|
|
from signals.base import AlphaSignal
|
|
|
|
|
|
class ReversalSignal(AlphaSignal):
|
|
"""Negative trailing return: oversold stocks score high.
|
|
|
|
The signal is ``-close.pct_change(lookback)``, so a stock that fell over the
|
|
lookback window gets a positive (bullish) score.
|
|
"""
|
|
|
|
def __init__(self, lookback: int = 5):
|
|
self.lookback = lookback
|
|
|
|
def compute(self, df: pd.DataFrame) -> pd.Series:
|
|
return -df["close"].pct_change(self.lookback)
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return f"reversal_{self.lookback}d"
|