Skip to content

Fix stale Binance crypto future funding after market data ends - #9802

Open
zahT3 wants to merge 1 commit into
QuantConnect:masterfrom
zahT3:bug-9801-stale-crypto-future-funding-rate
Open

zahT3 wants to merge 1 commit into
QuantConnect:masterfrom
zahT3:bug-9801-stale-crypto-future-funding-rate

Conversation

@zahT3

@zahT3 zahT3 commented Sep 16, 2026

Copy link
Copy Markdown

Description

Stop applying Binance/Bybit/dYdX crypto-future funding from a cached MarginInterestRate once the security is no longer receiving current market data.

MarginInterestRate is auxiliary data and can intentionally be reused across multiple funding applications at coarser resolutions (for example, the existing daily regression). The fix therefore checks the security's last market data via Security.GetLastData() instead of comparing each cached funding point against every 00:00/08:00/16:00 window. When the market data is stale, the model skips the current funding application and realigns _nextFundingRateApplication so a later data point is not retrospectively charged for missed intervals.

Related Issue

Fixes #9801

Motivation and Context

For a delisted or settled Binance contract, the data feed stops but Security.Cache keeps returning the last MarginInterestRate. The model previously reused that final rate indefinitely. In the reported A2ZUSDT backtest this turned a small Binance-implied funding cost into a large, repeated charge after the contract's data ended.

The guard is deliberately based on market-data freshness rather than a per-interval timestamp comparison on the auxiliary rate. A per-interval comparison was tested first and failed the existing daily funding regression because it reduced the expected three applications to two. Existing hourly and daily funding behavior remains unchanged.

Requires Documentation Change

No.

How Has This Been Tested?

  • Added focused unit tests under Tests/Common/Securities/CryptoFuture/:
    • stale cached funding rate is not applied after market data stops;
    • a current funding interval with fresh market data still applies;
    • a new valid rate after stale data is applied once, without retrospective charges.
  • dotnet test Tests/QuantConnect.Tests.csproj --filter "FullyQualifiedName~BinanceFutureMarginInterestRateModelTests": 3/3 passed.
  • dotnet test Tests/QuantConnect.Tests.csproj --filter "FullyQualifiedName~QuantConnect.Tests.Common.Securities.CryptoFuture": 24/24 passed.
  • Local regressions with CryptoFutureDailyMarginInterestRegressionAlgorithm and CryptoFutureHourlyMarginInterestRegressionAlgorithm both completed with their expected statistics (daily end equity 1000206.40; hourly end equity 1000207.90).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

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.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

@zahT3

zahT3 commented Sep 16, 2026

Copy link
Copy Markdown
Author

The CI workflows are currently waiting for first-time-contributor approval (action_required). Local verification is complete: the 3 focused tests passed, the full CryptoFuture test namespace passed 24/24, and the existing daily/hourly margin-interest regressions both matched their expected statistics. Please approve the workflows when convenient.

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.

Crypto future funding keeps being applied from a stale cached MarginInterestRate after the contract's data ends

1 participant