yufeng 4 years ago
parent
commit
423c9aaeca

BIN
mix/5d_578A_dnn_seq.h5


+ 72 - 11
mix/mix_predict_600.py

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

+ 17 - 23
mix/mix_predict_by_day_578A.py

@@ -4,12 +4,14 @@ from keras.models import load_model
4
 import joblib
4
 import joblib
5
 
5
 
6
 
6
 
7
+indent = -1
8
+
7
 def read_data(path):
9
 def read_data(path):
8
     day_lines = {}
10
     day_lines = {}
9
     with open(path) as f:
11
     with open(path) as f:
10
         for line in f.readlines()[:]:
12
         for line in f.readlines()[:]:
11
             line = eval(line.strip())
13
             line = eval(line.strip())
12
-            date = str(line[-1][-1])
14
+            date = str(line[indent][-1])
13
             if date in day_lines:
15
             if date in day_lines:
14
                 day_lines[date].append(line)
16
                 day_lines[date].append(line)
15
             else:
17
             else:
@@ -40,21 +42,16 @@ def predict(file_path='', model_path='15min_dnn_seq', rows=18, cols=18):
40
         x4 = 0
42
         x4 = 0
41
 
43
 
42
         for line in lines:
44
         for line in lines:
43
-            train_x = np.array([line[:size - 1]])
44
-            train_x_a = train_x[:,:rows*cols]
45
-            train_x_a = train_x_a.reshape(train_x.shape[0], rows, cols, 1)
46
-            # train_x_b = train_x[:, 18*18:18*18+2*18]
47
-            # train_x_b = train_x_b.reshape(train_x.shape[0], 18, 2, 1)
48
-            train_x_c = train_x[:,rows*cols:]
45
+            train_x = np.array([line[:size + indent]])
49
 
46
 
50
-            result = model.predict([train_x_c, train_x_a])
47
+            result = model.predict([train_x])
51
 
48
 
52
             ratio = 1
49
             ratio = 1
53
-            if train_x_c[0][-1] == 1:
54
-                ratio = 2
55
-            elif train_x_c[0][-2] == 1:
50
+            if train_x[0][-1] == 1:
51
+                ratio = 2.1
52
+            elif train_x[0][-2] == 1:
56
                 ratio = 1.6
53
                 ratio = 1.6
57
-            elif train_x_c[0][-3] == 1:
54
+            elif train_x[0][-3] == 1:
58
                 ratio = 1.3
55
                 ratio = 1.3
59
 
56
 
60
             if result[0][0]> 0.5:
57
             if result[0][0]> 0.5:
@@ -62,29 +59,26 @@ def predict(file_path='', model_path='15min_dnn_seq', rows=18, cols=18):
62
             elif result[0][1] > 0.5:
59
             elif result[0][1] > 0.5:
63
                 up_num = up_num + 0.4*ratio
60
                 up_num = up_num + 0.4*ratio
64
             elif result[0][2] > 0.5:
61
             elif result[0][2] > 0.5:
65
-                down_num = down_num + 0.4*ratio
66
-            else:
67
                 down_num = down_num + ratio
62
                 down_num = down_num + ratio
68
 
63
 
69
             maxx = max(result[0])
64
             maxx = max(result[0])
70
             if maxx - result[0][0] == 0:
65
             if maxx - result[0][0] == 0:
71
                 x0 = x0 + 1
66
                 x0 = x0 + 1
72
-            if maxx - result[0][1] == 0:
67
+            elif maxx - result[0][1] == 0:
73
                 x1 = x1 + 1
68
                 x1 = x1 + 1
74
-            if maxx - result[0][2] == 0:
69
+            else:
75
                 x2 = x2 + 1
70
                 x2 = x2 + 1
76
-            if maxx - result[0][3] == 0:
77
-                x3 = x3 + 1
78
 
71
 
79
         # print(key, int(up_num), int(down_num), (down_num*1.2 + 2)/(up_num*1.2 + 2), )
72
         # 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.5 + 2)/(up_num*1.2 + 2))
73
+        print(key, x0, x1, x2, (down_num*1.5 + 2)/(up_num*1.2 + 2))
81
 
74
 
82
 
75
 
83
 import datetime
76
 import datetime
84
 if __name__ == '__main__':
77
 if __name__ == '__main__':
85
     today = datetime.datetime.now()
78
     today = datetime.datetime.now()
86
     today = today
79
     today = today
87
-    today =  today.strftime('%Y%m%d')
80
+    today = today.strftime('%Y%m%d')
81
+    today = '20200512'
88
     # predict(file_path='D:\\data\\quantization\\stock6_5_test.log', model_path='5d_dnn_seq.h5')
82
     # predict(file_path='D:\\data\\quantization\\stock6_5_test.log', model_path='5d_dnn_seq.h5')
89
     # predict(file_path='D:\\data\\quantization\\stock9_18_20200220.log', model_path='18d_dnn_seq.h5')
83
     # predict(file_path='D:\\data\\quantization\\stock9_18_20200220.log', model_path='18d_dnn_seq.h5')
90
     # predict(file_path='D:\\data\\quantization\\stock9_18_2.log', model_path='18d_dnn_seq.h5')
84
     # predict(file_path='D:\\data\\quantization\\stock9_18_2.log', model_path='18d_dnn_seq.h5')
@@ -92,10 +86,10 @@ if __name__ == '__main__':
92
     # predict(file_path='D:\\data\\quantization\\stock196_18d_20200326.log', model_path='196_18d_mix_6D_ma5_s_seq')
86
     # predict(file_path='D:\\data\\quantization\\stock196_18d_20200326.log', model_path='196_18d_mix_6D_ma5_s_seq')
93
 
87
 
94
 
88
 
95
-    # 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)
96
-
97
-    predict(file_path='D:\\data\\quantization\\stock327_28d_' + today + '.log', model_path='327_28d_mix_5D_ma5_s_seq', rows=28, cols=20)
89
+    # predict(file_path='D:\\data\\quantization\\stock578N_12d_train3.log', model_path='5d_578N_dnn_seq', rows=28, cols=20)
98
 
90
 
91
+    predict(file_path='D:\\data\\quantization\\stock578N_5d_' + today + '.log', model_path='5d_578N_dnn_seq', rows=28, cols=20)
92
+    #
99
 
93
 
100
 
94
 
101
     # predict(file_path='D:\\data\\quantization\\stock9_18_4.log', model_path='18d_dnn_seq.h5')
95
     # predict(file_path='D:\\data\\quantization\\stock9_18_4.log', model_path='18d_dnn_seq.h5')

+ 4 - 4
mix/mix_predict_everyday_600.py

@@ -44,7 +44,7 @@ def predict_today(file, day, model='10_18d', log=True):
44
         # print(result, line[-1])
44
         # print(result, line[-1])
45
         stock = code_table.find_one({'ts_code':line[-1][0]})
45
         stock = code_table.find_one({'ts_code':line[-1][0]})
46
 
46
 
47
-        if result[0][0] > 0.85:
47
+        if result[0][0] > 0.8:
48
             if line[-1][0].startswith('688'):
48
             if line[-1][0].startswith('688'):
49
                 continue
49
                 continue
50
             # 去掉ST
50
             # 去掉ST
@@ -78,10 +78,10 @@ def predict_today(file, day, model='10_18d', log=True):
78
                 with open('D:\\data\\quantization\\predict\\' + str(day) + '_mix.txt', mode='a', encoding="utf-8") as f:
78
                 with open('D:\\data\\quantization\\predict\\' + str(day) + '_mix.txt', mode='a', encoding="utf-8") as f:
79
                     f.write(str(line[-1]) + ' ' + stock['name'] + ' ' + stock['sw_industry'] + ' ' + str(concept_detail_list) + ' ' + str(result[0][0]) + '\n')
79
                     f.write(str(line[-1]) + ' ' + stock['name'] + ' ' + stock['sw_industry'] + ' ' + str(concept_detail_list) + ' ' + str(result[0][0]) + '\n')
80
 
80
 
81
-        elif result[0][1] > 0.5:
81
+        elif result[0][1] > 0.4:
82
             if stock['ts_code'] in holder_stock_list:
82
             if stock['ts_code'] in holder_stock_list:
83
                 print(stock['ts_code'], stock['name'], '震荡评级')
83
                 print(stock['ts_code'], stock['name'], '震荡评级')
84
-        elif result[0][2] > 0.5:
84
+        elif result[0][2] > 0.4:
85
             if stock['ts_code'] in holder_stock_list:
85
             if stock['ts_code'] in holder_stock_list:
86
                 print(stock['ts_code'], stock['name'], '赶紧卖出')
86
                 print(stock['ts_code'], stock['name'], '赶紧卖出')
87
 
87
 
@@ -124,6 +124,6 @@ if __name__ == '__main__':
124
     # multi_predict()
124
     # multi_predict()
125
     # predict_today("D:\\data\\quantization\\stock405_30d_20200413.log", 20200413, model='405_30d_mix_5D_ma5_s_seq.h5', log=True)
125
     # predict_today("D:\\data\\quantization\\stock405_30d_20200413.log", 20200413, model='405_30d_mix_5D_ma5_s_seq.h5', log=True)
126
     # 模型 下跌趋势,没大涨的不要买
126
     # 模型 下跌趋势,没大涨的不要买
127
-    predict_today("D:\\data\\quantization\\stock578A_5d_20200430.log", 20200430, model='5d_578A_dnn_seq.h5', log=True)
127
+    predict_today("D:\\data\\quantization\\stock578A_5d_20200512.log", 20200430, model='5d_578A_dnn_seq.h5', log=True)
128
     # join_two_day(20200305, 20200305)
128
     # join_two_day(20200305, 20200305)
129
     # check_everyday(20200311, 20200312)
129
     # check_everyday(20200311, 20200312)

+ 7 - 6
mix/stock_source.py

@@ -19,7 +19,8 @@ zixuan_stock_list = [
19
     '603568.SH', '000967.SZ', '603018.SH','002062.SZ','600452.SH',
19
     '603568.SH', '000967.SZ', '603018.SH','002062.SZ','600452.SH',
20
     # 华为
20
     # 华为
21
     '300687.SZ','002316.SZ','300339.SZ','300378.SZ','300020.SZ','300634.SZ','002570.SZ', '300766.SZ',
21
     '300687.SZ','002316.SZ','300339.SZ','300378.SZ','300020.SZ','300634.SZ','002570.SZ', '300766.SZ',
22
-
22
+    # hsgt
23
+    '603713.SH',
23
 ]
24
 ]
24
 
25
 
25
 zeng_stock_list = [
26
 zeng_stock_list = [
@@ -27,7 +28,7 @@ zeng_stock_list = [
27
     '300097.SZ', '000625.SZ', '000876.SZ', '603258.SH', '002973.SZ', '300390.SZ', '002030.SZ', '002041.SZ', '000767.SZ', '002214.SZ', '002869.SZ',
28
     '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
     '300541.SZ', '002185.SZ',
29
     '002555.SZ','600585.SH','600276.SH','002415.SZ','000651.SZ',
30
     '002555.SZ','600585.SH','600276.SH','002415.SZ','000651.SZ',
30
-    '601800.SH', '601108.SH', '601186.SH',
31
+    '601800.SH', '601186.SH',
31
 ]
32
 ]
32
 
33
 
33
 ROE_stock_list =   [                      # ROE
34
 ROE_stock_list =   [                      # ROE
@@ -49,12 +50,12 @@ ROE_stock_list =   [                      # ROE
49
 
50
 
50
 
51
 
51
 holder_stock_list = [
52
 holder_stock_list = [
52
-    '002415.SZ','002214.SZ', '002459.SZ'
53
+    '002415.SZ','002214.SZ', '002459.SZ', '002035.SZ', '000963.SZ',
53
 
54
 
54
-    '300639.SZ','300003.SZ', '300185.SZ',
55
+    '300639.SZ','300185.SZ', '601162.SH',
55
 
56
 
56
-    '600196.SH', '601108.SH', '600057.SH',
57
-    '601211.SH', '600452.SH', '603638.SH',
57
+    '600196.SH', '600057.SH',
58
+    '603638.SH',
58
 ]
59
 ]
59
 
60
 
60
 
61
 

+ 5 - 20
stock/dnn_predict_by_day.py

@@ -35,13 +35,13 @@ def predict(file_path='', model_path='15min_dnn_seq'):
35
 
35
 
36
         up_num = 0
36
         up_num = 0
37
         down_num = 0
37
         down_num = 0
38
-        x = 16 # 每条数据项数
38
+        x = 24 # 每条数据项数
39
         k = 18 # 周期
39
         k = 18 # 周期
40
         for line in lines:
40
         for line in lines:
41
-            v = line[0:x*k]
41
+            v = line[1:x*k+1]
42
             v = np.array(v)
42
             v = np.array(v)
43
             v = v.reshape(k, x)
43
             v = v.reshape(k, x)
44
-            v = v[:,6:10]
44
+            v = v[:,4:8]
45
             v = v.reshape(1, 4*k)
45
             v = v.reshape(1, 4*k)
46
             # print(v)
46
             # print(v)
47
             r = estimator.predict(v)
47
             r = estimator.predict(v)
@@ -52,22 +52,7 @@ def predict(file_path='', model_path='15min_dnn_seq'):
52
             if result[0][3] > 0.5 or result[0][4] > 0.5:
52
             if result[0][3] > 0.5 or result[0][4] > 0.5:
53
                 down_num = down_num + 1
53
                 down_num = down_num + 1
54
             elif result[0][1] > 0.5 or result[0][0] > 0.5:
54
             elif result[0][1] > 0.5 or result[0][0] > 0.5:
55
-                up_num = up_num + 0.5  # 乐观调大 悲观调小
56
-
57
-            # if result[0][0] > 0.5 or result[0][1] > 0.5:
58
-            #     if r[0] in [0,2,3,4,5,9,10,11]:
59
-            #         up_num = up_num + 1
60
-            #     elif r[0] in [8]:
61
-            #         up_num = up_num + 0.6
62
-            #     else:
63
-            #         up_num = up_num + 0.4
64
-            # if result[0][3] > 0.5 or result[0][4] > 0.5:
65
-            #     if r[0] in [4,6,]:
66
-            #         down_num = down_num + 1
67
-            #     elif r[0] in [0,1,3,7,8,]:
68
-            #         down_num = down_num + 0.6
69
-            #     else:
70
-            #         down_num = down_num + 0.4
55
+                up_num = up_num + 0.6  # 乐观调大 悲观调小
71
 
56
 
72
         print(key, int(up_num), int(down_num), (down_num*1.2 + 2)/(up_num*1.2 + 2))
57
         print(key, int(up_num), int(down_num), (down_num*1.2 + 2)/(up_num*1.2 + 2))
73
 
58
 
@@ -76,6 +61,6 @@ if __name__ == '__main__':
76
     # predict(file_path='D:\\data\\quantization\\stock6_5_test.log', model_path='5d_dnn_seq.h5')
61
     # predict(file_path='D:\\data\\quantization\\stock6_5_test.log', model_path='5d_dnn_seq.h5')
77
     # predict(file_path='D:\\data\\quantization\\stock9_18_20200220.log', model_path='18d_dnn_seq.h5')
62
     # predict(file_path='D:\\data\\quantization\\stock9_18_20200220.log', model_path='18d_dnn_seq.h5')
78
     # predict(file_path='D:\\data\\quantization\\stock9_18_2.log', model_path='18d_dnn_seq.h5')
63
     # predict(file_path='D:\\data\\quantization\\stock9_18_2.log', model_path='18d_dnn_seq.h5')
79
-    predict(file_path='D:\\data\\quantization\\stock19_18d_20200309.log', model_path='19_18d_dnn_seq')
64
+    predict(file_path='D:\\data\\quantization\\stock16_18d_20200311.log', model_path='16_18d_dnn_seq')
80
     # predict(file_path='D:\\data\\quantization\\stock11_18d_20190103_20190604.log', model_path='14_18d_dnn_seq')
65
     # predict(file_path='D:\\data\\quantization\\stock11_18d_20190103_20190604.log', model_path='14_18d_dnn_seq')
81
     # predict(file_path='D:\\data\\quantization\\stock9_18_4.log', model_path='18d_dnn_seq.h5')
66
     # predict(file_path='D:\\data\\quantization\\stock9_18_4.log', model_path='18d_dnn_seq.h5')

+ 24 - 23
stock/dnn_predict_dmi_everyday.py

@@ -6,13 +6,13 @@ import joblib
6
 
6
 
7
 holder_stock_list = [
7
 holder_stock_list = [
8
                      '000063.SZ',
8
                      '000063.SZ',
9
-                     '002796.SZ',
10
                      '002373.SZ',
9
                      '002373.SZ',
11
                      '300253.SZ',
10
                      '300253.SZ',
12
                      '300059.SZ',
11
                      '300059.SZ',
13
                     # b账户
12
                     # b账户
14
                      '002373.SZ',
13
                      '002373.SZ',
15
                      '300422.SZ',
14
                      '300422.SZ',
15
+                     '300468.SZ',
16
     ]
16
     ]
17
 
17
 
18
 
18
 
@@ -91,6 +91,7 @@ def predict_today(day, model='10_18d', log=True):
91
 
91
 
92
     x = 24 # 每条数据项数
92
     x = 24 # 每条数据项数
93
     k = 18 # 周期
93
     k = 18 # 周期
94
+    shift = 1
94
     for line in lines:
95
     for line in lines:
95
         # print(line)
96
         # print(line)
96
         v = line[1:x*k + 1]
97
         v = line[1:x*k + 1]
@@ -107,7 +108,7 @@ def predict_today(day, model='10_18d', log=True):
107
         # print(result, line[-1])
108
         # print(result, line[-1])
108
         stock = code_table.find_one({'ts_code':line[-1][0]})
109
         stock = code_table.find_one({'ts_code':line[-1][0]})
109
 
110
 
110
-        if result[0][0] > 0.6 or result[0][1] > 0.6:
111
+        if result[0][0] > 0.5 or result[0][1] > 0.5:
111
             if line[-1][0].startswith('688'):
112
             if line[-1][0].startswith('688'):
112
                 continue
113
                 continue
113
             # 去掉ST
114
             # 去掉ST
@@ -132,29 +133,29 @@ def predict_today(day, model='10_18d', log=True):
132
             concept_detail_list = []
133
             concept_detail_list = []
133
 
134
 
134
             # 处理行业
135
             # 处理行业
135
-            if stock['industry'] in hangye_map:
136
-                i_c = hangye_map[stock['industry']]
137
-                hangye_map[stock['industry']] = i_c + 1
136
+            if stock['sw_industry'] in hangye_map:
137
+                i_c = hangye_map[stock['sw_industry']]
138
+                hangye_map[stock['sw_industry']] = i_c + 1
138
             else:
139
             else:
139
-                hangye_map[stock['industry']] = 1
140
-
141
-            if len(concept_code_list) > 0:
142
-                for concept in concept_code_list:
143
-                    for c in all_concept_code_list:
144
-                        if c['code'] == concept['concept_code']:
145
-                            concept_detail_list.append(c['name'])
146
-
147
-                            if c['name'] in gainian_map:
148
-                                g_c = gainian_map[c['name']]
149
-                                gainian_map[c['name']] = g_c + 1
150
-                            else:
151
-                                gainian_map[c['name']] = 1
152
-
153
-            print(line[-1], stock['name'], stock['industry'], str(concept_detail_list), 'buy', k_table_list[0]['pct_chg'])
140
+                hangye_map[stock['sw_industry']] = 1
141
+
142
+            # if len(concept_code_list) > 0:
143
+            #     for concept in concept_code_list:
144
+            #         for c in all_concept_code_list:
145
+            #             if c['code'] == concept['concept_code']:
146
+            #                 concept_detail_list.append(c['name'])
147
+            #
148
+            #                 if c['name'] in gainian_map:
149
+            #                     g_c = gainian_map[c['name']]
150
+            #                     gainian_map[c['name']] = g_c + 1
151
+            #                 else:
152
+            #                     gainian_map[c['name']] = 1
153
+
154
+            print(line[-1], stock['name'], stock['sw_industry'], str(concept_detail_list), 'buy', k_table_list[0]['pct_chg'])
154
 
155
 
155
             if log is True:
156
             if log is True:
156
                 with open('D:\\data\\quantization\\predict\\' + str(day) + '.txt', mode='a', encoding="utf-8") as f:
157
                 with open('D:\\data\\quantization\\predict\\' + str(day) + '.txt', mode='a', encoding="utf-8") as f:
157
-                    f.write(str(line[-1]) + ' ' + stock['name'] + ' ' + stock['industry'] + ' ' + str(concept_detail_list) + ' buy' + '\n')
158
+                    f.write(str(line[-1]) + ' ' + stock['name'] + ' ' + stock['sw_industry'] + ' ' + str(concept_detail_list) + ' buy' + '\n')
158
 
159
 
159
 
160
 
160
             # concept_list = list(stock_concept_table.find({'ts_code':stock['ts_code']}))
161
             # concept_list = list(stock_concept_table.find({'ts_code':stock['ts_code']}))
@@ -196,5 +197,5 @@ if __name__ == '__main__':
196
     # predict(file_path='D:\\data\\quantization\\stock6_5_test.log', model_path='5d_dnn_seq.h5')
197
     # predict(file_path='D:\\data\\quantization\\stock6_5_test.log', model_path='5d_dnn_seq.h5')
197
     # predict(file_path='D:\\data\\quantization\\stock6_test.log', model_path='15m_dnn_seq.h5')
198
     # predict(file_path='D:\\data\\quantization\\stock6_test.log', model_path='15m_dnn_seq.h5')
198
     # multi_predict()
199
     # multi_predict()
199
-    # predict_today(20200303, model='11_18d', log=True)
200
-    join_two_day(20200303, 20200303)
200
+    # predict_today(20200305, model='11_18d', log=True)
201
+    join_two_day(20200311, 20200311)

+ 22 - 7
stock/dnn_train.py

@@ -18,9 +18,9 @@ def read_data(path):
18
         for line in f.readlines()[:]:
18
         for line in f.readlines()[:]:
19
             lines.append(eval(line.strip()))
19
             lines.append(eval(line.strip()))
20
 
20
 
21
-    # with open("D:\\data\\quantization\\stock578A_12d_train1.log") as f:
22
-    #     for line in f.readlines()[:]:
23
-    #         lines.append(eval(line.strip()))
21
+    with open("D:\\data\\quantization\\stock578N_12d_train3.log") as f:
22
+        for line in f.readlines()[:]:
23
+            lines.append(eval(line.strip()))
24
 
24
 
25
     random.shuffle(lines)
25
     random.shuffle(lines)
26
     print('读取数据完毕')
26
     print('读取数据完毕')
@@ -119,7 +119,6 @@ def train(result_class=3, file_path="D:\\data\\quantization\\stock6.log", model_
119
 
119
 
120
 568 3d-3 input_dim=  >0.7 35,97,64   
120
 568 3d-3 input_dim=  >0.7 35,97,64   
121
 569 4d-3 input_dim=  >0.7 33,100,52   >0.9 33,100.3,50
121
 569 4d-3 input_dim=  >0.7 33,100,52   >0.9 33,100.3,50
122
-570 5d-3 input_dim=  >0.9 32,102,42   随机45,99,56
123
 571 6d-3 >0.7 37,100,48
122
 571 6d-3 >0.7 37,100,48
124
 572 5d-3 + macd+roc 37,101,46
123
 572 5d-3 + macd+roc 37,101,46
125
 573 +index  32,101,44
124
 573 +index  32,101,44
@@ -129,11 +128,27 @@ def train(result_class=3, file_path="D:\\data\\quantization\\stock6.log", model_
129
 577 加上r0_ratio 34,100,48
128
 577 加上r0_ratio 34,100,48
130
 578 570修正 30,101,47 
129
 578 570修正 30,101,47 
131
 578A 38,101.7 44
130
 578A 38,101.7 44
132
-578B 4class 38,101.7 44
133
-574A >0.8 34,98,59
131
+578B 4class 
132
+578C 加上指数 38,99,52
133
+578D 指数涨幅 34,100,50
134
+578E 涨停数 39,100,51
135
+578F 加上是否最高最低 34,,100.9,48
136
+579G 换成dmi 32 100.9 47
137
+579H 回退 去掉roc等  39,101.5,45
138
+579I 加上是否最高最低 30,100,50
139
+579J 加上DMI 34,101,47
140
+
141
+574A >0.8 34,98,59           36,1.86,25  
142
+570 5d-3 input_dim=  >0.9                       32,102,42   随机45,99,56
143
+
144
+578K 用上日收盘价 39,101,46
145
+578L 仅ROC   41,101.6,43     41,2.036,29
146
+578M 仅macd  41,101.7,43     41,2.035,28
147
+578N 仅DMI                   42,2.079,33  随机45,1.82,20
148
+578O 都去掉                  41,2.013,29
134
 '''
149
 '''
135
 if __name__ == '__main__':
150
 if __name__ == '__main__':
136
     # train(input_dim=176, result_class=5, file_path="D:\\data\\quantization\\stock6_5.log", model_name='5d_dnn_seq.h5')
151
     # train(input_dim=176, result_class=5, file_path="D:\\data\\quantization\\stock6_5.log", model_name='5d_dnn_seq.h5')
137
-    train(result_class=4, file_path="D:\\data\\quantization\\stock578B_12d_train2.log", model_name='5d_578B_dnn_seq.h5')
152
+    train(result_class=3, file_path="D:\\data\\quantization\\stock578N_12d_train2.log", model_name='5d_578N_dnn_seq.h5')
138
     # resample('D:\\data\\quantization\\stock8_14.log')
153
     # resample('D:\\data\\quantization\\stock8_14.log')
139
     # mul_train()
154
     # mul_train()