"""
动量因子：N 日收益率。
"""

import pandas as pd

from factors.base import BaseFactor


class MomentumFactor(BaseFactor):
    """N 日价格动量 = (close_t - close_{t-N}) / close_{t-N} * 100"""

    category = "technical"

    def __init__(self, period: int = 20):
        self.period = period
        self.name = f"momentum_{period}"

    def calculate(self, df: pd.DataFrame) -> pd.Series:
        return df["close"].pct_change(periods=self.period) * 100

    def get_required_columns(self) -> list[str]:
        return ["close"]
