Hi,
I was trying to run below code in research platform during US trading hours (11:30AM EST). However, the History() returns empty dataframe for all the symbols in sym_list. Before the trading hour, it seems to be working for a few of the symbols (ex. AAPL, ADBE, ADM), but most the symbols still not working. Wonder what's the problem with this? Thanks.
sym_list = ['MOS', 'NVDA','AAPL','INTC','AMD','META']
for sym_str in sym_list:
trade_bars_df = qb.History(TradeBar, sym_str, 5)
display(trade_bars_df) # <-- all the df are empty
Mia Alissi
Hi Stanley,
The
History
method in QuantConnect is used to retrieve historical data for a given symbol. If there is no data in the period you request, the history result is empty. This could be the case if the market is closed at the time you're making the request or if the symbol doesn't have data for the requested period.In your case, you're requesting the last 5 bars of data for each symbol in your list. If you're running this during trading hours and still getting an empty DataFrame, it's possible that the data for the current trading day hasn't been recorded yet.
Also, please note that the
History
method expects aSymbol
object as the first parameter, not a string. You might need to convert your string symbols toSymbol
objects before passing them to theHistory
method.Here's how you can do it:
If you're still getting empty DataFrames, you might want to check if the symbols you're requesting data for are available in the data you have. You can do this by checking your data directory or by using the
AddEquity
method to add the symbols to your algorithm before making the history request.If you're running the Research Environment on your local machine and history requests return no data, check if your data directory contains the data you request. To download datasets, see Download.
I hope this helps! Let me know if you have any other questions.
Sources:
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.
Stanley
Hi Mia,
Thanks for getting back. I tried your solution, but it seems I can't create symbol for these: 'MOS', 'NVDA','INTC','AMD','META'
I am getting `InvalidOperationException` error when try to create a Symbol object using `qb.Symbol(sym_str)`.
What could be wrong? These are very popular symbol and exist.
Mia Alissi
Hi Stanley,
I apologize for the confusion. The
qb.Symbol()
method is not used to create a Symbol object from a string. In QuantConnect, Symbol objects are used to uniquely identify securities. These are class objects which encode all the information required to uniquely identify a symbol.When you want to use a specific ticker symbol, you can use the
AddEquity()
method to add the symbol to your algorithm. This method returns aSecurity
object, and you can get theSymbol
object from theSecurity
object.Here's how you can do it:
Please note that the
AddEquity()
method should be called in your algorithm'sInitialize()
method. If you're using the Research environment, you might need to use a different approach to get theSymbol
object.If you're still having trouble, it might be helpful to check out the QuantConnect Documentation and the QuantConnect Forum for more information and examples.
Sources:
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.
Stanley
I can run now. But now I am getting 'Failed to connect to the remote Jupyter Server 'https://node02.research.quantconnect.com/user/xxx/xxxx'. Verify the server is running and reachable.' error. There's one cell executing runs much longer (about 10min).Then I got this error message and the run just stopped. What could be wrong?
Mia Alissi
Hi Stanley,
The error message you're seeing suggests that there might be a problem with the connection to the remote Jupyter server. This could be due to a network issue, or it could be that the server is not running or not reachable for some reason.
If you're running a local Jupyter server and you're seeing this error, it could be that the server has stopped running or that there's a problem with your network connection. You might want to check if the server is still running and if your network connection is stable.
If you're running a remote Jupyter server, the server might be down or there might be a problem with the network connection between your machine and the server. You might want to check if the server is up and running and if there are any network issues that could be causing the problem.
If you're running a notebook and it's taking a long time to execute a cell, it could be that the operation you're performing is resource-intensive and is taking a long time to complete. If this is the case, you might want to consider optimizing your code or using a more powerful machine.
If you're still having trouble, you might want to check out the QuantConnect Documentation and the QuantConnect Forum for more information and examples.
Sources:
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.
Stanley
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!