Body to Range Ratio
Intuição
Quantifica o quanto do range total da barra foi “corpo” (|close - open|). Ajuda a separar candles de convicção (corpo grande) de indecisão (doji-like).
Definição
BTR = |close - open| / (high - low)
O resultado fica em [0, 1].
Uso
from quantmaster.features.trend import body_to_range_ratio
btr = body_to_range_ratio(ohlc_df)
API
Source code in src/quantmaster/features/trend.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 | def body_to_range_ratio(
data: pd.DataFrame,
*,
open_col: str = "open",
high_col: str = "high",
low_col: str = "low",
close_col: str = "close",
) -> pd.Series:
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)
rng = h - l
out = (c - o).abs() / rng.where(rng != 0)
out = out.where(rng != 0, 0.0)
out = out.clip(lower=0.0, upper=1.0)
out.name = "body_to_range_ratio"
return out
|