-
Notifications
You must be signed in to change notification settings - Fork 5
/
list_percent.py
executable file
·448 lines (317 loc) · 22.5 KB
/
list_percent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# -*- coding: utf-8 -*-
"""
產生每日漲跌%統計資料
@author: tim
"""
import os
from datetime import datetime
from grs import BestFourPoint
from grs import Stock
from grs import TWSENo
from grs import OTCNo
import time, itertools
try:
os.remove("list_percent.txt")
except OSError:
pass
# 記錄開始時間 Record start time
tStart = time.time()
Stock_no_name = TWSENo().all_stock # 所有上市股票名稱與代碼字典 type: dict
OTC_no_name = OTCNo().all_stock # 所有上櫃股票名稱與代碼字典 type: dict
stock_no_list = TWSENo().all_stock_no # 所有上市股票代碼
OTC_no_list = OTCNo().all_stock_no # 所有上櫃股票代碼
content = "贏要衝,輸要縮." #沒有辦法換行
time_now = datetime.now().strftime("%Y-%m%d") #今天的日期 ex:2015-0411
title = str(time_now+"-今日各股漲跌幅度統計") #Email郵件的標題 ex:2015-0411-選股機器人
attachment = str(time_now)+'percent.txt' #附件名稱使用當日時間 ex:2015-0411.txt
fileopen = open("list_percent.txt", 'w') #開啟檔案,w沒有該檔案就新增
f = open('/home/tim/GMAIL.txt','r') #於前一個相對目錄中放置登入GMAIL帳號密碼,目的為了不再GitHub顯示出來.
ID = f.readline().strip('\n') #不包含換行符號\n
PW = f.readline().strip('\n')
fileopen.write(time_now+'上市公司股票篩選\n\n\n')
#上市漲跌幅%
twse_pos0 = [] #平盤
twse_pos0_1 = []
twse_pos1_2 = []
twse_pos2_3 = []
twse_pos3_4 = []
twse_pos4_5 = []
twse_pos5_6 = []
twse_pos6_7 = []
twse_pos7_8 = []
twse_pos8_9 = []
twse_pos9_10 = []
twse_minus0_1 = []
twse_minus1_2 = []
twse_minus2_3 = []
twse_minus3_4 = []
twse_minus4_5 = []
twse_minus5_6 = []
twse_minus6_7 = []
twse_minus7_8 = []
twse_minus8_9 = []
twse_minus9_10 = []
#=====================
total_twse = 0
for i in stock_no_list:
try:
percent = float(Stock(i,mons=2)._SimpleAnalytics__raw_data[-1][7]) / float(Stock(i,mons=2)._SimpleAnalytics__raw_data[-2][6])
percent = percent * 100
if percent > 0 and percent < 1:
twse_pos0_1.append(i)
if percent >= 1 and percent < 2:
twse_pos1_2.append(i)
if percent >= 2 and percent < 3:
twse_pos2_3.append(i)
if percent >= 3 and percent < 4:
twse_pos3_4.append(i)
if percent >= 4 and percent < 5:
twse_pos4_5.append(i)
if percent >= 5 and percent < 6:
twse_pos5_6.append(i)
if percent >= 6 and percent < 7:
twse_pos6_7.append(i)
if percent >= 7 and percent < 8:
twse_pos7_8.append(i)
if percent >= 8 and percent < 9:
twse_pos8_9.append(i)
if percent >= 9 and percent < 10.5:
twse_pos9_10.append(i)
if percent < 0 and percent > -1:
twse_minus0_1.append(i)
if percent <= -1 and percent > -2:
twse_minus1_2.append(i)
if percent <= -2 and percent > -3:
twse_minus2_3.append(i)
if percent <= -3 and percent > -4:
twse_minus3_4.append(i)
if percent <= -4 and percent > -5:
twse_minus4_5.append(i)
if percent <= -5 and percent > -6:
twse_minus5_6.append(i)
if percent <= -6 and percent > -7:
twse_minus6_7.append(i)
if percent <= -7 and percent > -8:
twse_minus7_8.append(i)
if percent <= -8 and percent > -9:
twse_minus8_9.append(i)
if percent <= -9 and percent > -10.5:
twse_minus9_10.append(i)
if percent == 0:
twse_pos0.append(i)
total_twse+=1
except: # 回傳為None 或 資料不足導致ValueError
pass
print '擷取到的上市公司有%d家'%int(total_twse)
fileopen.write('擷取到的上市公司有%d家'%int(total_twse)+'\n\n')
print '上市公司中收平盤的有%d家,共佔了%.1f percent'%(len(twse_pos0), len(twse_pos0)/float(total_twse)*100)
fileopen.write('上市公司中收平盤的有%d家,共佔了%.1f percent'%(len(twse_pos0), len(twse_pos0)/float(total_twse)*100)+'\n')
print '上市公司中漲0~1 percent的有%d家,共佔了%.1f percent'%(len(twse_pos0_1), len(twse_pos0_1)/float(total_twse)*100)
fileopen.write('上市公司中漲0~1 percent的有%d家,共佔了%.1f percent'%(len(twse_pos0_1), len(twse_pos0_1)/float(total_twse)*100)+'\n')
print '上市公司中漲>=1~2 percent的有%d家,共佔了%.1f percent'%(len(twse_pos1_2), len(twse_pos1_2)/float(total_twse)*100)
fileopen.write('上市公司中漲>=1~2 percent的有%d家,共佔了%.1f percent'%(len(twse_pos1_2), len(twse_pos1_2)/float(total_twse)*100)+'\n')
print '上市公司中漲2~3 percent的有%d家,共佔了%.1f percent'%(len(twse_pos2_3), len(twse_pos2_3)/float(total_twse)*100)
fileopen.write('上市公司中漲2~3 percent的有%d家,共佔了%.1f percent'%(len(twse_pos2_3), len(twse_pos2_3)/float(total_twse)*100)+'\n')
print '上市公司中漲3~4 percent的有%d家,共佔了%.1f percent'%(len(twse_pos3_4), len(twse_pos3_4)/float(total_twse)*100)
fileopen.write('上市公司中漲3~4 percent的有%d家,共佔了%.1f percent'%(len(twse_pos3_4), len(twse_pos3_4)/float(total_twse)*100)+'\n')
print '上市公司中漲4~5 percent的有%d家,共佔了%.1f percent'%(len(twse_pos4_5), len(twse_pos4_5)/float(total_twse)*100)
fileopen.write('上市公司中漲4~5 percent的有%d家,共佔了%.1f percent'%(len(twse_pos4_5), len(twse_pos4_5)/float(total_twse)*100)+'\n')
print '上市公司中漲5~6 percent的有%d家,共佔了%.1f percent'%(len(twse_pos5_6), len(twse_pos5_6)/float(total_twse)*100)
fileopen.write('上市公司中漲5~6 percent的有%d家,共佔了%.1f percent'%(len(twse_pos5_6), len(twse_pos5_6)/float(total_twse)*100)+'\n')
print '上市公司中漲6~7 percent的有%d家,共佔了%.1f percent'%(len(twse_pos6_7), len(twse_pos6_7)/float(total_twse)*100)
fileopen.write('上市公司中漲6~7 percent的有%d家,共佔了%.1f percent'%(len(twse_pos6_7), len(twse_pos6_7)/float(total_twse)*100)+'\n')
print '上市公司中漲7~8 percent的有%d家,共佔了%.1f percent'%(len(twse_pos7_8), len(twse_pos7_8)/float(total_twse)*100)
fileopen.write('上市公司中漲7~8 percent的有%d家,共佔了%.1f percent'%(len(twse_pos7_8), len(twse_pos7_8)/float(total_twse)*100)+'\n')
print '上市公司中漲8~9 percent的有%d家,共佔了%.1f percent'%(len(twse_pos8_9), len(twse_pos8_9)/float(total_twse)*100)
fileopen.write('上市公司中漲7~8 percent的有%d家,共佔了%.1f percent'%(len(twse_pos8_9), len(twse_pos8_9)/float(total_twse)*100)+'\n')
print '上市公司中漲9~10 percent的有%d家,共佔了%.1f percent'%(len(twse_pos9_10), len(twse_pos9_10)/float(total_twse)*100)
fileopen.write('上市公司中漲9~10 percent的有%d家,共佔了%.1f percent'%(len(twse_pos9_10), len(twse_pos9_10)/float(total_twse)*100)+'\n')
print '***************************'
fileopen.write('***************************\n')
print '上市公司中跌0~1 percent的有%d家,共佔了%.1f percent'%(len(twse_minus0_1), len(twse_minus0_1)/float(total_twse)*100)
fileopen.write('上市公司中跌0~1 percent的有%d家,共佔了%.1f percent'%(len(twse_minus0_1), len(twse_minus0_1)/float(total_twse)*100)+'\n')
print '上市公司中跌>=1~2 percent的有%d家,共佔了%.1f percent'%(len(twse_minus1_2), len(twse_minus1_2)/float(total_twse)*100)
fileopen.write('上市公司中跌>=1~2 percent的有%d家,共佔了%.1f percent'%(len(twse_minus1_2), len(twse_minus1_2)/float(total_twse)*100)+'\n')
print '上市公司中跌2~3 percent的有%d家,共佔了%.1f percent'%(len(twse_minus2_3), len(twse_minus2_3)/float(total_twse)*100)
fileopen.write('上市公司中跌2~3 percent的有%d家,共佔了%.1f percent'%(len(twse_minus2_3), len(twse_minus2_3)/float(total_twse)*100)+'\n')
print '上市公司中跌3~4 percent的有%d家,共佔了%.1f percent'%(len(twse_minus3_4), len(twse_minus3_4)/float(total_twse)*100)
fileopen.write('上市公司中跌3~4 percent的有%d家,共佔了%.1f percent'%(len(twse_minus3_4), len(twse_minus3_4)/float(total_twse)*100)+'\n')
print '上市公司中跌4~5 percent的有%d家,共佔了%.1f percent'%(len(twse_minus4_5), len(twse_minus4_5)/float(total_twse)*100)
fileopen.write('上市公司中跌4~5 percent的有%d家,共佔了%.1f percent'%(len(twse_minus4_5), len(twse_minus4_5)/float(total_twse)*100)+'\n')
print '上市公司中跌5~6 percent的有%d家,共佔了%.1f percent'%(len(twse_minus5_6), len(twse_minus5_6)/float(total_twse)*100)
fileopen.write('上市公司中跌5~6 percent的有%d家,共佔了%.1f percent'%(len(twse_minus5_6), len(twse_minus5_6)/float(total_twse)*100)+'\n')
print '上市公司中跌6~7 percent的有%d家,共佔了%.1f percent'%(len(twse_minus6_7), len(twse_minus6_7)/float(total_twse)*100)
fileopen.write('上市公司中跌6~7 percent的有%d家,共佔了%.1f percent'%(len(twse_minus6_7), len(twse_minus6_7)/float(total_twse)*100)+'\n')
print '上市公司中跌7~8 percent的有%d家,共佔了%.1f percent'%(len(twse_minus7_8), len(twse_minus7_8)/float(total_twse)*100)
fileopen.write('上市公司中跌7~8 percent的有%d家,共佔了%.1f percent'%(len(twse_minus7_8), len(twse_minus7_8)/float(total_twse)*100)+'\n')
print '上市公司中跌8~9 percent的有%d家,共佔了%.1f percent'%(len(twse_minus8_9), len(twse_minus8_9)/float(total_twse)*100)
fileopen.write('上市公司中跌8~9 percent的有%d家,共佔了%.1f percent'%(len(twse_minus8_9), len(twse_minus8_9)/float(total_twse)*100)+'\n')
print '上市公司中跌9~10 percent的有%d家,共佔了%.1f percent'%(len(twse_minus9_10), len(twse_minus9_10)/float(total_twse)*100)
fileopen.write('上市公司中跌9~10 percent的有%d家,共佔了%.1f percent'%(len(twse_minus9_10), len(twse_minus9_10)/float(total_twse)*100)+'\n')
print '***************************'
fileopen.write('***************************\n')
print '買到上市平盤股票機率%.1f,上漲股票機率%.1f,下跌股票機率%.1f'%(len(twse_pos0)/float(total_twse)*100,(len(twse_pos0_1)+len(twse_pos1_2)+len(twse_pos2_3)+len(twse_pos3_4)+len(twse_pos4_5)+len(twse_pos5_6)+len(twse_pos6_7)+len(twse_pos7_8)+len(twse_pos8_9)+len(twse_pos9_10))/float(total_twse)*100, (len(twse_minus0_1)+len(twse_minus1_2)+len(twse_minus2_3)+len(twse_minus3_4)+len(twse_minus4_5)+len(twse_minus5_6)+len(twse_minus6_7)+len(twse_minus7_8)+len(twse_minus8_9)+len(twse_minus9_10))/float(total_twse)*100)
twse_zero = len(twse_pos0)/float(total_twse)*100
twse_up = (len(twse_pos0_1)+len(twse_pos1_2)+len(twse_pos2_3)+len(twse_pos3_4)+len(twse_pos4_5)+len(twse_pos5_6)+len(twse_pos6_7)+len(twse_pos7_8)+len(twse_pos8_9)+len(twse_pos9_10))/float(total_twse)*100
tswe_down = (len(twse_minus0_1)+len(twse_minus1_2)+len(twse_minus2_3)+len(twse_minus3_4)+len(twse_minus4_5)+len(twse_minus5_6)+len(twse_minus6_7)+len(twse_minus7_8)+len(twse_minus8_9)+len(twse_minus9_10))/float(total_twse)*100
fileopen.write('買到上市平盤股票機率%.1f,上漲股票機率%.1f,下跌股票機率%.1f'%(twse_zero,twse_up,tswe_down)+'\n')
#======================
# 上櫃股票漲跌%
otc_pos0 = [] #平盤
otc_pos0_1 = []
otc_pos1_2 = []
otc_pos2_3 = []
otc_pos3_4 = []
otc_pos4_5 = []
otc_pos5_6 = []
otc_pos6_7 = []
otc_pos7_8 = []
otc_pos8_9 = []
otc_pos9_10 = []
otc_minus0_1 = []
otc_minus1_2 = []
otc_minus2_3 = []
otc_minus3_4 = []
otc_minus4_5 = []
otc_minus5_6 = []
otc_minus6_7 = []
otc_minus7_8 = []
otc_minus8_9 = []
otc_minus9_10 = []
total_otc = 0
for i in OTC_no_list:
try:
percent = float(Stock(i,mons=2)._SimpleAnalytics__raw_data[-1][7]) / float(Stock(i,mons=2)._SimpleAnalytics__raw_data[-2][6])
percent = percent * 100
if percent > 0 and percent < 1:
otc_pos0_1.append(i)
if percent >= 1 and percent < 2:
otc_pos1_2.append(i)
if percent >= 2 and percent < 3:
otc_pos2_3.append(i)
if percent >= 3 and percent < 4:
otc_pos3_4.append(i)
if percent >= 4 and percent < 5:
otc_pos4_5.append(i)
if percent >= 5 and percent < 6:
otc_pos5_6.append(i)
if percent >= 6 and percent < 7:
otc_pos6_7.append(i)
if percent >= 7 and percent < 8:
otc_pos7_8.append(i)
if percent >= 8 and percent < 9:
otc_pos8_9.append(i)
if percent >= 9 and percent < 10.5:
otc_pos9_10.append(i)
if percent < 0 and percent > -1:
otc_minus0_1.append(i)
if percent <= -1 and percent > -2:
otc_minus1_2.append(i)
if percent <= -2 and percent > -3:
otc_minus2_3.append(i)
if percent <= -3 and percent > -4:
otc_minus3_4.append(i)
if percent <= -4 and percent > -5:
otc_minus4_5.append(i)
if percent <= -5 and percent > -6:
otc_minus5_6.append(i)
if percent <= -6 and percent > -7:
otc_minus6_7.append(i)
if percent <= -7 and percent > -8:
otc_minus7_8.append(i)
if percent <= -8 and percent > -9:
otc_minus8_9.append(i)
if percent <= -9 and percent > -10.5:
otc_minus9_10.append(i)
if percent == 0 :
otc_pos0.append(i)
total_otc+=1
except: # 回傳為None 或 資料不足導致ValueError
pass
print '***************************'
fileopen.write('***************************\n\n\n\n\n')
print '擷取到的上櫃公司有%d家'%int(total_otc)
fileopen.write('擷取到的上櫃公司有%d家'%int(total_otc)+'\n')
print '上櫃公司中收平盤的有%d家,共佔了%.1f percent'%(len(otc_pos0), len(otc_pos0)/float(total_otc)*100)
fileopen.write('上櫃公司中收平盤的有%d家,共佔了%.1f percent'%(len(otc_pos0), len(otc_pos0)/float(total_otc)*100)+'\n')
print '上櫃公司中漲0~1 percent的有%d家,共佔了%.1f percent'%(len(otc_pos0_1), len(otc_pos0_1)/float(total_otc)*100)
fileopen.write('上櫃公司中漲0~1 percent的有%d家,共佔了%.1f percent'%(len(otc_pos0_1), len(otc_pos0_1)/float(total_otc)*100)+'\n')
print '上櫃公司中漲>=1~2 percent的有%d家,共佔了%.1f percent'%(len(otc_pos1_2), len(otc_pos1_2)/float(total_otc)*100)
fileopen.write('上櫃公司中漲>=1~2 percent的有%d家,共佔了%.1f percent'%(len(otc_pos1_2), len(otc_pos1_2)/float(total_otc)*100)+'\n')
print '上櫃公司中漲2~3 percent的有%d家,共佔了%.1f percent'%(len(otc_pos2_3), len(otc_pos2_3)/float(total_otc)*100)
fileopen.write('上櫃公司中漲2~3 percent的有%d家,共佔了%.1f percent'%(len(otc_pos2_3), len(otc_pos2_3)/float(total_otc)*100)+'\n')
print '上櫃公司中漲3~4 percent的有%d家,共佔了%.1f percent'%(len(otc_pos3_4), len(otc_pos3_4)/float(total_otc)*100)
fileopen.write('上櫃公司中漲3~4 percent的有%d家,共佔了%.1f percent'%(len(otc_pos3_4), len(otc_pos3_4)/float(total_otc)*100)+'\n')
print '上櫃公司中漲4~5 percent的有%d家,共佔了%.1f percent'%(len(otc_pos4_5), len(otc_pos4_5)/float(total_otc)*100)
fileopen.write('上櫃公司中漲4~5 percent的有%d家,共佔了%.1f percent'%(len(otc_pos4_5), len(otc_pos4_5)/float(total_otc)*100)+'\n')
print '上櫃公司中漲5~6 percent的有%d家,共佔了%.1f percent'%(len(otc_pos5_6), len(otc_pos5_6)/float(total_otc)*100)
fileopen.write('上櫃公司中漲5~6 percent的有%d家,共佔了%.1f percent'%(len(otc_pos5_6), len(otc_pos5_6)/float(total_otc)*100)+'\n')
print '上櫃公司中漲6~7 percent的有%d家,共佔了%.1f percent'%(len(otc_pos6_7), len(otc_pos6_7)/float(total_otc)*100)
fileopen.write('上櫃公司中漲6~7 percent的有%d家,共佔了%.1f percent'%(len(otc_pos6_7), len(otc_pos6_7)/float(total_otc)*100)+'\n')
print '上櫃公司中漲7~8 percent的有%d家,共佔了%.1f percent'%(len(otc_pos7_8), len(otc_pos7_8)/float(total_otc)*100)
fileopen.write('上櫃公司中漲7~8 percent的有%d家,共佔了%.1f percent'%(len(otc_pos7_8), len(otc_pos7_8)/float(total_otc)*100)+'\n')
print '上櫃公司中漲8~9 percent的有%d家,共佔了%.1f percent'%(len(otc_pos8_9), len(otc_pos8_9)/float(total_otc)*100)
fileopen.write('上櫃公司中漲8~9 percent的有%d家,共佔了%.1f percent'%(len(otc_pos8_9), len(otc_pos8_9)/float(total_otc)*100)+'\n')
print '上櫃公司中漲9~10 percent的有%d家,共佔了%.1f percent'%(len(otc_pos9_10), len(otc_pos9_10)/float(total_otc)*100)
fileopen.write('上櫃公司中漲9~10 percent的有%d家,共佔了%.1f percent'%(len(otc_pos9_10), len(otc_pos9_10)/float(total_otc)*100)+'\n')
print '***************************'
fileopen.write('***************************'+'\n')
print '上櫃公司中跌0~1 percent的有%d家,共佔了%.1f percent'%(len(otc_minus0_1), len(otc_minus0_1)/float(total_otc)*100)
fileopen.write('上櫃公司中跌0~1 percent的有%d家,共佔了%.1f percent'%(len(otc_minus0_1), len(otc_minus0_1)/float(total_otc)*100)+'\n')
print '上櫃公司中跌>=1~2 percent的有%d家,共佔了%.1f percent'%(len(otc_minus1_2), len(otc_minus1_2)/float(total_otc)*100)
fileopen.write('上櫃公司中跌>=1~2 percent的有%d家,共佔了%.1f percent'%(len(otc_minus1_2), len(otc_minus1_2)/float(total_otc)*100)+'\n')
print '上櫃公司中跌2~3 percent的有%d家,共佔了%.1f percent'%(len(otc_minus2_3), len(otc_minus2_3)/float(total_otc)*100)
fileopen.write('上櫃公司中跌2~3 percent的有%d家,共佔了%.1f percent'%(len(otc_minus2_3), len(otc_minus2_3)/float(total_otc)*100)+'\n')
print '上櫃公司中跌3~4 percent的有%d家,共佔了%.1f percent'%(len(otc_minus3_4), len(otc_minus3_4)/float(total_otc)*100)
fileopen.write('上櫃公司中跌3~4 percent的有%d家,共佔了%.1f percent'%(len(otc_minus3_4), len(otc_minus3_4)/float(total_otc)*100)+'\n')
print '上櫃公司中跌4~5 percent的有%d家,共佔了%.1f percent'%(len(otc_minus4_5), len(otc_minus4_5)/float(total_otc)*100)
fileopen.write('上櫃公司中跌4~5 percent的有%d家,共佔了%.1f percent'%(len(otc_minus4_5), len(otc_minus4_5)/float(total_otc)*100)+'\n')
print '上櫃公司中跌5~6 percent的有%d家,共佔了%.1f percent'%(len(otc_minus5_6), len(otc_minus5_6)/float(total_otc)*100)
fileopen.write('上櫃公司中跌5~6 percent的有%d家,共佔了%.1f percent'%(len(otc_minus5_6), len(otc_minus5_6)/float(total_otc)*100)+'\n')
print '上櫃公司中跌6~7 percent的有%d家,共佔了%.1f percent'%(len(otc_minus6_7), len(otc_minus6_7)/float(total_otc)*100)
fileopen.write('上櫃公司中跌6~7 percent的有%d家,共佔了%.1f percent'%(len(otc_minus6_7), len(otc_minus6_7)/float(total_otc)*100)+'\n')
print '上櫃公司中跌7~8 percent的有%d家,共佔了%.1f percent'%(len(otc_minus7_8), len(otc_minus7_8)/float(total_otc)*100)
fileopen.write('上櫃公司中跌7~8 percent的有%d家,共佔了%.1f percent'%(len(otc_minus7_8), len(otc_minus7_8)/float(total_otc)*100)+'\n')
print '上櫃公司中跌8~9 percent的有%d家,共佔了%.1f percent'%(len(otc_minus8_9), len(otc_minus8_9)/float(total_otc)*100)
fileopen.write('上櫃公司中跌8~9 percent的有%d家,共佔了%.1f percent'%(len(otc_minus8_9), len(otc_minus8_9)/float(total_otc)*100)+'\n')
print '上櫃公司中跌9~10 percent的有%d家,共佔了%.1f percent'%(len(otc_minus9_10), len(otc_minus9_10)/float(total_otc)*100)
fileopen.write('上櫃公司中跌9~10 percent的有%d家,共佔了%.1f percent'%(len(otc_minus9_10), len(otc_minus9_10)/float(total_otc)*100)+'\n')
print '***************************'
fileopen.write('***************************'+'\n')
print '買到上櫃平盤股票機率%.1f,上漲股票機率%.1f,下跌股票機率%.1f'%(len(otc_pos0)/float(total_otc)*100,(len(otc_pos0_1)+len(otc_pos1_2)+len(otc_pos2_3)+len(otc_pos3_4)+len(otc_pos4_5)+len(otc_pos5_6)+len(otc_pos6_7)+len(otc_pos7_8)+len(otc_pos8_9)+len(otc_pos9_10))/float(total_otc)*100, (len(otc_minus0_1)+len(otc_minus1_2)+len(otc_minus2_3)+len(otc_minus3_4)+len(otc_minus4_5)+len(otc_minus5_6)+len(otc_minus6_7)+len(otc_minus7_8)+len(otc_minus8_9)+len(otc_minus9_10))/float(total_otc)*100)
otc_zero = len(otc_pos0)/float(total_otc)*100
otc_up = (len(otc_pos0_1)+len(otc_pos1_2)+len(otc_pos2_3)+len(otc_pos3_4)+len(otc_pos4_5)+len(otc_pos5_6)+len(otc_pos6_7)+len(otc_pos7_8)+len(otc_pos8_9)+len(otc_pos9_10))/float(total_otc)*100
otc_down = (len(otc_minus0_1)+len(otc_minus1_2)+len(otc_minus2_3)+len(otc_minus3_4)+len(otc_minus4_5)+len(otc_minus5_6)+len(otc_minus6_7)+len(otc_minus7_8)+len(otc_minus8_9)+len(otc_minus9_10))/float(total_otc)*100
fileopen.write('買到上櫃平盤股票機率%.1f,上漲股票機率%.1f,下跌股票機率%.1f'%(otc_zero,otc_up,otc_down)+'\n\n\n\n\n\n\n\n')
print '***************************'
fileopen.write('***************************'+'\n')
print '買到全上市與上櫃平盤股票機率%.1f,上漲股票機率%.1f,下跌股票機率%.1f'%( (len(otc_pos0)+len(twse_pos0))/float(total_twse+total_otc)*100 ,\
( (len(otc_pos0_1)+len(otc_pos1_2)+len(otc_pos2_3)+len(otc_pos3_4)+len(otc_pos4_5)+len(otc_pos5_6)+len(otc_pos6_7)+len(otc_pos7_8) \
+len(otc_pos8_9)+len(otc_pos9_10))+(len(twse_pos0_1)+len(twse_pos1_2)+len(twse_pos2_3)+len(twse_pos3_4)+len(twse_pos4_5)+len(twse_pos5_6)+ \
len(twse_pos6_7)+len(twse_pos7_8)+len(twse_pos8_9)+len(twse_pos9_10)) ) / float(total_twse+total_otc )*100, \
((len(otc_minus0_1)+len(otc_minus1_2)+len(otc_minus2_3)+len(otc_minus3_4)+len(otc_minus4_5)+len(otc_minus5_6)+len(otc_minus6_7)+ \
len(otc_minus7_8)+len(otc_minus8_9)+len(otc_minus9_10))+(len(twse_minus0_1)+len(twse_minus1_2)+len(twse_minus2_3)+len(twse_minus3_4) \
+len(twse_minus4_5)+len(twse_minus5_6)+len(twse_minus6_7)+len(twse_minus7_8)+len(twse_minus8_9)+len(twse_minus9_10))) / float(total_twse+total_otc )*100 )
total_zero = (len(otc_pos0)+len(twse_pos0))/float(total_twse+total_otc)*100
total_up = ( (len(otc_pos0_1)+len(otc_pos1_2)+len(otc_pos2_3)+len(otc_pos3_4)+len(otc_pos4_5)+len(otc_pos5_6)+len(otc_pos6_7)+len(otc_pos7_8)+len(otc_pos8_9)+len(otc_pos9_10))+ \
(len(twse_pos0_1)+len(twse_pos1_2)+len(twse_pos2_3)+len(twse_pos3_4)+len(twse_pos4_5)+len(twse_pos5_6)+len(twse_pos6_7)+len(twse_pos7_8)+len(twse_pos8_9)+len(twse_pos9_10))) / float(total_twse+total_otc )*100
total_down = ((len(otc_minus0_1)+len(otc_minus1_2)+len(otc_minus2_3)+len(otc_minus3_4)+len(otc_minus4_5)+len(otc_minus5_6)+len(otc_minus6_7)++len(otc_minus7_8)+len(otc_minus8_9)+len(otc_minus9_10)) \
+(len(twse_minus0_1)+len(twse_minus1_2)+len(twse_minus2_3)+len(twse_minus3_4)+len(twse_minus4_5)+len(twse_minus5_6)+len(twse_minus6_7)+len(twse_minus7_8)+len(twse_minus8_9)+len(twse_minus9_10))) / float(total_twse+total_otc )*100
fileopen.write('買到全上市與上櫃平盤股票機率%.1f,上漲股票機率%.1f,下跌股票機率%.1f'%(total_zero,total_up,total_down))
# 記錄結束時間 Record stop time
tStop = time.time()
print "共花費了幾秒"
print(tStop - tStart)
fileopen.close() #關閉檔案
# u027425@gmail.com
os.system('sendEmail -o \
-f u160895@taipower.com.tw \
-t "WEI <weihautin@gmail.com>" \
-s smtp.gmail.com:587 \
-xu %s \
-xp %s \
-u %s \
-o message-file=/home/tim/Stock_Bot/list_percent.txt \
'%(ID, PW, title))
os.remove("list_percent.txt")
# figoman1979@gmail.com