API documentation for tradingstrategy.utils.groupeduniverse.fix_bad_wicks Python function.

fix_bad_wicks(df, threshold=(0.1, 1.9), too_slow_threshold=15, verbose=False, bad_open_close_threshold=3.0)[source]#

Correct out bad high/low values in OHLC data.

Applicable for both OHLCV price feeds and liquidity feeds.

On Uniswap v2 and compatibles, Bad wicks are caused by e.g. very large flash loan, oracle price manipulation attacks, and misbheaving bots.

This function removes bad high/low values and sets them to open/close if they seem to be wildly out of sample.

  • threshold

    How many pct % wicks are allowed through.

    Tuple (low threshold, high threshold) relative to close.

    Default to 50%. A high wick cannot be more than 50% of close.

  • too_slow_threshold – Complain if this takes too long

  • bad_open_close_threshold (float | None) –

    How many X open must be above the high to be considered a broken data point.

    The open price will be replaced with high price.

    Do not set for liquidity processing.

  • verbose – Make some debug logging when using the function for manual data diagnostics.

  • df (DataFrame) –

Return type: