yufeng 4 years ago
parent
commit
06103b47aa
5 changed files with 503 additions and 21 deletions
  1. 102 0
      mix/mix_predict_518.py
  2. 212 0
      mix/mix_train_518.py
  3. 100 0
      week/predict_everyweek_100.py
  4. 60 6
      week/week_predict_100.py
  5. 29 15
      week/week_train_100.py

+ 102 - 0
mix/mix_predict_518.py

@@ -0,0 +1,102 @@
1
+# -*- encoding:utf-8 -*-
2
+import numpy as np
3
+from keras.models import load_model
4
+import joblib
5
+
6
+
7
+def read_data(path):
8
+    lines = []
9
+    with open(path) as f:
10
+        for line in f.readlines()[:]:
11
+            line = eval(line.strip())
12
+            lines.append(line)
13
+
14
+    size = len(lines[0])
15
+    train_x=[s[:size - 2] for s in lines]
16
+    train_y=[s[size-1] for s in lines]
17
+    return np.array(train_x, dtype=np.float32),np.array(train_y, dtype=np.float32),lines
18
+
19
+
20
+def _score(fact, line):
21
+    up_right = 0
22
+    up_error = 0
23
+
24
+    if fact[0] == 1:
25
+        up_right = up_right + 1.1
26
+    elif fact[1] == 1:
27
+        up_error = up_error + 0.2
28
+        up_right = up_right + 1.04
29
+    elif fact[2] == 1:
30
+        up_error = up_error + 0.5
31
+        up_right = up_right + 0.98
32
+    else:
33
+        up_error = up_error + 1
34
+        up_right = up_right + 0.94
35
+    return up_right,up_error
36
+
37
+
38
+def predict(file_path='', model_path='15min_dnn_seq.h5', idx=-1, row=18, col=20):
39
+    test_x,test_y,lines=read_data(file_path)
40
+
41
+    test_x_a = test_x[:,:row*col]
42
+    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)
45
+    test_x_c = test_x[:,row*col:]
46
+
47
+    model=load_model(model_path)
48
+    score = model.evaluate([test_x_c, test_x_a, ], test_y)
49
+    print('MIX', score)
50
+
51
+    up_num = 0
52
+    up_error = 0
53
+    up_right = 0
54
+    down_num = 0
55
+    down_error = 0
56
+    down_right = 0
57
+    i = 0
58
+    result = model.predict([test_x_c, test_x_a, ])
59
+    win_dnn = []
60
+    for r in result:
61
+        fact = test_y[i]
62
+
63
+        if idx in [-2]:
64
+            if r[0] > 0.5 or r[1] > 0.5:
65
+                pass
66
+        else:
67
+            if r[0] > 0.5 :
68
+                tmp_right,tmp_error = _score(fact, lines[i])
69
+                up_right = tmp_right + up_right
70
+                up_error = tmp_error + up_error
71
+                up_num = up_num + 1
72
+            elif r[2] > 0.5 or r[3] > 0.5:
73
+                if fact[0] == 1:
74
+                    down_error = down_error + 1
75
+                    down_right = down_right + 1.1
76
+                elif fact[1] == 1:
77
+                    down_error = down_error + 0.5
78
+                    down_right = down_right + 1.04
79
+                elif fact[2] == 1:
80
+                    down_right = down_right + 0.98
81
+                else:
82
+                    down_right = down_right + 0.92
83
+                down_num = down_num + 1
84
+
85
+        i = i + 1
86
+    if up_num == 0:
87
+        up_num = 1
88
+    if down_num == 0:
89
+        down_num = 1
90
+    print('MIX', up_right, up_num, up_right/up_num, up_error/up_num, down_right/down_num, down_error/down_num)
91
+    return win_dnn,up_right/up_num,down_right/down_num
92
+
93
+
94
+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)

+ 212 - 0
mix/mix_train_518.py

@@ -0,0 +1,212 @@
1
+import keras
2
+# -*- encoding:utf-8 -*-
3
+import numpy as np
4
+from keras.models import Sequential
5
+# 优化方法选用Adam(其实可选项有很多,如SGD)
6
+from keras.optimizers import Adam
7
+import random
8
+from keras.models import load_model
9
+from imblearn.over_sampling import RandomOverSampler
10
+from keras.utils import np_utils
11
+# 用于模型初始化,Conv2D模型初始化、Activation激活函数,MaxPooling2D是池化层
12
+# Flatten作用是将多位输入进行一维化
13
+# Dense是全连接层
14
+from keras.layers import Conv2D, Activation, MaxPool2D, Flatten, Dense,Dropout,Input,MaxPooling2D,BatchNormalization,concatenate
15
+from keras import regularizers
16
+from keras.models import Model
17
+from keras.callbacks import EarlyStopping
18
+
19
+early_stopping = EarlyStopping(monitor='accuracy', patience=5, verbose=2)
20
+
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
+row = 28
27
+col = 16
28
+'''
29
+0    dmi            28*20      38,98,51/5     下跌预判非常准                                    
30
+1    macd           28*19      41,98,53/8  
31
+2    dmi-对大盘对比 28*20      35,99,46/17 
32
+3    5d-dmi-对大盘对比 28*20   42,99,39/10
33
+4    3d-dmi-对大盘对比 28*20   40,99,39/07   
34
+5    3d-beta1                  55,99,52/07    当前用这个
35
+6    3d-ma20                   40,99,41/07
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,102,30-35  !
47
+
48
+'''
49
+
50
+def read_data(path, path1=file_path1):
51
+    lines = []
52
+    with open(path) as f:
53
+        for x in range(size): #680000
54
+            line = eval(f.readline().strip())
55
+            lines.append(line)
56
+
57
+    with open(path1) as f:
58
+        for x in range(30000): #6w
59
+            line = eval(f.readline().strip())
60
+            lines.append(line)
61
+
62
+    random.shuffle(lines)
63
+    print('读取数据完毕')
64
+
65
+    d=int(0.85*len(lines))
66
+    length = len(lines[0])
67
+
68
+    train_x=[s[:length - 2] for s in lines[0:d]]
69
+    train_y=[s[-1] for s in lines[0:d]]
70
+    test_x=[s[:length - 2] for s in lines[d:]]
71
+    test_y=[s[-1] for s in lines[d:]]
72
+
73
+    print('转换数据完毕')
74
+
75
+    ros = RandomOverSampler(random_state=0)
76
+    X_resampled, y_resampled = ros.fit_sample(np.array(train_x, dtype=np.float32), np.array(train_y, dtype=np.float32))
77
+
78
+    print('数据重采样完毕')
79
+
80
+    return X_resampled,y_resampled,np.array(test_x, dtype=np.float32),np.array(test_y, dtype=np.float32)
81
+
82
+
83
+train_x,train_y,test_x,test_y=read_data(file_path)
84
+
85
+train_x_a = train_x[:,:row*col]
86
+train_x_a = train_x_a.reshape(train_x.shape[0], row, col, 1)
87
+# train_x_b = train_x[:, 9*26:18*26]
88
+# train_x_b = train_x_b.reshape(train_x.shape[0], 9, 26, 1)
89
+train_x_c = train_x[:,row*col:]
90
+
91
+
92
+def create_mlp(dim, regress=False):
93
+    # define our MLP network
94
+    model = Sequential()
95
+    model.add(Dense(256, input_dim=dim, activation="relu"))
96
+    model.add(Dropout(0.2))
97
+    model.add(Dense(256, activation="relu"))
98
+    model.add(Dense(256, activation="relu"))
99
+    model.add(Dense(128, activation="relu"))
100
+
101
+    # check to see if the regression node should be added
102
+    if regress:
103
+        model.add(Dense(1, activation="linear"))
104
+
105
+    # return our model
106
+    return model
107
+
108
+
109
+def create_cnn(width, height, depth, size=48, kernel_size=(5, 6), regress=False, output=24):
110
+    # initialize the input shape and channel dimension, assuming
111
+    # TensorFlow/channels-last ordering
112
+    inputShape = (width, height, 1)
113
+    chanDim = -1
114
+
115
+    # define the model input
116
+    inputs = Input(shape=inputShape)
117
+    # x = inputs
118
+    # CONV => RELU => BN => POOL
119
+    x = Conv2D(size, kernel_size, strides=2, padding="same")(inputs)
120
+    x = Activation("relu")(x)
121
+    x = BatchNormalization(axis=chanDim)(x)
122
+
123
+    # y = Conv2D(24, (2, 8), strides=2, padding="same")(inputs)
124
+    # y = Activation("relu")(y)
125
+    # y = BatchNormalization(axis=chanDim)(y)
126
+
127
+    # flatten the volume, then FC => RELU => BN => DROPOUT
128
+    x = Flatten()(x)
129
+    x = Dense(output)(x)
130
+    x = Activation("relu")(x)
131
+    x = BatchNormalization(axis=chanDim)(x)
132
+    x = Dropout(0.2)(x)
133
+
134
+    # apply another FC layer, this one to match the number of nodes
135
+    # coming out of the MLP
136
+    x = Dense(output)(x)
137
+    x = Activation("relu")(x)
138
+
139
+    # check to see if the regression node should be added
140
+    if regress:
141
+        x = Dense(1, activation="linear")(x)
142
+
143
+    # construct the CNN
144
+    model = Model(inputs, x)
145
+
146
+    # return the CNN
147
+    return model
148
+
149
+
150
+# create the MLP and CNN models
151
+mlp = create_mlp(train_x_c.shape[1], regress=False)
152
+# cnn_0 = create_cnn(18, 20, 1, kernel_size=(3, 3), size=90, regress=False, output=96)       # 31 97 46
153
+cnn_0 = create_cnn(row, col, 1, kernel_size=(6, col), size=96, regress=False, output=96)         # 29 98 47
154
+# cnn_0 = create_cnn(18, 20, 1, kernel_size=(9, 9), size=90, regress=False, output=96)         # 28 97 53
155
+# cnn_0 = create_cnn(18, 20, 1, kernel_size=(3, 20), size=90, regress=False, output=96)
156
+# cnn_1 = create_cnn(18, 20, 1, kernel_size=(18, 10), size=80, regress=False, output=96)
157
+# cnn_1 = create_cnn(9, 26, 1, kernel_size=(2, 14), size=36, regress=False, output=64)
158
+
159
+# create the input to our final set of layers as the *output* of both
160
+# the MLP and CNN
161
+combinedInput = concatenate([mlp.output, cnn_0.output, ])
162
+
163
+# our final FC layer head will have two dense layers, the final one
164
+# being our regression head
165
+x = Dense(1024, activation="relu", kernel_regularizer=regularizers.l1(0.003))(combinedInput)
166
+x = Dropout(0.2)(x)
167
+x = Dense(1024, activation="relu")(x)
168
+x = Dense(1024, activation="relu")(x)
169
+# 在建设一层
170
+x = Dense(4, activation="softmax")(x)
171
+
172
+# our final model will accept categorical/numerical data on the MLP
173
+# input and images on the CNN input, outputting a single value (the
174
+# predicted price of the house)
175
+model = Model(inputs=[mlp.input, cnn_0.input, ], outputs=x)
176
+
177
+
178
+print("Starting training ")
179
+# h = model.fit(train_x, train_y, batch_size=4096*2, epochs=500, shuffle=True)
180
+
181
+# compile the model using mean absolute percentage error as our loss,
182
+# implying that we seek to minimize the absolute percentage difference
183
+# between our price *predictions* and the *actual prices*
184
+opt = Adam(lr=1e-3, decay=1e-3 / 200)
185
+model.compile(loss="categorical_crossentropy", optimizer=opt, metrics=['accuracy'])
186
+
187
+# train the model
188
+print("[INFO] training model...")
189
+model.fit(
190
+    [train_x_c, train_x_a, ], train_y,
191
+    # validation_data=([testAttrX, testImagesX], testY),
192
+    # epochs=int(3*train_x_a.shape[0]/1300),
193
+    epochs=epochs,
194
+    batch_size=2048, shuffle=True,
195
+    callbacks=[early_stopping]
196
+)
197
+
198
+model.save(model_path)
199
+
200
+test_x_a = test_x[:,:row*col]
201
+test_x_a = test_x_a.reshape(test_x.shape[0], row, col, 1)
202
+# test_x_b = test_x[:, 9*26:9*26+9*26]
203
+# test_x_b = test_x_b.reshape(test_x.shape[0], 9, 26, 1)
204
+test_x_c = test_x[:,row*col:]
205
+
206
+# make predictions on the testing data
207
+print("[INFO] predicting house prices...")
208
+score  = model.evaluate([test_x_c, test_x_a,], test_y)
209
+
210
+print(score)
211
+print('Test score:', score[0])
212
+print('Test accuracy:', score[1])

+ 100 - 0
week/predict_everyweek_100.py

@@ -0,0 +1,100 @@
1
+# -*- encoding:utf-8 -*-
2
+import numpy as np
3
+from keras.models import load_model
4
+import random
5
+from mix.stock_source import *
6
+import pymongo
7
+from util.mongodb import get_mongo_table_instance
8
+
9
+code_table = get_mongo_table_instance('tushare_code')
10
+k_table = get_mongo_table_instance('stock_day_k')
11
+stock_concept_table = get_mongo_table_instance('tushare_concept_detail')
12
+all_concept_code_list = list(get_mongo_table_instance('tushare_concept').find({}))
13
+
14
+
15
+gainian_map = {}
16
+hangye_map = {}
17
+
18
+
19
+Z_list = []  # 自选
20
+R_list = []  #  ROE
21
+O_list = []  # 其他
22
+
23
+
24
+def predict_today(file, day, model='10_18d', log=True):
25
+    industry_list = get_hot_industry(day)
26
+
27
+    lines = []
28
+    with open(file) as f:
29
+        for line in f.readlines()[:]:
30
+            line = eval(line.strip())
31
+            lines.append(line)
32
+
33
+    size = len(lines[0])
34
+
35
+    model=load_model(model)
36
+
37
+    row = 18
38
+    col = 11
39
+
40
+    for line in lines:
41
+        train_x = np.array([line[:size - 1]])
42
+
43
+        train_x_a = train_x[:,:row*col]
44
+        train_x_a = train_x_a.reshape(train_x.shape[0], row, col, 1)
45
+        train_x_b = train_x[:, row*col:row*col + 11*16]
46
+        train_x_b = train_x_b.reshape(train_x.shape[0], 11, 16, 1)
47
+        train_x_c = train_x[:,row*col + 11*16:]
48
+
49
+        result = model.predict([train_x_c, train_x_a, train_x_b])
50
+        # print(result, line[-1])
51
+        stock = code_table.find_one({'ts_code':line[-1][0]})
52
+
53
+        if result[0][0] > 0.5:
54
+            if line[-1][0].startswith('688'):
55
+                continue
56
+            # 去掉ST
57
+            if stock['name'].startswith('ST') or stock['name'].startswith('N') or stock['name'].startswith('*'):
58
+                continue
59
+
60
+            if stock['ts_code'] in ROE_stock_list or stock['ts_code'] in zeng_stock_list:
61
+                R_list.append([stock['ts_code'], stock['name']])
62
+
63
+            concept_code_list = list(stock_concept_table.find({'ts_code':stock['ts_code']}))
64
+            concept_detail_list = []
65
+
66
+            if len(concept_code_list) > 0:
67
+                for concept in concept_code_list:
68
+                    for c in all_concept_code_list:
69
+                        if c['code'] == concept['concept_code']:
70
+                            concept_detail_list.append(c['name'])
71
+
72
+            if log is True:
73
+                with open('D:\\data\\quantization\\predict\\' + str(day) + '_week_100.txt', mode='a', encoding="utf-8") as f:
74
+                    f.write(str(line[-1]) + ' ' + stock['name'] + ' ' + stock['sw_industry'] + ' ' + str(concept_detail_list) + ' ' + str(result[0][0]) + '\n')
75
+
76
+        elif result[0][1] > 0.5:
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'], '警告危险')
81
+        elif result[0][3] > 0.5:
82
+            if stock['ts_code'] in holder_stock_list or stock['ts_code'] in zixuan_stock_list:
83
+                print(stock['ts_code'], stock['name'], '赶紧卖出')
84
+        else:
85
+            pass
86
+
87
+    # print(gainian_map)
88
+    # print(hangye_map)
89
+    random.shuffle(O_list)
90
+    print(O_list[:3])
91
+
92
+    random.shuffle(R_list)
93
+    print('----ROE----')
94
+    print(R_list[:3])
95
+
96
+
97
+if __name__ == '__main__':
98
+    # 策略B
99
+    # predict_today("D:\\data\\quantization\\stock505_28d_20200416.log", 20200416, model='505_28d_mix_5D_ma5_s_seq.h5', log=True)
100
+    predict_today("D:\\data\\quantization\\week101_18d_20200421.log", 20200421, model='103_18d_mix_3W_s_seq.h5', log=True)

+ 60 - 6
week/week_predict_100.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
 def read_data(path):
@@ -17,14 +17,14 @@ def read_data(path):
17 17
     return np.array(train_x, dtype=np.float32),np.array(train_y, dtype=np.float32),lines
18 18
 
19 19
 
20
-def _score(fact, line):
20
+def _score(fact, ):
21 21
     up_right = 0
22 22
     up_error = 0
23 23
 
24 24
     if fact[0] == 1:
25
-        up_right = up_right + 1.15
25
+        up_right = up_right + 1.14
26 26
     elif fact[1] == 1:
27
-        up_error = up_error + 0.1
27
+        up_error = up_error + 0.2
28 28
         up_right = up_right + 1.08
29 29
     elif fact[2] == 1:
30 30
         up_error = up_error + 0.7
@@ -59,13 +59,14 @@ def predict(file_path='', model_path='15min_dnn_seq.h5', idx=-1, row=18, col=20)
59 59
     win_dnn = []
60 60
     for r in result:
61 61
         fact = test_y[i]
62
+        xx = random.uniform(0, 4)
62 63
 
63 64
         if idx in [-2]:
64 65
             if r[0] > 0.5 or r[1] > 0.5:
65 66
                 pass
66 67
         else:
67 68
             if r[0] > 0.5:
68
-                tmp_right,tmp_error = _score(fact, lines[i])
69
+                tmp_right,tmp_error = _score(fact, )
69 70
                 up_right = tmp_right + up_right
70 71
                 up_error = tmp_error + up_error
71 72
                 up_num = up_num + 1
@@ -77,6 +78,7 @@ def predict(file_path='', model_path='15min_dnn_seq.h5', idx=-1, row=18, col=20)
77 78
                     down_error = down_error + 0.5
78 79
                     down_right = down_right + 1.02
79 80
                 elif fact[2] == 1:
81
+                    down_error = down_error + 0.2
80 82
                     down_right = down_right + 0.98
81 83
                 else:
82 84
                     down_right = down_right + 0.95
@@ -91,5 +93,57 @@ def predict(file_path='', model_path='15min_dnn_seq.h5', idx=-1, row=18, col=20)
91 93
     return win_dnn,up_right/up_num,down_right/down_num
92 94
 
93 95
 
96
+def random_predict(file_path=''):
97
+    test_x,test_y,lines=read_data(file_path)
98
+    a=0
99
+    b=0
100
+    c=0
101
+    d=0
102
+    R=0
103
+
104
+    up_num = 0
105
+    up_error = 0
106
+    up_right = 0
107
+    down_num = 0
108
+    down_error = 0
109
+    down_right = 0
110
+
111
+    for x in test_y:
112
+        xx = random.uniform(0, 4)
113
+        if xx > 3:
114
+            if x[0] == 1:
115
+                R = R + 1
116
+            tmp_right,tmp_error = _score(x,)
117
+            up_num = up_num + 1
118
+            up_right = up_right + tmp_right
119
+            up_error = tmp_error + up_error
120
+        elif xx > 2:
121
+            if x[1] == 1:
122
+                R = R + 1
123
+        elif xx > 1:
124
+            if x[2] == 1:
125
+                R = R + 1
126
+        elif xx > 0:
127
+            if x[3] == 1:
128
+                R = R + 1
129
+
130
+        if x[0] == 1:
131
+            a = a + 1
132
+        elif x[1] == 1:
133
+            b = b + 1
134
+        elif x[2] == 1:
135
+            c = c + 1
136
+        else:
137
+            d = d + 1
138
+
139
+    if up_num == 0:
140
+        up_num = 1
141
+    if down_num == 0:
142
+        down_num = 1
143
+
144
+    print(R/(a + b + c +d), up_right/up_num, up_error/up_num)
145
+
146
+
94 147
 if __name__ == '__main__':
95
-    predict(file_path='D:\\data\\quantization\\week101_18d_test.log', model_path='103_18d_mix_3W_s_seq.h5', row=18, col=11)
148
+    predict(file_path='D:\\data\\quantization\\week113_18d_test.log', model_path='113_18d_mix_3W_s_seq.h5', row=18, col=6)
149
+    # random_predict(file_path='D:\\data\\quantization\\week109/_18d_test.log')

+ 29 - 15
week/week_train_100.py

@@ -16,29 +16,43 @@ from keras.callbacks import EarlyStopping
16 16
 
17 17
 early_stopping = EarlyStopping(monitor='accuracy', patience=5, verbose=2)
18 18
 
19
-epochs= 55
19
+epochs= 38
20 20
 # size = 24000 #共68W
21
-file_path = 'D:\\data\\quantization\\week101_18d_train1.log'
22
-model_path = '105_18d_mix_3W_s_seq.h5'
23
-file_path1='D:\\data\\quantization\\week101_18d_train1.log'
21
+file_path = 'D:\\data\\quantization\\week112_18d_train1.log'
22
+model_path = '112_18d_mix_3W_s_seq.h5'
24 23
 row = 18
25 24
 col = 11
25
+col1 = 17
26 26
 '''
27 27
 0   18-3                    18*11           25,102,47-29
28 28
 1   18W预测3周后最高价+pe   18*11           37,101,44-22
29 29
 2                           18*11 + 11*16   33,101,41-30
30
-3   stripe=1                18*11 + 11*16   32,106,24-23
31
-4   stripe=1,win=3          18*11 + 11*16   35,105,27-27
30
+3   stripe=1,win=4-3        18*11 + 11*16   38,104,32-20  ----- 随机25,100,51-26            
31
+4   stripe=1,win=3          18*11 + 11*16   34,103,41-26
32 32
 5   stripe=1,win=3          18*11           
33
+6   用ma来衡量    
34
+7   简化模型                
35
+8   ma5-大盘相关+alpha_6       18*11 + 11*16         ------25,96,69
36
+9   ma5-大盘相关+alpha_44+alpha_2            51,96,68-07    
37
+10  ma5-大盘相关+alpha_53+alpha_18           48,97,61-06
38
+
39
+11  high-大盘相关+alpha_53+alpha_18                             35,103,39-37
40
+12  high-大盘相关+alpha_53+alpha_18(每日)    18*11 + 11*17      
41
+13  high-大盘相关+alpha_53+alpha_18-dmi      18*6 + 11*16       37,105,33-32
33 42
 '''
34 43
 
35
-def read_data(path, path1=file_path1):
44
+def read_data(path):
36 45
     lines = []
37 46
     with open(path) as f:
38 47
         for x in f.readlines()[:]: #680000
39 48
             line = eval(x.strip())
40 49
             lines.append(line)
41 50
 
51
+    # with open(path1) as f:
52
+    #     for x in f.readlines()[:]: #680000
53
+    #         line = eval(x.strip())
54
+    #         lines.append(line)
55
+
42 56
 
43 57
     random.shuffle(lines)
44 58
     print('读取数据完毕')
@@ -65,9 +79,9 @@ train_x,train_y,test_x,test_y=read_data(file_path)
65 79
 
66 80
 train_x_a = train_x[:,:row*col]
67 81
 train_x_a = train_x_a.reshape(train_x.shape[0], row, col, 1)
68
-train_x_b = train_x[:, row*col:row*col + 11*16]
69
-train_x_b = train_x_b.reshape(train_x.shape[0], 11, 16, 1)
70
-train_x_c = train_x[:,row*col + 11*16:]
82
+train_x_b = train_x[:, row*col:row*col + 11*col1]
83
+train_x_b = train_x_b.reshape(train_x.shape[0], 11, col1, 1)
84
+train_x_c = train_x[:,row*col + 11*col1:]
71 85
 
72 86
 
73 87
 def create_mlp(dim, regress=False):
@@ -131,10 +145,10 @@ def create_cnn(width, height, depth, size=48, kernel_size=(5, 6), regress=False,
131 145
 # create the MLP and CNN models
132 146
 mlp = create_mlp(train_x_c.shape[1], regress=False)
133 147
 # cnn_0 = create_cnn(18, 20, 1, kernel_size=(3, 3), size=90, regress=False, output=96)       # 31 97 46
134
-cnn_0 = create_cnn(row, col, 1, kernel_size=(3, col), size=66, regress=False, output=66)         # 29 98 47
148
+cnn_0 = create_cnn(row, col, 1, kernel_size=(4, col), size=66, regress=False, output=66)         # 29 98 47
135 149
 # cnn_0 = create_cnn(18, 20, 1, kernel_size=(9, 9), size=90, regress=False, output=96)         # 28 97 53
136 150
 # cnn_0 = create_cnn(18, 20, 1, kernel_size=(3, 20), size=90, regress=False, output=96)
137
-cnn_1 = create_cnn(11, 16, 1, kernel_size=(3, 16), size=66, regress=False, output=66)
151
+cnn_1 = create_cnn(11, col1, 1, kernel_size=(3, col1), size=66, regress=False, output=66)
138 152
 # cnn_1 = create_cnn(9, 26, 1, kernel_size=(2, 14), size=36, regress=False, output=64)
139 153
 
140 154
 # create the input to our final set of layers as the *output* of both
@@ -180,9 +194,9 @@ model.save(model_path)
180 194
 
181 195
 test_x_a = test_x[:,:row*col]
182 196
 test_x_a = test_x_a.reshape(test_x.shape[0], row, col, 1)
183
-test_x_b = test_x[:, row*col:row*col + 11*16]
184
-test_x_b = test_x_b.reshape(test_x.shape[0],11, 16, 1)
185
-test_x_c = test_x[:,row*col + 11*16:]
197
+test_x_b = test_x[:, row*col:row*col + 11*col1]
198
+test_x_b = test_x_b.reshape(test_x.shape[0],11, col1, 1)
199
+test_x_c = test_x[:,row*col + 11*col1:]
186 200
 
187 201
 # make predictions on the testing data
188 202
 print("[INFO] predicting house prices...")