Skip to content

Fix concurrent futures margin history lookups - #10037

Open
mkzung wants to merge 1 commit into
QuantConnect:masterfrom
mkzung:bug-10036-future-margin-row-race
Open

mkzung wants to merge 1 commit into
QuantConnect:masterfrom
mkzung:bug-10036-future-margin-row-race

Conversation

@mkzung

@mkzung mkzung commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Description

Use a local search index for each futures margin lookup. Clamp the cached hint to the loaded history and search backward when a refreshed table moves the effective row.

Related Issue

Fixes #10036.

Motivation and Context

Concurrent first lookups can increment the shared index beyond the history, causing every later order on that security to fail. A shorter or reordered history after cache refresh can also return the wrong margin or throw.

Requires Documentation Change

No.

How Has This Been Tested?

Clean checkout of this commit, .NET 10.0.400 on macOS arm64, Python 3.12. All 75 futures margin tests pass. The full Common.Securities test set passes: 5,588 passed, 4 skipped.

The added tests cover concurrent lookups and cache replacement with shorter or shifted histories. Restoring the original implementation makes all three cases fail; restoring the fix passes the fixture again.

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 CONTRIBUTING.md.
  • I have added tests to cover my changes.
  • All new and existing tests in Common.Securities passed.
  • 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.

FutureMarginModel: concurrent first calls on one security push the margin row index past the table and every later call throws IndexOutOfRangeException

1 participant