missing hourly quote of spy and stockplot data is empty
error log : Backtest Handled Error: Data Missing on: 2023-12-15 00:00:00
Received backtest 'Dancing Magenta Tapir' request
44
|
8:43:53
:
Initializing algorithm...
45
|
8:43:53
:
Launching analysis for 3b827b694df04a38d47b781dd14a2f01 with LEAN Engine v2.5.0.0.16267
46
|
8:43:53
:
Backtest Handled Error: Data Missing on: 2023-12-15 00:00:00
47
|
8:43:53
:
Algorithm '3b827b694df04a38d47b781dd14a2f01' completed
48
|
8:43:53
:
Algorithm Id:(3b827b694df04a38d47b781dd14a2f01) completed in 0.58 seconds at 0k data points per second. Processing total of 289 data points.
49
|
8:43:53
:
Backtest deployed in 9.798 seconds
source code:
from AlgorithmImports import *
# endregion
ticker="SPY"
class MACDTrendAlgorithm(QCAlgorithm):
def Initialize(self):
#self.ticker="SPY"
#self.SetStartDate(2022, 1, 1)
self.SetStartDate(2023, 12, 1)
self.SetEndDate(2024, 1, 1)
self.SetCash(1000) # Find more symbols here: http://quantconnect.com/data
self.symbol=self.AddEquity(ticker, Resolution.Hour)
# define our daily macd(12,26) with a 9 day signal
self.__macd = self.MACD(ticker, 12, 26, 9, MovingAverageType.Exponential, Resolution.Hour)
self.__previous = datetime.min
self.PlotIndicator("MACD", True, self.__macd, self.__macd.Signal)
self.PlotIndicator(ticker, self.__macd.Fast, self.__macd.Slow)
self.crossupTOLERANCE = 0
self.crossDownTOLERANCE= 0
#self.crossupTOLERANCE = 0.002
#self.crossDownTOLERANCE= 0.002
stockPlot = Chart('Trade Plot')
from System.Drawing import Color
stockPlot.AddSeries(Series('Price', SeriesType.Line, '$', Color.Green))
stockPlot.AddSeries(Series('Buy', SeriesType.Scatter, '$', Color.Red, ScatterMarkerSymbol.Triangle))
stockPlot.AddSeries(Series('Sell', SeriesType.Scatter, '$', Color.Blue, ScatterMarkerSymbol.TriangleDown))
self.AddChart(stockPlot)
def OnData(self, data):
if not self.__macd.IsReady: return
if data[self.symbol.Symbol]:
self.Plot("TEST", "CLOSE", data[self.symbol.Symbol].Close)
tolerance = 0.0025
holdings = self.Portfolio[ticker].Quantity
price=data[ticker].Close
signalDeltaPercent = (self.__macd.Current.Value - self.__macd.Signal.Current.Value)/self.__macd.Fast.Current.Value
if holdings <= 0 and signalDeltaPercent > self.crossupTOLERANCE: # 0.01%
self.Log(f"Buying SPY | Holding: {holdings} | Delta%:{signalDeltaPercent} | UP_Tolerance{self.crossupTOLERANCE}")
self.SetHoldings(ticker, 1.0)
self.Plot(ticker, "Buy", price)
elif holdings >= 0 and signalDeltaPercent < -self.crossDownTOLERANCE:
self.Log(f"Selling SPY | Holding: {holdings} | Delta%:{signalDeltaPercent} | DOWN_Tolerance{self.crossDownTOLERANCE}")
self.Liquidate(ticker)
#self.SetHoldings("SPY", -1.0)
self.Plot(ticker, "Sell", price)
else:
self.Log(f"Nothing | Holding: {holdings} | Delta%:{signalDeltaPercent} | UP_Tolerance{self.crossupTOLERANCE} | DOWN_Tolerance{self.crossDownTOLERANCE}")
else:
self.Error(f"Data Missing on: {self.Time}")
Mia Alissi
Based on the information provided in the extracts, it seems like the issue "Replyxf" is facing with missing hourly quote data for "SPY" and an empty stock plot could be related to how data is being accessed and handled within the algorithm. While the extracts do not directly address the specific issue of missing data for "SPY" on the date mentioned, they do offer insights into common issues and solutions when dealing with data in QuantConnect.
One potential issue could be related to how data is being checked before it's used. As mentioned in one of the extracts, ensuring that data for a specific symbol is available before attempting to access it is crucial. This is highlighted in the extract discussing the importance of checking if data contains the symbol key before proceeding with operations on the data:
Applying a similar check in "Replyxf's" algorithm could help prevent attempts to access data that isn't available, which might be causing the error. Specifically, before accessing
data[self.symbol.Symbol].Close
and performing operations based on it, ensuring thatdata.ContainsKey(self.symbol)
could prevent the error if the data for "SPY" is missing at certain times.Additionally, the issue with the stock plot being empty could be related to how or when the plotting functions are called. Ensuring that plotting functions are called only when valid data is available and after any necessary checks could help in displaying the intended plots.
While these suggestions are based on the general advice and examples provided in the extracts, without direct access to the specific details of the error log and the complete context of "Replyxf's" algorithm, it's challenging to provide a precise solution. If these suggestions do not resolve the issue, it might be beneficial to reach out directly to QuantConnect's support or consult the community forums for more targeted assistance, especially since the extracts mention the utility of community resources and support channels for troubleshooting.
For further assistance and more detailed guidance, consulting the QuantConnect Documentation and the community forums could provide additional insights and solutions tailored to the specific issues encountered.
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.
Replyxf
in addition, macd hourly chart seems to be daily:
Replyxf
how to generate macd hourly chart, self.__macd = self.MACD(ticker, 12, 26, 9, MovingAverageType.Exponential, Resolution.Hour) doesn't work
Ashutosh
Hi replyxf
Thank you for bringing up your query. Your implementation of MACD is correct.
QuantConnect provides interactive charts so if you zoom in to the MACD chart you will be able to see the hourly resolutions.
You can even get minute resolutions if you set the resolution as minute.
The missing data alert is at 00:00:00 which does not break anything. There is data available for the rest of the day and QuantConnect handles it internally while updating prices in the indicators.
Let me know if this helps!
Best,
Ashutosh
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.
Replyxf
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!