Hi, I am trying to calculate VWAP where it uses all data from the beginning of each day (including premarket), and resets after each day. I saw this post:
https://www.quantconnect.com/forum/discussion/2681which seems to have a solution and also seems to be almost the same question as mine. However I am having difficulty implementing the indicator in my own code. It does not seem to be resetting after each day, or if it is it is still using data from the previous day. I also tried using the Reset() method from the documentation (https://www.quantconnect.com/lean/documentation/topic29400.html) but I don't think it is doing what I expect either. I attached a backtest (which is based off of the responder's backtest here
https://www.quantconnect.com/forum/discussion/9927/difficulty-adding-leverage-when-using-coarseselectionfunction/p1), the code meant to reset VWAP is on lines 99-101 and 124-126. If someone knows the issue it would be greatly appreciated if they could offer guidance. Thanks.
Derek Melchin
Hi Dahui,
The reason the indicator isn't resetting properly is because the definition of OnEndOfDay is indented too far. In addition, when setting up indicators for a dynamic universe, we should create the indicators manually (`VolumeWeightedAveragePriceIndicator`) instead of using the shortcut methods (`self.VWAP`). This allows us to remove the data subscription when the symbol is removed from the universe.
See the attached backtest for reference.
Best,
Derek Melchin
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.
Dahui
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!