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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4b6abf9bdffe278408b4a11ce08efba6cbf5c8c59db6b48fa08e24c9229ddd2
|
|
| MD5 |
50374bbee23c7256758675f893b75f65
|
|
| BLAKE2b-256 |
3890ead969b1bda3e805eca33e1278fd50254610942d59bffd2c19d3f96ed23b
|
Provenance
The following attestation bundles were made for freshmeat_heikinashi-0.1.1.tar.gz:
Publisher:
release.yml on yalcin/freshmeat-heikinashi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
freshmeat_heikinashi-0.1.1.tar.gz -
Subject digest:
a4b6abf9bdffe278408b4a11ce08efba6cbf5c8c59db6b48fa08e24c9229ddd2 - Sigstore transparency entry: 1091018418
- Sigstore integration time:
-
Permalink:
yalcin/freshmeat-heikinashi@0f7ea861163c993d5b708ba63d14bde829680c50 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/yalcin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0f7ea861163c993d5b708ba63d14bde829680c50 -
Trigger Event:
push
-
Statement type:
File details
Details for the file freshmeat_heikinashi-0.1.1-py3-none-any.whl.
File metadata
- Download URL: freshmeat_heikinashi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69fe89ac7578fe9f00abb71379f0159730e90c03b09f89bac53b3efed5480373
|
|
| MD5 |
36268f7f33480aa527aa1a839078c26b
|
|
| BLAKE2b-256 |
56212cb66bf21a5e70296838c290b0492bd39825aa37fa8382d233f5039c7793
|
Provenance
The following attestation bundles were made for freshmeat_heikinashi-0.1.1-py3-none-any.whl:
Publisher:
release.yml on yalcin/freshmeat-heikinashi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
freshmeat_heikinashi-0.1.1-py3-none-any.whl -
Subject digest:
69fe89ac7578fe9f00abb71379f0159730e90c03b09f89bac53b3efed5480373 - Sigstore transparency entry: 1091018429
- Sigstore integration time:
-
Permalink:
yalcin/freshmeat-heikinashi@0f7ea861163c993d5b708ba63d14bde829680c50 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/yalcin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0f7ea861163c993d5b708ba63d14bde829680c50 -
Trigger Event:
push
-
Statement type: