-
Notifications
You must be signed in to change notification settings - Fork 2
/
examples.py
50 lines (36 loc) · 1.7 KB
/
examples.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
from tabulate import tabulate
from examples import Examples, ExamplesInterface
from examples.common.candle import get_candle_type
from libs.stock import Stock
class Runner(Stock):
def __init__(self):
super().__init__()
self.examples = Examples()
def simulate_real_market_sync(self):
for example in self.examples.get_all():
print(f'Running {example["name"]} Example ...')
diagnostic = {
"Orders": 0,
"Winners": 0,
"Losers": 0
}
for stock_price_index in range(5, len(self.stock)):
stock_mocked_data = self.stock[:stock_price_index]
example_class: ExamplesInterface = example["class"](stock_mocked_data)
entry_signal, entry_direction = example_class.strategy()
if entry_signal:
market_order_details = example_class.market_order_stock_details()
""" Compute order """
diagnostic["Orders"] += 1
""" Mock order result """
closed_signal_candle = self.stock[stock_price_index+1]
if entry_direction == get_candle_type(closed_signal_candle["close"], closed_signal_candle["open"]):
diagnostic["Winners"] += 1
else:
diagnostic["Losers"] += 1
diagnostic["Avg"] = "{0} %".format(round(100 * float(diagnostic["Winners"]) / float(diagnostic["Orders"])))
print(tabulate({h: [d] for h, d in diagnostic.items()}, headers="keys"))
print("\n")
if __name__ == "__main__":
runner = Runner()
runner.simulate_real_market_sync()