Incorrect values for SMA

When I run this code in initialize:


self.spy = self.Securities["SPY"].Price

self.spy_mavg = self.SMA("SPY", 10, Resolution.Daily, Field.Close)

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!

Update Backtest


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).


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?


Update Backtest


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.


This discussion is closed