Skip to content

Commit acd8c55

Browse files
committed
TEST: Cover absolute-size margin warning
1 parent b0f55cf commit acd8c55

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

backtesting/test/_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,19 @@ def test_broker_params(self):
231231
cash=1000, spread=.01, margin=.1, trade_on_close=True)
232232
bt.run()
233233

234+
def test_absolute_size_order_warns_on_insufficient_margin(self):
235+
class S(Strategy):
236+
def init(self):
237+
pass
238+
239+
def next(self):
240+
self.buy(size=10_000)
241+
242+
bt = Backtest(GOOG.iloc[:3], S, cash=1000)
243+
with self.assertWarnsRegex(UserWarning, 'insufficient margin'):
244+
stats = bt.run()
245+
self.assertEqual(stats['# Trades'], 0)
246+
234247
def test_spread_commission(self):
235248
class S(Strategy):
236249
def init(self):

0 commit comments

Comments
 (0)