heal_anomalies#

API documentation for tradingstrategy.utils.wrangle.heal_anomalies Python function.

heal_anomalies(ohlcv_df, high_diff=5.0, low_diff=- 0.99, indication_column='close', hint='<unknown pair>')[source]#

Fix bad open/close/high/low prices where the open price is very different from the value of previous and next day.

  • Fix columns open/high/low/close/volume

  • Caused by MEV trades generating spikes and volume

  • If we detect bad candle with MEV trades in it dominating close price, blend the values from previous candles

TODO: Work in progress.

Parameters:
  • ohlcv_df (DataFrame) – Incoming OHLCV or single price series.

  • high_diff – A price between days cannot be higher than this multiplier.

  • low_diff – A price between days cannot be lower than this multiplier.

  • indication_column (str) –

    Column name to check.

    Only relevant if input is DataFrame.

Returns:

The same DataFrame with OHLCV columns manipulated. None if nothing was done.

New flag column healed added to mark rows we manipulated.

Return type:

pandas.core.frame.DataFrame | None