Ejemplo n.º 1
0
    def __init__(self, settings, name=None):
        NoScaleInEntryManager.__init__(self, settings, name)

        self.minPrice = settings.getfloat("JBMarwoodSupernovaShortEntry", "minPrice")
        self.maxPrice = settings.getfloat("JBMarwoodSupernovaShortEntry", "maxPrice")
        self.minVol = settings.getint("JBMarwoodSupernovaShortEntry", "minVol")
        self.minPctChange = settings.getfloat("JBMarwoodSupernovaShortEntry", "minPctChange")
        self.numdays = settings.getint("JBMarwoodSupernovaShortEntry", "numBars")
        self.onOpen = settings.getboolean("JBMarwoodSupernovaShortEntry", "enterNextOpen")
        self.onDownClose = settings.getboolean("JBMarwoodSupernovaShortEntry", "enterNextDayDownClose")
        targetstr = settings.get("JBMarwoodSupernovaShortEntry", "target")
        if targetstr == "None":
            self.target = None
        else:
            self.target = float(targetstr)
        self.stopPercent = settings.getfloat("JBMarwoodSupernovaShortEntry", "stopPercent")
        self.setupYesterday = True

        self.rawclose = Close()
        self.close = AdjustedClose()
        self.oldClose = HistoricMetric(self.close, period=self.numdays)
        self.change = Subtract(self.close, self.oldClose)
        self.pctChange = Divide(self.change, self.oldClose)
        self.volume = Volume()

        self._addMetric(self.rawclose)
        self._addMetric(self.close)
        self._addMetric(self.oldClose)
        self._addMetric(self.change)
        self._addMetric(self.pctChange)
        self._addMetric(self.volume)
Ejemplo n.º 2
0
class JBMarwoodSupernovaShortEntryManager(NoScaleInEntryManager):
    def __init__(self, settings, name=None):
        NoScaleInEntryManager.__init__(self, settings, name)

        self.minPrice = settings.getfloat("JBMarwoodSupernovaShortEntry", "minPrice")
        self.maxPrice = settings.getfloat("JBMarwoodSupernovaShortEntry", "maxPrice")
        self.minVol = settings.getint("JBMarwoodSupernovaShortEntry", "minVol")
        self.minPctChange = settings.getfloat("JBMarwoodSupernovaShortEntry", "minPctChange")
        self.numdays = settings.getint("JBMarwoodSupernovaShortEntry", "numBars")
        self.onOpen = settings.getboolean("JBMarwoodSupernovaShortEntry", "enterNextOpen")
        self.onDownClose = settings.getboolean("JBMarwoodSupernovaShortEntry", "enterNextDayDownClose")
        targetstr = settings.get("JBMarwoodSupernovaShortEntry", "target")
        if targetstr == "None":
            self.target = None
        else:
            self.target = float(targetstr)
        self.stopPercent = settings.getfloat("JBMarwoodSupernovaShortEntry", "stopPercent")
        self.setupYesterday = True

        self.rawclose = Close()
        self.close = AdjustedClose()
        self.oldClose = HistoricMetric(self.close, period=self.numdays)
        self.change = Subtract(self.close, self.oldClose)
        self.pctChange = Divide(self.change, self.oldClose)
        self.volume = Volume()

        self._addMetric(self.rawclose)
        self._addMetric(self.close)
        self._addMetric(self.oldClose)
        self._addMetric(self.change)
        self._addMetric(self.pctChange)
        self._addMetric(self.volume)

    def _checkTradeNoScale(self):
        trade = None
        if self.setupYesterday:
            if self.onOpen:
                entry = self.periodData.adjustedOpen
                stop = entry * (1 + self.stopPercent)
                if entry != stop:
                    trade = Trade(self.periodData.stock, self.periodData.date, entry, stop)
                    if self.target != None:
                        target = self.close.value() * (1.0 - self.target)
                        trade.target = target
            elif self.onDownClose and self.periodData.adjustedClose < self.periodData.adjustedOpen:
                stop = self.periodData.adjustedHigh + 0.01
                # stop = self.close.value()*(1+self.stopPercent)
                if stop != self.close.value():
                    trade = Trade(self.periodData.stock, self.periodData.date, self.close.value(), stop)
                    if self.target != None:
                        target = self.close.value() * (1.0 - self.target)
                        trade.target = target
        if (
            self.pctChange.ready()
            and self.rawclose.value() >= self.minPrice
            and self.rawclose.value() <= self.maxPrice
            and self.volume.value() >= self.minVol
            and self.pctChange.value() >= self.minPctChange
        ):
            if not self.onDownClose and not self.onOpen:
                # enter immediately
                stop = self.close.value() * (1 + self.stopPercent)
                if stop != self.close.value():
                    trade = Trade(self.periodData.stock, self.periodData.date, self.close.value(), stop)
                    if self.target != None:
                        target = self.close.value() * (1.0 - self.target)
                        trade.target = target
            self.setupYesterday = True
        else:
            self.setupYesterday = False
        if trade is not None and (trade.entryPrice == 0 or trade.entryPrice == trade.stop):
            return None
        return trade