This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
dependency_injection_containers.py
244 lines (208 loc) · 10.4 KB
/
dependency_injection_containers.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
'''
Created on 09.11.2017
@author: jtymoszuk
'''
import dependency_injector.containers as containers
import dependency_injector.providers as providers
from definitions import DQLTRADER_PERFECT_PREDICTOR, DQLTRADER_RANDOM_PREDICTOR, \
DQLTRADER_PERFECT_NN_BINARY_PREDICTOR, DQLTRADER_NN_BINARY_PREDICTOR
from model.CompanyEnum import CompanyEnum
from predicting.predictor.reference.random_predictor import RandomPredictor
from predicting.predictor.reference.perfect_predictor import PerfectPredictor
from predicting.predictor.reference.nn_binary_predictor import StockANnBinaryPredictor, \
StockBNnBinaryPredictor
from predicting.predictor.reference.nn_perfect_binary_predictor import StockANnPerfectBinaryPredictor, \
StockBNnPerfectBinaryPredictor
from trading.trader.reference.simple_trader import SimpleTrader
from trading.trader.reference.buy_and_hold_trader import BuyAndHoldTrader
from trading.trader.reference.dql_trader import DqlTrader
from predicting.predictor.team_blue.team_blue_predictor import TeamBlueStockAPredictor, \
TeamBlueStockBPredictor
from predicting.predictor.team_green.team_green_predictor import TeamGreenStockAPredictor, \
TeamGreenStockBPredictor
from predicting.predictor.team_black.team_black_predictor import TeamBlackStockBPredictor, \
TeamBlackStockAPredictor
from predicting.predictor.team_red.team_red_predictor import TeamRedStockBPredictor, \
TeamRedStockAPredictor
from trading.trader.team_blue.team_blue_simple_trader import TeamBlueSimpleTrader
from trading.trader.team_green.team_green_simple_trader import TeamGreenSimpleTrader
from trading.trader.team_black.team_black_simple_trader import TeamBlackSimpleTrader
from trading.trader.team_red.team_red_simple_trader import TeamRedSimpleTrader
from trading.trader.team_blue.team_blue_dql_trader import TeamBlueDqlTrader
from trading.trader.team_blue import team_blue_dql_trader
from trading.trader.team_green.team_green_dql_trader import TeamGreenDqlTrader
from trading.trader.team_green import team_green_dql_trader
from trading.trader.team_black.team_black_dql_trader import TeamBlackDqlTrader
from trading.trader.team_black import team_black_dql_trader
from trading.trader.team_red.team_red_dql_trader import TeamRedDqlTrader
from trading.trader.team_red import team_red_dql_trader
class Predictors(containers.DeclarativeContainer):
"""IoC container of predictor providers."""
""" Random predictor delivering value of last share +- Random[0,1]"""
RandomPredictor = providers.Factory(RandomPredictor)
""" Perfect predictors knowing future"""
# Task 0 and Task 2
PerfectPredictor_stock_a = providers.Factory(PerfectPredictor, CompanyEnum.COMPANY_A)
PerfectPredictor_stock_b = providers.Factory(PerfectPredictor, CompanyEnum.COMPANY_B)
""" Predictors based on neural networks, trying to estimate next future value of share"""
# Currently not in use
# StockANnValuePredictor = providers.Factory(StockANnValuePredictor)
# StockBNnValuePredictor = providers.Factory(StockBNnValuePredictor)
""" Binary predictors based on neural networks trained only with historical data (till 2011).
Predictors are estimating only if next value will go up or down - returned result is then value of last share +- constant value """
StockANnBinaryPredictor = providers.Factory(StockANnBinaryPredictor)
StockBNnBinaryPredictor = providers.Factory(StockBNnBinaryPredictor)
""" Predictors based on neural networks trained only with all available data (till 2017).
Predictors are estimating only if next value will go up or down - returned result is then value of last share +- constant value """
StockANnPerfectBinaryPredictor = providers.Factory(StockANnPerfectBinaryPredictor)
StockBNnPerfectBinaryPredictor = providers.Factory(StockBNnPerfectBinaryPredictor)
"""Initial empty Predictors for training purposes"""
"""Team Blue Predictors"""
# Task 1
TeamBlueStockAPredictor = providers.Factory(TeamBlueStockAPredictor)
TeamBlueStockBPredictor = providers.Factory(TeamBlueStockBPredictor)
"""Team Green Predictors"""
# Task 1
TeamGreenStockAPredictor = providers.Factory(TeamGreenStockAPredictor)
TeamGreenStockBPredictor = providers.Factory(TeamGreenStockBPredictor)
"""Team Black Predictors"""
# Task 1
TeamBlackStockAPredictor = providers.Factory(TeamBlackStockAPredictor)
TeamBlackStockBPredictor = providers.Factory(TeamBlackStockBPredictor)
"""Team Red Predictors"""
# Task 1
TeamRedStockAPredictor = providers.Factory(TeamRedStockAPredictor)
TeamRedStockBPredictor = providers.Factory(TeamRedStockBPredictor)
class Traders(containers.DeclarativeContainer):
"""IoC container of trader providers."""
"""Simple Trader"""
SimpleTrader_with_perfect_prediction = providers.Factory(
SimpleTrader,
stock_a_predictor=Predictors.PerfectPredictor_stock_a,
stock_b_predictor=Predictors.PerfectPredictor_stock_b
)
SimpleTrader_with_random_prediction = providers.Factory(
SimpleTrader,
stock_a_predictor=Predictors.RandomPredictor,
stock_b_predictor=Predictors.RandomPredictor
)
SimpleTrader_with_nn_binary_perfect_prediction = providers.Factory(
SimpleTrader,
stock_a_predictor=Predictors.StockANnPerfectBinaryPredictor,
stock_b_predictor=Predictors.StockBNnPerfectBinaryPredictor
)
SimpleTrader_with_nn_binary_prediction = providers.Factory(
SimpleTrader,
stock_a_predictor=Predictors.StockANnBinaryPredictor,
stock_b_predictor=Predictors.StockBNnBinaryPredictor
)
"""Buy and Hold Trader"""
BuyAndHoldTrader = providers.Factory(
BuyAndHoldTrader
)
"""DQL Trader"""
DqlTrader_with_perfect_prediction = providers.Factory(
DqlTrader,
stock_a_predictor=Predictors.PerfectPredictor_stock_a,
stock_b_predictor=Predictors.PerfectPredictor_stock_b,
name=DQLTRADER_PERFECT_PREDICTOR
)
DqlTrader_with_random_prediction = providers.Factory(
DqlTrader,
stock_a_predictor=Predictors.RandomPredictor,
stock_b_predictor=Predictors.RandomPredictor,
name=DQLTRADER_RANDOM_PREDICTOR
)
DqlTrader_with_nn_binary_perfect_prediction = providers.Factory(
DqlTrader,
stock_a_predictor=Predictors.StockANnPerfectBinaryPredictor,
stock_b_predictor=Predictors.StockBNnPerfectBinaryPredictor,
name=DQLTRADER_PERFECT_NN_BINARY_PREDICTOR
)
DqlTrader_with_nn_binary_prediction = providers.Factory(
DqlTrader,
stock_a_predictor=Predictors.StockANnBinaryPredictor,
stock_b_predictor=Predictors.StockBNnBinaryPredictor,
name=DQLTRADER_NN_BINARY_PREDICTOR
)
"""Traders for training purposes"""
"""Team Blue Traders"""
# Task 0
TeamBlueSimpleTrader_with_perfect_prediction = providers.Factory(
TeamBlueSimpleTrader,
stock_a_predictor=Predictors.PerfectPredictor_stock_a,
stock_b_predictor=Predictors.PerfectPredictor_stock_b
)
# Task 1
SimpleTrader_with_team_blue_prediction = providers.Factory(
SimpleTrader,
stock_a_predictor=Predictors.TeamBlueStockAPredictor,
stock_b_predictor=Predictors.TeamBlueStockBPredictor
)
# Task 2
TeamBlueDqlTrader_with_perfect_prediction = providers.Factory(
TeamBlueDqlTrader,
stock_a_predictor=Predictors.PerfectPredictor_stock_a,
stock_b_predictor=Predictors.PerfectPredictor_stock_b,
network_filename=team_blue_dql_trader.MODEL_FILENAME_DQLTRADER_NN_BINARY_PREDICTOR
)
"""Team Green Traders"""
# Task 0
TeamGreenSimpleTrader_with_perfect_prediction = providers.Factory(
TeamGreenSimpleTrader,
stock_a_predictor=Predictors.PerfectPredictor_stock_a,
stock_b_predictor=Predictors.PerfectPredictor_stock_b
)
# Task 1
SimpleTrader_with_team_green_prediction = providers.Factory(
SimpleTrader,
stock_a_predictor=Predictors.TeamGreenStockAPredictor,
stock_b_predictor=Predictors.TeamGreenStockBPredictor
)
# Task 2
TeamGreenDqlTrader_with_perfect_prediction = providers.Factory(
TeamGreenDqlTrader,
stock_a_predictor=Predictors.PerfectPredictor_stock_a,
stock_b_predictor=Predictors.PerfectPredictor_stock_b,
network_filename=team_green_dql_trader.MODEL_FILENAME_DQLTRADER_NN_BINARY_PREDICTOR
)
"""Team Black Traders"""
# Task 0
TeamBlackSimpleTrader_with_perfect_prediction = providers.Factory(
TeamBlackSimpleTrader,
stock_a_predictor=Predictors.PerfectPredictor_stock_a,
stock_b_predictor=Predictors.PerfectPredictor_stock_b
)
# Task 1
SimpleTrader_with_team_black_prediction = providers.Factory(
SimpleTrader,
stock_a_predictor=Predictors.TeamBlackStockAPredictor,
stock_b_predictor=Predictors.TeamBlackStockBPredictor
)
# Task 2
TeamBlackDqlTrader_with_perfect_prediction = providers.Factory(
TeamBlackDqlTrader,
stock_a_predictor=Predictors.PerfectPredictor_stock_a,
stock_b_predictor=Predictors.PerfectPredictor_stock_b,
network_filename=team_black_dql_trader.MODEL_FILENAME_DQLTRADER_NN_BINARY_PREDICTOR
)
"""Team Red Traders"""
# Task 0
TeamRedSimpleTrader_with_perfect_prediction = providers.Factory(
TeamRedSimpleTrader,
stock_a_predictor=Predictors.PerfectPredictor_stock_a,
stock_b_predictor=Predictors.PerfectPredictor_stock_b
)
# Task 1
SimpleTrader_with_team_red_prediction = providers.Factory(
SimpleTrader,
stock_a_predictor=Predictors.TeamRedStockAPredictor,
stock_b_predictor=Predictors.TeamRedStockBPredictor
)
# Task 2
TeamRedDqlTrader_with_perfect_prediction = providers.Factory(
TeamRedDqlTrader,
stock_a_predictor=Predictors.PerfectPredictor_stock_a,
stock_b_predictor=Predictors.PerfectPredictor_stock_b,
network_filename=team_red_dql_trader.MODEL_FILENAME_DQLTRADER_NN_BINARY_PREDICTOR
)