Skip to content

Value inverse crypto futures correctly in closed-trade statistics - #10039

Open
mkzung wants to merge 2 commits into
QuantConnect:masterfrom
mkzung:bug-10031-inverse-crypto-trade-statistics
Open

mkzung wants to merge 2 commits into
QuantConnect:masterfrom
mkzung:bug-10031-inverse-crypto-trade-statistics

Conversation

@mkzung

@mkzung mkzung commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Description

Value inverse crypto futures in closed-trade statistics using signed reciprocal prices and the base currency's conversion rate. For BTCUSD, long 100 contracts from 40,000 to 44,000 reports USD 1,000 rather than USD 40,000,000.

Apply the same valuation to FillToFill excursions and drawdown. FlatToFlat and FlatToReduced average settlement values separately from the reported entry and exit prices, so scaling in and taking partial exits use the actual fills. Linear contracts, including DYDX BTCUSD, keep their price-difference calculation.

Related Issue

Fixes #10031.

Motivation and Context

Inverse contracts settle in the base asset. Treating their USD face value as a base-asset quantity makes closed-trade profit and risk statistics incorrect.

Requires Documentation Change

No.

How Has This Been Tested?

Pristine checkout of the exact commit, fresh Release build, .NET 10.0.400, macOS arm64. Python 3.11.15 with the project's pinned NumPy 1.26.4, SciPy 1.13.1 and pandas 2.3.3 dependencies.

  • All 362 TradeBuilder tests and all 413 statistics tests pass. Cases cover long/short inverse and linear contracts, all three grouping methods, FIFO/LIFO partial exits, fees, USD/EUR conversion, excursions and drawdown.
  • Restoring the original TradeBuilder fails 22 regression cases and passes the other 340; restoring the fix passes all 362 again.
  • The full main CI selection ran twice after fixing the local Python environment: 39,359 passed, 100 skipped and two failed in each run. ZipBytesReturnsByteArrayWithCorrectLength expects 906,121 bytes on macOS but gets 905,693; this also fails with the original TradeBuilder. One run additionally failed MultiThreadReadWriteTest, the other ProcessesOrdersConcurrently. Their test and production files are unchanged; they pass in 15 and 10 isolated original-code runs respectively.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed. The full-run failures are described above.
  • My branch follows the naming convention bug-<issue#>-<description>.

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.

Closed-trade profit of coin-margined crypto futures uses the linear formula

1 participant