Commit Graph

29 Commits

Author SHA1 Message Date
porcelaincode fb3a2dda25 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>
2026-06-03 21:47:08 +05:30
porcelaincode 3420edee2b fix(indicators): correct test_macd signal line warmup assertion
signal_start = (slow_period-1) + (signal_period-1) = 24+8 = 32,
so signal_line[33] is the first valid value, not NaN. Test was
asserting [33].is_nan() which was always wrong.

Co-Authored-By: porcelaincode <contact@alphabench.in>
2026-06-03 21:28:00 +05:30
porcelaincode fa6959bb99 feat(tick): add run_tick_backtest — tick-native simulation engine, bump to 0.4.0
Adds a full tick-level backtest path that operates on raw tick arrays
(ltp, bid, ask, per-tick buy/sell qty deltas, oi) plus caller-computed
entry/exit signal bool arrays. Entry fills at ask+slippage; stop/target
checked against ltp on every tick; max-hold-seconds time exit; cooldown
between entries. Produces identical BacktestMetrics as run_single_backtest
via the new compute_backtest_metrics free fn.

5 Rust unit tests: target-hit, stop-hit, time-exit, multi-trade-with-cooldown,
empty-ticks edge case — all pass (138 total, 0 failed).

Co-Authored-By: porcelaincode <contact@alphabench.in>
2026-06-03 21:27:54 +05:30
porcelaincode 514c235f1c feat(core): add TickData struct, TimeExit reason, compute_backtest_metrics pub fn
- TickData: parallel tick arrays (timestamps, ltp, bid, ask, buy_qty_delta,
  sell_qty_delta, oi) with len/is_empty helpers; callers must pre-convert
  Zerodha cumulative totals to per-tick deltas before passing
- ExitReason::TimeExit: max hold time exceeded variant for tick backtest
- compute_backtest_metrics: pub free fn wrapping PortfolioEngine::calculate_metrics
  so non-OHLCV strategies can produce identical metrics without duplication

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-03 21:26:51 +05:30
vatsal 7e91293e1a Merge pull request #13 from alphabench/feat/options-settlement
feat: add option settlement handling and single-leg spread types, bump to 0.3.4
v0.3.4
2026-03-07 06:40:10 +05:30
porcelaincode c9451069d8 feat: add option settlement handling and single-leg spread types, bump to 0.3.4
Add settlement logic for option expiry with Settlement exit reason, leg_expiry_timestamps parameter for per-leg expiry tracking, and new single-leg spread types (LongCall, LongPut, NakedCall, NakedPut). Positions are force-closed at settlement with premiums replaced by intrinsic value, and re-entry is prevented after all legs expire.
2026-03-07 06:37:31 +05:30
vatsal 997e234a85 Merge pull request #12 from alphabench/feat/refining-metrics-for-portfolio
feat: add batch spread backtest with parallel execution, bump to 0.3.3
v0.3.3
2026-02-25 15:21:29 +05:30
porcelaincode e049a2f968 feat: add batch spread backtest with parallel execution, bump to 0.3.3
Introduces PyBatchSpreadItem and batch_spread_backtest function for running multiple spread strategies in parallel using Rayon, enabling efficient multi-strategy backtesting workflows.
2026-02-25 15:19:42 +05:30
vatsal f7592d5d79 Merge pull request #11 from alphabench/feat/refining-metrics-for-portfolio
docs: remove iframe from README, post1 release
v0.3.2.post1
2026-02-18 19:17:46 +05:30
porcelaincode 87545683eb docs: remove iframe from README, post1 release 2026-02-18 19:15:15 +05:30
vatsal eb5335e809 Merge pull request #10 from alphabench/feat/refining-metrics-for-portfolio
feat: add payoff_ratio and recovery_factor metrics, bump to 0.3.2
v0.3.2
2026-02-18 18:58:08 +05:30
porcelaincode 0ff67e7fe2 feat: add payoff_ratio and recovery_factor metrics, bump to 0.3.2
Add two new risk/reward metrics to BacktestMetrics:
- payoff_ratio: avg winning return / avg losing return (absolute)
- recovery_factor: net profit / max drawdown in absolute terms
Computed in both StreamingMetrics::finalize() and PortfolioEngine.
Exposed via PyO3 with #[pyo3(get)] on PyBacktestMetrics.
Updated README with API reference and changelog.
2026-02-18 18:57:42 +05:30
vatsal ab568cc9fb Merge pull request #9 from alphabench/feat/porfolio-simulation
feat: add Monte Carlo portfolio simulation and bump to 0.3.1
v0.3.1
2026-02-17 00:36:45 +05:30
porcelaincode 4d4ea2e5e9 feat: add Monte Carlo portfolio simulation and bump to 0.3.1
- Add Monte Carlo forward simulation using Geometric Brownian Motion
- Support correlated multi-asset simulation with Cholesky decomposition
- Implement parallel execution via Rayon for performance
- Expose simulate_portfolio_mc function in Python bindings
- Update version from 0.3.0 to 0.3.1 across all project files
2026-02-17 00:35:20 +05:30
vatsal a82ddc598a Merge pull request #8 from alphabench/feat/instrument-level-config
feat: add instrument level config and bump to 0.3.0
v0.3.0
2026-02-10 05:05:38 +05:30
porcelaincode bb6ce05c57 feat: add instrument level config and bump to 0.3.0 2026-02-10 05:03:39 +05:30
vatsal aad09da117 Merge pull request #7 from alphabench/fix/spread-backtest
feat: add new backtest functions
v0.2.2
2026-02-08 06:06:30 +05:30
porcelaincode c711e9ce8e feat: add new backtest functions 2026-02-08 06:04:43 +05:30
vatsal 4d0d4cbfa3 feat: update version to 0.2.1 and add rolling min/max indicators (#6)
* feat: add session tracking and multi-leg spread backtesting

Add SessionTracker for trading session management:                             - Market hours detection (pre-open, trading, squareoff, post-close)
 - Session boundary tracking with configurable timezone    - Squareoff time support for intraday strategies                                   - Session high/low/open price tracking

Add SpreadBacktest for multi-leg options strategies:                                  - Support for straddles, strangles, vertical spreads, iron condors                                      - Coordinated entry/exit across all legs                                             - Net premium P&L calculation with max loss/target profit exits                                            - Helper functions for common spread configurations

Extend StreamingMetrics for backtest integration:                                - Add equity and drawdown tracking (update_equity, current_drawdown_pct)           - Add trade recording (record_trade, record_fees)                              - Add finalize() method to produce BacktestMetrics                        - Add with_initial_capital() constructor

Bump version to 0.2.0.

* chore: bump up version to 0.2.0

* feat: update version to 0.2.1 and add rolling min/max indicators

* fix: formatting
v0.2.1
2026-02-02 04:24:45 +05:30
vatsal 03ac0192b7 Merge pull request #5 from alphabench/chore/fix-readme
chore: fix README for relevance
2026-01-30 03:54:47 +05:30
porcelaincode baa87b476b chore: fix README for relevance 2026-01-30 03:54:14 +05:30
vatsal f4a40617c0 Merge pull request #4 from alphabench/chore/project-metadata
update project metadata
2026-01-29 23:12:29 +05:30
porcelaincode 196f63f5c3 update project metadata and documentation for clarity and branding 2026-01-29 23:11:15 +05:30
vatsal 5ca413ebbf Fix/release workflow python (#3)
* Fix release workflow: Python compatibility issues

- Linux: Add --find-interpreter for cross-compilation
- macOS/Windows: Pin Python to 3.12 (PyO3 0.20.3 max supported)

* Fix Linux release: limit Python versions to 3.10-3.12

PyO3 0.20.3 only supports up to Python 3.12. Using --find-interpreter detected Python 3.13/3.14 in the manylinux container which caused build failures.
2026-01-28 16:05:18 +05:30
vatsal ca2965aade Fix release workflow: Python compatibility issues (#2)
- Linux: Add --find-interpreter for cross-compilation
- macOS/Windows: Pin Python to 3.12 (PyO3 0.20.3 max supported)
2026-01-28 15:54:37 +05:30
vatsal 0f032dd39e Fix CI workflow: use correct rust-toolchain action (#1)
* Fix CI workflow: use correct rust-toolchain action

* Fix CI: resolve Rust compilation and formatting issues
- Fix rust-toolchain action name in CI workflow
- Add missing Direction import in test modules
- Add missing entry_fees argument to open_position test calls
- Comment out nightly-only rustfmt options
- Auto-format code with cargo fmt
v0.1.0
2026-01-28 15:38:31 +05:30
porcelaincode e6476b771f Prepare package for PyPI publishing
- Add MIT LICENSE file
- Enhance pyproject.toml with full metadata
- Add GitHub Actions workflows for CI and release
2026-01-28 15:07:07 +05:30
porcelaincode b367cdb275 fix product name 2026-01-28 14:53:10 +05:30
porcelaincode f6c60d7b8b Initial backtesting engine 2026-01-28 06:30:03 +05:30