3be267cb03
A multi-language technical analysis library: 25 indicators across trend,
momentum, volatility, and volume families, every one a state machine with
O(1) per-tick updates. Batch evaluation is provided by a blanket extension
trait over the streaming primitive, so live trading bots and historical
backtests run the same code path.
What ships in this initial drop:
crates/wickra-core - 25 indicators, Indicator/BatchExt/Chain traits,
OHLCV types with validation; 171 unit tests,
property tests, Wilder/Bollinger textbook tests.
crates/wickra - top-level facade + criterion benches for every
indicator at 1K/10K/100K series sizes.
crates/wickra-data - streaming CSV reader, tick-to-candle aggregator,
multi-timeframe resampler, Binance Spot kline
WebSocket adapter behind feature live-binance;
11 unit + 1 doctest.
bindings/python - PyO3 + maturin, NumPy I/O, type stubs (.pyi),
56 pytest tests including streaming==batch
equivalence, Wilder reference values, lifecycle.
bindings/node - napi-rs native module, TypeScript .d.ts
auto-generated, 7 node --test cases.
bindings/wasm - wasm-bindgen ES module for browser/bundler/Node;
interactive HTML demo at examples/index.html.
examples/ - Python and Rust scripts: backtest, live trading,
parallel multi-asset, multi-timeframe, Binance.
benchmarks/ - cross-library comparison against TA-Lib,
pandas-ta, finta, talipp; Wickra wins every
category by 11-1030x (batch) and 17x+ streaming.
.github/workflows/ - CI matrix (Rust + Python + Node + WASM on
Linux/macOS/Windows), release pipeline for
PyPI wheels and npm.
Indicators (25):
Trend SMA EMA WMA DEMA TEMA HMA KAMA
Momentum RSI MACD Stochastic CCI ROC WilliamsR ADX MFI TRIX
AwesomeOscillator Aroon
Volatility BollingerBands ATR Keltner Donchian PSAR
Volume OBV VWAP (cumulative + rolling)
cargo clippy --workspace --all-targets -D warnings is clean. License: Apache-2.0.
89 lines
2.2 KiB
Python
89 lines
2.2 KiB
Python
"""Tests for the indicator lifecycle methods: reset, is_ready, warmup_period, repr."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
import pytest
|
|
|
|
import wickra as ta
|
|
|
|
SCALAR_INDICATORS = [
|
|
(ta.SMA, (14,)),
|
|
(ta.EMA, (14,)),
|
|
(ta.WMA, (14,)),
|
|
(ta.RSI, (14,)),
|
|
(ta.MACD, ()),
|
|
(ta.BollingerBands, ()),
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("cls, args", SCALAR_INDICATORS)
|
|
def test_is_ready_transitions_after_warmup(cls, args):
|
|
ind = cls(*args)
|
|
assert not ind.is_ready()
|
|
series = np.linspace(1.0, 200.0, 200)
|
|
ind.batch(series)
|
|
assert ind.is_ready()
|
|
|
|
|
|
@pytest.mark.parametrize("cls, args", SCALAR_INDICATORS)
|
|
def test_reset_returns_to_initial_state(cls, args):
|
|
ind = cls(*args)
|
|
ind.batch(np.linspace(1.0, 200.0, 200))
|
|
assert ind.is_ready()
|
|
ind.reset()
|
|
assert not ind.is_ready()
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"cls, args, period",
|
|
[
|
|
(ta.SMA, (14,), 14),
|
|
(ta.EMA, (14,), 14),
|
|
(ta.WMA, (14,), 14),
|
|
(ta.RSI, (14,), 15),
|
|
(ta.BollingerBands, (20, 2.0), 20),
|
|
],
|
|
)
|
|
def test_warmup_period(cls, args, period):
|
|
assert cls(*args).warmup_period() == period
|
|
|
|
|
|
def test_repr_contains_class_and_parameters():
|
|
assert "SMA" in repr(ta.SMA(14))
|
|
assert "14" in repr(ta.SMA(14))
|
|
assert "BollingerBands" in repr(ta.BollingerBands(20, 2.0))
|
|
|
|
|
|
def test_constructor_rejects_zero_period():
|
|
with pytest.raises(ValueError):
|
|
ta.SMA(0)
|
|
with pytest.raises(ValueError):
|
|
ta.RSI(0)
|
|
|
|
|
|
def test_macd_rejects_fast_geq_slow():
|
|
with pytest.raises(ValueError):
|
|
ta.MACD(fast=26, slow=12, signal=9)
|
|
|
|
|
|
def test_bollinger_rejects_non_positive_multiplier():
|
|
with pytest.raises(ValueError):
|
|
ta.BollingerBands(20, 0.0)
|
|
with pytest.raises(ValueError):
|
|
ta.BollingerBands(20, -1.0)
|
|
|
|
|
|
def test_candle_dict_input_supported():
|
|
atr = ta.ATR(2)
|
|
atr.update({"open": 10.0, "high": 11.0, "low": 9.0, "close": 10.5, "volume": 1.0})
|
|
v = atr.update({"open": 10.5, "high": 12.0, "low": 10.0, "close": 11.0, "volume": 1.0})
|
|
assert v is not None
|
|
|
|
|
|
def test_candle_tuple_input_supported():
|
|
atr = ta.ATR(2)
|
|
atr.update((10.0, 11.0, 9.0, 10.5, 1.0, 0))
|
|
v = atr.update((10.5, 12.0, 10.0, 11.0, 1.0, 1))
|
|
assert v is not None
|