Question

I am using python to design some trading strategies. My library includes Pyalgotrade and TA-lib mainly. I got an error from the code below.

from pyalgotrade.tools import yahoofinance
from pyalgotrade import strategy
from pyalgotrade.barfeed import yahoofeed
from pyalgotrade.technical import stoch
from pyalgotrade import dataseries
from pyalgotrade.technical import ma
from pyalgotrade import technical
from pyalgotrade.technical import highlow
from pyalgotrade import bar
from 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 then Load the yahoo feed from the CSV file
        yahoofinance.download_daily_bars('002389.SZ', 2013, '002389.csv')
        feed = yahoofeed.Feed()
        feed.addBarsFromCSV("002389.SZ", "002389.csv")

        # Evaluate the strategy with the feed's bars.
        myStrategy = MyStrategy(feed, "002389.SZ")
        myStrategy.run()

The error is :

>>> ================================ RESTART ================================
>>> 
>>> 

Nothing printed out.

I think the error might be caused by the variable called self._LL. But I have no idea about how to write self._DD and self.__LL in the correct way. Can someone give me a help?

Était-ce utile?

La solution

self.__position is None doesn't create the attribute. Use self.__position = None. Also remember that attributes with 2 leading underscores are considered "private" (at least in CPython implementation) and to prevent undesired, eventual access are mangled internally into _<ClassName>__<AttributeName>.

Fix the line run_strategy(). The class MyStrategy isn't yet fully defined at this point.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top