e385734275
## B15 Microstructure — three new indicators (485 → 488) | Indicator | Input | Output | Notes | |-----------|-------|--------|-------| | `TradeSignAutocorrelation` | `Trade` | `f64` ∈ [-1,1] | lag-1 autocorrelation of the signed aggressor (order-flow persistence) | | `Pin` | `Trade` | `f64` ∈ [0,1] | probability of informed trading from rolling buy/sell imbalance (EKOP single-window estimator); `name()` = `"PIN"` | | `HasbrouckInformationShare` | `(f64, f64)` | `f64` ∈ [0,1] | variance-ratio proxy for each venue's share of price discovery | ### Wiring - Core structs + full unit tests (every branch). - Hand-written Python/Node/WASM bindings for the two `Trade`-input indicators (precedent `TradeImbalance`); `node_pair_indicator!` / `wasm_pair_indicator!` macro bindings + hand Python pyclass for the pairwise Hasbrouck (precedent `RollingCorrelation`). - Fuzz drives added to `indicator_update_trade.rs` and `indicator_update_pair.rs`. - Dedicated Python + Node streaming-vs-batch and reference tests; Hasbrouck in the `PAIR` registry. - README counter (3 spots) + `docs/README.md` + `FAMILIES` assert bumped to 488. ### Verify (all green, local) - `cargo test -p wickra-core --lib`: 3991 passed - `cargo test -p wickra-core --doc`: 438 passed - `cargo clippy --workspace --all-targets --all-features -- -D warnings`: clean - node: 561 passed · pytest: 926 passed
58 lines
2.2 KiB
Rust
58 lines
2.2 KiB
Rust
#![no_main]
|
|
//! Fuzz trade-flow `Indicator<Input = Trade>` implementations with arbitrary
|
|
//! trade tapes.
|
|
//!
|
|
//! Each iteration consumes a byte stream, interprets it as a sequence of `f64`
|
|
//! values (8 bytes each), and packs consecutive values into `(price, size)`
|
|
//! trades whose aggressor side alternates with the sign of the size field.
|
|
//! Trades are built with `Trade::new_unchecked` so the fuzzer can explore
|
|
//! degenerate values (non-finite, negative) that the validating constructor
|
|
//! would reject — the indicators must never panic, streaming or batched.
|
|
|
|
use libfuzzer_sys::fuzz_target;
|
|
use wickra_core::{AmihudIlliquidity, BatchExt, CumulativeVolumeDelta, Footprint, Indicator, Pin, RollMeasure, Side, SignedVolume, Trade, TradeImbalance, TradeSignAutocorrelation, Vpin};
|
|
|
|
#[inline(never)]
|
|
fn drive<I>(make: impl Fn() -> I, trades: &[Trade])
|
|
where
|
|
I: Indicator<Input = Trade, Output = f64> + BatchExt,
|
|
{
|
|
let mut streaming = make();
|
|
for &trade in trades {
|
|
let _ = streaming.update(trade);
|
|
}
|
|
let _ = make().batch(trades);
|
|
}
|
|
|
|
fuzz_target!(|data: &[u8]| {
|
|
let floats: Vec<f64> = data
|
|
.chunks_exact(8)
|
|
.map(|c| f64::from_le_bytes(c.try_into().expect("8 bytes")))
|
|
.collect();
|
|
let trades: Vec<Trade> = floats
|
|
.chunks_exact(2)
|
|
.map(|c| {
|
|
let side = if c[1] >= 0.0 { Side::Buy } else { Side::Sell };
|
|
Trade::new_unchecked(c[0], c[1], side, 0)
|
|
})
|
|
.collect();
|
|
|
|
drive(SignedVolume::new, &trades);
|
|
drive(CumulativeVolumeDelta::new, &trades);
|
|
drive(|| TradeImbalance::new(5).unwrap(), &trades);
|
|
drive(|| Vpin::new(8.0, 5).unwrap(), &trades);
|
|
drive(|| AmihudIlliquidity::new(20).unwrap(), &trades);
|
|
drive(|| RollMeasure::new(20).unwrap(), &trades);
|
|
drive(|| TradeSignAutocorrelation::new(20).unwrap(), &trades);
|
|
drive(|| Pin::new(20).unwrap(), &trades);
|
|
|
|
// Footprint emits a variable-length `FootprintOutput` rather than an `f64`,
|
|
// so it is driven directly rather than through the scalar-output helper.
|
|
let mut footprint = Footprint::new(0.5).unwrap();
|
|
for &trade in &trades {
|
|
let _ = footprint.update(trade);
|
|
}
|
|
footprint.reset();
|
|
let _ = Footprint::new(0.5).unwrap().batch(&trades);
|
|
});
|