18
18
###############################################################################
19
19
from __future__ import absolute_import , division , print_function , unicode_literals
20
20
21
+ import datetime
22
+ import os
21
23
import time
22
24
25
+
23
26
try :
24
27
time_clock = time .process_time
25
28
except :
26
29
time_clock = time .clock
27
30
28
31
import backtrader as bt
29
- import pandas as pd
30
-
31
32
32
33
class SlipTestStrategy (bt .SignalStrategy ):
33
34
params = (
@@ -116,9 +117,7 @@ def next(self):
116
117
self .print_signal ()
117
118
118
119
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 )
122
121
if self .p .printops :
123
122
self .log ("SELL ISSUED @ %0.2f" % self .price )
124
123
self .counter += 1
@@ -140,19 +139,16 @@ def test_run(main=False):
140
139
141
140
cerebro .broker .setcash (10000.0 )
142
141
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
+ )
156
152
cerebro .adddata (data0 )
157
153
158
154
# Slippage/expected sell executed price
0 commit comments