feat(tick): add tick signal generation and feature extraction functions

Tick signal generation (src/signals/tick_signals.rs):
- tick_momentum_entry: O(N) single-pass entry signal array from spread/BSI/return
  gates with cooldown enforcement; replaces the Python O(N×120) entry-check loop
- tick_momentum_exit: time-based (EOD) exit bool array from tick timestamps

Tick feature extraction (src/indicators/tick_features.rs):
- tick_spread_pct: (ask-bid)/mid * 100, element-wise
- buy_sell_imbalance_delta: per-tick delta BSI from Zerodha cumulative session
  totals — fixes the ~0.95 all-day artefact from raw cumulative sums
- return_window: lookback return over configurable time window, binary search
  O(N log N); returns NaN where history insufficient (no silent pass-through)
- realized_vol_rolling: rolling stddev of log-returns as realized vol proxy
- oi_position_pct: OI position within day's high/low range [0, 100]
- tick_velocity: rolling ticks/min over configurable window

Python bindings: compute_tick_entry_signals, compute_tick_exit_signals,
tick_spread_pct, buy_sell_imbalance_delta, return_window, realized_vol_rolling,
oi_position_pct, tick_velocity — all with numpy array I/O and default args.

15 new Rust unit tests (7 signal, 8 feature); 153 total, 0 failed.

Co-Authored-By: porcelaincode <contact@alphabench.in>
This commit is contained in:
porcelaincode
2026-06-03 21:47:08 +05:30
parent 3420edee2b
commit fb3a2dda25
7 changed files with 645 additions and 0 deletions
+20
View File
@@ -32,6 +32,16 @@ from raptorbt._raptorbt import (
batch_spread_backtest,
# Monte Carlo simulation
simulate_portfolio_mc,
# Tick signal functions
compute_tick_entry_signals,
compute_tick_exit_signals,
# Tick feature functions
tick_spread_pct,
buy_sell_imbalance_delta,
return_window,
realized_vol_rolling,
oi_position_pct,
tick_velocity,
# Indicator functions
sma,
ema,
@@ -72,6 +82,16 @@ __all__ = [
"batch_spread_backtest",
# Monte Carlo simulation
"simulate_portfolio_mc",
# Tick signal functions
"compute_tick_entry_signals",
"compute_tick_exit_signals",
# Tick feature functions
"tick_spread_pct",
"buy_sell_imbalance_delta",
"return_window",
"realized_vol_rolling",
"oi_position_pct",
"tick_velocity",
# Indicator functions
"sma",
"ema",