Browse Source

我要随机

yufeng 4 years ago
parent
commit
84d2f1c266
1 changed files with 59 additions and 45 deletions
  1. 59 45
      mix/mix_predict_everyday_200.py

+ 59 - 45
mix/mix_predict_everyday_200.py

@@ -1,7 +1,7 @@
1 1
 # -*- encoding:utf-8 -*-
2 2
 import numpy as np
3 3
 from keras.models import load_model
4
-import joblib
4
+import random
5 5
 
6 6
 
7 7
 holder_stock_list = [
@@ -17,40 +17,28 @@ holder_stock_list = [
17 17
                         '300341.SZ', '300670.SZ', '300018.SZ', '600268.SH', '002879.SZ',
18 18
                         # 基础建设
19 19
                         '300041.SZ', '603568.SH', '000967.SZ', '603018.SH',
20
-                        # B
21
-                        '002555.SZ', '002174.SZ',
22
-                        # ROE
23
-    '002976.SZ', '002847.SZ', '002597.SZ', '300686.SZ', '000708.SZ', '603948.SH', '600507.SH', '300401.SZ', '002714.SZ', '600732.SH', '300033.SZ', '300822.SZ', '300821.SZ',
24
-    '002458.SZ', '000708.SZ', '600732.SH', '603719.SH', '300821.SZ', '300800.SZ', '300816.SZ', '300812.SZ', '603195.SH', '300815.SZ', '603053.SH', '603551.SH', '002975.SZ',
25
-    '603949.SH', '002970.SZ', '300809.SZ', '002968.SZ', '300559.SZ', '002512.SZ', '300783.SZ', '300003.SZ', '603489.SH', '300564.SZ', '600802.SH', '002600.SZ',
26
-    '000933.SZ', '601918.SH', '000651.SZ', '002916.SZ', '000568.SZ', '000717.SZ', '600452.SH', '603589.SH', '600690.SH', '603886.SH', '300117.SZ', '000858.SZ', '002102.SZ',
27
-    '300136.SZ', '600801.SH', '600436.SH', '300401.SZ', '002190.SZ', '300122.SZ', '002299.SZ', '603610.SH', '002963.SZ', '600486.SH', '300601.SZ', '300682.SZ', '300771.SZ',
28
-    '000868.SZ', '002607.SZ', '603068.SH', '603508.SH', '603658.SH', '300571.SZ', '603868.SH', '600768.SH', '300760.SZ', '002901.SZ', '603638.SH', '601100.SH', '002032.SZ',
29
-    '600083.SH', '600507.SH', '603288.SH', '002304.SZ', '000963.SZ', '300572.SZ', '000885.SZ', '600995.SH', '300080.SZ', '601888.SH', '000048.SZ', '000333.SZ', '300529.SZ',
30
-    '000537.SZ', '002869.SZ', '600217.SH', '000526.SZ', '600887.SH', '002161.SZ', '600267.SH', '600668.SH', '600052.SH', '002379.SZ', '603369.SH', '601360.SH', '002833.SZ',
31
-    '002035.SZ', '600031.SH', '600678.SH', '600398.SH', '600587.SH', '600763.SH', '002016.SZ', '603816.SH', '000031.SZ', '002555.SZ', '603983.SH', '002746.SZ', '603899.SH',
32
-    '300595.SZ', '300632.SZ', '600809.SH', '002507.SZ', '300198.SZ', '600779.SH', '603568.SH', '300638.SZ', '002011.SZ', '603517.SH', '000661.SZ', '300630.SZ', '000895.SZ',
33
-    '002841.SZ', '300602.SZ', '300418.SZ', '603737.SH', '002755.SZ', '002803.SZ', '002182.SZ', '600132.SH', '300725.SZ', '600346.SH', '300015.SZ', '300014.SZ', '300628.SZ',
34
-    '000789.SZ', '600368.SH', '300776.SZ', '600570.SH', '000509.SZ', '600338.SH', '300770.SZ', '600309.SH', '000596.SZ', '300702.SZ', '002271.SZ', '300782.SZ', '300577.SZ',
35
-    '603505.SH', '603160.SH', '300761.SZ', '603327.SH', '002458.SZ', '300146.SZ', '002463.SZ', '300417.SZ', '600566.SH', '002372.SZ', '600585.SH', '000848.SZ', '600519.SH',
36
-    '000672.SZ', '300357.SZ', '002234.SZ', '603444.SH', '300236.SZ', '603360.SH', '002677.SZ', '300487.SZ', '600319.SH', '002415.SZ', '000403.SZ', '600340.SH', '601318.SH',
37
-
38
-
20
+                        # 华为
21
+                        '300687.SZ','002316.SZ','300339.SZ','300378.SZ','300020.SZ','300634.SZ','002570.SZ',
22
+                        '600801.SH', '300113.SZ','002555.SZ', '002174.SZ',
39 23
 ]
40 24
 
25
+ROE_stock_list =   [                      # ROE
26
+'002976.SZ', '002847.SZ', '002597.SZ', '300686.SZ', '000708.SZ', '603948.SH', '600507.SH', '300401.SZ', '002714.SZ', '600732.SH', '300033.SZ', '300822.SZ', '300821.SZ',
27
+'002458.SZ', '000708.SZ', '600732.SH', '603719.SH', '300821.SZ', '300800.SZ', '300816.SZ', '300812.SZ', '603195.SH', '300815.SZ', '603053.SH', '603551.SH', '002975.SZ',
28
+'603949.SH', '002970.SZ', '300809.SZ', '002968.SZ', '300559.SZ', '002512.SZ', '300783.SZ', '300003.SZ', '603489.SH', '300564.SZ', '600802.SH', '002600.SZ',
29
+'000933.SZ', '601918.SH', '000651.SZ', '002916.SZ', '000568.SZ', '000717.SZ', '600452.SH', '603589.SH', '600690.SH', '603886.SH', '300117.SZ', '000858.SZ', '002102.SZ',
30
+'300136.SZ', '600801.SH', '600436.SH', '300401.SZ', '002190.SZ', '300122.SZ', '002299.SZ', '603610.SH', '002963.SZ', '600486.SH', '300601.SZ', '300682.SZ', '300771.SZ',
31
+'000868.SZ', '002607.SZ', '603068.SH', '603508.SH', '603658.SH', '300571.SZ', '603868.SH', '600768.SH', '300760.SZ', '002901.SZ', '603638.SH', '601100.SH', '002032.SZ',
32
+'600083.SH', '600507.SH', '603288.SH', '002304.SZ', '000963.SZ', '300572.SZ', '000885.SZ', '600995.SH', '300080.SZ', '601888.SH', '000048.SZ', '000333.SZ', '300529.SZ',
33
+'000537.SZ', '002869.SZ', '600217.SH', '000526.SZ', '600887.SH', '002161.SZ', '600267.SH', '600668.SH', '600052.SH', '002379.SZ', '603369.SH', '601360.SH', '002833.SZ',
34
+'002035.SZ', '600031.SH', '600678.SH', '600398.SH', '600587.SH', '600763.SH', '002016.SZ', '603816.SH', '000031.SZ', '002555.SZ', '603983.SH', '002746.SZ', '603899.SH',
35
+'300595.SZ', '300632.SZ', '600809.SH', '002507.SZ', '300198.SZ', '600779.SH', '603568.SH', '300638.SZ', '002011.SZ', '603517.SH', '000661.SZ', '300630.SZ', '000895.SZ',
36
+'002841.SZ', '300602.SZ', '300418.SZ', '603737.SH', '002755.SZ', '002803.SZ', '002182.SZ', '600132.SH', '300725.SZ', '600346.SH', '300015.SZ', '300014.SZ', '300628.SZ',
37
+'000789.SZ', '600368.SH', '300776.SZ', '600570.SH', '000509.SZ', '600338.SH', '300770.SZ', '600309.SH', '000596.SZ', '300702.SZ', '002271.SZ', '300782.SZ', '300577.SZ',
38
+'603505.SH', '603160.SH', '300761.SZ', '603327.SH', '002458.SZ', '300146.SZ', '002463.SZ', '300417.SZ', '600566.SH', '002372.SZ', '600585.SH', '000848.SZ', '600519.SH',
39
+'000672.SZ', '300357.SZ', '002234.SZ', '603444.SH', '300236.SZ', '603360.SH', '002677.SZ', '300487.SZ', '600319.SH', '002415.SZ', '000403.SZ', '600340.SH', '601318.SH',
41 40
 
42
-def read_data(path):
43
-    lines = []
44
-    with open(path) as f:
45
-        for line in f.readlines()[:]:
46
-            line = eval(line.strip())
47
-            if line[-2][0].startswith('0') or line[-2][0].startswith('3'):
48
-                lines.append(line)
49
-
50
-    size = len(lines[0])
51
-    train_x=[s[:size - 2] for s in lines]
52
-    train_y=[s[size-1] for s in lines]
53
-    return np.array(train_x),np.array(train_y),lines
41
+]
54 42
 
55 43
 
56 44
 import pymongo
@@ -94,12 +82,15 @@ A_concept_code_list = [   'TS2', # 5G
94 82
 gainian_map = {}
95 83
 hangye_map = {}
96 84
 
85
+Z_list = []  # 自选
86
+R_list = []  #  ROE
87
+O_list = []  # 其他
88
+
97 89
 def predict_today(file, day, model='10_18d', log=True):
98 90
     lines = []
99 91
     with open(file) as f:
100 92
         for line in f.readlines()[:]:
101 93
             line = eval(line.strip())
102
-            # if line[-1][0].startswith('0') or line[-1][0].startswith('3'):
103 94
             lines.append(line)
104 95
 
105 96
     size = len(lines[0])
@@ -124,10 +115,6 @@ def predict_today(file, day, model='10_18d', log=True):
124 115
             if stock['name'].startswith('ST') or stock['name'].startswith('N') or stock['name'].startswith('*'):
125 116
                 continue
126 117
 
127
-            if stock['ts_code'] in holder_stock_list:
128
-                print(stock['ts_code'], stock['name'], '维持买入评级')
129
-
130
-            # 跌的
131 118
             k_table_list = list(k_table.find({'code':line[-1][0], 'tradeDate':{'$lte':day}}).sort("tradeDate", pymongo.DESCENDING).limit(5))
132 119
             # if k_table_list[0]['close'] > k_table_list[-1]['close']*1.20:
133 120
             #     continue
@@ -160,21 +147,29 @@ def predict_today(file, day, model='10_18d', log=True):
160 147
                             else:
161 148
                                 gainian_map[c['name']] = 1
162 149
 
163
-            print(line[-1], stock['name'], stock['sw_industry'], str(concept_detail_list), 'buy', k_table_list[0]['pct_chg'])
150
+            if stock['ts_code'] in holder_stock_list:
151
+                print(line[-1], stock['name'], stock['sw_industry'], str(concept_detail_list), 'buy', k_table_list[0]['pct_chg'])
152
+                print(stock['ts_code'], stock['name'], '买入评级')
153
+                Z_list.append([stock['name'], stock['sw_industry'], k_table_list[0]['pct_chg']])
154
+            elif stock['ts_code'] in ROE_stock_list:
155
+                print(line[-1], stock['name'], stock['sw_industry'], str(concept_detail_list), 'buy', k_table_list[0]['pct_chg'])
156
+                print(stock['ts_code'], stock['name'], '买入评级')
157
+                R_list.append([stock['name'], stock['sw_industry'], k_table_list[0]['pct_chg']])
158
+            else:
159
+                O_list.append([stock['name'], stock['sw_industry'], k_table_list[0]['pct_chg']])
164 160
 
165 161
             if log is True:
166 162
                 with open('D:\\data\\quantization\\predict\\' + str(day) + '_mix.txt', mode='a', encoding="utf-8") as f:
167 163
                     f.write(str(line[-1]) + ' ' + stock['name'] + ' ' + stock['sw_industry'] + ' ' + str(concept_detail_list) + ' buy' + '\n')
168 164
 
169
-        elif result[0][1] > 0.4:
170
-            if stock['ts_code'] in holder_stock_list:
165
+        elif result[0][1] > 0.5:
166
+            if stock['ts_code'] in holder_stock_list or stock['ts_code'] in ROE_stock_list:
171 167
                 print(stock['ts_code'], stock['name'], '震荡评级')
172
-
173
-        elif result[0][2] > 0.5:
174
-            if stock['ts_code'] in holder_stock_list:
168
+        elif result[0][2] > 0.4:
169
+            if stock['ts_code'] in holder_stock_list or stock['ts_code'] in ROE_stock_list:
175 170
                 print(stock['ts_code'], stock['name'], '赶紧卖出')
176 171
         else:
177
-            if stock['ts_code'] in holder_stock_list:
172
+            if stock['ts_code'] in holder_stock_list or stock['ts_code'] in ROE_stock_list:
178 173
                 print(stock['ts_code'], stock['name'], result[0],)
179 174
 
180 175
     # print(gainian_map)
@@ -189,6 +184,25 @@ def predict_today(file, day, model='10_18d', log=True):
189 184
     print(gainian_list)
190 185
     print(hangye_list)
191 186
 
187
+    print('-----买入列表---------')
188
+    print(Z_list)
189
+    print(R_list)
190
+    print(O_list)
191
+
192
+    print('------随机结果--------')
193
+    random.shuffle(Z_list)
194
+    print('自选')
195
+    print(Z_list[:3])
196
+
197
+    random.shuffle(R_list)
198
+    print('ROE')
199
+    print(R_list[:3])
200
+
201
+    random.shuffle(O_list)
202
+    print('其他')
203
+    print(O_list[:3])
204
+
205
+
192 206
 def _read_pfile_map(path):
193 207
     s_list = []
194 208
     with open(path, encoding='utf-8') as f:
@@ -227,6 +241,6 @@ if __name__ == '__main__':
227 241
     # predict(file_path='D:\\data\\quantization\\stock6_5_test.log', model_path='5d_dnn_seq.h5')
228 242
     # predict(file_path='D:\\data\\quantization\\stock6_test.log', model_path='15m_dnn_seq.h5')
229 243
     # multi_predict()
230
-    predict_today("D:\\data\\quantization\\stock215_18d_20200323.log", 20200327, model='215_18d_mix_6D_ma5_s_seq.h5', log=True)
244
+    predict_today("D:\\data\\quantization\\stock216_18d_20200327.log", 20200327, model='216_18d_mix_6D_ma5_s_seq.h5', log=True)
231 245
     # join_two_day(20200305, 20200305)
232 246
     # check_everyday(20200311, 20200312)