Skip to content

OHLC

quantflow.ta.ohlc.OHLC pydantic-model

Bases: BaseModel

Aggregates OHLC data over a given period and series

Optionally calculates the range-based variance estimators for the series. Range-based estimator are called like that because they are calculated from the difference between the period high and low.

Fields:

series pydantic-field

series

series to aggregate

period pydantic-field

period

down-sampling period, e.g. 1h, 1d, 1w

index_column pydantic-field

index_column = 'index'

column to group by

parkinson_variance pydantic-field

parkinson_variance = False

add Parkinson variance column

garman_klass_variance pydantic-field

garman_klass_variance = False

add Garman Klass variance column

rogers_satchell_variance pydantic-field

rogers_satchell_variance = False

add Rogers Satchell variance column

percent_variance pydantic-field

percent_variance = False

log-transform the variance columns

parkinson

parkinson(df)

Adds parkinson variance column to the dataframe

This requires the series high and low columns to be present

Source code in quantflow/ta/ohlc.py
def parkinson(self, df: DataFrame) -> pd.DataFrame:
    """Adds parkinson variance column to the dataframe

    This requires the series high and low columns to be present
    """
    high = self._get_col(df, "high")
    low = self._get_col(df, "low")
    pk = (high - low) ** 2 / np.sqrt(4 * np.log(2))
    df = df.copy()
    df[self._col("pk")] = pk
    return df

garman_klass

garman_klass(df)

Adds Garman Klass variance estimator column to the dataframe

This requires the series high and low columns to be present.

Source code in quantflow/ta/ohlc.py
def garman_klass(self, df: DataFrame) -> pd.DataFrame:
    """Adds Garman Klass variance estimator column to the dataframe

    This requires the series high and low columns to be present.
    """
    o = self._get_col(df, "open")
    hh = self._get_col(df, "high") - o
    ll = self._get_col(df, "low") - o
    cc = self._get_col(df, "close") - o
    gk = (
        0.522 * (hh - ll) ** 2
        - 0.019 * (cc * (hh + ll) + 2.0 * ll * hh)
        - 0.383 * cc**2
    )
    df = df.copy()
    df[self._col("gk")] = gk
    return df

rogers_satchell

rogers_satchell(df)

Adds Rogers Satchell variance estimator column to the dataframe

This requires the series high and low columns to be present.

Source code in quantflow/ta/ohlc.py
def rogers_satchell(self, df: DataFrame) -> pd.DataFrame:
    """Adds Rogers Satchell variance estimator column to the dataframe

    This requires the series high and low columns to be present.
    """
    o = self._get_col(df, "open")
    hh = self._get_col(df, "high") - o
    ll = self._get_col(df, "low") - o
    cc = self._get_col(df, "close") - o
    rs = hh * (hh - cc) + ll * (ll - cc)
    df = df.copy()
    df[self._col("rs")] = rs
    return df