Skip to content

ROGERS–SATCHELL VOLATILITY

Intuição

O estimador Rogers–Satchell é um estimador range-based que permanece útil em presença de drift (tendências), sendo frequentemente usado como componente em estimadores mais completos (ex: Yang–Zhang).

Definição

Seja:

  • HO_t = ln(high_t/open_t)
  • HC_t = ln(high_t/close_t)
  • LO_t = ln(low_t/open_t)
  • LC_t = ln(low_t/close_t)

A variância RS diária é:

RS_t = HC_t * HO_t + LC_t * LO_t

A série é agregada via média rolling em janela n, e a volatilidade é sqrt(max(RS, 0)).

Uso

from quantmaster.features.volatility import rogers_satchell_volatility

df["rs"] = rogers_satchell_volatility(df, window=20)

API

Source code in src/quantmaster/features/volatility.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
def rogers_satchell_volatility(
    data: pd.DataFrame,
    *,
    window: int = 20,
    open_col: str = "open",
    high_col: str = "high",
    low_col: str = "low",
    close_col: str = "close",
) -> pd.Series:
    window = validate_positive_int(window, name="window")
    validate_columns(data, required=(open_col, high_col, low_col, close_col))

    o = pd.to_numeric(data[open_col], errors="coerce").astype(float)
    h = pd.to_numeric(data[high_col], errors="coerce").astype(float)
    l = pd.to_numeric(data[low_col], errors="coerce").astype(float)
    c = pd.to_numeric(data[close_col], errors="coerce").astype(float)

    o = o.where(o > 0)
    h = h.where(h > 0)
    l = l.where(l > 0)
    c = c.where(c > 0)

    log_hc = np.log(h / c)
    log_ho = np.log(h / o)
    log_lc = np.log(l / c)
    log_lo = np.log(l / o)
    rs_var = log_hc * log_ho + log_lc * log_lo
    var = rs_var.rolling(window).mean()

    out = np.sqrt(var.clip(lower=0.0))
    out.name = f"rogers_satchell_volatility_{window}"
    return out