-
Notifications
You must be signed in to change notification settings - Fork 119
/
sklearn_evaluation_script.py
67 lines (51 loc) · 2.3 KB
/
sklearn_evaluation_script.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
import numpy as np
from random import randint, choice
from trading_strategy_fitting import fit_strategy, offset_scan_validation, tic, underlined_output
from strategy_evaluation import output_strategy_results
def random_search(strategy_dictionary_local, n_iterations):
toc = tic()
counter = 0
error = -1e5
while counter < n_iterations:
counter += 1
strategy_dictionary_local = randomise_dictionary_inputs(strategy_dictionary_local)
fitting_dictionary, data_to_predict, profit_factor = fit_strategy(strategy_dictionary_local)
error_loop = fitting_dictionary['error']
if error_loop > error and fitting_dictionary['n_trades'] != 0:
error = error_loop
strategy_dictionary_local_optimum = strategy_dictionary_local
fitting_dictionary_optimum = fitting_dictionary
underlined_output('Best strategy fit')
output_strategy_results(strategy_dictionary_local_optimum, fitting_dictionary_optimum, data_to_predict, toc)
return strategy_dictionary_local_optimum
def randomise_dictionary_inputs(strategy_dictionary_local):
strategy_dictionary_local['ml_mode'] = choice(['adaboost', 'randomforest', 'gradientboosting', 'extratreesfitting']) #'svm'
strategy_dictionary_local['regression_mode'] = choice(['regression', 'classification'])
strategy_dictionary_local['preprocessing'] = choice(['PCA', 'FastICA', 'None'])
return strategy_dictionary_local
if __name__ == '__main__':
strategy_dictionary = {
'trading_currencies': ['ETH', 'BTC'],
'ticker_1': 'BTC_ETH',
'ticker_2': 'USDT_BTC',
'candle_size': 300,
'n_days': 20,
'offset': 0,
'bid_ask_spread': 0.001,
'transaction_fee': 0.0025,
'train_test_ratio': 0.5,
'output_flag': True,
'plot_flag': False,
'ml_iterations': 100,
'target_score': 'idealstrategy',
'windows': [1, 5, 10, 50, 100],
'web_flag': 'False',
'filename1': "USDT_BTC.csv",
'filename2': "BTC_ETH.csv"
}
search_iterations = 50
strategy_dictionary = random_search(strategy_dictionary, search_iterations)
underlined_output('Offset validation')
offsets = np.linspace(0, 300, 5)
offset_scan_validation(strategy_dictionary, offsets)
print strategy_dictionary