Hello,
I'm backtesting a credit spread strategy and have some issues qualifying my backtests because the statistics are innacurate:
- The win / rate is wrong: my attached backtest shows 2 trend up days where I sell 1 PCS ATM which expires worthless each day. Despite that, the win rate is 50% win 50% loss. Average win and average loss and Profit-loss ratio are wrong too.
- At last day of backtest, latest spread is still marked as unrealized, it doesn't process the settlement for last day.
- Total orders shows 6 but I only bought 2 credit spreads so 4 contracts.
- Sortino ratio is 0
Thank you for your help!
Have a good one!
Derek Melchin
Hi Cedric,
Subscribe to the following GitHub Issue to follow our progress in addressing this problem:
Add TradeBuilder Strategy Support
Best,
Derek Melchin
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.
Cedric Tang
Thank you Derek. The issue above is not directly related to my problem (above is about TradeBuilder).
I noticed that even the OptionStrategies strategy are affected: with an optionStrategy like below, the win rate is wrong:
Alexandre Catarino
Hi Cedric,
Thanks for the well-isolated test case — all four observations have concrete explanations, and only the first one is a limitation we're tracking.
1. Win rate, average win/loss, profit-loss ratio. These statistics are computed from closed round trips per contract, not per strategy. Each credit spread therefore produces two "trades": the short put is a win (you keep its premium) and the long put is a loss (its premium is paid and expires worthless). One win plus one loss per spread is exactly the 50%/50% you see, and the average win/loss are per-leg figures. Grouping the legs of a multi-leg position into a single strategy-level trade is precisely what Add TradeBuilder Strategy Support covers — its description reads "Trade builder generates multiple 'trades' which mean stats are affected, 50% loss etc". The trade accounting is leg-based regardless of how the order is entered, which is why OptionStrategies helpers show the same win rate as combo_market_order — so despite the title, that issue is the right one to subscribe to for this.
2. Last spread left unrealized. Settlement of an expiring position is triggered by the contract's delisting event, which LEAN emits on the next trading day after expiry. Your backtest ends on the same day the last spread expires, so that event never fires inside the backtest window. Extend set_end_date at least one trading day past the final expiry and the last spread will settle and enter the statistics.
3. Total orders = 6. You placed 4 orders (2 legs × 2 spreads). When the first day's contracts expired worthless, LEAN generated 2 automatic option-exercise orders to remove those positions — you can see them in the Orders tab with an "OTM" message — and they count toward total orders: 4 + 2 = 6. The second spread's exercise orders would land on the day after the backtest ends, which is the same cause as point 2.
4. Sortino ratio = 0. Sortino divides by the downside deviation of daily returns, and LEAN reports 0 whenever that denominator is 0 (see PortfolioStatistics.cs). Over a two-day backtest that only collects premium there are no negative daily returns, so the statistic is defined as 0 rather than infinity. It will populate on longer backtests with at least one down day.
In short: point 1 is tracked in the issue above; points 2–4 resolve on their own once the backtest window extends past the final expiry.
Cedric Tang
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!