feat(derivatives): leverage, OI/volume, perpetual premium, funding APR, OI momentum (B16) (#214)
## B16 Derivatives — five new indicators (488 → 493)
All consume a `DerivativesTick` and emit `f64`:
| Indicator | Reads | Formula |
|-----------|-------|---------|
| `EstimatedLeverageRatio` | open_interest, long_size, short_size | `OI / (long + short)` |
| `OiToVolumeRatio` | open_interest, taker_buy_volume, taker_sell_volume | `OI / (buy + sell)` |
| `PerpetualPremiumIndex` | mark_price, index_price | `(mark − index) / index` |
| `FundingImpliedApr` | funding_rate | `rate × intervals_per_year` |
| `OpenInterestMomentum` | open_interest | `100 · (OI_t − OI_{t−period}) / OI_{t−period}` |
### Wiring
- Core structs + full unit tests (incl. zero-denominator branches).
- Hand-written Python/Node/WASM tick bindings; two new tick helpers (`deriv_oi_long_short`, `deriv_oi_taker`).
- Fuzz drives in `indicator_update_derivatives.rs`; dedicated reference + streaming-vs-batch tests (Python + Node).
- README counter + `docs/README.md` + `FAMILIES` assert bumped to 493.
### Verify (local, all green)
- `cargo test -p wickra-core --lib`: 4028 · `--doc`: 443
- clippy workspace: clean
- node: 563 · pytest: 928
This commit is contained in:
@@ -10,11 +10,7 @@
|
||||
//! never panic, streaming or batched.
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use wickra_core::{
|
||||
BatchExt, CalendarSpread, DerivativesTick, FundingBasis, FundingRate, FundingRateMean,
|
||||
FundingRateZScore, Indicator, LiquidationFeatures, LongShortRatio, OIPriceDivergence,
|
||||
OIWeighted, OpenInterestDelta, TakerBuySellRatio, TermStructureBasis,
|
||||
};
|
||||
use wickra_core::{BatchExt, CalendarSpread, DerivativesTick, EstimatedLeverageRatio, FundingBasis, FundingImpliedApr, FundingRate, FundingRateMean, FundingRateZScore, Indicator, LiquidationFeatures, LongShortRatio, OIPriceDivergence, OIWeighted, OiToVolumeRatio, OpenInterestDelta, OpenInterestMomentum, PerpetualPremiumIndex, TakerBuySellRatio, TermStructureBasis};
|
||||
|
||||
#[inline(never)]
|
||||
fn drive<I>(make: impl Fn() -> I, ticks: &[DerivativesTick])
|
||||
@@ -53,6 +49,11 @@ fuzz_target!(|data: &[u8]| {
|
||||
drive(TakerBuySellRatio::new, &ticks);
|
||||
drive(TermStructureBasis::new, &ticks);
|
||||
drive(CalendarSpread::new, &ticks);
|
||||
drive(EstimatedLeverageRatio::new, &ticks);
|
||||
drive(OiToVolumeRatio::new, &ticks);
|
||||
drive(PerpetualPremiumIndex::new, &ticks);
|
||||
drive(|| FundingImpliedApr::new(1095.0).unwrap(), &ticks);
|
||||
drive(|| OpenInterestMomentum::new(14).unwrap(), &ticks);
|
||||
|
||||
// LiquidationFeatures emits a struct, not an f64, so drive it directly.
|
||||
let mut liq = LiquidationFeatures::new();
|
||||
|
||||
Reference in New Issue
Block a user