LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
If portfolio drawdown from start of day is below a threshold set all holdings to 0
Also don't enter into any new transactions for the rest of the day
I could do the portfolio drawdown check in a RiskManagementModel, the problem is that I need a way to clear all the ActiveInsights so that the algorithm does not make additional transactions based on them. I can't emit insights in the risk model because the RiskModel is executed inside the ProcessInsights loop and EmitInsights would kick off another ProcessInsights loop.
So I decided to do it in my alpha model and check for drawdown as a first step in the Update process. I set the Insights to flat and the Portfolio Target to 0 on the holding. This does not work though. Setting the portfolio target does nothing because it will be overwritten by the targets created from the Insights. However the targets created from the flat insights do not cause the sale of the holdings.
It seems at this point the only way to implement this will be with a custom PortfolioConstructionModel. Any recommendation or suggestions would be welcomed.
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.
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.
The most elegant solution is to implement it in a RiskManagementModel. In general, it is good practice to keep the AlphaModel's calculations independent of the contents of the portfolio. It is also good practice to limit AlphaModel to emitting insights and not calling Liquidate within that class.
0
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.
I tried my best to do that. The challenge is that the risk management model cannot expire the insights, so even if it sets the portfolio targets to 0 and exits the position, it will simply re-enter based on the unexpired insights. This is also a problem with the current RiskManagementModels, not just the one I want to implement.
We had a thread in Slack about it and there was some discussion about the best way to handle this going forward. Jared suggested adding the ability to expire insights.
Thanks, KC we've added a Github issue for expiring insights and will get there ASAP.
If you can post a mock example of the risk model getting ignored it would help debug this. I think the model's outputs are meant to be "pulsing" not "steady-state", so if something is getting overridden/ignored we might need to really look into why.
Also really consider if you need the framework; if you need to control each trade you might not want to use the framework scaffolding.
0
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.
Jared Broad Here is a backtest that shows the issue. A UGAZ insight is generated at 9:31 and the framework enters the position. The risk model exits the position shortly past 10am. At 12pm we generate an insight for DGAZ. At that point the framework enters an equal position on both DGAZ and UGAZ because the UGAZ insight has not expired.
I think the crux of the issue is that sending in additional insights for any security causes ProcessInsights to execute and it continues to use all unexpired insights, regardless of what the Risk Management Model has done.
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.
Loading...
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!
You do not have enough QC Credit to send this award, get a QC Credit Pack
here.
Award Sent Successfully
Thank you for giving back to the community.
Processing...
Choose a Credit Pack
Payment Confirmation
QuantConnect Credit (QCC) can be applied to your cloud-invoices or
gifted to others in the community with Community Awards in recognition of their contributions.
Community Awards highlight the awesome work your fellow community members are doing and inspires
high quality algorithm contributions to the community. Select an option below to add
QuantConnect Credit to your account:
$5
500 Credit Points
 
$10
1,000 Credit Points
 
$18
2,000 Credit Points
10% bonus
$45
5,000 Credit Points
10% bonus
03/23XXXX XXXX XXXX 0592
We will charge your default organization credit card on file, click
here to update.