feat(microstructure): trade-sign autocorrelation, PIN, Hasbrouck information share (B15) (#212)
## 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
This commit is contained in:
@@ -563,6 +563,11 @@ wasm_pair_indicator!(
|
||||
"BetaNeutralSpread",
|
||||
wc::BetaNeutralSpread
|
||||
);
|
||||
wasm_pair_indicator!(
|
||||
WasmHasbrouckInformationShare,
|
||||
"HasbrouckInformationShare",
|
||||
wc::HasbrouckInformationShare
|
||||
);
|
||||
|
||||
// ---------- PairSpreadZScore (two params) ----------
|
||||
|
||||
@@ -9279,6 +9284,66 @@ impl WasmTradeImbalance {
|
||||
}
|
||||
}
|
||||
|
||||
// Trade-sign autocorrelation carries a `period` parameter, so it is hand-written.
|
||||
#[wasm_bindgen(js_name = TradeSignAutocorrelation)]
|
||||
pub struct WasmTradeSignAutocorrelation {
|
||||
inner: wc::TradeSignAutocorrelation,
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_class = TradeSignAutocorrelation)]
|
||||
impl WasmTradeSignAutocorrelation {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(period: usize) -> Result<WasmTradeSignAutocorrelation, JsError> {
|
||||
Ok(Self {
|
||||
inner: wc::TradeSignAutocorrelation::new(period).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
pub fn update(&mut self, price: f64, size: f64, is_buy: bool) -> Result<Option<f64>, JsError> {
|
||||
Ok(self.inner.update(build_trade(price, size, is_buy)?))
|
||||
}
|
||||
pub fn reset(&mut self) {
|
||||
self.inner.reset();
|
||||
}
|
||||
#[wasm_bindgen(js_name = isReady)]
|
||||
pub fn is_ready(&self) -> bool {
|
||||
self.inner.is_ready()
|
||||
}
|
||||
#[wasm_bindgen(js_name = warmupPeriod)]
|
||||
pub fn warmup_period(&self) -> usize {
|
||||
self.inner.warmup_period()
|
||||
}
|
||||
}
|
||||
|
||||
// PIN carries a `window` parameter, so it is hand-written.
|
||||
#[wasm_bindgen(js_name = Pin)]
|
||||
pub struct WasmPin {
|
||||
inner: wc::Pin,
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_class = Pin)]
|
||||
impl WasmPin {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(window: usize) -> Result<WasmPin, JsError> {
|
||||
Ok(Self {
|
||||
inner: wc::Pin::new(window).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
pub fn update(&mut self, price: f64, size: f64, is_buy: bool) -> Result<Option<f64>, JsError> {
|
||||
Ok(self.inner.update(build_trade(price, size, is_buy)?))
|
||||
}
|
||||
pub fn reset(&mut self) {
|
||||
self.inner.reset();
|
||||
}
|
||||
#[wasm_bindgen(js_name = isReady)]
|
||||
pub fn is_ready(&self) -> bool {
|
||||
self.inner.is_ready()
|
||||
}
|
||||
#[wasm_bindgen(js_name = warmupPeriod)]
|
||||
pub fn warmup_period(&self) -> usize {
|
||||
self.inner.warmup_period()
|
||||
}
|
||||
}
|
||||
|
||||
// Order Flow Imbalance: order-book input with a `period` parameter.
|
||||
#[wasm_bindgen(js_name = OrderFlowImbalance)]
|
||||
pub struct WasmOrderFlowImbalance {
|
||||
|
||||
Reference in New Issue
Block a user