ExecuteMarginCall can liquidate the same deficit across several groups in one batch
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Description
DefaultMarginCallModel.ExecuteMarginCall can submit multiple liquidations for the same margin deficit within its first execution batch, even when the first pending order would already cover the whole deficit. This is separate from generating duplicate orders for the same group on later scans (#10008).
GetMarginCallOrders sizes every position group's request from the same current portfolio deficit. ExecuteMarginCall submits a group and calls SecurityTransactionManager.WaitForOrder, but ignores its false return when the wait times out. If the order is still open, holdings and MarginRemaining are unchanged, so execution continues to the next group and submits another order covering the same deficit.
In backtesting, MarketOrderFillTimeout is zero, and market orders on daily subscriptions can remain open until the next bar. Thus multiple distinct groups can all be liquidated for the same deficit during a single margin call, even without any subsequent scans.
Reproduction and observed result
Reproduced locally with a temporary NUnit test in MarginCallModelTests, using the existing portfolio/security helpers and FakeOrderProcessor:
- Create two distinct USD equity positions, SPY and AAPL, each holding 100 shares at a current price of $100 and leverage 2. Use zero fees and set cash to -$14,000.
- Use
DefaultMarginCallModelwith its default margin buffer and setportfolio.Transactions.MarketOrderFillTimeout = TimeSpan.Zero. - Verify portfolio value is $6,000, maintenance margin is $10,000, and the deficit is $4,000.
- Call
GetMarginCallOrders, then callExecuteMarginCallexactly once, leaving submitted orders open.
Observed:
- Generation returns one request for each group, each selling 81 shares.
- A single execution submits both requests, returning two tickets.
- Each sale releases $4,050 of margin at current prices; combined projected relief is $8,100 against a $4,000 deficit.
- An assertion expecting only one submitted liquidation fails:
Expected: 1, But was: 2.
The reproduction fails identically on master (da4d8e4a4) and on 6dd4b06d1; this is a pre-existing execution/sizing problem, not a regression introduced by the pending-ticket guard.
Tested end to end with daily SPY and minute AAPL as well: AAPL's liquidation can fill while a further SPY liquidation is already being submitted from the same unchanged deficit snapshot.
What a fix must achieve
Avoid committing the entire deficit more than once when multiple position groups are processed in one margin call. Continue to allow additional liquidation when pending orders cannot cover the deficit, preserve combo-order grouping, and handle cancellation/rejection without leaving the portfolio indefinitely under-margined.
One possible approach is to account for pending reductions when deciding whether and how much to liquidate from the next group, rather than assuming a timed-out wait means the first liquidation has completed.
- Ngôn ngữ chính
- C#
- Star
- 22.5k
- Fork
- 5.4k
- Merge trung bình
- 22 giờ 6 phút
- Pull request đã merge (30 ngày)
- 81
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của QuantConnect/Lean
-
PDF report generation can overwrite HTML when the destination extension is not lowercase .htmlĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
QuantConnect/Lean#10082 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
QuantConnect/Lean#10059 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Library Request: highspyĐang mởlibrary-request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
QuantConnect/Lean#10034 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
QuantConnect/Lean#9965 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
QuantConnect/Lean#9955 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của QuantConnect/Lean
Issue tương tự
-
bug emitter:client:csharp
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
microsoft/typespec#12572 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-area-label
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
AWS Lambda: KeyNotFoundException drops HTTP-triggered transactions when allowAllHeaders is disabledĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
newrelic/newrelic-dotnet-agent#3949 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area-networking
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
dotnet/aspnetcore#70545 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 87/100
Maintainer thường phản hồi trong vòng 1 ngày