Files
chinese-equity-quant/signals/reversal_vol.py
T

28 lines
981 B
Python

"""Volatility-scaled short-horizon reversal signal."""
import pandas as pd
from signals.base import AlphaSignal
class ReversalVolSignal(AlphaSignal):
"""Reversal score normalized by trailing volatility.
The raw reversal ``-close.pct_change(lookback)`` is divided by the rolling
standard deviation of daily returns over ``vol_window``. Scaling by
volatility damps the score of noisy, high-vol names so the signal favors
oversold stocks whose move is large *relative* to their own volatility.
"""
def __init__(self, lookback: int = 5, vol_window: int = 20):
self.lookback = lookback
self.vol_window = vol_window
def compute(self, df: pd.DataFrame) -> pd.Series:
reversal = -df["close"].pct_change(self.lookback)
vol = df["close"].pct_change().rolling(self.vol_window).std()
return reversal / vol
@property
def name(self) -> str:
return f"reversal_vol_{self.lookback}d_{self.vol_window}d"