QuantConnect / Lean

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
https://lean.io
Apache License 2.0
9.41k stars 3.2k forks source link

OptionStrategies fail silently when a contract is missing #8045

Open DerekMelchin opened 3 months ago

DerekMelchin commented 3 months ago

Expected Behavior

When we call one of the OptionStrategies functions, if it can't find the selected contracts in the OptionChain, it throws an error message.

Actual Behavior

It throws no error message. We only get an error message after we try to place the order.

Potential Solution

The leg 'SPY 210416C00390000' does not have an active subscription.

or

short_straddle = OptionStrategies.short_straddle(self._option_symbol, strike, expiry)
if short_straddle.is_tradable:
    tickets = self.buy(short_straddle, 1)

Reproducing the Problem

In this algorithm, the call contract is removed from the chain but the put contract remains in the chain. As a result, when I try to create the Option strategy the second time, I get

The security with symbol 'SPY 210416C00390000' is marked as non-tradable.

(and end up with a missing leg) https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_f06123357019037c268be2826cc9fb5d.html

2021-03-22 09:31:00 2021-03-22 09:31:00 - 0 in chain
2021-03-22 09:31:00 2021-03-22 09:31:00 - 1 in chain
2021-03-22 09:31:00 2021-03-22 09:31:00 - expiry: 2021-04-16 00:00:00; strike: 390.0
2021-04-12 06:30:00 2021-04-12 06:30:00 - exercised
2021-04-12 09:31:00 The security with symbol 'SPY   210416C00390000' is marked as non-tradable.
2021-04-12 09:31:00 2021-04-12 09:31:00 - 1 in chain
2021-04-12 09:31:00 2021-04-12 09:31:00 - expiry: 2021-04-16 00:00:00; strike: 390.0

System Information

QC Cloud

Checklist

Martin-Molinero commented 3 months ago

Believe this is related to https://github.com/QuantConnect/Lean/issues/6659, option strategies are just a blue print at the moment, they do no validation which happens later while using them, which is causing the reported behavior in this issue