yufeng 4 years ago
parent
commit
c025ea15d1

+ 4 - 4
industry/industry_predict_everyday_100.py

@@ -36,10 +36,10 @@ def predict_today(file, day, model='10_18d', log=True):
36 36
 
37 37
     for line in lines:
38 38
         train_x = np.array([line[:size - 1]])
39
-        train_x_tmp = train_x[:,:10*8]
40
-        train_x_a = train_x_tmp.reshape(train_x.shape[0], 10, 8, 1)
39
+        train_x_tmp = train_x[:,:11*11]
40
+        train_x_a = train_x_tmp.reshape(train_x.shape[0], 11, 11, 1)
41 41
         # train_x_b = train_x_tmp.reshape(train_x.shape[0], 18, 24)
42
-        train_x_c = train_x[:,10*8:]
42
+        train_x_c = train_x[:,11*11:]
43 43
 
44 44
         result = model.predict([train_x_c, train_x_a, ])
45 45
         # print(result, line[-1])
@@ -66,6 +66,6 @@ def predict_today(file, day, model='10_18d', log=True):
66 66
 
67 67
 
68 68
 if __name__ == '__main__':
69
-    predict_today("D:\\data\\quantization\\industry\\stock13_10d_3D_20200417.log", 20200417, model='107_10d_mix_3D_s_seq.h5', log=True)
69
+    predict_today("D:\\data\\quantization\\industry\\stock15_10d_3D_20200417.log", 20200417, model='111_10d_mix_3D_s_seq.h5', log=True)
70 70
     # join_two_day(20200305, 20200305)
71 71
     # check_everyday(20200311, 20200312)

+ 19 - 8
industry/industry_train_100.py

@@ -16,13 +16,14 @@ from keras.callbacks import EarlyStopping
16 16
 
17 17
 early_stopping = EarlyStopping(monitor='accuracy', patience=5, verbose=2)
18 18
 
19
-epochs= 50
19
+epochs= 33
20 20
 # size = 24000 #共68W
21
-file_path = 'D:\\data\\quantization\\industry\\stock13_10d_3D_train1.log'
22
-model_path = '107_10d_mix_3D_s_seq.h5'
23
-file_path1='D:\\data\\quantization\\industry\\stock13_10d_3D_train2.log'
24
-row = 10
25
-col = 8
21
+file_path = 'D:\\data\\quantization\\industry\\stock15_10d_3D_train1.log'
22
+model_path = '111_10d_mix_3D_s_seq.h5'
23
+file_path1='D:\\data\\quantization\\industry\\stock15_10d_3D_train2.log'
24
+file_path2='D:\\data\\quantization\\industry\\stock15_10d_3D_train3.log'
25
+row = 11
26
+col = 11
26 27
 '''
27 28
 1   10-3天    10*9    35,103,34-28
28 29
 2   10-3/             34,101,35-28    !
@@ -31,6 +32,11 @@ col = 8
31 32
 5   18-3 win=3  18*9  32,100,42-30
32 33
 6   18-3 win=6  18*9  37,100,38,27
33 34
 7   10-3 win=3 amount涨幅 10*8 37,100,40-27
35
+8   10-3 ma5 10*9     36,100,40-27     
36
+9   11-3 win=3 low+high  11*11      31,100,42-24   
37
+10  11-3 win=4 low+high  11*11      35,100,43-29
38
+11  11-3 win=6 low+high  11*11      38,100,41     !
39
+12  12-5 win=6 ma5       12*11      37,100,42-27
34 40
 '''
35 41
 
36 42
 def read_data(path, path1=file_path1):
@@ -45,6 +51,11 @@ def read_data(path, path1=file_path1):
45 51
             line = eval(x.strip())
46 52
             lines.append(line)
47 53
 
54
+    with open(file_path2) as f:
55
+        for x in f.readlines(): #680000
56
+            line = eval(x.strip())
57
+            lines.append(line)
58
+
48 59
     random.shuffle(lines)
49 60
     print('读取数据完毕')
50 61
 
@@ -81,7 +92,7 @@ def create_mlp(dim, regress=False):
81 92
     model.add(Dense(256, input_dim=dim, activation="relu"))
82 93
     model.add(Dropout(0.2))
83 94
     model.add(Dense(256, activation="relu"))
84
-    model.add(Dense(256, activation="relu"))
95
+    # model.add(Dense(256, activation="relu"))
85 96
     model.add(Dense(128, activation="relu"))
86 97
 
87 98
     # check to see if the regression node should be added
@@ -136,7 +147,7 @@ def create_cnn(width, height, depth, size=48, kernel_size=(5, 6), regress=False,
136 147
 # create the MLP and CNN models
137 148
 mlp = create_mlp(train_x_c.shape[1], regress=False)
138 149
 # cnn_0 = create_cnn(18, 20, 1, kernel_size=(3, 3), size=90, regress=False, output=96)       # 31 97 46
139
-cnn_0 = create_cnn(row, col, 1, kernel_size=(3, col), size=96, regress=False, output=96)         # 29 98 47
150
+cnn_0 = create_cnn(row, col, 1, kernel_size=(6, col), size=88, regress=False, output=88)         # 29 98 47
140 151
 # cnn_0 = create_cnn(18, 20, 1, kernel_size=(9, 9), size=90, regress=False, output=96)         # 28 97 53
141 152
 # cnn_0 = create_cnn(18, 20, 1, kernel_size=(3, 20), size=90, regress=False, output=96)
142 153
 # cnn_1 = create_cnn(18, 20, 1, kernel_size=(18, 10), size=80, regress=False, output=96)

+ 12 - 10
mix/mix_predict_500.py

@@ -22,15 +22,16 @@ def _score(fact, line):
22 22
     up_error = 0
23 23
 
24 24
     if fact[0] == 1:
25
-        up_right = up_right + 1.12
25
+        up_right = up_right + 1.1
26 26
     elif fact[1] == 1:
27
-        up_right = up_right + 1.04
27
+        up_error = up_error + 0.4
28
+        up_right = up_right + 1.03
28 29
     elif fact[2] == 1:
29
-        up_error = up_error + 0.3
30
-        up_right = up_right + 0.98
30
+        up_error = up_error + 0.7
31
+        up_right = up_right + 0.96
31 32
     else:
32 33
         up_error = up_error + 1
33
-        up_right = up_right + 0.94
34
+        up_right = up_right + 0.9
34 35
     return up_right,up_error
35 36
 
36 37
 
@@ -63,15 +64,15 @@ def predict(file_path='', model_path='15min_dnn_seq.h5', idx=-1, row=18, col=20)
63 64
             if r[0] > 0.5 or r[1] > 0.5:
64 65
                 pass
65 66
         else:
66
-            if r[0] > 0.6 :
67
+            if r[0] > 0.5 :
67 68
                 tmp_right,tmp_error = _score(fact, lines[i])
68 69
                 up_right = tmp_right + up_right
69 70
                 up_error = tmp_error + up_error
70 71
                 up_num = up_num + 1
71
-            elif r[2] > 0.6 or r[3] > 0.6:
72
+            elif r[2] > 0.5 or r[3] > 0.5:
72 73
                 if fact[0] == 1:
73 74
                     down_error = down_error + 1
74
-                    down_right = down_right + 1.14
75
+                    down_right = down_right + 1.1
75 76
                 elif fact[1] == 1:
76 77
                     down_error = down_error + 0.5
77 78
                     down_right = down_right + 1.04
@@ -94,7 +95,8 @@ if __name__ == '__main__':
94 95
     # predict(file_path='D:\\data\\quantization\\stock181_18d_test.log', model_path='181_18d_mix_6D_ma5_s_seq.h5')
95 96
     # predict(file_path='D:\\data\\quantization\\stock217_18d_train1.log', model_path='218_18d_mix_5D_ma5_s_seq.h5', row=18, col=18)
96 97
     # predict(file_path='D:\\data\\quantization\\stock400_18d_train1.log', model_path='400_18d_mix_5D_ma5_s_seq.h5', row=18, col=18)
97
-    predict(file_path='D:\\data\\quantization\\stock507_28d_train1.log', model_path='507_28d_mix_5D_ma5_s_seq.h5', row=28, col=19)
98
+    predict(file_path='D:\\data\\quantization\\stock517_28d_train1.log', model_path='517_28d_mix_3D_ma5_s_seq.h5', row=28, col=16)
98 99
     # predict(file_path='D:\\data\\quantization\\stock6_test.log', model_path='15m_dnn_seq.h5')
99 100
     # multi_predict(model='15_18d')
100
-    # predict_today(20200229, model='11_18d')
101
+    # predict_today(20200229, model='11_18d')
102
+    # predict(file_path='D:\\data\\quantization\\stock513_28d_train1.log', model_path='513_28d_mix_3D_ma5_s_seq.h5', row=28, col=16)

+ 74 - 21
mix/mix_predict_518.py

@@ -2,6 +2,7 @@
2 2
 import numpy as np
3 3
 from keras.models import load_model
4 4
 import joblib
5
+import random
5 6
 
6 7
 
7 8
 def read_data(path):
@@ -17,31 +18,82 @@ def read_data(path):
17 18
     return np.array(train_x, dtype=np.float32),np.array(train_y, dtype=np.float32),lines
18 19
 
19 20
 
20
-def _score(fact, line):
21
+def _score(fact,):
21 22
     up_right = 0
22 23
     up_error = 0
23 24
 
24 25
     if fact[0] == 1:
25 26
         up_right = up_right + 1.1
26 27
     elif fact[1] == 1:
27
-        up_error = up_error + 0.2
28
-        up_right = up_right + 1.04
28
+        up_error = up_error + 0.4
29
+        up_right = up_right + 1.03
29 30
     elif fact[2] == 1:
30
-        up_error = up_error + 0.5
31
-        up_right = up_right + 0.98
31
+        up_error = up_error + 0.7
32
+        up_right = up_right + 0.96
32 33
     else:
33 34
         up_error = up_error + 1
34
-        up_right = up_right + 0.94
35
+        up_right = up_right + 0.9
35 36
     return up_right,up_error
36 37
 
37 38
 
39
+def random_predict(file_path=''):
40
+    test_x,test_y,lines=read_data(file_path)
41
+    a=0
42
+    b=0
43
+    c=0
44
+    d=0
45
+    R=0
46
+
47
+    up_num = 0
48
+    up_error = 0
49
+    up_right = 0
50
+    down_num = 0
51
+    down_error = 0
52
+    down_right = 0
53
+
54
+    for x in test_y:
55
+        xx = random.uniform(0, 4)
56
+        if xx > 3:
57
+            if x[0] == 1:
58
+                R = R + 1
59
+            tmp_right,tmp_error = _score(x,)
60
+            up_num = up_num + 1
61
+            up_right = up_right + tmp_right
62
+            up_error = tmp_error + up_error
63
+        elif xx > 2:
64
+            if x[1] == 1:
65
+                R = R + 1
66
+        elif xx > 1:
67
+            if x[2] == 1:
68
+                R = R + 1
69
+        elif xx > 0:
70
+            if x[3] == 1:
71
+                R = R + 1
72
+
73
+        if x[0] == 1:
74
+            a = a + 1
75
+        elif x[1] == 1:
76
+            b = b + 1
77
+        elif x[2] == 1:
78
+            c = c + 1
79
+        else:
80
+            d = d + 1
81
+
82
+    if up_num == 0:
83
+        up_num = 1
84
+    if down_num == 0:
85
+        down_num = 1
86
+
87
+    print(R/(a + b + c +d), up_right/up_num, up_error/up_num)
88
+
89
+
38 90
 def predict(file_path='', model_path='15min_dnn_seq.h5', idx=-1, row=18, col=20):
39 91
     test_x,test_y,lines=read_data(file_path)
40 92
 
41 93
     test_x_a = test_x[:,:row*col]
42 94
     test_x_a = test_x_a.reshape(test_x.shape[0], row, col, 1)
43
-    # test_x_b = test_x[:, row*col:row*col+18*2]
44
-    # test_x_b = test_x_b.reshape(test_x.shape[0], 18, 2, 1)
95
+    # test_x_b = test_x[:, 18*col:row*col]
96
+    # test_x_b = test_x_b.reshape(test_x.shape[0], 10, col, 1)
45 97
     test_x_c = test_x[:,row*col:]
46 98
 
47 99
     model=load_model(model_path)
@@ -56,16 +108,19 @@ def predict(file_path='', model_path='15min_dnn_seq.h5', idx=-1, row=18, col=20)
56 108
     down_right = 0
57 109
     i = 0
58 110
     result = model.predict([test_x_c, test_x_a, ])
111
+
112
+
59 113
     win_dnn = []
60 114
     for r in result:
61 115
         fact = test_y[i]
116
+        xx = random.uniform(0, 4)
62 117
 
63 118
         if idx in [-2]:
64 119
             if r[0] > 0.5 or r[1] > 0.5:
65 120
                 pass
66 121
         else:
67
-            if r[0] > 0.5 :
68
-                tmp_right,tmp_error = _score(fact, lines[i])
122
+            if r[1] > 0.6 :
123
+                tmp_right,tmp_error = _score(fact,)
69 124
                 up_right = tmp_right + up_right
70 125
                 up_error = tmp_error + up_error
71 126
                 up_num = up_num + 1
@@ -74,12 +129,13 @@ def predict(file_path='', model_path='15min_dnn_seq.h5', idx=-1, row=18, col=20)
74 129
                     down_error = down_error + 1
75 130
                     down_right = down_right + 1.1
76 131
                 elif fact[1] == 1:
77
-                    down_error = down_error + 0.5
132
+                    down_error = down_error + 0.7
78 133
                     down_right = down_right + 1.04
79 134
                 elif fact[2] == 1:
80
-                    down_right = down_right + 0.98
135
+                    down_error = down_error + 0.3
136
+                    down_right = down_right + 0.94
81 137
                 else:
82
-                    down_right = down_right + 0.92
138
+                    down_right = down_right + 0.9
83 139
                 down_num = down_num + 1
84 140
 
85 141
         i = i + 1
@@ -92,11 +148,8 @@ def predict(file_path='', model_path='15min_dnn_seq.h5', idx=-1, row=18, col=20)
92 148
 
93 149
 
94 150
 if __name__ == '__main__':
95
-    # predict(file_path='D:\\data\\quantization\\stock181_18d_test.log', model_path='181_18d_mix_6D_ma5_s_seq.h5')
96
-    # predict(file_path='D:\\data\\quantization\\stock217_18d_train1.log', model_path='218_18d_mix_5D_ma5_s_seq.h5', row=18, col=18)
97
-    # predict(file_path='D:\\data\\quantization\\stock400_18d_train1.log', model_path='400_18d_mix_5D_ma5_s_seq.h5', row=18, col=18)
98
-    predict(file_path='D:\\data\\quantization\\stock517_28d_train1.log', model_path='517_28d_mix_3D_ma5_s_seq.h5', row=28, col=16)
99
-    # predict(file_path='D:\\data\\quantization\\stock6_test.log', model_path='15m_dnn_seq.h5')
100
-    # multi_predict(model='15_18d')
101
-    # predict_today(20200229, model='11_18d')
102
-    # predict(file_path='D:\\data\\quantization\\stock513_28d_train1.log', model_path='513_28d_mix_3D_ma5_s_seq.h5', row=28, col=16)
151
+    xx = random.uniform(0,4)
152
+    # predict(file_path='D:\\data\\quantization\\stock513_28d_train1.log', model_path='513_28d_mix_3D_ma5_s_seq.h5', row=28, col=16)
153
+    predict(file_path='D:\\data\\quantization\\stock538_28d_train1.log', model_path='539_28d_mix_5D_ma5_s_seq.h5', row=28, col=17)
154
+    # random_predict(file_path='D:\\data\\quantization\\week101_18d_test.log')
155
+    # random_predict(file_path='D:\\data\\quantization\\stock537_28d_train1.log')

+ 18 - 5
mix/mix_predict_by_day_324.py

@@ -60,9 +60,9 @@ def predict(file_path='', model_path='15min_dnn_seq', rows=18, cols=18):
60 60
             if result[0][0]> 0.5:
61 61
                 up_num = up_num + ratio
62 62
             elif result[0][1] > 0.5:
63
-                up_num = up_num + 0.01*ratio
63
+                up_num = up_num + 0.4*ratio
64 64
             elif result[0][2] > 0.5:
65
-                down_num = down_num + 0.01*ratio
65
+                down_num = down_num + 0.4*ratio
66 66
             else:
67 67
                 down_num = down_num + ratio
68 68
 
@@ -77,10 +77,23 @@ def predict(file_path='', model_path='15min_dnn_seq', rows=18, cols=18):
77 77
                 x3 = x3 + 1
78 78
 
79 79
         # print(key, int(up_num), int(down_num), (down_num*1.2 + 2)/(up_num*1.2 + 2), )
80
-        print(key, x0, x1, x2,x3, (down_num*1.2 + 2)/(up_num*1.2 + 2))
80
+        print(key, x0, x1, x2,x3, (down_num*1.5 + 2)/(up_num*1.2 + 2))
81 81
 
82 82
 
83 83
 if __name__ == '__main__':
84
-    # predict(file_path='D:\\data\\quantization\\stock324_28d_3D_20200415.log', model_path='324_28d_mix_5D_ma5_s_seq', rows=28, cols=18)
84
+    # predict(file_path='D:\\data\\quantization\\stock6_5_test.log', model_path='5d_dnn_seq.h5')
85
+    # predict(file_path='D:\\data\\quantization\\stock9_18_20200220.log', model_path='18d_dnn_seq.h5')
86
+    # predict(file_path='D:\\data\\quantization\\stock9_18_2.log', model_path='18d_dnn_seq.h5')
87
+    # predict(file_path='D:\\data\\quantization\\stock16_18d_20200310.log', model_path='16_18d_mix_seq')
88
+    # predict(file_path='D:\\data\\quantization\\stock196_18d_20200326.log', model_path='196_18d_mix_6D_ma5_s_seq')
85 89
 
86
-    predict(file_path='D:\\data\\quantization\\stock324_28d_3D_20191221.log', model_path='324_28d_mix_5D_ma5_s_seq', rows=28, cols=18)
90
+
91
+    # predict(file_path='D:\\data\\quantization\\stock321_28d_5D_20200429.log', model_path='321_28d_mix_5D_ma5_s_seq_2', rows=28, cols=20)
92
+
93
+    predict(file_path='D:\\data\\quantization\\stock327_28d_20200429.log', model_path='327_28d_mix_5D_ma5_s_seq', rows=28, cols=20)
94
+
95
+
96
+
97
+    # predict(file_path='D:\\data\\quantization\\stock9_18_4.log', model_path='18d_dnn_seq.h5')
98
+    # predict(file_path='D:\\data\\quantization\\stock324_28d_3D_20200414_A.log', model_path='324_28d_mix_5D_ma5_s_seq', rows=28, cols=18)
99
+    # predict(file_path='D:\\data\\quantization\\stock324_28d_3D_20200414_A.log', model_path='603_30d_mix_5D_ma5_s_seq', rows=30, cols=19)

+ 22 - 10
mix/mix_predict_everyday_500.py

@@ -36,16 +36,16 @@ def predict_today(file, day, model='10_18d', log=True):
36 36
 
37 37
     for line in lines:
38 38
         train_x = np.array([line[:size - 1]])
39
-        train_x_tmp = train_x[:,:28*20]
40
-        train_x_a = train_x_tmp.reshape(train_x.shape[0], 28, 20, 1)
39
+        train_x_tmp = train_x[:,:28*16]
40
+        train_x_a = train_x_tmp.reshape(train_x.shape[0], 28, 16, 1)
41 41
         # train_x_b = train_x_tmp.reshape(train_x.shape[0], 18, 24)
42
-        train_x_c = train_x[:,28*20:]
42
+        train_x_c = train_x[:,28*16:]
43 43
 
44 44
         result = model.predict([train_x_c, train_x_a, ])
45 45
         # print(result, line[-1])
46 46
         stock = code_table.find_one({'ts_code':line[-1][0]})
47 47
 
48
-        if result[0][0] > 0.5 and stock['sw_industry'] in industry_list:
48
+        if result[0][0] > 0.5:
49 49
             if line[-1][0].startswith('688'):
50 50
                 continue
51 51
             # 去掉ST
@@ -67,12 +67,17 @@ def predict_today(file, day, model='10_18d', log=True):
67 67
             print(stock['ts_code'], stock['name'], '买入')
68 68
             O_list.append([stock['ts_code'], stock['name']])
69 69
 
70
-            if log is True:
71
-                with open('D:\\data\\quantization\\predict\\' + str(day) + '_mix500.txt', mode='a', encoding="utf-8") as f:
70
+            if result[0][0] > 0.9:
71
+                R_list.append([stock['ts_code'], stock['name']])
72
+
73
+                with open('D:\\data\\quantization\\predict\\' + str(day) + '_mix537.txt', mode='a', encoding="utf-8") as f:
72 74
                     f.write(str(line[-1]) + ' ' + stock['name'] + ' ' + stock['sw_industry'] + ' ' + str(concept_detail_list) + ' ' + str(result[0][0]) + '\n')
73 75
 
74
-        elif result[0][1] > 0.5 or result[0][2] > 0.5 :
76
+        elif result[0][1] > 0.5:
75 77
             pass
78
+        elif result[0][2] > 0.5:
79
+            if stock['ts_code'] in holder_stock_list:
80
+                print(stock['ts_code'], stock['name'], '警告危险')
76 81
         elif result[0][3] > 0.5:
77 82
             if stock['ts_code'] in holder_stock_list or stock['ts_code'] in zixuan_stock_list:
78 83
                 print(stock['ts_code'], stock['name'], '赶紧卖出')
@@ -81,8 +86,12 @@ def predict_today(file, day, model='10_18d', log=True):
81 86
 
82 87
     # print(gainian_map)
83 88
     # print(hangye_map)
84
-    random.shuffle(O_list)
85
-    print(O_list[:3])
89
+    # random.shuffle(O_list)
90
+    # print(O_list[:3])
91
+
92
+    random.shuffle(R_list)
93
+    print('----ROE----')
94
+    print(R_list[:])
86 95
 
87 96
 
88 97
 if __name__ == '__main__':
@@ -90,6 +99,9 @@ if __name__ == '__main__':
90 99
     # predict(file_path='D:\\data\\quantization\\stock6_test.log', model_path='15m_dnn_seq.h5')
91 100
     # multi_predict()
92 101
     # 策略B
93
-    predict_today("D:\\data\\quantization\\stock505_28d_20200415.log", 20200415, model='505_28d_mix_5D_ma5_s_seq.h5', log=True)
102
+    # predict_today("D:\\data\\quantization\\stock505_28d_20200416.log", 20200416, model='505_28d_mix_5D_ma5_s_seq.h5', log=True)
103
+    predict_today("D:\\data\\quantization\\stock517_28d_20200429.log", 20200429, model='517_28d_mix_3D_ma5_s_seq.h5', log=True)
104
+    # predict_today("D:\\data\\quantization\\stock538_28d_20200205.log", 20200205, model='539_28d_mix_5D_ma5_s_seq.h5', log=True)
105
+
94 106
     # join_two_day(20200305, 20200305)
95 107
     # check_everyday(20200311, 20200312)

+ 13 - 8
mix/mix_train_300.py

@@ -18,14 +18,14 @@ from keras.callbacks import EarlyStopping
18 18
 
19 19
 early_stopping = EarlyStopping(monitor='accuracy', patience=5, verbose=2)
20 20
 
21
-epochs= 77
22
-size = 440000 #共68W
23
-file_path = 'D:\\data\\quantization\\stock324_28d_train2.log'
24
-model_path = '324_28d_mix_5D_ma5_s_seq.h5'
25
-file_path1='D:\\data\\quantization\\stock324_28d_test.log'
26
-file_path2='D:\\data\\quantization\\stock324_28d_train1.log'
21
+epochs= 60
22
+size = 444000 #共68W
23
+file_path = 'D:\\data\\quantization\\stock327_28d_train2.log'
24
+model_path = '327_28d_mix_5D_ma5_s_seq.h5'
25
+file_path1='D:\\data\\quantization\\stock327_28d_test.log'
26
+file_path2='D:\\data\\quantization\\stock327_28d_train1.log'
27 27
 row = 28
28
-col = 18
28
+col = 20
29 29
 '''
30 30
 30d+ma5+流通市值>40
31 31
 0 ROC     30*18           38,100,17
@@ -39,10 +39,15 @@ col = 18
39 39
 28d+ma5+5+流通市值>10
40 40
 21 DMI     28*20          43,102,9  非常好    46,102,8
41 41
 22 MACD    28*19          46,102,9
42
+25 DMI ma5+涨幅int 28*18  40,102,8/14
43
+26 DMI 向量化   28*22     41,101,14,14
44
+27 DMI 向量化 修正   28*20     41,101,14,14
45
+
42 46
 1d close
43 47
 23 DMI     28*20          34,97,36
44 48
 3d close 去掉ma的两个字段
45 49
 24 DMI     28*18          41,96,42-13
50
+
46 51
        
47 52
 30d+close
48 53
 4 ROC     30*18           
@@ -62,7 +67,7 @@ def read_data(path, path1=file_path1):
62 67
             lines.append(line)
63 68
 
64 69
     with open(path1) as f:
65
-        for x in range(50000): #6w
70
+        for x in range(30000): #6w
66 71
             line = eval(f.readline().strip())
67 72
             lines.append(line)
68 73
 

+ 19 - 8
mix/mix_train_500.py

@@ -18,22 +18,33 @@ from keras.callbacks import EarlyStopping
18 18
 
19 19
 early_stopping = EarlyStopping(monitor='accuracy', patience=5, verbose=2)
20 20
 
21
-epochs= 44
22
-size = 440000 #共68W
23
-file_path = 'D:\\data\\quantization\\stock507_28d_train2.log'
24
-model_path = '507_28d_mix_5D_ma5_s_seq.h5'
25
-file_path1='D:\\data\\quantization\\stock507_28d_test.log'
21
+epochs= 30
22
+size = 470000 #共68W
23
+file_path = 'D:\\data\\quantization\\stock517_28d_train2.log'
24
+model_path = '517_28d_mix_3D_ma5_s_seq.h5'
25
+file_path1='D:\\data\\quantization\\stock517_28d_test.log'
26 26
 row = 28
27
-col = 19
27
+col = 16
28 28
 '''
29 29
 0    dmi            28*20      38,98,51/5     下跌预判非常准                                    
30 30
 1    macd           28*19      41,98,53/8  
31 31
 2    dmi-对大盘对比 28*20      35,99,46/17 
32 32
 3    5d-dmi-对大盘对比 28*20   42,99,39/10
33 33
 4    3d-dmi-对大盘对比 28*20   40,99,39/07   
34
-5    3d-beta1                  55,99,39/07    ==> 用这个
34
+5    3d-beta1                  55,99,52/07    当前用这个 
35 35
 6    3d-ma20                   40,99,41/07
36 36
 7    3d-macd   28*19           55,99,40/07
37
+8    3d-市值>30  28*20         57,101,36/14   最高价  用这个!
38
+9    3d-市值>30  28*20         57,99,31/08   收盘最高价 
39
+10   5d-市值>30  28*20   收盘最高价  
40
+11   5d-市值>30  28*20   ma5
41
+12   5d-极简     28*16 有ma5,ma20  46,102,16/26
42
+13   3d-最高价   28*16         57,101,39,16
43
+14   5d-极简-最高价     28*16   40,102,30-34
44
+15   5d+dmi+最高价      28*20   40,102,31-34    
45
+16   同12,14,参数11,10  28*16   38,102,29-36
46
+17   同上参数11,6       28*16   39,101,46-35  !    33,100,48
47
+
37 48
 '''
38 49
 
39 50
 def read_data(path, path1=file_path1):
@@ -44,7 +55,7 @@ def read_data(path, path1=file_path1):
44 55
             lines.append(line)
45 56
 
46 57
     with open(path1) as f:
47
-        for x in range(33000): #6w
58
+        for x in range(30000): #6w
48 59
             line = eval(f.readline().strip())
49 60
             lines.append(line)
50 61
 

+ 5 - 4
mix/mix_train_600.py

@@ -18,15 +18,16 @@ early_stopping = EarlyStopping(monitor='accuracy', patience=5, verbose=2)
18 18
 
19 19
 epochs= 44
20 20
 size = 440000 #共68W
21
-file_path = 'D:\\data\\quantization\\stock603_30d_train2.log'
22
-model_path = '603_30d_mix_5D_ma5_s_seq.h5'
23
-file_path1='D:\\data\\quantization\\stock603_30d_test.log'
21
+file_path = 'D:\\data\\quantization\\stock604_30d_train2.log'
22
+model_path = '604_30d_mix_5D_ma5_s_seq.h5'
23
+file_path1='D:\\data\\quantization\\stock604_30d_test.log'
24 24
 row = 30
25 25
 col = 19
26 26
 '''
27 27
 1   macd+beta1 盈利       30*19             64,99,31-31
28 28
 2   macd+beta1 亏损       30*19
29
-3   macd+减少指数参数     30*19             train1:69,99,32-31 |train3:62,100,23-39
29
+3   macd+减少指数参数 最高价     30*19             train1:69,99,32-31 |train3:62,100,23-39 !!    >>   39,97,54
30
+4   macd+减少指数参数 收盘最高价     30*19         53,98,38-23    X
30 31
 '''
31 32
 
32 33
 def read_data(path, path1=file_path1):

+ 16 - 8
mix/stock_source.py

@@ -5,7 +5,8 @@ mysql_handler = Mysql()
5 5
 
6 6
 zixuan_stock_list = [
7 7
     # 医疗
8
-    '603990.SH', '300759.SZ', '300347.SZ','002421.SZ','300168.SZ','002432.SZ','300074.SZ','300677.SZ',
8
+    '603990.SH', '300759.SZ', '300347.SZ','002421.SZ','300168.SZ','002432.SZ','300074.SZ','300677.SZ','002223.SZ', '300253.SZ', '300629.SZ',
9
+    '002603.SZ', '300147.SZ', '002107.SZ',
9 10
     # 5G
10 11
     '300003.SZ', '600498.SH', '300310.SZ', '603912.SH', '603220.SH', '300602.SZ', '600260.SH', '002463.SZ','300738.SZ','002402.SZ',
11 12
     # 车联网
@@ -15,12 +16,18 @@ zixuan_stock_list = [
15 16
     # 特高压
16 17
     '300341.SZ', '300670.SZ', '300018.SZ', '600268.SH', '002879.SZ','002028.SZ','300477.SZ',
17 18
     # 基础建设
18
-    '603568.SH', '000967.SZ', '603018.SH','002062.SZ',
19
+    '603568.SH', '000967.SZ', '603018.SH','002062.SZ','600452.SH',
19 20
     # 华为
20 21
     '300687.SZ','002316.SZ','300339.SZ','300378.SZ','300020.SZ','300634.SZ','002570.SZ', '300766.SZ',
21 22
 
22
-    '002555.SZ','600585.SH','600276.SH','002415.SZ','000651.SZ',
23
+]
23 24
 
25
+zeng_stock_list = [
26
+    # 业绩
27
+    '300097.SZ', '000625.SZ', '000876.SZ', '603258.SH', '002973.SZ', '300390.SZ', '002030.SZ', '002041.SZ', '000767.SZ', '002214.SZ', '002869.SZ',
28
+    '300541.SZ', '002185.SZ',
29
+    '002555.SZ','600585.SH','600276.SH','002415.SZ','000651.SZ',
30
+    '601800.SH', '601108.SH', '601186.SH',
24 31
 ]
25 32
 
26 33
 ROE_stock_list =   [                      # ROE
@@ -42,11 +49,12 @@ ROE_stock_list =   [                      # ROE
42 49
 
43 50
 
44 51
 holder_stock_list = [
45
-    '600498.SH', '002223.SZ',
46
-    '600496.SH', '300682.SZ','601162.SH','002401.SZ','601111.SH',
47
-    '000851.SZ','300639.SZ','603990.SH','603003.SH','603628.SH','601186.SH',
48
-    '600196.SH', '300003.SZ','300748.SZ','603638.SZ',
49
-    '601211.SH'
52
+    '002415.SZ','002214.SZ', '002459.SZ'
53
+
54
+    '300639.SZ','300003.SZ', '300185.SZ',
55
+
56
+    '600196.SH', '601108.SH', '600057.SH',
57
+    '601211.SH', '600452.SH', '603638.SH',
50 58
 ]
51 59
 
52 60
 

+ 63 - 2
stock/kmeans.py

@@ -8,7 +8,7 @@ import joblib
8 8
 def read_data(path):
9 9
     lines = []
10 10
     with open(path) as f:
11
-        for x in range(600000):
11
+        for x in range(400000):
12 12
             line = eval(f.readline().strip())
13 13
             # if line[-1][0] == 1 or line[-1][1] == 1:
14 14
             lines.append(line)
@@ -84,7 +84,68 @@ def class_fic_k(file_path=''):
84 84
     print(estimator.predict(v_x[10:20]))
85 85
 
86 86
 
87
+def class_fic_roc(file_path=''):
88
+    lines = read_data(file_path)
89
+    print('读取数据完毕')
90
+    size = len(lines[0])
91
+    x_list = []
92
+
93
+    length = 18  # 周期是多少
94
+    j = 10
95
+
96
+    for s in lines:
97
+        tmp_list = []
98
+        for x in range(0, length):
99
+            tmp_list = tmp_list + s[x*j+8:x*j+10]
100
+        x_list.append(tmp_list)
101
+    train_x = np.array(x_list)
102
+
103
+    v_x = train_x.reshape(train_x.shape[0], 2*length)
104
+
105
+    estimator = KMeans(n_clusters=8, random_state=73011)
106
+    estimator.fit(v_x)
107
+    label_pred = estimator.labels_  # 获取聚类标签
108
+    centroids = estimator.cluster_centers_
109
+    joblib.dump(estimator , 'km_k_roc_8.pkl')
110
+
111
+    print(estimator.predict(v_x[:10]))
112
+
113
+    estimator = joblib.load('km_k_roc_8.pkl')
114
+    print(estimator.predict(v_x[10:20]))
115
+
116
+
117
+def class_fic_dapan(file_path=''):
118
+    lines = read_data(file_path)
119
+    print('读取数据完毕')
120
+    size = len(lines[0])
121
+    x_list = []
122
+
123
+    length = 18  # 周期是多少
124
+    j = 24
125
+
126
+    for s in lines:
127
+        tmp_list = []
128
+        for x in range(0, length):
129
+            tmp_list = tmp_list + s[x*j+16:x*j+17]
130
+        x_list.append(tmp_list)
131
+    train_x = np.array(x_list)
132
+
133
+    v_x = train_x.reshape(train_x.shape[0], length)
134
+
135
+    estimator = KMeans(n_clusters=8, random_state=82430)
136
+    estimator.fit(v_x)
137
+    label_pred = estimator.labels_  # 获取聚类标签
138
+    centroids = estimator.cluster_centers_
139
+    joblib.dump(estimator , 'km_k_dapan_8.pkl')
140
+
141
+    print(estimator.predict(v_x[:10]))
142
+
143
+    estimator = joblib.load('km_k_dapan_8.pkl')
144
+    print(estimator.predict(v_x[10:20]))
145
+
146
+
87 147
 if __name__ == '__main__':
88 148
     # class_fic(file_path="D:\\data\\quantization\\stock2_10.log")
89 149
     # class_fic_k(file_path="D:\\data\\quantization\\stock10_18_train.log")
90
-    class_fic_dmi(file_path="D:\\data\\quantization\\stock12_18d_train.log")
150
+    # class_fic_dmi(file_path="D:\\data\\quantization\\stock12_18d_train.log")
151
+    class_fic_dapan(file_path="D:\\data\\quantization\\stock160_18d_train.log")