-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_new_model.py
More file actions
117 lines (98 loc) · 5.2 KB
/
train_new_model.py
File metadata and controls
117 lines (98 loc) · 5.2 KB
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
import pickle
import pandas as pd
from fund import Fund
from fund_model import FundModel
from result_evaluator import SingleTanhResultEvaluator
from pricing_models import NormPricer
from features_v2 import GROWTH_NAMES
#n100_data: pd.DataFrame = pickle.load(open('n100_daily.pickle', 'rb'))
# sp_data: pd.DataFrame = pickle.load(open('sp500_daily.pickle', 'rb'))
#
# thresholds = list(range(3, 30))
# thresholds = [t/(365 * 50) for t in thresholds]
# my_pricing_model = NormPricer(lower_z_bound=0, upper_z_bound=2.5, num_partitions=100, call=True, decay=0.00002,
# reg_base_mu=200000)
# sp_model: Fund = Fund('sp100_april_2023', base_data=sp_data)
def create_fund_model(data, name, pricing_model, thresholds, pricing_frac=0.3):
this_fund: Fund = Fund(name, base_data=data)
this_fund.set_pricing_model(thresholds=thresholds, price_model_prototype=pricing_model, frac=pricing_frac)
my_evaluator = SingleTanhResultEvaluator(16, 2.5, 0.2)
for num_days in GROWTH_NAMES:
this_fund.create_models(num_days=num_days, num_selection_bundles=12, results_evaluator=my_evaluator,
num_trials=5,
jitter_count=4, master_seed=71, cont_jitter_magnitude=0.15, overwrite=False, frac=0.2)
this_fund.save()
this_fund.tune_classifiers(evaluator=my_evaluator, frac=0.35, num_trials=6, min_improvement=0.05)
this_fund.save('classifiers_tuned')
this_fund.tune_regressors(frac=0.35, num_trials=6, min_leaves=4)
this_fund.save('regressors_tuned')
this_fund.train_classifiers(jitter_magnitude=0.15, jitter_count=1, frac=None)
this_fund.train_regressors(jitter_magnitude=0.15, jitter_count=1, frac=None)
this_fund.save('trained')
return this_fund
#n100_fund: Fund = Fund('n100_v92', base_data=n100_data)
# n100_fund.set_pricing_model(thresholds=thresholds, rough=False, price_model_prototype=my_pricing_model, frac=0.3)
# n100_fund.save('pricing_set')
# my_evaluator = SingleTanhResultEvaluator(16, 2.5, 0.2)
# #my_fund: Fund = pickle.load(open('model_snapshots/sp_v91_pricing_set.pickle', 'rb'))
# for num_days in GROWTH_NAMES:
# n100_fund.create_models(num_days=num_days, num_selection_bundles=12, results_evaluator=my_evaluator, num_trials=5,
# jitter_count=4, master_seed=71, cont_jitter_magnitude=0.15, overwrite=False, frac=0.2)
# n100_fund.save()
#n100_fund: Fund = pickle.load(open('model_snapshots/n100_v9_classifiers_tuned.pickle', 'rb'))
#
# n100_fund.tune_classifiers(evaluator=my_evaluator, frac=0.35, num_trials=6, min_improvement=0.05)
# n100_fund.save('classifiers_tuned')
#
# n100_fund.tune_regressors(frac=0.35, num_trials=6, min_leaves=4)
# n100_fund.save('regressors_tuned')
#
# n100_fund.train_classifiers(jitter_magnitude=0.15, jitter_count=1, frac=None)
# n100_fund.train_regressors(jitter_magnitude=0.15, jitter_count=1, frac=None)
#
# n100_fund.save('trained')
# my_fund: Fund = Fund('sp_v93', base_data=sp_data)
# my_fund.set_pricing_model(thresholds=thresholds, rough=False, price_model_prototype=my_pricing_model, frac=0.3)
# my_fund.save('pricing_set')
# my_fund.report_prices(sp_data, price_today=390.58, num_days_offset=10)
# # my_fund: Fund = pickle.load(open('model_snapshots/temp_pricing_set.pickle', 'rb'))
#
# #my_fund = pickle.load(open('SP500v8_pricing_set.pickle', 'rb'))
#
# # my_fund: Fund = pickle.load(open('SP500_v7_2022-09-08 21_14_23.pickle', 'rb'))
# # pickle.dump(my_fund.pricing_model, open('N100_pricing_model.pickle', 'wb'))
# # pricing_model = pickle.load(open('N100_pricing_model.pickle', 'rb'))
# # my_fund.pricing_model = pricing_model
# # my_fund.set_growth_data()
#
# # for key in my_trained_fund.models:
# # my_fund.models[key] = my_trained_fund.models[key]
#
# # my_fund: Fund = pickle.load(open('SandP500_v6_2022-07-16 02_45_37.pickle', 'rb'))
#
# # old_fund: Fund= pickle.load(open('N100_v7_2022-09-08 20_11_07.pickle', 'rb'))
# # my_fund: Fund = Fund.extend_fund(old_fund, name='N100_v7_expanded', base_data=my_data)
# # my_fund.pricing_model = my_ref_fund.pricing_model
#
# # my_fund: Fund = pickle.load(open('temp_pricing_set.pickle', 'rb'))
#
# my_fund: Fund = pickle.load(open('model_snapshots/sp_v91_2023-01-14 11_02_38.pickle', 'rb'))
# my_evaluator = SingleTanhResultEvaluator(16, 2.5, 0.2)
# #my_fund: Fund = pickle.load(open('model_snapshots/sp_v91_pricing_set.pickle', 'rb'))
# for num_days in GROWTH_NAMES:
# my_fund.create_models(num_days=num_days, num_selection_bundles=12, results_evaluator=my_evaluator, num_trials=5,
# jitter_count=4, master_seed=71, cont_jitter_magnitude=0.15, overwrite=False, frac=0.2)
# my_fund.save()
# my_fund: Fund = pickle.load(open('model_snapshots/sp_v91_2023-01-13 06_55_19.pickle', 'rb'))
# my_fund.tune_classifiers(evaluator=my_evaluator, frac=0.35, num_trials=6, min_improvement=0.05)
# my_fund.save('classifiers_tuned')
#
# # my_fund = pickle.load(open('model_snapshots/sp_v90_classifiers_tuned.pickle', 'rb'))
#
# my_fund.tune_regressors(frac=0.35, num_trials=6, min_leaves=4)
# my_fund.save('regressors_tuned')
#
# my_fund.train_classifiers(jitter_magnitude=0.15, jitter_count=1, frac=None)
# my_fund.train_regressors(jitter_magnitude=0.15, jitter_count=1, frac=None)
#
# my_fund.save('trained')