0

我正在尝试使用 TA-Lib 获取股票交易量的移动平均线,但出现上述错误。对于如何解决这个问题,有任何的建议吗?谢谢!

请参见下面的代码:

import pandas_datareader as pdr
import datetime 
import pandas as pd
import numpy as np
import talib as ta

#Download Data
aapl = pdr.get_data_yahoo('AAPL', start=datetime.datetime(2006, 10, 1), end=datetime.datetime(2012, 1, 1))

#Saves Data as CSV on desktop
aapl.to_csv('C:\\Users\\JDOG\\Desktop\\aapl_ohlc.csv', encoding='utf-8')

#Save to dataframe
df = pd.read_csv('C:\\Users\JDOG\\Desktop\\aapl_ohlc.csv', header=0, index_col='Date', parse_dates=True)

twenty_ma = 20

signals = pd.DataFrame(index=aapl.index)
signals['signal'] = 0.0

signals['20 MA'] = ta.SMA(aapl.Volume.values,twenty_ma)
4

1 回答 1

2

看起来SMA需要一个浮点数组而不是整数:

In [11]: ta.SMA(aapl.Volume.values.astype('float64'), twenty_ma)
Out[11]:
array([       nan,        nan,        nan, ...,  78960385.,  76585880.,
        73991890.])
于 2017-11-07T05:37:49.407 回答