When I run this code in initialize:
self.AddEquity("SPY")
self.spy = self.Securities["SPY"].Price
self.spy_mavg = self.SMA("SPY", 10, Resolution.Daily, Field.Close)
self.SetWarmUp(20)
And this code on market open:
spy_price = float(str(self.Securities["SPY"].Price))
spy_mavg = float(str(self.spy_mavg))
if (spy_price < spy_mavg):
#run method code
The spy_mavg is significantly less than what I know is correct. What about the above code would cause the Simple Moving Average for SPY to be incorrect? Finaly tidbit: I'm running this code live to IBKR and using their data (I do have the appropriate subscription). Should run live using QC's data? Any help greatly appreciated. Thanks!
Douglas Stridsberg
Hi!
If you're able to attach a backtest, that would help enormously. I'm in particular interested in your start date (it could be trying to warm up using non-existent data). Also, what is the SMA value reported and what are you expecting? I'm interested in whether the difference is orders of magnitude (indicating missing data) or a few decimal points (indicating something more benign).
Eric Clymer
Part of the issue is that the data in backtests are correct and the data live trading is incorrect. Example: I using the same code for VXX I get a backtest value of 44 and a live trading value of 38. Any theories as to why there wouldn't be parody?
Jack Simonson
Hi Eric,
Looking at the code you posted above, it looks like the algorithm should set the value for the SMA to use Current.Value, otherwise it will return the same as the SPY price. Try running the code again using that and hopefully it will help solve the issue. Additionally, there is no need to convert the values for SPY price and SMA to strings and then back to floats -- these values are already floats and will work fine when using logical comparison of values. If this modification doesn't help fix the algorithm, attaching a backtest will better help the QuantConnect team or the community debug the issue.
Also, regarding the data inconsistencies you're encountering, please send your live algorithm with the deployment ID attached to support for assistance with your live questions.
spy_mavg = self.spy_mavg.Current.Value
Â
Eric Clymer
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!