forward_fill_ohlcv_single_pair#

API documentation for tradingstrategy.utils.forward_fill.forward_fill_ohlcv_single_pair Python function.

forward_fill_ohlcv_single_pair(df, freq, forward_fill_until, pair_id=None)[source]#

Forward-fill OHLCV data in a Pandas DataFrame, ensuring OHCLV logical consistency.

This function forward-fills missing OHLCV (Open, High, Low, Close, Volume) data in a Pandas DataFrame while maintaining logical rules: - High, Low, and Open are set to the last valid Close value. - Volume is set to 0. - A boolean column ‘forward_filled’ is added to indicate which rows were forward-filled.

Parameters:
  • df (DataFrame) – The Pandas DataFrame containing OHLCV data. The DataFrame must have a DatetimeIndex.

  • freq (pandas._libs.tslibs.offsets.DateOffset | str) – The frequency to resample the data to (e.g., ‘1H’ for hourly).

  • columns – A list of columns to forward-fill. Must include ‘open’, ‘high’, ‘low’, ‘close’, and ‘volume’.

  • forward_fill_until (pandas._libs.tslibs.timestamps.Timestamp | datetime.datetime) – An optional timestamp to limit the forward-fill to.

  • pair_id (int | None) – Fill in pair_id column with this value.

Returns:

A new Pandas DataFrame with forward-filled OHLCV data and a ‘forward_filled’ column.

Return type:

DataFrame