Exemple #1
0
    def __processJob(self, job, barsFreq, instruments, bars):
        bestResult = None
        parameters = job.getNextParameters()
        bestParams = parameters
        while parameters is not None:
            # Wrap the bars into a feed.
            feed = barfeed.OptimizerBarFeed(barsFreq, instruments, bars)
            # Run the strategy.
            self.getLogger().info("Running strategy with parameters %s" %
                                  (str(parameters)))
            result = None
            try:
                result = self.runStrategy(feed, *parameters)
            except Exception as e:
                self.getLogger().exception(
                    "Error running strategy with parameters %s: %s" %
                    (str(parameters), e))
            self.getLogger().info("Result %s" % result)
            if bestResult is None or result > bestResult:
                bestResult = result
                bestParams = parameters
            # Run with the next set of parameters.
            parameters = job.getNextParameters()

        assert (bestParams is not None)
        self.pushJobResults(job.getId(), bestResult, bestParams)
Exemple #2
0
 def testBaseBarFeedNoAdjClose(self):
     bars = [
         bar.Bars({"orcl": bar.BasicBar(datetime.datetime(2001, 1, 1), 1, 1, 1, 1, 1, None, bar.Frequency.DAY)}),
         bar.Bars({"orcl": bar.BasicBar(datetime.datetime(2001, 1, 2), 1, 1, 1, 1, 1, None, bar.Frequency.DAY)}),
     ]
     barFeed = barfeed.OptimizerBarFeed(bar.Frequency.DAY, ["orcl"], bars)
     check_base_barfeed(self, barFeed, False)
Exemple #3
0
 def testDateTimesNotInOrder(self):
     bars = [
         bar.Bars({"orcl": bar.BasicBar(datetime.datetime(2001, 1, 2), 1, 1, 1, 1, 1, 1, bar.Frequency.DAY)}),
         bar.Bars({"orcl": bar.BasicBar(datetime.datetime(2001, 1, 1), 1, 1, 1, 1, 1, 1, bar.Frequency.DAY)}),
     ]
     f = barfeed.OptimizerBarFeed(bar.Frequency.DAY, ["orcl"], bars)
     with self.assertRaisesRegexp(Exception, "Bar date times are not in order.*"):
         for dt, b in f:
             pass
 def resultFunction2(self, parametres):
     assert(len(parametres) == len(self.lowerBound))            
     
     feedToBuildOnEveryLoop = barfeed.OptimizerBarFeed(self.feed.getFrequency(), 
     self.feed.getRegisteredInstruments(), self.bars)        
     
     myStrategy = UnionStrategy(feedToBuildOnEveryLoop, "btc", parametres)
     myStrategy.run()
     return myStrategy.getResult()    
Exemple #5
0
	def runStrategy(self, stratExecConfig, paramValues):
		bars = self.__loadBars(stratExecConfig)

		barFeed = barfeed.OptimizerBarFeed(barfeed.Frequency.DAY, [stratExecConfig.instrument], bars)

		# Evaluate the strategy with the feed bars.
		params = [barFeed]
		params.extend(paramValues)
		myStrategy = cls.Class(stratExecConfig.className).getClass()(*params)
		myStrategy.run()
		return myStrategy.getResult()
Exemple #6
0
 def testBaseBarFeedNoAdjClose(self):
     bars = [
         bar.Bars([
             bar.BasicBar(INSTRUMENT, datetime.datetime(2001, 1, 1), 1, 1,
                          1, 1, 1, None, bar.Frequency.DAY)
         ]),
         bar.Bars([
             bar.BasicBar(INSTRUMENT, datetime.datetime(2001, 1, 2), 1, 1,
                          1, 1, 1, None, bar.Frequency.DAY)
         ]),
     ]
     barFeed = barfeed.OptimizerBarFeed(bar.Frequency.DAY, [INSTRUMENT],
                                        bars)
     check_base_barfeed(self, barFeed, False)
Exemple #7
0
 def testDupliateDateTimesForTradeBars(self):
     bars = [
         bar.Bars([
             bar.BasicBar(INSTRUMENT, datetime.datetime(2001, 1, 1), 1, 1,
                          1, 1, 1, 1, bar.Frequency.TRADE)
         ]),
         bar.Bars([
             bar.BasicBar(INSTRUMENT, datetime.datetime(2001, 1, 1), 1, 1,
                          1, 1, 2, 1, bar.Frequency.TRADE)
         ]),
     ]
     f = barfeed.OptimizerBarFeed(bar.Frequency.TRADE, [INSTRUMENT], bars)
     expected_volume = 1
     for dt, b in f:
         assert b[INSTRUMENT].getVolume() == expected_volume
         expected_volume += 1
Exemple #8
0
 def testDupliateDateTimesForDailyBars(self):
     bars = [
         bar.Bars([
             bar.BasicBar(INSTRUMENT, datetime.datetime(2001, 1, 1), 1, 1,
                          1, 1, 1, 1, bar.Frequency.DAY)
         ]),
         bar.Bars([
             bar.BasicBar(INSTRUMENT, datetime.datetime(2001, 1, 1), 1, 1,
                          1, 1, 1, 1, bar.Frequency.DAY)
         ]),
     ]
     f = barfeed.OptimizerBarFeed(bar.Frequency.DAY, [INSTRUMENT], bars)
     with self.assertRaisesRegexp(Exception, "%s bars are not in order.*" %
                                  INSTRUMENT):
         for dt, b in f:
             pass
Exemple #9
0
	def __processJob(self, job, instruments, bars):
		bestResult = 0
		parameters = job.getNextParameters()
		bestParams = parameters 
		while parameters != None:
			# Wrap the bars into a feed.
			feed = barfeed.OptimizerBarFeed(instruments, bars)
			# Run the strategy.
			self.getLogger().info("Running strategy with parameters %s" % (str(parameters)))
			result = self.runStrategy(feed, *parameters)
			self.getLogger().info("Result %s" % result)
			if result > bestResult:
				bestResult = result
				bestParams = parameters
			# Run with the next set of parameters.
			parameters = job.getNextParameters()

		assert(bestParams != None)
		self.pushJobResults(job.getId(), bestResult, bestParams)
Exemple #10
0
 def testEmtpy(self):
     barFeed = barfeed.OptimizerBarFeed(bar.Frequency.DAY, ["orcl"], [])
     self.assertEquals(barFeed.barsHaveAdjClose(), False)