@@ -16,15 +16,25 @@ def __init__(self):
16
16
self .dataclose = self .datas [0 ].close
17
17
self .datavol = self .datas [0 ].volume
18
18
19
- # def stop(self):
20
- # cash = self.broker.getvalue()
21
- # print('Result cash: {}'.format(cash))
19
+ def stop (self ):
20
+ cash = self .broker .getvalue ()
21
+ print ('Result cash: {}' .format (cash ))
22
+
23
+ def notify_order (self , order ):
24
+ if order .status in [order .Submitted , order .Accepted ]:
25
+ return
26
+
27
+ self .order = None
22
28
23
29
def next (self ):
24
30
if self .order :
25
31
return
26
32
27
- inp = np .asanyarray ([self .dataclose [0 ], self .datavol [0 ]])
33
+ input_data = []
34
+ for i in range (7 ):
35
+ input_data .append (self .dataclose [i - 6 ])
36
+ input_data .append (self .datavol [i - 6 ])
37
+ inp = np .asanyarray (input_data )
28
38
inp = np .expand_dims (inp , 0 )
29
39
30
40
predict = self .p .model .predict (inp )[0 ]
@@ -44,6 +54,15 @@ def next(self):
44
54
if predict == 0 :
45
55
self .order = self .buy ()
46
56
57
+ model = Sequential ()
58
+ model .add (Dense (128 , input_dim = 14 , activation = 'relu' ))
59
+ model .add (Dense (256 , activation = 'relu' ))
60
+ model .add (Dense (512 , activation = 'relu' ))
61
+ model .add (Dense (1024 , activation = 'relu' ))
62
+ model .add (Dense (2 , activation = 'relu' ))
63
+
64
+ model .compile (optimizer = 'Adam' , loss = 'mse' )
65
+
47
66
data = bt .feeds .GenericCSVData (
48
67
dataname = 'eur_usd_1d.csv' ,
49
68
separator = ',' ,
@@ -59,19 +78,12 @@ def next(self):
59
78
openinterest = - 1
60
79
)
61
80
62
- model = Sequential ()
63
- model .add (Dense (128 , input_dim = 2 , activation = 'relu' ))
64
- model .add (Dense (1024 , activation = 'relu' ))
65
- model .add (Dense (2 , activation = 'relu' ))
66
-
67
- model .compile (optimizer = 'Adam' , loss = 'mse' )
68
-
69
-
70
81
def get_reward (weights ):
71
82
model .set_weights (weights )
72
83
cerebro = bt .Cerebro ()
73
84
cerebro .addstrategy (ESStrategy , model = model )
74
85
cerebro .adddata (data )
86
+ cerebro .broker .setcash (1000 )
75
87
cerebro .addsizer (bt .sizers .FixedSize , stake = 50 )
76
88
77
89
cerebro .run ()
0 commit comments