business-science / tidyquant

Bringing financial analysis to the tidyverse
https://business-science.github.io/tidyquant/
Other
852 stars 175 forks source link

get_dataframe function for multiple tickers with intraday prices #171

Closed MrHarBear closed 4 years ago

MrHarBear commented 4 years ago

I am a new user trying to get some intraday stock data. In the documentation, it says we could use get "any intraday frequency for both the get_ticker_price and get_dataframe methods", but I couldn't get it to work.

Please see the code I've used below. The objective is trying to pull multiple tickers with say 5min timeframe.

ticker_history = client.get_dataframe(['GOOGL', 'AAPL'],
                                      frequency='30Min',
                                      metric_name='adjClose',
                                      startDate='2017-01-01',
                                      endDate='2018-05-31')

Error I am getting

Traceback (most recent call last):

  File "C:\Users\chenh\anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2646, in get_loc
    return self._engine.get_loc(key)

  File "pandas\_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\hashtable_class_helper.pxi", line 1619, in pandas._libs.hashtable.PyObjectHashTable.get_item

  File "pandas\_libs\hashtable_class_helper.pxi", line 1627, in pandas._libs.hashtable.PyObjectHashTable.get_item

KeyError: 'GOOGL'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "<ipython-input-12-42944e325660>", line 5, in <module>
    endDate='2018-05-31')

  File "C:\Users\chenh\anaconda3\lib\site-packages\tiingo\api.py", line 270, in get_dataframe
    prices = pd.concat([prices, df[stock]], axis=1)

  File "C:\Users\chenh\anaconda3\lib\site-packages\pandas\core\frame.py", line 2800, in __getitem__
    indexer = self.columns.get_loc(key)

  File "C:\Users\chenh\anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2648, in get_loc
    return self._engine.get_loc(self._maybe_cast_indexer(key))

  File "pandas\_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\hashtable_class_helper.pxi", line 1619, in pandas._libs.hashtable.PyObjectHashTable.get_item

  File "pandas\_libs\hashtable_class_helper.pxi", line 1627, in pandas._libs.hashtable.PyObjectHashTable.get_item

KeyError: 'GOOGL'
chalg commented 4 years ago

tidyquant is an R package, have you tried using R?

MrHarBear commented 4 years ago

tidyquant is an R package, have you tried using R?

Yeah... I realized I posted in the wrong Github...