Open tommifi opened 4 years ago
Hi @tommifi!
The functionality you are proposing is not done yet, since the retrieval function just admits one stock symbol per request, which means that just one str
can be sent as stock
parameter. Anyways, the improvement you are proposing will be evaluated, and if aproved, it will be available in next releases via allowing stock
parameter to be a list
of stock symbols in order to retrieve more than one stock pandas.DataFrame
of historical data.
Currently, here is the solution to retrieve more than one stock historical data pandas.DataFrame
and add them into a list
of stock historical data objects:
import investpy
stocks = ['AAPL', 'GOOG']
dfs = list()
for stock in stocks:
df = investpy.get_stock_historical_data(stock=stock,
country='united states',
from_date='01/01/2010',
to_date='01/01/2019')
dfs.append(df)
Hope this helped you! :octocat: Stay tunned for future updates on this issue!
Hi @tommifi!
Just let you know that this issue will not be worked on for now, since currently using a for loop
seems to be enough. Anyways, if you think that this issue is a relevant feature to include in investpy just let me know and I will re-open the issue whenever I have time to include it.
Thank you for the support! :star: :octocat:
Hi Alvaro,
Could you please write the complete code from
extracting multiple stocks historical data (AAPL, GOOG)
structure the data under Column 'AAPL','Date','Open','High','Low','Close','Volume','Currency',GOOG','Date','Open','High','Low','Close','Volume','Currency'
export to CSV or Excel
I'm very new to programming. Appreciate your kind guidance and support along my learning journey.
Thanks in advance!
Sure @freddie3399! I'll try to prepare a sample Python code for you to do that 🤗
Can I also see that python code sample??
Sure! I'll try to share it with you later today as I'm currently working and I need to create that script from scratch! 👍🏻
Sure! I'll try to share it with you later today as I'm currently working and I need to create that script from scratch! 👍🏻
Hi Alvaro! Were you able to write the code? I'm looking forward to hearing from you!
Hi @gahoccode, sorry I forgot to share that code, I'll try to prepare a simple code to achieve that so that you can use it! :hugs:
Anyway, could you please share with me what do you exactly want? Is it something like:
- [AAPL,GOOG]
- Retrive latest stock information
- Append both DFs
- Save DF as Excel File
Hi @gahoccode, sorry I forgot to share that code, I'll try to prepare a simple code to achieve that so that you can use it! 🤗
Anyway, could you please share with me what do you exactly want? Is it something like:
- [AAPL,GOOG] - Retrive latest stock information - Append both DFs - Save DF as Excel File
So just as what @freddie3399 said, I'd like to see how you 1.extracting multiple stocks historical data (AAPL, GOOG)
2.structure the data under Column 'AAPL','Date','Open','High','Low','Close','Volume','Currency',GOOG','Date','Open','High','Low','Close','Volume','Currency'
I tried to pull 2 stocks by applying the code you gave but the result turns out not quite what I expected. It seems that it only pulls either pull only 1 of the 2 or include prices in one column. I'd like to separate price by stock column. Trying to do a percent change calculation for multiple stocks in a table. Thanks!
Hi @gahoccode, sorry I forgot to share that code, I'll try to prepare a simple code to achieve that so that you can use it! 🤗
Anyway, could you please share with me what do you exactly want? Is it something like:
- [AAPL,GOOG] - Retrive latest stock information - Append both DFs - Save DF as Excel File
Hello there Alvaro, I too had the same query. I tried your earlier vode of for loop but it shows run time error 520. I am not sure you are aware but there is a similar library nsepy which I used for Indian markets it distinguishes stocks very diligently under different columns and we can append the list with ease
Hi Alvaro, I am able to get historical data on one stock per each request. But I can not get historical data for multiple stocks in a single request. Here below the code I used:
tickers = "aapl, goog"
df = investpy.get_stock_historical_data(stock=tickers, country='united states', from_date='01/01/2010', to_date='01/01/2019')
Here below the error:
Traceback (most recent call last): File "C:\Users\tommaso\miniconda3\envs\3.7\lib\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 4, in
to_date='01/01/2019')
File "C:\Users\tommaso\miniconda3\envs\3.7\lib\site-packages\investpy__init__.py", line 522, in get_stock_historical_data
raise RuntimeError("ERR#0018: stock " + stock + " not found, check if it is correct.")
RuntimeError: ERR#0018: stock aapl, goog not found, check if it is correct.
Regards t