Upper Shadow Ratio
Intuição
Mede a proporção do shadow superior da vela, capturando rejeição de preços altos.
Definição
USR = (high - max(open, close)) / (high - low)
O resultado fica em [0, 1].
Uso
from quantmaster.features.trend import upper_shadow_ratio
usr = upper_shadow_ratio(ohlc_df)
API
Source code in src/quantmaster/features/trend.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184 | def upper_shadow_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
top_body = np.maximum(o, c)
out = (h - top_body) / rng.where(rng != 0)
out = out.where(rng != 0, 0.0)
out = out.clip(lower=0.0, upper=1.0)
out.name = "upper_shadow_ratio"
return out
|