Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 48b656b

Browse filesBrowse files
committed
BUG: Fix bug with buy/sell size=0
Fixes kernc#900
1 parent 8f2c1d2 commit 48b656b
Copy full SHA for 48b656b

1 file changed

+3-2Lines changed: 3 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎backtesting/backtesting.py‎

Copy file name to clipboardExpand all lines: backtesting/backtesting.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def buy(self, *,
208208
209209
See also `Strategy.sell()`.
210210
"""
211-
assert 0 < size < 1 or round(size) == size, \
211+
assert 0 < size < 1 or round(size) == size >= 1, \
212212
"size must be a positive fraction of equity, or a positive whole number of units"
213213
return self._broker.new_order(size, limit, stop, sl, tp, tag)
214214

@@ -228,7 +228,7 @@ def sell(self, *,
228228
If you merely want to close an existing long position,
229229
use `Position.close()` or `Trade.close()`.
230230
"""
231-
assert 0 < size < 1 or round(size) == size, \
231+
assert 0 < size < 1 or round(size) == size >= 1, \
232232
"size must be a positive fraction of equity, or a positive whole number of units"
233233
return self._broker.new_order(-size, limit, stop, sl, tp, tag)
234234

@@ -741,6 +741,7 @@ def new_order(self,
741741
tp = tp and float(tp)
742742

743743
is_long = size > 0
744+
assert size != 0, size
744745
adjusted_price = self._adjusted_price(size)
745746

746747
if is_long:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.