【发布时间】:2016-06-29 10:13:51
【问题描述】:
我是 python 和 pandas 的新手,主要是学习它来丰富我的编程技能以及 python 作为通用程序语言的优势。在这个程序中,我使用它从 yahoo 获取历史数据并使用 talib 中的函数进行一些技术分析
import pandas_datareader.data as web
import datetime
import talib as ta
start = datetime.datetime.strptime('12/1/2015', '%m/%d/%Y')
end = datetime.datetime.strptime('2/20/2016', '%m/%d/%Y')
f = web.DataReader('GOOG', 'yahoo', start, end)
print 'Closing Prices'
print f['Close'].describe()
print f.Close
print ta.RSI(f.Close,2)
print ta.SMA(f.Close,2)
print ta.SMA(f.Volume,4)
print ta.ATR
print ta.ATR(f.High,f.Low,f.Close,3)
上面的代码在print f.Close 之前一直有效,但随后显示此错误
print ta.RSI(f.Close,2)
TypeError: Argument 'real' has incorrect type (expected numpy.ndarray, got Series)
我使用 R 及其库对股票进行技术分析,它有一个名为 Quantmod 的内置库,它使技术分析更容易并且代码更少。
library(quantmod)
symbol=getSymbols(AAPL)
SMA=SMA(Cl(Symbol),2)
有没有可用于 Python 的类似库?
【问题讨论】:
-
据我所知,
ta.xxx的输入应该是 numpy 数组,而不是 pandas 系列。试试ta.RSI(f.Close.values,2)。同样,.values属性适用于其他talib指标 -
谢谢谢尔盖。它工作得很好
标签: python pandas ta-lib technical-indicator