0.3.0
ohlc-toolkit 0.3.0
This release adds support for transforming a 1-minute OHLC dataframe into any arbitrary timeframe that you like, with custom step sizes and robust data validation throughout.
A rolling-aggregation (ohlc_toolkit.transform.rolling_ohlc
) method is defined that computes OHLC's for any desired timeframe.
This can be achieved using the new method: ✨
def transform_ohlc(
df_input: pd.DataFrame, timeframe: Union[int, str], step_size_minutes: int = 1
) -> pd.DataFrame:
"""Transform OHLC data to a different timeframe resolution.
Args:
df_input (pd.DataFrame): Input DataFrame with OHLC data.
timeframe (Union[int, str]): Desired timeframe resolution, which can be
an integer (in minutes) or a string (e.g., '1h', '4h30m').
step_size_minutes (int): Step size in minutes for the rolling window.
Returns:
pd.DataFrame: Transformed OHLC data.
"""
This means that if you have 1-minute data, you can use transform_ohlc
to generate a new view of the data, for any arbitrary timeframe.
Developer notes:
The rolling-aggregation iterates at the same resolution of the input (1-minute data yields 1-minute granularity for any timeframe size). So, if you are only interested in large step-sizes (e.g. you want 1-week timeframe output, and a 1-minute granularity doesn't make sense for you), then rolling-aggregation can be very inefficient, since we will discard many of those computed values by applying the requested step size after the fact. Therefore, when appropriate, we optimize runtime by utilizing a chunk-based aggregation method instead of the rolling one.
Please be aware that a timeit script was used to determine a reasonable cut-off point for when to use rolling vs chunk-based OHLC aggregation. This script is included in examples/experiment/chunk_vs_rolling_aggregation.py
for documentation purposes.
To compute a new OHLC dataset for 50 days of 1-minute data, it takes about 5 seconds (using rolling aggregation). If step-size is increased to 15m, it takes about 1 second (using chunk-based aggregation).
What's Changed
Full Changelog: 0.2.0...0.3.0