Skip to content

Bar Range Position

Intuição

Mede onde o close ficou dentro do range da barra (lowhigh). É uma feature simples e muito informativa para price action.

Definição

  • Se high != low: BRP = (close - low) / (high - low)
  • Caso contrário: BRP = 0.5

O resultado fica em [0, 1].

Uso

from quantmaster.features.trend import bar_range_position

brp = bar_range_position(ohlc_df)

API

Source code in src/quantmaster/features/trend.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
def bar_range_position(
    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])

    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 - l) / rng.where(rng != 0)
    out = out.where(rng != 0, 0.5)
    out = out.clip(lower=0.0, upper=1.0)
    out.name = "bar_range_position"
    return out