MCPcopy Create free account
hub / github.com/kernc/backtesting.py / test_compute_stats_bordercase

Method test_compute_stats_bordercase

backtesting/test/_test.py:374–405  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

372 *indicator_columns]))
373
374 def test_compute_stats_bordercase(self):
375
376 class SingleTrade(Strategy):
377 def init(self):
378 self._done = False
379
380 def next(self):
381 if not self._done:
382 self.buy()
383 self._done = True
384 if self.position:
385 self.position.close()
386
387 class SinglePosition(_S):
388 def next(self):
389 if not self.position:
390 self.buy()
391
392 class NoTrade(_S):
393 def next(self):
394 pass
395
396 for strategy in (SmaCross,
397 SingleTrade,
398 SinglePosition,
399 NoTrade):
400 with self.subTest(strategy=strategy.__name__):
401 stats = Backtest(GOOG.iloc[:100], strategy).run()
402
403 self.assertFalse(np.isnan(stats['Equity Final [$]']))
404 self.assertFalse(stats['_equity_curve']['Equity'].isnull().any())
405 self.assertEqual(stats['_strategy'].__class__, strategy)
406
407 def test_trade_enter_hit_sl_on_same_day(self):
408 the_day = pd.Timestamp("2012-10-17 00:00:00")

Callers

nothing calls this directly

Calls 2

BacktestClass · 0.90
runMethod · 0.45

Tested by

no test coverage detected