9b8e1346ed
* feat(family-16): add ValueArea + InitialBalance + OpeningRange Opens family #16 (Market Profile) with the three OHLCV-compatible scalar / multi-output indicators: - ValueArea(period, bin_count, value_area_pct) -> {poc, vah, val}. Rolling bin-approximation volume profile over the last `period` candles. Each candle's volume is spread uniformly across [low, high]; POC is the bin with highest cumulative volume; the value area expands symmetrically from POC and always absorbs the higher-volume neighbour next, until `value_area_pct` (default 0.70) of total volume is enclosed. Defaults (20, 50, 0.70). - InitialBalance(period) -> {high, low}. Tracks session-opening high and low over the first `period` bars, then locks. Default period = 12 (one-hour IB on 5-minute bars for US equities). Callers MUST invoke reset() at every session boundary, otherwise IB stays fixed for the lifetime of the instance. - OpeningRange(period) -> {high, low, breakout_distance}. Same lock-after-N-bars semantics as IB with a shorter default period (6 = 30 min on 5-minute bars) and a third output that tracks close - or_mid (positive above the range mid, negative below). Histogram-output Market Profile variants (Volume Profile, VPVR, Composite Profile) are deferred because they need a new histogram output API layer rather than fixed-arity scalars. Tick-data-only variants (TPO Profile, Single Print, Order Flow Delta, Cumulative Delta, Volume-Weighted Open) are out of scope because `wickra-data` does not currently expose tick / L2 data. All four bindings (Rust core, Python, Node, WASM) ship the new indicators with parity tests; benches added; fuzz target extended. Counter 71 -> 74 across 8 -> 9 families. cargo check --workspace --all-features green. * fix(family-16): cover cold paths in InitialBalance + ValueArea InitialBalance::value() public getter had no test covering the post-update Some(...) branch — extended accessors_and_metadata to call value() after one update. ValueArea single-print bar path (c.high == c.low) was unreachable in existing tests since the only single-print test used a uniform 100-price window which exits early via the span == 0 guard; added a mixed-window test that triggers the c.high <= c.low branch directly. The (None, None) arm of the expansion match was by-construction unreachable (the loop condition already requires at least one neighbour) and has been folded into an if/else.
100 lines
2.6 KiB
Python
100 lines
2.6 KiB
Python
"""Smoke tests: every public class can be constructed and emits the right shape."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
import pytest
|
|
|
|
import wickra as ta
|
|
|
|
|
|
def test_version_is_a_nonempty_string():
|
|
assert isinstance(ta.__version__, str)
|
|
assert ta.__version__
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"cls, args",
|
|
[
|
|
(ta.SMA, (14,)),
|
|
(ta.EMA, (14,)),
|
|
(ta.WMA, (14,)),
|
|
(ta.RSI, (14,)),
|
|
],
|
|
)
|
|
def test_scalar_batch_returns_same_length(cls, args, sine_prices):
|
|
out = cls(*args).batch(sine_prices)
|
|
assert out.shape == sine_prices.shape
|
|
assert out.dtype == np.float64
|
|
|
|
|
|
def test_macd_batch_returns_n_by_3(sine_prices):
|
|
out = ta.MACD().batch(sine_prices)
|
|
assert out.shape == (sine_prices.size, 3)
|
|
|
|
|
|
def test_bollinger_batch_returns_n_by_4(sine_prices):
|
|
out = ta.BollingerBands().batch(sine_prices)
|
|
assert out.shape == (sine_prices.size, 4)
|
|
|
|
|
|
def test_atr_batch_shape(ohlc_series):
|
|
high, low, close = ohlc_series
|
|
out = ta.ATR(14).batch(high, low, close)
|
|
assert out.shape == close.shape
|
|
|
|
|
|
def test_stochastic_batch_shape(ohlc_series):
|
|
high, low, close = ohlc_series
|
|
out = ta.Stochastic(14, 3).batch(high, low, close)
|
|
assert out.shape == (close.size, 2)
|
|
|
|
|
|
def test_obv_batch_shape(ohlc_series):
|
|
_, _, close = ohlc_series
|
|
volume = np.ones_like(close)
|
|
out = ta.OBV().batch(close, volume)
|
|
assert out.shape == close.shape
|
|
|
|
|
|
def test_value_area_batch_shape(ohlc_series):
|
|
high, low, close = ohlc_series
|
|
volume = np.ones_like(close)
|
|
out = ta.ValueArea(20, 50, 0.70).batch(high, low, volume)
|
|
assert out.shape == (close.size, 3)
|
|
|
|
|
|
def test_initial_balance_batch_shape(ohlc_series):
|
|
high, low, _close = ohlc_series
|
|
out = ta.InitialBalance(12).batch(high, low)
|
|
assert out.shape == (high.size, 2)
|
|
|
|
|
|
def test_opening_range_batch_shape(ohlc_series):
|
|
high, low, close = ohlc_series
|
|
out = ta.OpeningRange(6).batch(high, low, close)
|
|
assert out.shape == (close.size, 3)
|
|
|
|
|
|
def test_ichimoku_batch_returns_n_by_5(ohlc_series):
|
|
high, low, close = ohlc_series
|
|
out = ta.Ichimoku().batch(high, low, close)
|
|
assert out.shape == (close.size, 5)
|
|
|
|
|
|
def test_heikin_ashi_batch_returns_n_by_4(ohlc_series):
|
|
high, low, close = ohlc_series
|
|
open_ = (high + low) / 2.0
|
|
out = ta.HeikinAshi().batch(open_, high, low, close)
|
|
assert out.shape == (close.size, 4)
|
|
|
|
|
|
def test_ehlers_super_smoother_batch_shape(sine_prices):
|
|
out = ta.SuperSmoother(10).batch(sine_prices)
|
|
assert out.shape == sine_prices.shape
|
|
|
|
|
|
def test_mama_batch_shape(sine_prices):
|
|
out = ta.MAMA().batch(sine_prices)
|
|
assert out.shape == (sine_prices.size, 2)
|