Skip to content

Price Acceleration

Intuição

A Price Acceleration é uma proxy simples da “segunda derivada” do preço: mede se o momentum (retorno) está aumentando ou diminuindo em relação ao que era window períodos atrás.

Definição

Com retornos log r_t = ln(P_t) - ln(P_{t-1}):

Accel_t = (r_t - r_{t-window}) / window

Uso

from quantmaster.features.trend import price_acceleration

df["price_acceleration_20"] = price_acceleration(df, window=20)

API

Source code in src/quantmaster/features/trend.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def price_acceleration(
    data: pd.DataFrame | pd.Series,
    *,
    window: int = 20,
    price_col: str = "close",
) -> pd.Series:
    window = validate_positive_int(window, name="window")

    price = get_price_series(data, price_col=price_col).astype(float)
    price = price.where(price > 0)
    rets = np.log(price).diff()

    out = (rets - rets.shift(window)) / float(window)
    out.name = f"price_acceleration_{window}"
    return out