-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_hyperopt.py
94 lines (76 loc) · 2.5 KB
/
test_hyperopt.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
from lazyft.command import create_commands
from lazyft.command_parameters import HyperoptParameters
from lazyft.hyperopt.runner import HyperoptRunner
from lazyft.models import HyperoptPerformance, HyperoptReport
STRATEGY = ["TestStrategy3"]
STRATEGY_WITH_ID = ["TestStrategy3-test"]
config_name = "config_test.json"
epochs = 5
days = 2
min_trades = 1
def get_commands(strategy, timerange=None, spaces="roi"):
hp = get_parameters(spaces, strategy, timerange)
commands = create_commands(
hp,
verbose=True,
)
return commands
def get_parameters(spaces, strategy, timerange):
hp = HyperoptParameters(
strategies=strategy,
config_path=config_name,
epochs=epochs,
spaces=spaces or "buy sell",
min_trades=min_trades,
days=days,
timerange=timerange,
download_data=True,
)
return hp
def test_hyperopt():
commands = get_commands(STRATEGY)
runner = HyperoptRunner(commands[0], notify=False)
runner.execute()
report = runner.report
print(report)
assert isinstance(report, HyperoptReport)
assert report.strategy == STRATEGY[0]
assert isinstance(report.performance, HyperoptPerformance)
print(runner.save())
def test_hyperopt_with_id():
commands = get_commands(STRATEGY_WITH_ID)
runner = HyperoptRunner(commands[0], notify=False)
runner.execute()
assert bool(runner.report)
def test_build_command_with_days():
commands = get_commands(STRATEGY)
assert any(commands)
print(commands[0].command_string)
# def test_celery():
# hp = get_parameters('roi stoploss', ['TestStrategy'], '20210801-')
# task_id = CeleryRunner.celery_execute(hp)
# time.sleep(3)
# runner = CeleryRunner.load(task_id)
# assert runner.report_id == task_id
# print(runner.output)
# def test_param_save():
# params = {'mock': 'data'}
# ...
# def test_multiple_hyperopt_runners():
# commands = create_commands(
# strategies=STRATEGIES,
# config=pathlib.Path(lazyft.constants.CONFIG_DIR, 'config_binance.json'),
# epochs=2,
# spaces='bs',
# days=10,
# )
# manager = HyperoptManager(commands)
# manager.create_runners()
# assert any(manager.runners)
# manager.execute()
# manager.generate_reports()
# assert isinstance(manager.reports, list)
# report = manager.reports[0]
# assert isinstance(report, HyperoptReport)
# best_run = manager.get_best_run()
# assert isinstance(best_run, HyperoptReport)