我一直在尝试修复此代码以搜索解决方案(请参阅我的标题中的错误消息)。它似乎与df系列的索引有关。我看到我打印的日期,但无法解决它。我可以找到一种可行的方法来设置日期作为索引,在转换为np数组之前可能需要它吗?
import datetime
import talib
import numpy as np
import pandas as pd
from numpy import array
from pandas_datareader import data, wb
start_date = datetime.datetime(2010, 1, 1)
end_date = datetime.datetime(2013, 1, 27)
stocks = ['AAPL', 'SPY']
df = data.DataReader(stocks, 'yahoo', start_date, end_date)
high = pd.DataFrame(df.ix['High'])
low = pd.DataFrame(df.ix['Low'])
close = pd.DataFrame(df.ix['Close'])
for stock in stocks:
slowk, slowd = talib.STOCH(high[stock],
low[stock],
close[stock],
fastk_period=5,
slowk_period=3,
slowk_matype=0,
slowd_period=3,
slowd_matype=0)
slowk = slowk[-1]
slowd = slowd[-1]
STO = slowk - slowd
print('STO', STO)