Unknown error from python while designing trading strategies -
i using python design trading strategies. library includes pyalgotrade , ta-lib mainly. got error code below.
from pyalgotrade.tools import yahoofinance pyalgotrade import strategy pyalgotrade.barfeed import yahoofeed pyalgotrade.technical import stoch pyalgotrade import dataseries pyalgotrade.technical import ma pyalgotrade import technical pyalgotrade.technical import highlow pyalgotrade import bar pyalgotrade.talibext import indicator import numpy import talib class mystrategy(strategy.backtestingstrategy): def __init__(self, feed, instrument): strategy.backtestingstrategy.__init__(self, feed) self.__instrument = instrument bards = self.getfeed().getdataseries("002389.sz") self.__fastk, self.__fastd = indicator.stochf(bards, 24, 3) self.__bias = self.__fastk * 25 self.__dd = indicator.ema(self.__bias, 4) self.__ll = (self.__dd - indicator.low(self.__dd,21))/(indicator.max(self.__dd,21) - indicator.low(self.__dd,21)) def onbars(self, bars): bar = bars[self.__instrument] self.info("%0.2f, %0.2f" % (bar.getclose(), self.__ll[-1])) # downdload load yahoo feed csv file yahoofinance.download_daily_bars('002389.sz', 2013, '002389.csv') feed = yahoofeed.feed() feed.addbarsfromcsv("002389.sz", "002389.csv") # evaluate strategy feed's bars. mystrategy = mystrategy(feed, "002389.sz") mystrategy.run() the error :
>>> ================================ restart ================================ >>> >>> nothing printed out.
i think error might caused variable called self._ll. have no idea how write self._dd , self.__ll in correct way. can give me help?
self.__position none doesn't create attribute. use self.__position = none. remember attributes 2 leading underscores considered "private" (at least in cpython implementation) , prevent undesired, eventual access mangled internally _<classname>__<attributename>.
fix line run_strategy(). class mystrategy isn't yet defined @ point.
Comments
Post a Comment