例外:真实不是双倍(PYTHON)

时间:2017-11-07 05:15:25

标签: python pandas dataframe ta-lib

我试图使用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)

1 个答案:

答案 0 :(得分:1)

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

In [11]: ta.SMA(aapl.Volume.values.astype('float64'), twenty_ma)
Out[11]:
array([       nan,        nan,        nan, ...,  78960385.,  76585880.,
        73991890.])