-
Notifications
You must be signed in to change notification settings - Fork 0
/
parameters.py
187 lines (133 loc) · 4.36 KB
/
parameters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import config
from pivot import Pivot
class PivotParameters:
def __init__(self, conf: config.PivotOptions):
self.window = Pivot.WINDOW
if conf is None:
return
tag = "window"
if conf.has(tag):
self.window = conf.get(tag)
# parameters for regular run
class RunParameters:
# conf: the JSON object, default if None
def __init__(self, conf: config.RunOptions):
# defaults
self.gap_window = Pivot.WINDOW + 1
self.backcandles = 40
self.sl_distance = 0.025
self.tp_sl_ratio = 1.9
self.zone_height = 0.001
self.breakout_factor = 1.84
if conf is None:
return
# copy provided parameters
tag = "gap_window"
if conf.has(tag):
self.gap_window = conf.get(tag)
tag = "backcandles"
if conf.has(tag):
self.backcandles = conf.get(tag)
tag = "sl_distance"
if conf.has(tag):
self.sl_distance = conf.get(tag)
tag = "tp_sl_ratio"
if conf.has(tag):
self.tp_sl_ratio = conf.get(tag)
tag = "zone_height"
if conf.has(tag):
self.zone_height = conf.get(tag)
tag = "breakout_factor"
if conf.has(tag):
self.breakout_factor = conf.get(tag)
# parameters for optimization run
class OptimizeParameters:
# conf: the JSON object, default if None
def __init__(self, conf: config.OptimizeOptions):
# defaults
self.gap_window = [Pivot.WINDOW+1]
self.backcandles = [39, 40]
self.sl_distance = [0.024 + x/1000 for x in range(0, 3)]
self.tp_sl_ratio = [1.5 + x/10 for x in range(0, 5)]
self.zone_height = [0.00090, 0.00095, 0.00100]
self.breakout_factor = [1.84 + x/25 for x in range(0, 5)]
if conf is None:
return
# copy provided parameters
tag = 'gap_window'
if conf.has(tag):
self.gap_window = conf.get(tag)
tag = 'backcandles'
if conf.has(tag):
self.backcandles = conf.get(tag)
tag = 'sl_distance'
if conf.has(tag):
self.sl_distance = conf.get(tag)
tag = 'tp_sl_ratio'
if conf.has(tag):
self.tp_sl_ratio = conf.get(tag)
tag = 'zone_height'
if conf.has(tag):
self.zone_height = conf.get(tag)
tag = 'breakout_factor'
if conf.has(tag):
self.breakout_factor = conf.get(tag)
# parameters for trading
class TradingParameters:
# conf: the JSON object, default if None
def __init__(self, conf: config.TradingOptions):
# defaults
self.amount = 10000.0
self.size = 0.9
self.commission = 0.0
self.plong: bool = True
self.pshort: bool = False
if conf is None:
return
# copy provided parameters
tag = "amount"
if conf.has(tag):
self.amount = conf.get(tag)
tag = "size"
if conf.has(tag):
self.size = conf.get(tag)
tag = "commission"
if conf.has(tag):
self.commission = conf.get(tag)
tag = "long"
if conf.has(tag):
self.plong = conf.get(tag)
tag = "short"
if conf.has(tag):
self.pshort = conf.get(tag)
# parameters to switch functions OFF | ON
class RuntimeParameters:
# conf: the JSON object, default if None
def __init__(self, conf: config.TradingOptions):
# defaults
self.SAVE_SNAPSHOT: bool = False
self.STORE_SIGNALS: bool = False
self.STORE_ACTIONS: bool = False
self.OPTIMIZE: bool = False
self.RUN: bool = False
self.PLOTTING: bool = False
if conf is None:
return
tag = "save_snapshot"
if conf.has(tag):
self.SAVE_SNAPSHOT = conf.get(tag)
tag = "store_signals"
if conf.has(tag):
self.STORE_ACTIONS = conf.get(tag)
tag = "store_actions"
if conf.has(tag):
self.STORE_ACTIONS = conf.get(tag)
tag = "optimize"
if conf.has(tag):
self.OPTIMIZE = conf.get(tag)
tag = "run"
if conf.has(tag):
self.RUN = conf.get(tag)
tag = "plotting"
if conf.has(tag):
self.PLOTTING = conf.get(tag)