Hi there,
I am having a weird issue with my quantconnect csharp script. It generally runs fine but what I find is that a bit later on in the time frame it throws an error that expiry dates don't match. I codded this so that it only does put spreads at the same expiry.
Do you know how I can fix this or mitigate the issue so it finds the right contracts with the same expiry?
Do you know why my stop losses are not working?
Derek Melchin
Hi Rajats179,
The contract selection logic allows the selection of a `_longPut` and `_shortPut` with different expires.
foreach (var contract in chain.Contracts.Values) { if (!(contract.Expiry.Date > w1 && contract.Expiry.Date < w2)) continue; var shortDiff = shortDelta - contract.Greeks.Delta; if (shortDiff < deltaShortDiff && shortDiff > 0) { deltaShortDiff = shortDiff; _shortPut = contract; } var longDiff = longDelta - contract.Greeks.Delta; if (longDiff < deltaLongDiff && longDiff > 0) { deltaLongDiff = longDiff; _longPut = contract; } }
One way to resolve this would be to create two lists, one sorted by `shortDiff` and one sorted by `longDiff`. Then select the contracts that minimize these values and have the same expiry.
The stop loss orders seem to be functioning properly. See the attached backtest logs for reference.
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.
Rajats179
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!