Skip to main content

Fast Heikin-Ashi candle computation with Numba JIT acceleration.

Project description

freshmeat-heikinashi

Fast Heikin-Ashi candle computation with Numba JIT acceleration.

A drop-in replacement for technical.candles.heikinashi() and qtpylib.indicators.heikinashi() — same formula, hundreds to thousands of times faster.

Why?

The standard Heikin-Ashi implementations in the Python trading ecosystem use pure-Python for loops or list comprehensions over pandas DataFrames. The recursive nature of ha_open (each bar depends on the previous bar) makes vectorization impossible with plain NumPy/pandas.

freshmeat-heikinashi solves this by compiling the loop with Numba JIT, achieving native-code speed while keeping a pure-Python API.

Installation

pip install freshmeat-heikinashi

Requirements: Python 3.10+, NumPy, pandas, Numba.

Usage

DataFrame API

from freshmeat_heikinashi import heikinashi

ha = heikinashi(df)  # df must have open/high/low/close columns
# Returns a new DataFrame with HA open/high/low/close

NumPy array API

from freshmeat_heikinashi import heikinashi_arrays

ha_open, ha_high, ha_low, ha_close = heikinashi_arrays(
    open_prices, high_prices, low_prices, close_prices,
)

Freqtrade strategy

from freshmeat_heikinashi import heikinashi

class MyStrategy(IStrategy):
    def populate_indicators(self, dataframe, metadata):
        ha = heikinashi(dataframe)
        dataframe["ha_open"] = ha["open"]
        dataframe["ha_high"] = ha["high"]
        dataframe["ha_low"] = ha["low"]
        dataframe["ha_close"] = ha["close"]
        return dataframe

Correctness

Output is verified to be bit-identical (within 1e-10 tolerance) to both technical.candles.heikinashi() and qtpylib.indicators.heikinashi() across 1k, 10k, and 100k row datasets:

pytest tests/test_benchmark.py -k "TestCorrectnessVsTechnical" -v

Benchmark

Latest local pytest-benchmark result on 100,000 OHLC rows (min time):

Implementation Min time Relative
freshmeat-heikinashi (Numba) 1.65 ms 1x
technical.candles.heikinashi (list comp) 423.50 ms 256x slower
qtpylib.indicators.heikinashi (for loop) 2,239.60 ms 1,354x slower

The absolute values are machine-dependent, but the speedup pattern is consistent.

Run the benchmarks yourself:

# pytest-benchmark (grouped comparison)
pytest tests/test_benchmark.py -v

# CLI script
python benchmarks/bench_heikinashi.py --rows 100000

Documentation

  • Heikin-Ashi Formula — step-by-step formula explanation with worked example, lookahead safety analysis.
  • Implementation Comparison — detailed source code comparison of qtpylib, technical.candles, and freshmeat-heikinashi with full benchmark tables.

Status

Experimental. This project is under active development. The API may change without notice between minor versions until 1.0.

Disclaimer

This software is provided for educational and research purposes only. It is not financial advice. The authors make no guarantees regarding the accuracy, reliability, or suitability of this software for any particular purpose, including but not limited to live trading.

Use at your own risk. The authors accept no responsibility or liability for any financial losses, trading losses, damages, or other consequences — direct or indirect — arising from the use of this software. This includes, without limitation, any commercial or trading losses incurred through live, paper, or backtested trading operations. Always validate outputs independently before making any trading decisions.

License

Apache License 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

freshmeat_heikinashi-0.1.1.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

freshmeat_heikinashi-0.1.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file freshmeat_heikinashi-0.1.1.tar.gz.

File metadata

  • Download URL: freshmeat_heikinashi-0.1.1.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for freshmeat_heikinashi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a4b6abf9bdffe278408b4a11ce08efba6cbf5c8c59db6b48fa08e24c9229ddd2
MD5 50374bbee23c7256758675f893b75f65
BLAKE2b-256 3890ead969b1bda3e805eca33e1278fd50254610942d59bffd2c19d3f96ed23b

See more details on using hashes here.

Provenance

The following attestation bundles were made for freshmeat_heikinashi-0.1.1.tar.gz:

Publisher: release.yml on yalcin/freshmeat-heikinashi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file freshmeat_heikinashi-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for freshmeat_heikinashi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 69fe89ac7578fe9f00abb71379f0159730e90c03b09f89bac53b3efed5480373
MD5 36268f7f33480aa527aa1a839078c26b
BLAKE2b-256 56212cb66bf21a5e70296838c290b0492bd39825aa37fa8382d233f5039c7793

See more details on using hashes here.

Provenance

The following attestation bundles were made for freshmeat_heikinashi-0.1.1-py3-none-any.whl:

Publisher: release.yml on yalcin/freshmeat-heikinashi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page