Skip to content

Commit a1325bc

Browse files
committed
Add unit test
1 parent a8082f1 commit a1325bc

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

backtesting/test/_test.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def almost_equal(a, b):
304304
self.assertSequenceEqual(
305305
sorted(stats['_trades'].columns),
306306
sorted(['Size', 'EntryBar', 'ExitBar', 'EntryPrice', 'ExitPrice',
307-
'PnL', 'ReturnPct', 'EntryTime', 'ExitTime', 'Duration']))
307+
'PnL', 'ReturnPct', 'EntryTime', 'ExitTime', 'Duration', 'Tag']))
308308

309309
def test_compute_stats_bordercase(self):
310310

@@ -506,6 +506,18 @@ def coroutine(self):
506506
stats = self._Backtest(coroutine).run()
507507
self.assertEqual(len(stats._trades), 1)
508508

509+
def test_order_tag(self):
510+
def coroutine(self):
511+
yield self.buy(size=2, tag=1)
512+
yield self.sell(size=1, tag='s')
513+
yield self.sell(size=1)
514+
515+
yield self.buy(tag=2)
516+
yield self.position.close()
517+
518+
stats = self._Backtest(coroutine).run()
519+
self.assertEqual(list(stats._trades.Tag), [1, 1, 2])
520+
509521

510522
class TestOptimize(TestCase):
511523
def test_optimize(self):

0 commit comments

Comments
 (0)