Hi guys, I'm trying to identify the cause of the closing order filled on the 2005-1-21. The alpha model did not emit any new signals once it went long in the market around 2004-08 and I was not expecting it to flatten until the SMA casued ‘TurningDown’ to become True. I'm currently debugging the algorithm and the activeinsights variable gets cleared for some reason and so this results in target weights ending up to be 0 around that time [2005-1-21.] . I am failing to understand why the algorithm would be setting the active insights to empty, given that I am long in the market and hte flattening condition has not been met. I have tried stepping through while setting the rebalancing parameter to None, within the equal weighting construction model but that doesn't seem to fix matters. What mechanism is causing the activeinsights object to become a length(0) please? . Any ideas would be hugely helpful. Many thanks, Alun
Mia Alissi
Based on the information provided in the extracts, it's not entirely clear why the
activeInsights
variable would be cleared in your algorithm. However, there are a few possibilities that could be causing this issue:Insight Expiration: In QuantConnect, Insights have a duration and they expire after this duration. If no new Insights are generated and the old ones expire, the
activeInsights
list would be empty. You might want to check the duration of your Insights and when they are expected to expire.Portfolio Rebalancing: In the EqualWeightingPortfolioConstructionModel, the portfolio is rebalanced based on the active Insights. If the Insights go flat/down, the model should re-shuffle the capital to be fully allocated to the remaining active insights assets. If this is not happening as expected, it could be a potential issue.
Risk Management: If you have a Risk Management model that uses stop loss logic, it could be generating
PortfolioTarget
objects with a 0 quantity, causing the Execution model to liquidate your positions. This could potentially clear youractiveInsights
.Universe Selection: If the Universe Selection model is removing securities from the universe, and you are not emitting flat Insights for these removed securities, they could be removed from
activeInsights
.Without more specific information about your algorithm and its behavior, it's hard to provide a more precise answer. I would recommend checking these aspects in your algorithm to see if they could be causing the issue. If the problem persists, you might want to consider reaching out to the QuantConnect community or support for more specific 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.
Alun Thomas
I can see that the insights have expired. In that case, how do I a) extend this or b) switch this functionality off within the algorithm? I dont want the insights to expire.
Mia Alissi
In QuantConnect, the duration of an Insight determines when it will expire. If you want to extend the duration of an Insight, you can do so when you create the Insight. The duration is typically set as a parameter when creating an Insight. For example, in your Alpha Model, when you create an Insight, you can set the duration like this:
In this line,
self.predictionInterval
is the duration of the Insight. You can increase this value to extend the duration of the Insight.If you want to "switch off" the expiration of Insights, one way to do this is to set a very long duration when you create the Insight. However, please note that this might not be a good idea in a live trading scenario because it could lead to holding onto positions for a very long time based on outdated Insights.
Remember, the purpose of an Insight's expiration is to indicate the period over which the prediction is expected to be valid. If an Insight never expires, it implies that the prediction is always valid, which is unlikely to be true in a real-world trading scenario.
If you want to keep positions open even after Insights have expired, you might want to reconsider your Portfolio Construction Model. The Portfolio Construction Model is responsible for determining portfolio targets based on the active Insights. You could potentially customize it to keep positions open even after the corresponding Insights have expired. However, this would require careful consideration and testing to ensure it aligns with your intended 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.
Alun Thomas
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!