Ticker | Wrong data for SPY daily close price in SMA calculation |
Security Type | Equity |
Market | USA |
Resolution | Daily |
Status | Waiting Review |
Hi,
I'm new to Quant Connect and was building an algorithm that uses SPY 200-day SMA. However, I found that the value is different from what I knew was correct, and I went ahead and checked the daily close price for SPY and found that it uses "Adj Close" as the close.
Code:
# region imports
from AlgorithmImports import *
# endregion
class FormalMagentaKangaroo(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 3, 18) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.spy = self.AddEquity("SPY", Resolution.Daily).Symbol
self.spyMovingAvg200Day = self.SMA(self.spy, 200, Resolution.Daily, Field.Close)
def OnData(self, data: Slice):
currSpyPrice = self.Securities["SPY"].Price
self.Log("SPY 200-Day moving avg: " + str(self.spyMovingAvg200Day.Current.Value))
self.Log("SPY close price: " + str(currSpyPrice))
Here are the logs:
2022-09-10 00:00:00 : SPY close price: 404.93615214
2022-09-13 00:00:00 : SPY 200-Day moving avg: 422.534731576175
2022-09-13 00:00:00 : SPY close price: 409.288269663
2022-09-14 00:00:00 : SPY 200-Day moving avg: 422.179981080665
2022-09-14 00:00:00 : SPY close price: 391.49139549
2022-09-15 00:00:00 : SPY 200-Day moving avg: 421.884269450135
2022-09-15 00:00:00 : SPY close price: 392.98525734
2022-09-16 00:00:00 : SPY 200-Day moving avg: 421.538519148475
2022-09-16 00:00:00 : SPY close price: 388.523589948
2022-09-17 00:00:00 : SPY 200-Day moving avg: 421.222477046435
2022-09-17 00:00:00 : SPY close price: 385.56
and here's data from Yahoo:
It looks like the close price it's using is the same as Yahoo's "Adj Close", and this is also used in the SMA calculation. Is there a way that I use the actual close price to calculate SMA? Thanks!