【发布时间】:2017-11-23 09:28:29
【问题描述】:
下午好,
我是一名学生,我正在尝试在 Quantopian 平台上实施 WaveTrend Oscillator 策略:https://www.tradingview.com/script/2KE8wTuF-Indicator-WaveTrend-Oscillator-WT/ 我想做的是在指标高时卖出 AAPL,低时买入。
它一直给我这个错误:
AttributeError: 'zipline.assets._assets.Equity' object has no attribute 'history'
谁能帮帮我?
import talib
import pandas
# ---------------------------------------------------
n1, n2, period, stock = 10, 21, 12, sid(24)
# ---------------------------------------------------
def initialize(context):
schedule_function(open_positions, date_rules.week_start(), time_rules.market_open())
def handle_data(context, data):
if get_open_orders(): return
close = stock.history(stock, 'close', period + 1, '1d')
low = stock.history(stock, 'low', period + 1, '1d')
high = stock.history(stock, 'high', period + 1, '1d')
ap = (high+low+close)/3
esa = talib.EMA(ap, timeperiod=n1)
d = talib.EMA(abs(ap - esa), timeperiod=n1)
ci = (ap - esa) / (0.015 * d)
wt1 = talib.EMA(ci, timeperiod=n2)
wt1 = wt1.dropna()
wt2 = talib.SMA(wt1, timeperiod=4)
wt2 = wt2.dropna()
def open_positions(context, data):
if data.can_trade(stock < wt1):
order_target_percent(stock, 2)
elif data.can_trade(stock > wt2):
order_target_percent(stock, -1)
【问题讨论】:
-
从代码和错误中我认为
stock没有您尝试使用的history方法 -
@Roars 是对的——
sid(...)方法正在返回一些没有history()方法的对象。 quantopian.com/help#ide-history 有帮助吗?
标签: python error-handling attributeerror quantitative-finance quantopian