如何在python中每天间隔获取每分钟/小时分辨率的库存数据

时间:2019-05-19 07:16:25

标签: python python-3.x

我进行了很多搜索,以了解如何才能在特定的几天之间以分钟的频率读取高分辨率的股票价格,但找不到太多。

以下应该起作用:

import fix_yahoo_finance as yf
data = yf.download(tickers='AAPL',start='2019-01-01',end='2019-01-03',interval = "1m")

根据:https://github.com/ranaroussi/fix-yahoo-finance/blob/master/README.rst 但这给我一个错误:

Traceback (most recent call last):
  File "C:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-330-5e5e1c98dd30>", line 1, in <module>
    data = yf.download(tickers='AAPL',start='2019-01-01',end='2019-01-03',prepost = True,interval = "90m")
  File "C:\anaconda3\lib\site-packages\fix_yahoo_finance\__init__.py", line 202, in download
    'Close', 'Adj Close', 'Volume']]
  File "C:\anaconda3\lib\site-packages\pandas\core\frame.py", line 2924, in __getitem__
    raise_missing=True)
  File "C:\anaconda3\lib\site-packages\pandas\core\indexing.py", line 1354, in _convert_to_indexer
    return self._get_listlike_indexer(obj, axis, **kwargs)[1]
  File "C:\anaconda3\lib\site-packages\pandas\core\indexing.py", line 1142, in _get_listlike_indexer
    kind=self.name)
  File "C:\anaconda3\lib\site-packages\pandas\core\indexes\multi.py", line 2127, in _convert_listlike_indexer
    _, indexer = self.reindex(keyarr, level=level)
  File "C:\anaconda3\lib\site-packages\pandas\core\indexes\multi.py", line 2216, in reindex
    keep_order=False)
  File "C:\anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 3457, in _join_level
    ngroups = 1 + new_lev_codes.max()
  File "C:\anaconda3\lib\site-packages\numpy\core\_methods.py", line 26, in _amax
    return umr_maximum(a, axis, None, out, keepdims)
ValueError: zero-size array to reduction operation maximum which has no identity

如果我使用每日分辨率的 1d ,则可以正常工作:

data = yf.download(tickers='AAPL',start='2019-01-01',end='2019-01-03',interval = "1d")

以下内容在分钟分辨率方面也能很好地工作,但是它给出了当天的结果,并且没有获得开始/结束日期作为输入参数,这使得它对于历史数据毫无用处。

from alpha_vantage.timeseries import TimeSeries
ts=TimeSeries(key='ACLIMSOTBCT8K3GV', output_format='pandas')
pulledData, meta_data = ts.get_intraday(symbol=stock,interval='1min', outputsize='full')

所以我想知道在开始/结束之间是否有任何方法可以获取盘中股价?

0 个答案:

没有答案