24e723fa7d
* feat(rvi): add Relative Vigor Index
Dorsey's RVI = SMA(close - open, period) / SMA(high - low, period) over
a rolling window of period candles. Candle input, single parameter
period (default 10). Positive on average-bullish windows, negative on
average-bearish. Holds the previous value if the entire window has
zero range (denominator undefined).
Reference: Donald Dorsey, also pandas-ta rvi.
Touchpoints: rvi.rs + mod.rs + lib.rs re-export, PyRvi + __init__.py
+ test_new_indicators CANDLE_SCALAR + test_known_values reference,
RviNode (4-column OHLC batch) + index.d.ts/index.js + indicators.test
.js factory + reference, WasmRvi + make_candle_ohlc helper, candle-fuzz
target + criterion bench, README + CHANGELOG.
* feat(pgo): add Pretty Good Oscillator
Mark Johnson's PGO = (close - SMA(close, period)) / EMA(TR, period).
Counts roughly how many ATR-equivalents the close sits from its
period-bar mean. Candle input, single parameter period (default 14).
Johnson's heuristic uses +3/-3 crossings as entry signals.
Touchpoints: pgo.rs + mod.rs + lib.rs re-export, PyPgo + __init__.py
+ test_new_indicators CANDLE_SCALAR + test_known_values flat-close
reference, PgoNode (h/l/c) + index.d.ts/index.js + indicators.test.js
factory + reference, WasmPgo, candle-fuzz target + bench, README +
CHANGELOG.
* feat(kst): add Know Sure Thing (Pring)
Pring's long-horizon momentum oscillator: weighted sum of four
SMA-smoothed ROC series with fixed weights 1, 2, 3, 4, plus an SMA
signal line. Nine parameters (four ROC periods, four SMA periods, one
signal period); classic() applies Pring's recommended defaults.
Multi-output indicator emitting KstOutput { kst, signal }.
Touchpoints: kst.rs + mod.rs + lib.rs re-export, PyKst + __init__.py
+ test_new_indicators MULTI + test_known_values flat-input reference,
KstNode + KstValue + index.d.ts/index.js + indicators.test.js multi
factory + reference, WasmKst (manual JsValue object), scalar-fuzz
target (handled outside the f64-output drive helper), README +
CHANGELOG.
* feat(smi): add Stochastic Momentum Index (Blau)
Blau's doubly-EMA-smoothed bounded oscillator: measures the close's
displacement from the centre of the recent high-low range, scaled by
the smoothed range. Candle input, three parameters (period, d_period,
d2_period) with defaults 5 / 3 / 3.
Internally feeds both the displacement-EMA stack and the range-EMA
stack on every candle so they warm up in parallel (gating either
behind the other starves the second by one input).
Touchpoints: smi.rs + mod.rs + lib.rs re-export, PySmi + __init__.py
+ test_new_indicators CANDLE_SCALAR + test_known_values flat-input
reference, SmiNode + index.d.ts/index.js + indicators.test.js factory
+ reference, WasmSmi, candle-fuzz target, README + CHANGELOG.
* feat(laguerre-rsi): add Ehlers Laguerre RSI
Four-stage Laguerre polynomial filter wrapped in an RSI-style up/down
accumulator. Single gamma in [0, 1] (default 0.5) trades lag for
smoothness. State is seeded by setting all four L_i to the first input
so a constant series stays at the neutral 50. Output clamped to
[0, 100] to absorb floating-point rounding.
Reference: Ehlers, Time Warp - Without Space Travel, 2002.
Touchpoints: laguerre_rsi.rs + mod.rs + lib.rs re-export, PyLaguerreRsi
+ __init__.py + test_new_indicators SCALAR + test_known_values neutral
reference, LaguerreRsiNode + index.d.ts/index.js + indicators.test.js
factory + reference, WasmLaguerreRsi via scalar macro, scalar-fuzz
target, README + CHANGELOG.
* feat(connors-rsi): add Connors RSI (CRSI)
Larry Connors' 3-component aggregate: RSI(close), RSI(streak), and
PercentRank of the 1-period return over the last period_rank returns.
Each component is bounded in [0, 100] so the aggregate is too.
Three parameters (period_rsi, period_streak, period_rank) with
defaults 3 / 2 / 100. Streak tracks consecutive up/down runs (resets
to 0 on unchanged close).
Touchpoints: connors_rsi.rs + mod.rs + lib.rs re-export, PyConnorsRsi
+ __init__.py + test_new_indicators SCALAR + test_known_values bounded
reference, ConnorsRsiNode + index.d.ts/index.js + indicators.test.js
factory + reference, WasmConnorsRsi via scalar macro, scalar-fuzz
target, README + CHANGELOG.
* feat(inertia): add Dorsey Inertia (RVI + LinReg)
Donald Dorsey's Inertia — a LinearRegression smoothing of the RVI
series. Endpoint of an n-bar least-squares fit of RVI is the indicator
reading. Preserves trend direction while damping the ratio. Candle
input, two parameters (rvi_period, linreg_period) with defaults 14 / 20.
Touchpoints: inertia.rs + mod.rs + lib.rs re-export, PyInertia +
__init__.py + test_new_indicators CANDLE_SCALAR + test_known_values
constant reference, InertiaNode (4-column OHLC batch) + index.d.ts /
index.js + indicators.test.js factory + reference, WasmInertia,
candle-fuzz target, README + CHANGELOG.
* test(kst): Move KST out of MULTI dict (it is scalar-input)
KST sits in the MULTI dict (candle-input, multi-output) but its
update() takes a single f64, not a candle tuple. The shared streaming
loop in test_multi_streaming_matches_batch fed the OHLCV tuple in,
which crashed with `TypeError: argument 'value': must be real number,
not tuple` on every Python matrix entry.
Split into a new MULTI_SCALAR_INPUT dict with its own test function
that feeds the close-price stream as floats. KST is currently the
only such indicator; structure is ready for future scalar-input
multi-output additions (e.g. some MACD-shaped indicators).
* test(coverage): Cover SMI zero-range and ConnorsRsi zero-prev cold paths
codecov/patch on PR 40 flagged two uncovered defensive branches:
- SMI returns self.current early when the smoothed range collapses to
zero (`r2 <= 0.0`) so the formula stays defined. Exercised by feeding
bars where high == low.
- ConnorsRsi skips the ROC ring-buffer update when the previous price
is exactly zero so the divide-by-zero in `(input - prev) / prev` is
impossible. Exercised by seeding the first bar at 0.0.
109 lines
4.6 KiB
Rust
109 lines
4.6 KiB
Rust
#![no_main]
|
|
//! Fuzz scalar-input indicator updates with arbitrary `f64` sequences.
|
|
//!
|
|
//! Every scalar indicator must tolerate any finite-or-not input stream — NaN,
|
|
//! ±inf, subnormals, abrupt jumps — without panicking. Each fuzz iteration
|
|
//! runs the **same** input sequence through every scalar indicator twice:
|
|
//! once as a streaming `update` loop and once as a full `batch` call. Neither
|
|
//! path may panic; `batch` is also expected to agree with the streaming path
|
|
//! (the `BatchExt` blanket implementation replays `update` internally, so the
|
|
//! agreement is structural — but exercising both paths surfaces any
|
|
//! state-mutation bugs in `update` that would only manifest mid-batch).
|
|
//!
|
|
//! Audit finding R9: the previous version covered only `Rsi(14)` and
|
|
//! `Ema(20)`. This target now covers every scalar indicator in the catalogue.
|
|
|
|
use libfuzzer_sys::fuzz_target;
|
|
use wickra_core::{
|
|
Alma, BatchExt, BollingerBands, Cmo, ConnorsRsi, Coppock, Dema, Dpo, Ema, Frama,
|
|
HistoricalVolatility, Hma, Indicator, Jma, Kama, Kst, LaguerreRsi, LinRegAngle, LinRegSlope,
|
|
LinearRegression, MacdIndicator, McGinleyDynamic, Mom, Pmo, Ppo, Roc, Rsi, Sma, Smma, StdDev,
|
|
StochRsi, T3, Tema, Trima, Trix, Tsi, UlcerIndex, VerticalHorizontalFilter, Vidya, Wma, ZScore,
|
|
Zlema,
|
|
};
|
|
|
|
/// Drive a single streaming + batch run through one scalar indicator. Marked
|
|
/// `#[inline(never)]` so a panic backtrace pin-points the specific indicator.
|
|
#[inline(never)]
|
|
fn drive<I>(make: impl Fn() -> I, data: &[f64])
|
|
where
|
|
I: Indicator<Input = f64, Output = f64> + BatchExt,
|
|
{
|
|
let mut streaming = make();
|
|
for &x in data {
|
|
let _ = streaming.update(x);
|
|
}
|
|
let _ = make().batch(data);
|
|
}
|
|
|
|
fuzz_target!(|data: Vec<f64>| {
|
|
// Bounded periods keep each iteration cheap and bias the fuzzer toward
|
|
// adversarial input patterns rather than enormous windows. The constants
|
|
// mirror the README's "common defaults" so we cover the parameterisations
|
|
// most users actually instantiate.
|
|
drive(|| Sma::new(14).unwrap(), &data);
|
|
drive(|| Ema::new(20).unwrap(), &data);
|
|
drive(|| Wma::new(14).unwrap(), &data);
|
|
drive(|| Rsi::new(14).unwrap(), &data);
|
|
drive(|| Dema::new(14).unwrap(), &data);
|
|
drive(|| Tema::new(14).unwrap(), &data);
|
|
drive(|| Hma::new(14).unwrap(), &data);
|
|
drive(|| Roc::new(14).unwrap(), &data);
|
|
drive(|| Trix::new(14).unwrap(), &data);
|
|
drive(|| Smma::new(14).unwrap(), &data);
|
|
drive(|| Trima::new(14).unwrap(), &data);
|
|
drive(|| Zlema::new(14).unwrap(), &data);
|
|
drive(|| Kama::new(10, 2, 30).unwrap(), &data);
|
|
drive(|| Alma::new(9, 0.85, 6.0).unwrap(), &data);
|
|
drive(|| McGinleyDynamic::new(10).unwrap(), &data);
|
|
drive(|| Frama::new(16).unwrap(), &data);
|
|
drive(|| Vidya::new(14, 9).unwrap(), &data);
|
|
drive(|| Jma::new(14, 0.0, 2).unwrap(), &data);
|
|
drive(|| T3::new(14, 0.7).unwrap(), &data);
|
|
drive(|| Mom::new(14).unwrap(), &data);
|
|
drive(|| Cmo::new(14).unwrap(), &data);
|
|
drive(|| Tsi::new(25, 13).unwrap(), &data);
|
|
drive(|| Pmo::new(35, 20).unwrap(), &data);
|
|
drive(|| StochRsi::new(14, 14).unwrap(), &data);
|
|
drive(|| Dpo::new(14).unwrap(), &data);
|
|
drive(|| Ppo::new(12, 26).unwrap(), &data);
|
|
drive(|| Coppock::new(14, 11, 10).unwrap(), &data);
|
|
drive(|| StdDev::new(14).unwrap(), &data);
|
|
drive(|| UlcerIndex::new(14).unwrap(), &data);
|
|
drive(|| HistoricalVolatility::new(14, 252).unwrap(), &data);
|
|
drive(|| LinearRegression::new(14).unwrap(), &data);
|
|
drive(|| LinRegSlope::new(14).unwrap(), &data);
|
|
drive(|| LinRegAngle::new(14).unwrap(), &data);
|
|
drive(|| VerticalHorizontalFilter::new(14).unwrap(), &data);
|
|
drive(|| ZScore::new(14).unwrap(), &data);
|
|
drive(|| LaguerreRsi::new(0.5).unwrap(), &data);
|
|
drive(|| ConnorsRsi::classic(), &data);
|
|
|
|
// KST is scalar-input but emits `KstOutput`, so it bypasses the generic
|
|
// `drive` helper. Streaming + batch are still both exercised.
|
|
{
|
|
let mut kst = Kst::classic();
|
|
for &x in &data {
|
|
let _ = kst.update(x);
|
|
}
|
|
let _ = Kst::classic().batch(&data);
|
|
}
|
|
|
|
// MACD and Bollinger Bands have non-`f64` outputs, so they cannot use the
|
|
// generic `drive` helper above. Streaming + batch are still both exercised.
|
|
{
|
|
let mut macd = MacdIndicator::new(12, 26, 9).unwrap();
|
|
for &x in &data {
|
|
let _ = macd.update(x);
|
|
}
|
|
let _ = MacdIndicator::new(12, 26, 9).unwrap().batch(&data);
|
|
}
|
|
{
|
|
let mut bb = BollingerBands::new(20, 2.0).unwrap();
|
|
for &x in &data {
|
|
let _ = bb.update(x);
|
|
}
|
|
let _ = BollingerBands::new(20, 2.0).unwrap().batch(&data);
|
|
}
|
|
});
|