예제 #1
0
class GapUpEntryManager:
    def __init__(self, settings):
        self.minPrice = settings.getfloat("GapAndGoSwingEntry", "minPrice")
        self.minAvgVol = settings.getint("GapAndGoSwingEntry", "minAvgVol")
        self.minPercent = settings.getfloat("GapAndGoSwingEntry", "minPercent")
        targetstr = settings.get("GapAndGoSwingEntry", "target")
        if targetstr == "None":
            self.target = None
        else:
            self.target = float(targetstr)
        self.volume = Volume()
        self.avgvol = SimpleMovingAverage(metric=self.volume, period=21)
        self.opn = AdjustedOpen()
        self.close = AdjustedClose()
        self.lastClose = HistoricMetric(metric=self.close, period=1)
        self.high = AdjustedHigh()
        self.lastHigh = HistoricMetric(metric=self.high, period=1)
        self.low = AdjustedLow()
        self.inBottomRange=0.1
        self.inTopRange=None
        
    def handle(self, perioddata):
        self.close.handle(perioddata)
        self.lastClose.handle(perioddata)
        self.high.handle(perioddata)
        self.lastHigh.handle(perioddata)
        self.opn.handle(perioddata)
        self.volume.handle(perioddata)
        self.avgvol.handle(perioddata)
        self.low.handle(perioddata)
        self.lastdd = perioddata

    def checkTrade(self):
        if self.close.ready() and self.lastClose.ready() \
                and self.opn.ready() and self.volume.ready() \
                and self.avgvol.ready():
            if self.lastdd.close >= self.minPrice and self.avgvol.value() >= self.minAvgVol \
                    and self.lastClose.value() > 0 and self.opn.value() > 0 \
                    and ((self.opn.value()-self.lastClose.value())/self.lastClose.value()) >= self.minPercent \
                    and self.low.value() >= self.lastHigh.value() \
                    and (self.inBottomRange == None or ((self.lastdd.adjustedHigh != self.lastdd.adjustedLow) and (self.close.value()-self.lastdd.adjustedLow)/(self.lastdd.adjustedHigh-self.lastdd.adjustedLow)) <= self.inBottomRange) \
                    and (self.inTopRange == None or ((self.lastdd.adjustedHigh != self.lastdd.adjustedLow) and (self.close.value()-self.lastdd.adjustedLow)/(self.lastdd.adjustedHigh-self.lastdd.adjustedLow)) >= self.inTopRange):
                stop = max(0.0, self.low.value() - 0.01)
#                 stop = max(0.0, self.lastHigh.value())
                trade = Trade(self.lastdd.stock, self.lastdd.date, self.close.value(), stop)
                if self.target != None:
                    target = self.close.value() + ((self.close.value()-stop)*self.target)
                    trade.target = target
                return trade
        return None
    
    def recommendedPreload(self):
        return 22
예제 #2
0
 def __init__(self, settings):
     self.minPrice = settings.getfloat("GapAndGoSwingEntry", "minPrice")
     self.minAvgVol = settings.getint("GapAndGoSwingEntry", "minAvgVol")
     self.minPercent = settings.getfloat("GapAndGoSwingEntry", "minPercent")
     targetstr = settings.get("GapAndGoSwingEntry", "target")
     if targetstr == "None":
         self.target = None
     else:
         self.target = float(targetstr)
     self.volume = Volume()
     self.avgvol = SimpleMovingAverage(metric=self.volume, period=21)
     self.opn = AdjustedOpen()
     self.close = AdjustedClose()
     self.lastClose = HistoricMetric(metric=self.close, period=1)
     self.high = AdjustedHigh()
     self.lastHigh = HistoricMetric(metric=self.high, period=1)
     self.low = AdjustedLow()
     self.inBottomRange=0.1
     self.inTopRange=None