Hi, i'm trying to do something fairly simple but somehow i can't do it and this is driving me crazy so if somebody can explain to me how to do it, i'd be grateful. i am trying to retrieve the close price for all symbols in nasdaq and display it to the console but it just crashes when i try to display the close price. here is the error message :
Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the 'pandas.core.series.Series'>) method. Please checkout the API documentation.
at OnData
self.Debug("past_close_price vaut " in main.py: line 68
Also i don't manage to display the whole df in the console i always get the 3 dots, i dont know how to increase the number of strings it can display, if somebody knows how to do that also it would be helpful.
Here is my code :
def Initialize(self):
self.nasdaq100 = ['AAPL', 'GOOG', 'MSFT', 'AMZN', 'FB', 'NVDA', 'TSLA'…]
def OnData(self, data: Slice):
if not self.Portfolio.Invested:
df = self.History(self.nasdaq100, start_time, end_time, Resolution.Daily)
df_close = df.close
self.Debug(df)
self.Debug(df_close)
for symbol in self.nasdaq100:
for i in range(100):
past_close_price = df_close.loc[self.nasdaq100[i]]
self.Debug("past_close_price is worth ", past_close_price)
#… doing a bunch of other things
Mia Alissi
Hi Matthieu,
It seems like you're trying to access the close prices of all symbols in the NASDAQ 100. From the error message, it appears that there might be an issue with how you're trying to access the close prices from the DataFrame.
Here's how you can access the close prices for all symbols:
This will transform the DataFrame so that the column indices are the
Symbol
of each ticker and each row contains the close value. You can then access the close price for a specific symbol like this:Regarding the display of the whole DataFrame in the console, pandas has a setting that limits the maximum number of rows and columns displayed. You can change this setting as follows:
This will remove the limit on the number of rows and columns displayed. However, please be aware that displaying a large DataFrame in the console might be slow.
Here's how you can modify your code:
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.
Matthieu Chaintron
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!