Hi, I created this algo and it seem to be working fine back then when i backtested it.
However, now the algo cant seem to filter those contracts within the minimum timeframe that i indicated. Can someone please help!
QUANTCONNECT COMMUNITY
Hi, I created this algo and it seem to be working fine back then when i backtested it.
However, now the algo cant seem to filter those contracts within the minimum timeframe that i indicated. Can someone please help!
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.
Mia Alissi
Based on the provided code, it seems like the issue might be related to the filtering of option contracts within the minimum timeframe. In the
Initialize
method, the option filter is set with a minimum expiry of 648 days and a maximum expiry of 99999 days. However, in theOnData
method, there is a condition to liquidate the option if it is too close to expiration, specifically if the current time plus the maximum expiry (470 days) is greater than the option's expiry date.This could potentially cause an issue where the algorithm is trying to trade options that are about to expire, but they have already been liquidated due to the condition in the
OnData
method.Here is the relevant code:
To resolve this issue, you might want to adjust the maximum expiry in the
SetFilter
method to match the maximum expiry used in theOnData
method. This way, the algorithm will only consider options that are within the desired timeframe.Please note that this is just a potential issue based on the provided code. There might be other issues in the code that are not apparent from the provided extract.
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.
Muhammad Yusuf Bin Salleh
No, the on data method condition, is to liquidate the options that are left with the “maximum_expiry” which is 470 days. I would only like to trade options that are at least 2 years out. I dont see that there is potential issue with this.
Mia Alissi
I see, thank you for the clarification, Muhammad. If you want to trade options that are at least 2 years out, then your current filter in the
Initialize
method is correctly set with a minimum expiry of 648 days (which is approximately 2 years).However, in your
OnData
method, you are liquidating options that are left with 470 days to expiry. This means that you are liquidating options that still have more than a year left until expiry. If your intention is to hold options that are at least 2 years out, you might want to adjust this condition to match your minimum expiry time.Here is the relevant code:
You might want to change the
OnData
method to something like this:This way, the algorithm will only liquidate options that are less than 2 years out, which seems to be your intention. Please note that this is just a suggestion based on your clarification and the provided code. There might be other factors to consider depending on your specific trading strategy.
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.
Muhammad Yusuf Bin Salleh
No, i want it to liquidate ONLY if it has 470 days left. but the algo is filtering contracts that are less than 648 days which is what i do not want! It use to work perfectly, please assist; im running this live and dont want any issue with this
Mia Alissi
I see, thank you for the clarification, Muhammad. If your algorithm is filtering contracts that are less than 648 days, it might be due to the way the
SetFilter
method is being used.In your
Initialize
method, you have the following line:This line is supposed to filter the options to only include those with an expiry between 648 days and 99999 days. However, if it's filtering contracts that are less than 648 days, it might be due to an issue with how the
SetFilter
method is interpreting thetimedelta
values.One possible solution could be to explicitly define the
timedelta
values in days, like this:This will ensure that the
SetFilter
method correctly interprets the minimum and maximum expiry times in days.If this doesn't solve the issue, it might be due to other parts of the code that are not included in the provided extract. In that case, I would recommend checking the rest of your code to make sure there are no other parts that could be affecting the option filtering.
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.
Muhammad Yusuf Bin Salleh
it still doesnt work. I'm still trading contracts that are less than the minimum days.
Ashutosh
Hello Muhammad Yusuf Bin Salleh
I was checking out the code that you have provided with some debugging to check if the contracts are out of place.
Used a simple debugging check:
But none of the contracts were filtered as wrong contracts.
Will you be able to share an example of an out of place contract as mentioned by you that you are still trading contracts that are less than the minimum days.
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.
Muhammad Yusuf Bin Salleh
Hi Ash,
Yes, it works well for the first set of contracts (getting into the first trade in), however if you backtest it from 2017 (i.e); you will see that the subsequent trades are placed with options expiry lesser than the minimum condition.
Use the same code as above and run it from 2017 or 2018 onwards.
Muhammad Yusuf Bin Salleh
Hi All,
Ignore the above - for some reason it works now!
Muhammad Yusuf Bin Salleh
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!