Repository navigation
Conversation
…atch Engine/broker: - A sell that overshoots the position only by float rounding now sells exactly the held quantity instead of leaving a microscopic short with shorting disabled; rounding dust after a fill is settled to zero. - A sell of float-noise size with no position is rejected instead of being filled. - Bars labelled with a symbol other than the engine's now raise instead of leaving every order pending forever. Metrics: - compute_trade_pnls ignores float-residue lots, which used to book an extra (winning) round trip after fractional partial closes. - CAGR that overflows a float on very short samples is reported as inf instead of raising OverflowError. - periods_per_year <= 0 and non-finite risk_free_rate raise ValueError. Tests: look-ahead invariance (rewrite the future, the past must not change; verified to fail when on_bar is handed the next bar), gaps, shorts past zero equity, long/short flip, end-of-data marking, hand- derived Sharpe/Sortino/volatility, and a check that the web demo's copy of the engine matches src/ and runs without pandas. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A42wbaQJVk97N5TsWqXP4G
- CSVDataFeed raises CSVFormatError (a ValueError) naming the file and line for missing columns, unparseable timestamps and blank or non-numeric values, instead of AttributeError/TypeError from pandas. - Header names are matched case-insensitively; timezone-aware timestamps work with naive start/end; sorting is stable. - start/end are inclusive in both feeds. YFinanceFeed used to pass end straight to Yahoo, where it is exclusive, so the last requested day was dropped; it now requests one more day and trims. A date-only end includes intraday bars on that day in CSVDataFeed too. - The CLI prints bad-data errors without a traceback and exits 1. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A42wbaQJVk97N5TsWqXP4G
- Equity figure gets a separate underwater drawdown panel (asserted to agree with compute_metrics' max drawdown) and exact $k tick labels (ticks at 102.5k were labelled "$102k"). - tests/test_determinism.py: repeated engine runs, CSV vs in-memory feeds and two CLI runs into one SQLite file are identical. - README and tutorial: margin-free shorts, no end-of-data liquidation, inclusive dates, CSV errors, annualisation conventions, and an explicit "past results do not predict future results". Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A42wbaQJVk97N5TsWqXP4G
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backtests can now export an auditable JSON report with
--report PATH: parameters, strategy/CSV SHA-256 hashes, metrics, equity curve, fills and runtime versions. Non-finite values become null. Atomic writes protect strategy, CSV and database files (including aliases); changed inputs are detected. Yahoo data and imported dependencies are not snapshotted, so this is not a full reproducibility guarantee.Validation for the current addition: 143 tests passed on Python 3.12; Ruff lint/format and mypy passed. Added tests cover deterministic exports, independent fill/equity reconciliation, changed hashes, protected files, atomic failure and optional CLI behavior. OmniRoute generated the initial report scaffold; it was completed and independently reviewed before commit.
Existing changes in this stacked PR:
Stacked on #6 (
claude/hardening). This is still backtesting only. There is no live or paper-trading engine, and the docs still say so.Defects fixed (each has a regression test that fails on the old code)
position == 0was never true again. Now the broker sells exactly the shares held, and rounding dust is set to 0.sell(1e-12)with no position went through. It is now rejected.compute_trade_pnls, buying 0.3 and then selling 0.1 three times left about 3e-17 shares as an open lot. The next round trip then counted an extra "winning" trade, which inflatednum_tradesand win rate.OverflowErroron short samples. For example 100x in one daily bar. It now reportsinf.ValueError.enddate was exclusive, but the README says--endis the last day included.YFinanceFeednow asks for one extra day and trims. Both feeds treatstart/endas inclusive, and inCSVDataFeeda date-onlyendnow includes that day's intraday bars.AttributeError/TypeError). It now raisesCSVFormatError(aValueError), naming the file, line and column. The CLI prints it and exits with code 1, with no traceback.periods_per_year <= 0or a non-finiterisk_free_ratenow raiseValueError.Tests added
kwith other prices; the orders, fills and equity up tokmust stay the same. I checked that this test fails when the engine is changed to pass the next bar toon_bar.docs/quantdeck_src) must matchsrc/and must run without pandas.Docs and visuals
compute_metrics.Behaviour changes, all covered by tests: the fixes above, and the
CSVDataFeeddate-onlyendchange. The pinned README/CLI numbers have not changed.Earlier numerical-fix validation: pytest (130 passed),
ruff check,ruff format --checkandmypy --strictare all clean. This was run with Python 3.11 and pandas 3.0.6; CI covers 3.10 to 3.12.