During the backtesting my strategy, I can't get the full daily data for anything except the ‘SPY’. Always got the same error as:
maybe I'm missing sth but I thought even in the free version, we should have also access to the full data of other instruments such as ‘AAPL’ or ‘QQQ’, no?
this is my OnData function:
def OnData(self, data: Slice):
if not self.spy in data:
return
price = data[self.spy].Close
Mia Alissi
Based on the information provided in the extracts, it seems like you're trying to access data for a symbol (in this case 'SPY') in your
OnData
function. The error message you're seeing suggests that the data for 'SPY' is not available in theSlice
object at the time yourOnData
function is called.This could be due to a number of reasons. One possibility is that there's no data available for 'SPY' for the dates you've specified in your backtest. This could be because the data is not available in QuantConnect's data library for those dates, or there might be an issue with the data subscription in your algorithm.
In your
OnData
function, you're checking if 'SPY' is in theSlice
object and if it's not, you're returning from the function. This is a good practice as it ensures that you're not trying to access data that is not available. However, if you're seeing the error message, it means that 'SPY' is not in theSlice
object when yourOnData
function is called.You might want to check the dates and make sure that data for 'SPY' is available for those dates in QuantConnect's data library. If the data is available and you're still seeing the error, there might be an issue with how you're subscribing to the data in your algorithm.
As for your question about the availability of data for other instruments like 'AAPL' or 'QQQ', QuantConnect does provide data for these instruments. However, the availability of data might depend on the specific dates you're interested in and the resolution of the data you're requesting.
Here is an example of how you can check if a symbol is in the
Slice
object in yourOnData
function:In this example,
self.symbol
is the symbol you're interested in (e.g., 'AAPL' or 'QQQ'). This code checks ifself.symbol
is in theSlice
object and if it is, it retrieves the data forself.symbol
.If you're still having issues, you might want to check the QuantConnect documentation for more information on how to work with data in QuantConnect.
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.
Dash
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!