现在正在寻找替代方案,雅虎金融似乎已经一去不复返了。遇到了看起来非常有趣的Alpha Vantage 。下面的代码正在运行,直到我尝试找到开始日期和结束日期之间的增量,但我收到以下错误:
from alpha_vantage.timeseries import TimeSeries
ts = TimeSeries(key=key, output_format="pandas")
data, meta_data = ts.get_daily("AAPL",outputsize="full")
days = (data.index[-1]- data.index[0]).days
输出:
days = (data.index[-1]- data.index[0]).days
TypeError: unsupported operand type(s) for -: 'str' and 'str'
我也试过:
days = (float(data.index[-1])- float(data.index[0])).days
和
days = (int(data.index[-1])- int(data.index[0])).days
如下所示的打印数据帧头
print(data.head())
输出:
open low close high volume
2000-01-03 104.87 101.69 111.94 112.50 4783900.0
2000-01-04 108.25 101.19 102.50 110.62 4574800.0
2000-01-05 103.75 103.00 104.00 110.56 6949300.0
2000-01-06 106.12 95.00 95.00 107.00 6856900.0
2000-01-07 96.50 95.50 99.50 101.00 4113700.0
没有任何运气,任何帮助将不胜感激!