* feat(alma): add Arnaud Legoux Moving Average
Gaussian-weighted moving average with configurable centre (offset in
[0, 1]) and kernel width (sigma > 0). Pre-computes normalised weights
at construction so each update is a single rolling window dot product.
Reference: Arnaud Legoux and Dimitrios Kouzis-Loukas, 2009.
Touchpoints:
- crates/wickra-core: alma.rs + mod.rs + lib.rs re-export
- bindings/python: PyAlma + __init__.py + test_new_indicators +
test_known_values reference
- bindings/node: AlmaNode + index.d.ts/index.js + indicators.test.js
factory + reference value
- bindings/wasm: wasm_scalar_indicator! macro
- fuzz: indicator_update target covers ALMA(9, 0.85, 6.0)
- crates/wickra/benches: bench_scalar entry
- README + CHANGELOG: Moving Averages row + Unreleased entry
* feat(mcginley): add McGinley Dynamic moving average
John McGinley's self-adjusting moving average with the recurrence
MD + (price - MD) / (0.6 * period * (price / MD)^4). Speeds up when
price falls below the indicator and damps when price runs above the
indicator. Seeded with the simple average of the first period inputs.
Reference: McGinley, Technical Analysis of Stocks & Commodities, 1990.
Touchpoints:
- crates/wickra-core: mcginley_dynamic.rs + mod.rs + lib.rs re-export
- bindings/python: PyMcGinleyDynamic + __init__.py + test_new_indicators
+ test_known_values reference
- bindings/node: McGinleyDynamicNode (scalar macro) + index.d.ts/index.js
+ indicators.test.js factory + reference value
- bindings/wasm: wasm_scalar_indicator! macro
- fuzz: indicator_update target covers McGinleyDynamic(10)
- crates/wickra/benches: bench_scalar entry
- README + CHANGELOG: Moving Averages row + Unreleased entry
* feat(frama): add Fractal Adaptive Moving Average
Ehlers' FRAMA adapts its smoothing constant to the fractal dimension of
the recent window: tight tracking in trends, heavy smoothing in chop.
Uses the close-only variant where max/min over each window half drive
the dimension estimate. Period must be even (default 16).
Reference: Ehlers, Fractal Adaptive Moving Average, 2005.
Touchpoints:
- crates/wickra-core: frama.rs + mod.rs + lib.rs re-export
- bindings/python: PyFrama + __init__.py + test_new_indicators +
test_known_values reference (constant series + uptrend tracking)
- bindings/node: FramaNode (scalar macro) + index.d.ts/index.js +
indicators.test.js factory + reference value
- bindings/wasm: wasm_scalar_indicator! macro
- fuzz: indicator_update target covers Frama(16)
- crates/wickra/benches: bench_scalar entry
- README + CHANGELOG: Moving Averages row + Unreleased entry
* feat(vidya): add Variable Index Dynamic Average
Chande's VIDYA — an EMA whose alpha scales with |CMO(cmo_period)| / 100.
Strong directional momentum lifts the smoothing constant toward the
EMA-of-period rate; flat or choppy windows shrink it toward zero so
VIDYA coasts on its previous value. Two parameters: period (14) and
cmo_period (9). Reuses the existing wickra-core Cmo internally.
Reference: Chande, Stocks & Commodities, 1992.
Also fixes a silent gap from d37fbd1 (feat(frama)): the PyFrama Python
class wrapper and its add_class registration were dropped because the
two edits hit "File has not been read yet" errors that scrolled past
in a batch. Adds them here alongside VIDYA's bindings.
Touchpoints (VIDYA): vidya.rs + mod.rs + lib.rs re-export, PyVidya +
__init__.py + test_new_indicators + test_known_values reference,
VidyaNode (manual two-param binding) + index.d.ts/index.js +
indicators.test.js factory + reference, wasm_scalar_indicator! macro,
fuzz target, bench, README + CHANGELOG.
* feat(jma): add Jurik Moving Average
Three-stage filter reconstruction of Mark Jurik's adaptive MA (the
algorithm is proprietary; this is the form used by most open-source
ports since the 1999 TASC article). Parameters: period (14), phase in
[-100, 100] (0), power in 1..=4 (2). State is seeded by setting
e0 = JMA = first input so a constant input stream is reproduced exactly.
Touchpoints: jma.rs + mod.rs + lib.rs re-export, PyJma + __init__.py +
test_new_indicators + test_known_values reference, JmaNode (manual
three-param binding) + index.d.ts/index.js + indicators.test.js factory
+ reference, wasm_scalar_indicator! macro, fuzz target, bench, README +
CHANGELOG.
* feat(alligator): add Bill Williams Alligator
Three SMMA lines (Jaw / Teeth / Lips) over the median price
(high + low) / 2 with default periods 13 / 8 / 5. Multi-output
indicator returning AlligatorOutput { jaw, teeth, lips }. The
original chart variant shifts each line forward for display; we
publish the unshifted SMMA values and leave the visual shift to
the consumer.
Reference: Bill Williams, Trading Chaos, 1995.
Touchpoints: alligator.rs + mod.rs + lib.rs re-export, PyAlligator
(Candle input, returns 3-tuple, ndarray (n, 3) batch) + __init__.py
+ test_new_indicators + test_known_values reference, AlligatorNode +
AlligatorValue + index.d.ts/index.js + indicators.test.js multi
factory + reference, WasmAlligator (manual JsValue object) +
candle-fuzz target + README + CHANGELOG.
* feat(evwma): add Elastic Volume-Weighted Moving Average
Christian P. Fries' elastic recurrence where the smoothing weight is the
bar's volume relative to the running window total:
V_sum_t = sum of volumes over the last period candles
EVWMA_t = ((V_sum_t - v_t) * EVWMA_{t-1} + v_t * close_t) / V_sum_t
A bar whose volume is small barely moves the average; a bar that
dominates the window pulls it strongly toward that bar's close. Seeded
with the close of the first full window; holds its previous value if
the entire window has zero volume.
Reference: Fries, Wilmott Magazine, 2001.
Touchpoints: evwma.rs + mod.rs + lib.rs re-export, PyEvwma (close +
volume batch) + __init__.py + test_new_indicators CANDLE_SCALAR +
test_known_values reference, EvwmaNode + index.d.ts/index.js +
indicators.test.js candleScalar factory + reference, WasmEvwma,
candle-fuzz target + README + CHANGELOG.
* ci: Force local wheel install in Python jobs
Use --no-index --no-deps so the Python matrix installs the freshly
built wheel from dist/ and never falls back to PyPI. Previously pip
sometimes picked the released 0.2.x wheel on macOS / Windows when its
platform tag was a wider match than the local build, which made the
job test the released package and miss any new symbols added in the
PR (e.g. AttributeError: module 'wickra' has no attribute 'ALMA').
numpy is already installed by the preceding pip step, so --no-deps
is safe.
134 lines
5.7 KiB
Rust
134 lines
5.7 KiB
Rust
#![no_main]
|
|
//! Fuzz OHLCV-input indicator updates with arbitrary candle sequences.
|
|
//!
|
|
//! Every candle-input indicator must tolerate any sequence of validated OHLCV
|
|
//! candles — extreme magnitudes, micro-spreads, zero-volume bars, abrupt
|
|
//! reversals — without panicking. The fuzzer chunks the raw `f64` stream into
|
|
//! `[open, high, low, close, volume]` tuples and constructs each candle via
|
|
//! `Candle::new`; entries that fail OHLCV-invariant validation are skipped so
|
|
//! the indicator only ever sees structurally-valid candles. Each iteration
|
|
//! then drives that candle stream through every candle-input indicator twice
|
|
//! (streaming `update` + batch).
|
|
//!
|
|
//! Audit finding R9: the previous fuzz suite had no candle-input coverage at
|
|
//! all. This target now covers every candle-input indicator including the
|
|
//! ones the audit named explicitly (ATR, ADX, Stochastic, PSAR) plus the
|
|
//! complete catalogue: Keltner, Donchian, SuperTrend, Chandelier Exit, ATR
|
|
//! Trailing Stop, Aroon, AwesomeOscillator, CCI, WilliamsR, MFI, OBV, VWAP,
|
|
//! RollingVWAP, ADL, VPT, ChaikinMoneyFlow, ChaikinOscillator, ForceIndex,
|
|
//! EaseOfMovement, NATR, AroonOscillator, ChandeKrollStop, Vortex, MassIndex,
|
|
//! ChoppinessIndex, TrueRange, ChaikinVolatility, AcceleratorOscillator,
|
|
//! BalanceOfPower, UltimateOscillator, VWMA, TypicalPrice, MedianPrice,
|
|
//! WeightedClose.
|
|
|
|
use libfuzzer_sys::fuzz_target;
|
|
use wickra_core::{
|
|
AcceleratorOscillator, Adl, Adx, Alligator, Aroon, AroonOscillator, Atr, AtrTrailingStop,
|
|
AwesomeOscillator, BalanceOfPower, BatchExt, Candle, Cci, ChaikinMoneyFlow, ChaikinOscillator,
|
|
ChaikinVolatility, ChandeKrollStop, ChandelierExit, ChoppinessIndex, Donchian, EaseOfMovement,
|
|
Evwma, ForceIndex, Indicator, Keltner, MassIndex, MedianPrice, Mfi, Natr, Obv, Psar,
|
|
RollingVwap,
|
|
Stochastic, SuperTrend, TrueRange, TypicalPrice, UltimateOscillator, VolumePriceTrend, Vortex,
|
|
Vwap, Vwma, WeightedClose, WilliamsR,
|
|
};
|
|
|
|
/// Convert a flat `f64` stream into a `Vec<Candle>` by chunking it into
|
|
/// `[open, high, low, close, volume]` groups. Tuples that fail OHLCV
|
|
/// validation are dropped so the indicator under test only ever sees a
|
|
/// structurally-valid candle stream (the *parser* is fuzz-tested elsewhere;
|
|
/// this target focuses on indicator robustness).
|
|
fn candles_from(data: &[f64]) -> Vec<Candle> {
|
|
data.chunks_exact(5)
|
|
.enumerate()
|
|
.filter_map(|(i, ch)| {
|
|
// A monotonic timestamp avoids surprising any indicator that might
|
|
// care about ordering. The fuzz input drives OHLCV; time is just a
|
|
// tie-breaker.
|
|
Candle::new(ch[0], ch[1], ch[2], ch[3], ch[4], i as i64).ok()
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
/// Streaming + batch sweep through one candle-input indicator. `#[inline(never)]`
|
|
/// keeps each indicator on its own frame in any panic backtrace.
|
|
#[inline(never)]
|
|
fn drive<I, O>(make: impl Fn() -> I, candles: &[Candle])
|
|
where
|
|
I: Indicator<Input = Candle, Output = O> + BatchExt,
|
|
{
|
|
let mut streaming = make();
|
|
for c in candles {
|
|
let _ = streaming.update(*c);
|
|
}
|
|
let _ = make().batch(candles);
|
|
}
|
|
|
|
fuzz_target!(|data: Vec<f64>| {
|
|
let candles = candles_from(&data);
|
|
if candles.is_empty() {
|
|
return;
|
|
}
|
|
|
|
// --- Volatility & ATR family ---
|
|
drive(|| Atr::new(14).unwrap(), &candles);
|
|
drive(|| Natr::new(14).unwrap(), &candles);
|
|
drive(TrueRange::new, &candles);
|
|
drive(|| ChaikinVolatility::new(10, 10).unwrap(), &candles);
|
|
|
|
// --- Bands & Channels ---
|
|
drive(|| Keltner::new(20, 10, 2.0).unwrap(), &candles);
|
|
drive(|| Donchian::new(20).unwrap(), &candles);
|
|
|
|
// --- Trailing Stops ---
|
|
drive(|| Psar::new(0.02, 0.02, 0.20).unwrap(), &candles);
|
|
drive(|| SuperTrend::new(14, 3.0).unwrap(), &candles);
|
|
drive(|| ChandelierExit::new(22, 3.0).unwrap(), &candles);
|
|
drive(|| ChandeKrollStop::new(10, 1.0, 9).unwrap(), &candles);
|
|
drive(|| AtrTrailingStop::new(14, 3.0).unwrap(), &candles);
|
|
|
|
// --- Trend & Directional ---
|
|
drive(|| Adx::new(14).unwrap(), &candles);
|
|
drive(|| Aroon::new(14).unwrap(), &candles);
|
|
drive(|| Alligator::new(13, 8, 5).unwrap(), &candles);
|
|
drive(|| AroonOscillator::new(14).unwrap(), &candles);
|
|
drive(|| Vortex::new(14).unwrap(), &candles);
|
|
drive(|| MassIndex::new(9, 25).unwrap(), &candles);
|
|
drive(|| ChoppinessIndex::new(14).unwrap(), &candles);
|
|
|
|
// --- Momentum & Oscillators ---
|
|
drive(|| Cci::new(20).unwrap(), &candles);
|
|
drive(|| WilliamsR::new(14).unwrap(), &candles);
|
|
drive(|| AwesomeOscillator::new(5, 34).unwrap(), &candles);
|
|
drive(|| AcceleratorOscillator::new(5, 34, 5).unwrap(), &candles);
|
|
drive(|| UltimateOscillator::new(7, 14, 28).unwrap(), &candles);
|
|
drive(BalanceOfPower::new, &candles);
|
|
|
|
// --- Volume ---
|
|
drive(Obv::new, &candles);
|
|
drive(|| Mfi::new(14).unwrap(), &candles);
|
|
drive(Vwap::new, &candles);
|
|
drive(|| RollingVwap::new(20).unwrap(), &candles);
|
|
drive(|| Vwma::new(20).unwrap(), &candles);
|
|
drive(|| Evwma::new(20).unwrap(), &candles);
|
|
drive(Adl::new, &candles);
|
|
drive(VolumePriceTrend::new, &candles);
|
|
drive(|| ChaikinMoneyFlow::new(20).unwrap(), &candles);
|
|
drive(|| ChaikinOscillator::new(3, 10).unwrap(), &candles);
|
|
drive(|| ForceIndex::new(13).unwrap(), &candles);
|
|
drive(|| EaseOfMovement::with_divisor(14, 1e8).unwrap(), &candles);
|
|
|
|
// --- Price transformations ---
|
|
drive(TypicalPrice::new, &candles);
|
|
drive(MedianPrice::new, &candles);
|
|
drive(WeightedClose::new, &candles);
|
|
|
|
// --- Stochastic (multi-output) ---
|
|
{
|
|
let mut s = Stochastic::new(14, 3).unwrap();
|
|
for c in &candles {
|
|
let _ = s.update(*c);
|
|
}
|
|
let _ = Stochastic::new(14, 3).unwrap().batch(&candles);
|
|
}
|
|
});
|