0

こんにちは、このAttributeErrorはなぜ発生しますか?

私は学生ですし、私はQuantopianプラットフォーム上WaveTrendオシレーター戦略を実行しようとしていた:私がやりたいこと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) 
+1

私は 'stock'は、あなたがしようとしている' history'メソッドを持っていないことを前提とするコードとエラーから – Roars

+0

@Roarsが正しいです - メソッド 'sid(...)'は 'history()'メソッドを持たないオブジェクトを返しています。 https://www.quantopian.com/help#ide-historyは役に立ちますか? – gtmtg

答えて

0

[OK]を、私はそれが正常に動作したと思う:

import talib 

# --------------------------------------------------- 
n1, n2, period, stock = 10, 21, 60, sid(24) 
# --------------------------------------------------- 
def initialize(context): 
    schedule_function(trade, date_rules.week_start(), time_rules.market_open()) 

def trade(context, data): 
    ob = 80 #"Over Bought Level" 
    os = -80 #"Over Sold Level" 
    if get_open_orders(): return 
    close = data.history(stock, 'close', period + 1, '1d').dropna() 
    low = data.history(stock, 'low', period + 1, '1d').dropna() 
    high = data.history(stock, 'high', period + 1, '1d').dropna() 
    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) 
    record(wt1 = wt1[-1], ob = ob,os = os) 
    if data.can_trade(stock): 
     if wt1[-1] > os: 
      order_target_percent(stock, 2) 
     elif wt1[-1] < ob: 
      order_target_percent(stock, 0) 
関連する問題