Skip to content

Add self-financing backtest accounting with drift-aware trades - #87

Merged
initial-d merged 2 commits into
mainfrom
codex/self-financing-accounting-20261120
Nov 20, 2026
Merged

initial-d merged 2 commits into
mainfrom
codex/self-financing-accounting-20261120

Conversation

@initial-d

Copy link
Copy Markdown
Owner

The existing vector backtest charges changes in consecutive target fractions. Constant targets therefore pay no ongoing fees even when relative price moves require rebalancing. Add an opt-in run_self_financing_backtest that marks old holdings, measures actual trades, jointly solves cash-paid proportional fees and post-fee targets, and carries residual cash without external funding.

mlquant backtest --accounting self_financing reuses existing artifacts; backtest_accounting also works through the demo config. The legacy target-difference path remains the default, and reports label the accounting convention. The complete result retains marked pre-trade weights, trade values, cash, fees, actual weights, NAV and executed turnover. Entry fees enter drawdown, small float32 budget overruns are corrected on a copy and recorded, and total-loss assets/accounts cannot be reinvested or restarted.

Validation:

  • 484 tests pass locally; Ruff passes. The 33 new cases cover independent 60-digit Decimal trade-partition solutions, cash/fee identities, target drift, entry/exit, future changes, scaling, bankruptcy, input validation, CLI overrides and saved ledgers.
  • Three synthetic cases spanning 827 account rows and 100,804 asset-row cells match an independent 50-digit Decimal breakpoint solver. Maximum NAV error is 5.04e-14; fee error is 6.77e-17. All three future-mutation checks preserve earlier ledgers.
  • In the constructed 252-row 50/50 case with alternating +/-2% asset returns and 20 bps one-way fees, the approximation ends at 0.998 versus 0.988034 for the cash ledger. The complete changing-target/cash case also preserves the opposite difference direction: 0.620930 versus 0.622116. These compare accounting conventions, not strategy improvements.
  • Compact daily evidence, code/input fingerprints, exact commands and the full-suite log are retained in docs/audits/self-financing-20261120/.

This is long-only/cash historical accounting with complete fills at each mark and zero cash interest. It does not add broker access, tradability enforcement, settlement, volume or price impact, and does not revalidate archived market results. Fee assumptions are uncalibrated synthetic inputs. No market data was downloaded and no GPU was used.

@initial-d
initial-d merged commit f24f0af into main Nov 20, 2026
3 checks passed
@initial-d
initial-d deleted the codex/self-financing-accounting-20261120 branch November 20, 2026 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant