Skip to content

Absolute Return Autocorrelation

Intuição

A Absolute Return Autocorrelation mede autocorrelação dos retornos em módulo, sendo uma proxy clássica para volatility clustering (memória longa na volatilidade).

Definição

Em uma janela n e lag k:

AC_abs(k) = corr(|r_t|, |r_{t-k}|)

Uso

from quantmaster.features.statistical import absolute_return_autocorrelation

df["acabs_60_1"] = absolute_return_autocorrelation(df, window=60, lag=1)

API

Source code in src/quantmaster/features/statistical.py
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
def absolute_return_autocorrelation(
    data: pd.DataFrame | pd.Series,
    *,
    window: int = 60,
    lag: int = 1,
    price_col: str = "close",
    log_returns: bool = True,
) -> pd.Series:
    window = validate_positive_int(window, name="window")
    lag = validate_positive_int(lag, name="lag")
    if lag >= window:
        raise ValueError(f"lag must be < window, got lag={lag} window={window}")

    price = get_price_series(data, price_col=price_col).astype(float)
    price = price.where(price > 0)

    if log_returns:
        r = np.log(price).diff().abs()
    else:
        r = price.pct_change().abs()

    def _fn(w: np.ndarray) -> float:
        a = w[lag:]
        b = w[:-lag]
        return _rolling_corr_1d(a, b)

    out = r.rolling(window).apply(_fn, raw=True)
    out.name = f"absolute_return_autocorrelation_{window}_{lag}"
    return out