Skip to content

OHLC

quantflow.ta.ohlc.OHLC pydantic-model

Bases: BaseModel

Aggregates OHLC data over a given period and serie

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

Fields:

serie pydantic-field

serie

serie 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

open_col property

open_col

high_col property

high_col

low_col property

low_col

close_col property

close_col

parkinson

parkinson(df)

Adds parkinson variance column to the dataframe

This requires the serie high and low columns to be present

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

    This requires the serie high and low columns to be present
    """
    c = (self.high_col - self.low_col) ** 2 / np.sqrt(4 * np.log(2))
    return to_polars(df).with_columns(c.alias(f"{self.serie}_pk"))

garman_klass

garman_klass(df)

Adds Garman Klass variance estimator column to the dataframe

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

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

    This requires the serie high and low columns to be present.
    """
    open = self.open_col
    hh = self.high_col - open
    ll = self.low_col - open
    cc = self.close_col - open
    c = (
        0.522 * (hh - ll) ** 2
        - 0.019 * (cc * (hh + ll) + 2.0 * ll * hh)
        - 0.383 * cc**2
    )
    return to_polars(df).with_columns(c.alias(f"{self.serie}_gk"))

rogers_satchell

rogers_satchell(df)

Adds Rogers Satchell variance estimator column to the dataframe

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

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

    This requires the serie high and low columns to be present.
    """
    open = self.open_col
    hh = self.high_col - open
    ll = self.low_col - open
    cc = self.close_col - open
    c = hh * (hh - cc) + ll * (ll - cc)
    return to_polars(df).with_columns(c.alias(f"{self.serie}_rs"))

var_column

var_column(suffix)

Returns a polars expression for the OHLC column

Source code in quantflow/ta/ohlc.py
def var_column(self, suffix: str) -> pl.Expr:
    """Returns a polars expression for the OHLC column"""
    col = pl.col(f"{self.serie}_{suffix}")
    return col.log() if self.percent_variance else col