atrΒΆ
Defined in fynance.features.ohlcv
- atr(high, low=None, close=None, w=14)[source]
Average True Range (Wilder), causal.
The true range \(TR_t = \max(H_t - L_t, |H_t - C_{t-1}|, |L_t - C_{t-1}|)\) smoothed by a Wilder moving average of window
w.- Parameters:
- high, low, closearray-like, or high = OHLCV
High/Low/Close series, or a single
OHLCV.- wint, optional
Smoothing window. Default 14.
- Returns:
- numpy.ndarray
ATR series,
>= 0, aligned with the input.
- Raises:
- ValueError
If
w < 1, or iflow/closeare missing without anOHLCVfirst argument.
Examples
>>> import numpy as np >>> h = np.array([10., 11., 12., 11.5]) >>> low = np.array([9., 9.5, 11., 10.5]) >>> c = np.array([9.5, 10.5, 11.5, 11.]) >>> atr(h, low, c, w=2).round(4) array([1. , 1.25 , 1.375 , 1.1875])