Hey everyone,
I've been coding a spot-future arbitrage strategy for Binance. It uses an universe selection to find matching Spot & Future Crypto Pairs, then simultaneously shorts one market and longs the other to capture the spread.
Unfortunately, it's impossible to backtest with Quantconnect.
The core issue is that LEAN's single portfolio model doesn't match the reality of Binance, where Spot Margin and Futures are completely separate accounts with their own collateral. The backtest unrealistically pools the margin and PnL, making the results unreliable. I think in live mode it would fail because of this limitations.
It's a fundamental limitation for this type of cross-wallet strategy. Just wanted to share the concept and this finding. I've attached a 3-Months backtest to show the potential.
Mia Alissi
Here are non-naming, non-allocation, non-import bugs or issues found in Michael's Main.cs logic:
Portfolio Separation Limitation: As described in the question, this approach cannot reliably simulate separate Spot and Futures portfolios on QuantConnect as margin and PnL are always pooled, so individual Spot/Futures collateral logic is not enforced.
Potential Bug in Spot Symbol Construction: In HandleDifferentCurrencySecurities, you assume the spot symbol is always {pairKey}{_spotQuoteCurrency}. This could break for assets with uncommon tickers or those delisted/renamed on Binance.
Market Order Filling Assumption: The code issues spot and future orders in immediate succession without checking first fill completion. Due to possible slippage or partial fills, a more robust implementation would await confirmations before proceeding with the next leg to reduce legging risk.
Use of Portfolio.MarginRemaining for Both Legs: Spot and future margins are handled separately in real Binance accounts. Here, Portfolio.MarginRemaining will not distinguish, so both legs could be rejected or partially filled in real-world use.
Catch-all Silent Exception Handling: In both HandleSameCurrencySecurities and HandleDifferentCurrencySecurities, empty catch blocks hide essential errors (e.g., symbol mapping failures), making debugging impossible in production use.
GetDecimalPlaces Implementation: Your GetDecimalPlaces method attempts to deduce decimal places using bit manipulation of a decimal, but this is not a robust or safe way to infer decimal precision for assets. The MinimumPriceVariation property may not reliably reflect decimal precision in all edge cases.
Null Handling Inconsistency: Several places (such as when removing or liquidating pairs) use checks like if (futureSymbol != null) without confirming that the corresponding dictionary value exists, which could cause NullReferenceExceptions if a symbol was removed elsewhere first.
Dust Detection Inconsistency: You add to _knownDustPairs if a holding is below liquidation thresholds, but you never clear this marker after dust is cleaned up, so pairs may become permanently untradable even if dust is removed.
No Check for Valid Contract Multiplier: In the trade entry method, if multiplier is zero (illiquid contracts, or data feed issues), you proceed without error—ideally this should be caught and handled gracefully.
Lack of Logging/Error Notification: Most error and trade path branches are silent; you may want to add Debug() or Log() statements to facilitate diagnosing missing trades, failures to liquidate, or mismatch in symbol sync.
Note: These are logic issues or QuantConnect model risks—some simply echo the platform limitation Michael described, while others are edge-case bugs/misassumptions. None are about naming, allocation, nor using statement issues.
Sources: Opening Range Breakout for Stocks in Play, Piotroski F-Score Investing, Key Concepts - QuantConnect.com
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Michael Hofer
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!