def testClenowTradeStart(self): mf = MultiFeed() self.setupFeed(mf) strat = ClenowBreakoutStrategy(mf, tradeStart=datetime.datetime( 2012, 8, 11)) # Attach a few analyzers to the strategy before executing it. retAnalyzer = returns.Returns() strat.attachAnalyzer(retAnalyzer) sharpeRatioAnalyzer = sharpe.SharpeRatio() strat.attachAnalyzer(sharpeRatioAnalyzer) drawDownAnalyzer = drawdown.DrawDown() strat.attachAnalyzer(drawDownAnalyzer) tradesAnalyzer = trades.Trades() strat.attachAnalyzer(tradesAnalyzer) mf.start() strat.exitPositions() strat.getBroker().executeSessionClose() tlog = '%s/trade3.log' % os.path.dirname(__file__) tradesAnalyzer.writeTradeLog(tlog) self.assertAlmostEqual(strat.getResult(), 986794.67, places=2) self.assertEqual(tradesAnalyzer.getCount(), 5) self.assertEqual(tradesAnalyzer.getProfitableCount(), 1) self.assertEqual(tradesAnalyzer.getUnprofitableCount(), 4) self.assertTrue( test_util.file_compare( '%s/trade3.reflog' % os.path.dirname(__file__), tlog)) os.remove(tlog)
def testMacross(self): mf = MultiFeed() self.setupFeed(mf) strat = MACrossStrategy(mf,shortPeriod=10,longPeriod=100) # Attach a few analyzers to the strategy before executing it. retAnalyzer = returns.Returns() strat.attachAnalyzer(retAnalyzer) sharpeRatioAnalyzer = sharpe.SharpeRatio() strat.attachAnalyzer(sharpeRatioAnalyzer) drawDownAnalyzer = drawdown.DrawDown() strat.attachAnalyzer(drawDownAnalyzer) tradesAnalyzer = trades.Trades() strat.attachAnalyzer(tradesAnalyzer) mf.start() strat.exitPositions() tlog = '%s/trade5.log' % os.path.dirname(__file__) tradesAnalyzer.writeTradeLog(tlog) self.assertAlmostEqual(strat.getResult(),992595.00,places=2) self.assertEqual(tradesAnalyzer.getCount(),10) self.assertEqual(tradesAnalyzer.getProfitableCount(),4) self.assertEqual(tradesAnalyzer.getUnprofitableCount(),6) self.assertTrue(test_util.file_compare('%s/trade5.reflog' % os.path.dirname(__file__), tlog)) os.remove(tlog)
def testBasic(self): mf = MultiFeed() mf.register_feed(self._feed) strat = MyStrategy(mf) # Attach a few analyzers to the strategy before executing it. retAnalyzer = returns.Returns() strat.attachAnalyzer(retAnalyzer) sharpeRatioAnalyzer = sharpe.SharpeRatio() strat.attachAnalyzer(sharpeRatioAnalyzer) drawDownAnalyzer = drawdown.DrawDown() strat.attachAnalyzer(drawDownAnalyzer) tradesAnalyzer = trades.Trades() strat.attachAnalyzer(tradesAnalyzer) mf.start() strat.exitPositions() self.assertAlmostEqual(strat.getResult(), 996193.19, places=2) self.assertEqual(tradesAnalyzer.getCount(), 2) self.assertEqual(tradesAnalyzer.getProfitableCount(), 0) self.assertEqual(tradesAnalyzer.getUnprofitableCount(), 2) tlog = '%s/trade.log' % os.path.dirname(__file__) tradesAnalyzer.writeTradeLog(tlog) self.assertTrue( test_util.file_compare( '%s/trade1.reflog' % os.path.dirname(__file__), tlog)) os.remove(tlog)
def __init__(self, strategy): self._strategy = strategy # Attach analyzers to the strategy self._retAnalyzer = returns.Returns() self._strategy.attachAnalyzer(self._retAnalyzer) self._sharpeRatioAnalyzer = sharpe.SharpeRatio() self._strategy.attachAnalyzer(self._sharpeRatioAnalyzer) self._drawDownAnalyzer = drawdown.DrawDown() self._strategy.attachAnalyzer(self._drawDownAnalyzer) self._tradesAnalyzer = trades.Trades() self._strategy.attachAnalyzer(self._tradesAnalyzer)
def testBasic(self): mf = MultiFeed() mf.register_feed(self._feed) strat = MyStrategy(mf) # Attach a few analyzers to the strategy before executing it. retAnalyzer = returns.Returns() strat.attachAnalyzer(retAnalyzer) sharpeRatioAnalyzer = sharpe.SharpeRatio() strat.attachAnalyzer(sharpeRatioAnalyzer) drawDownAnalyzer = drawdown.DrawDown() strat.attachAnalyzer(drawDownAnalyzer) tradesAnalyzer = trades.Trades() strat.attachAnalyzer(tradesAnalyzer) mf.start() self.assertAlmostEqual(strat.getResult(), 1007071.67, places=2) self.assertEqual(tradesAnalyzer.getCount(), 1) self.assertEqual(tradesAnalyzer.getProfitableCount(), 1) self.assertEqual(tradesAnalyzer.getUnprofitableCount(), 0)