Guest User

Untitled

a guest
Nov 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. AttributeError: 'zipline.assets._assets.Equity' object has no attribute 'history'
  2.  
  3. import talib
  4. import pandas
  5.  
  6. # ---------------------------------------------------
  7. n1, n2, period, stock = 10, 21, 12, sid(24)
  8. # ---------------------------------------------------
  9. def initialize(context):
  10. schedule_function(open_positions, date_rules.week_start(), time_rules.market_open())
  11.  
  12. def handle_data(context, data):
  13. if get_open_orders(): return
  14. close = stock.history(stock, 'close', period + 1, '1d')
  15. low = stock.history(stock, 'low', period + 1, '1d')
  16. high = stock.history(stock, 'high', period + 1, '1d')
  17. ap = (high+low+close)/3
  18. esa = talib.EMA(ap, timeperiod=n1)
  19. d = talib.EMA(abs(ap - esa), timeperiod=n1)
  20. ci = (ap - esa) / (0.015 * d)
  21. wt1 = talib.EMA(ci, timeperiod=n2)
  22. wt1 = wt1.dropna()
  23. wt2 = talib.SMA(wt1, timeperiod=4)
  24. wt2 = wt2.dropna()
  25.  
  26. def open_positions(context, data):
  27. if data.can_trade(stock < wt1):
  28. order_target_percent(stock, 2)
  29. elif data.can_trade(stock > wt2):
  30. order_target_percent(stock, -1)
Add Comment
Please, Sign In to add comment