Greetings! I'm very new to algorithm trading, and wanted to share something I've been working on to both solicit feedback, and to serve as an example for others who want to do forex bracket orders using the Algorithm Framework.
I've attached an example backtest of a project I cobbled together from various sources (though much of it is based on a C# port of Thom Yorke's Python legacy algorithm code). I'm still very new to QuantConnect and the QC API, so I may not have the execution exactly right. I would appreciate any feedback I can get from more experienced QC developers!
Spacetime
should check if riskPerUnit is not zero before using itÂ
File: ExampleForexRiskManagementModel.cs
Line: maxQuantityRisk = Math.Round(maxRiskPerTrade / riskPerUnit, 0);Â
John Cardenas
spacetime - That's a fair example of a case where I should be applying defensive programming, thanks! Given that this is within the risk management model, perhaps the proper way to handle an inability to calculate riskPerUnit would be to simply drop the trade. What isn't clear to me about the Algorithm Framework is when RiskManagementModel.ManageRisk() is called. If it occurs before the execution model fires off the trade, this would be fine. However, if the trade is executed first, and then risk management fires, perhaps this needs a rethink.
John Cardenas
I found the section of code relevant to how risk management is applied. Risk management occurs after portfolio selection, and if a risk management model exists, it always triggers before reaching the execution model. The graphic on the Algorithm Framework documentation led me to believe it was interacting with only the execution model.
I've attached a 1.1 version of the code. I'd appreciate any feedback!
John Cardenas
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!