Just sharing some Sunday hacking fun - a framework for building and testing signals which tracks and manages each signal as a trade; closing out the contract for each separately.
In this example I've made it a "support and resistance" signal - when there are whole numbers that provide a psychological resistance on growth or support on falling. I coded it up 2 months ago and then left it since March 7th and it's OK in the rebound.
This is intended to help those seeking help "tracking trades". With LEAN you can build any style of strategy. The key concept I'd recommend taking away here is a strong separation of concerns - pull apart the parts of your code into classes and it makes the algorithms very tidy and easy to evolve your strategy. In this case, we've made a TradeManagement class to track each "trade".
- TradeManagement - tracking positions for PnL and exiting when near expiry.
- Levels - our signal file in this scaffold; providing the direction to trade.
- Main - just using trade/levels to orchestrate the strategy.
Jared Broad
The same backtest extended for 2 months with 1 bug fix on the new data
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.
.ekz.
Nice one. I'm in the middle of refactoring my options order management, and there are some things here I didn't think about. Thanks for sharing.
Jared Broad
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!