Skip to content

Commit 0b052e5

Browse files
committed
Changes plimit to pmin in _try_exec_limit.
But fixed to now use pmin instead of plimit in the sell side of _try_exec_limit. Test files created to check for valid entry for various levels of slippage.
1 parent ccc3207 commit 0b052e5

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

datas/bbroker_try_exec_limit.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Date,Open,High,Low,Close,Volume,OpenInterest
2+
2019-01-01, 1295.5, 1305.5, 1290.1, 1298.6, 235334, 319231,
3+
2019-01-02, 1297.5, 1303.5, 1293.1, 1296.6, 235334, 319231,
4+
2019-01-03, 1301.0, 1309.4, 1298.9, 1307.3, 244542, 311254,
5+
2019-01-04, 1309.0, 1312.9, 1285.0, 1298.3, 316063, 302111,

tests/test_bbroker_try_exec_limit.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@
1818
###############################################################################
1919
from __future__ import absolute_import, division, print_function, unicode_literals
2020

21+
import datetime
22+
import os
2123
import time
2224

25+
2326
try:
2427
time_clock = time.process_time
2528
except:
2629
time_clock = time.clock
2730

2831
import backtrader as bt
29-
import pandas as pd
30-
3132

3233
class SlipTestStrategy(bt.SignalStrategy):
3334
params = (
@@ -116,9 +117,7 @@ def next(self):
116117
self.print_signal()
117118

118119
if self.counter == 0:
119-
self.order = self.sell(
120-
exectype=bt.Order.Limit, price=self.price
121-
)
120+
self.order = self.sell(exectype=bt.Order.Limit, price=self.price)
122121
if self.p.printops:
123122
self.log("SELL ISSUED @ %0.2f" % self.price)
124123
self.counter += 1
@@ -140,19 +139,16 @@ def test_run(main=False):
140139

141140
cerebro.broker.setcash(10000.0)
142141

143-
short_data = [
144-
(20190101, 1295.5, 1305.5, 1290.1, 1298.6, 235334, 319231,),
145-
(20190102, 1297.5, 1303.5, 1293.1, 1296.6, 235334, 319231,),
146-
(20190103, 1301.0, 1309.4, 1298.9, 1307.3, 244542, 311254,),
147-
(20190104, 1309.0, 1312.9, 1285.0, 1298.3, 316063, 302111,),
148-
]
149-
df = pd.DataFrame(
150-
short_data,
151-
columns=["dt", "open", "high", "low", "close", "volume", "openinterest"],
152-
).set_index("dt")
153-
df.index = pd.to_datetime(df.index, format="%Y%m%d")
154-
155-
data0 = bt.feeds.PandasData(dataname=df)
142+
modpath = os.path.dirname(os.path.abspath(__file__))
143+
dataspath = "../datas"
144+
datafile = "bbroker_try_exec_limit.txt"
145+
datapath = os.path.join(modpath, dataspath, datafile)
146+
data0 = bt.feeds.GenericCSVData(
147+
dataname=datapath,
148+
dtformat=("%Y-%m-%d"),
149+
timeframe=bt.TimeFrame.Days,
150+
compression=1,
151+
)
156152
cerebro.adddata(data0)
157153

158154
# Slippage/expected sell executed price

0 commit comments

Comments
 (0)