MA5 = Stock(i, mons=2).moving_average(5)[0][-1] MA10 = Stock(i, mons=2).moving_average(10)[0][-1] MA20 = Stock(i, mons=2).moving_average(20)[0][-1] Bias5 = (close_price - MA5) / MA5 * 100 Bias10 = (close_price - MA10) / MA10 * 100 Bias20 = (close_price - MA20) / MA20 * 100 turnover_ration = float(Stock(i).raw[-1][1] / 1000) / ( float(rank_market_value()[i][3]) * 10000) * 100 try: fileopen.write(Stock_no_name[i].encode("UTF-8")+"("+i+")"+"TWSE"+","+"成交張數"+str(int(Stock(i).raw[-1][1]/1000))+","+"殖利率" \ +str(fields()[i][2])+","+"收盤價"+str(close_price)+","+"週均線"+"%.1f"%Bias5+"%"+","+"雙週均價"+"%.1f"%Bias10+"%"\ +","+"月均價"+"%.1f"%Bias20+"%"+","+"發行"+rank_market_value()[i][3]+"萬張"+","+"市值"+rank_market_value()[i][4]+"億"+","+"上市" \ +rank_market_value()[i][5]+"年"+","+rank_market_value()[i][6].encode("UTF-8")+","+"市值排名:"+rank_market_value()[i][0]+"/1548"+"," \ +"周轉率"+"%.3f"%turnover_ration+"%"+","+"政府機構"+vip_other()[i][1]+"%"+"橋外投資"+vip_other()[i][2]+"%"+"本國金融"+vip_other()[i][3]+"%" \ +"本國法人"+vip_other()[i][4]+"%"+"本國個人含董監"+vip_other()[i][5]+"%"+"董監持股"+vip_main()[i][2]+str(one_day)+"\n") except: pass index = index + 1 except: # 回傳為None 或 資料不足導致ValueError pass #===================== """ j = 1 for i in stock_no_list:
MA20 = Stock(i,mons=2).moving_average(20)[0][-1] Bias5 = (close_price-MA5)/MA5*100 Bias10 = (close_price-MA10)/MA10*100 Bias20 = (close_price-MA20)/MA20*100 turnover_ration = float(Stock(i).raw[-1][1]/1000)/(float(rank_market_value()[i][3])*10000)*100 fileopen.write(str(index)+"."+Stock_no_name[i].encode("UTF-8")+"("+i+")"+"-"+"成交張數"+str(int(Stock(i).raw[-1][1]/1000))+"-"+"殖利率" \ +str(fields()[i][2])+"-"+"收盤價"+str(close_price)+"-"+"週均線"+str(MA5)+"("+"%.1f"%Bias5+"%"+")"+"-"+"雙週均價"+str(MA10)+"("+"%.1f"%Bias10+"%"+")"\ +"-"+"月均價"+str(MA20)+"("+"%.1f"%Bias20+"%"+")"+"-"+"發行"+rank_market_value()[i][3]+"萬張"+"-"+"市值"+rank_market_value()[i][4]+"億"+"-"+"上市" \ +rank_market_value()[i][5]+"年"+"-"+rank_market_value()[i][6].encode("UTF-8")+"-"+"市值排名:"+rank_market_value()[i][0]+"/1548"+"-" \ +"週轉率"+"("+"%.3f"%turnover_ration+"%"+")"+"-"+str(one_day)+"\n") index = index + 1 except: # 回傳為None 或 資料不足導致ValueError pass #===================== fileopen.write('\n\n\n上櫃公司股票篩選'+"\n") index = 1 for i in OTC_no_list:
MA20 = Stock(i,mons=2).moving_average(20)[0][-1] Bias5 = (close_price-MA5)/MA5*100 Bias10 = (close_price-MA10)/MA10*100 Bias20 = (close_price-MA20)/MA20*100 turnover_ration = float(Stock(i).raw[-1][1]/1000)/(float(rank_market_value()[i][3])*10000)*100 try: fileopen.write(Stock_no_name[i].encode("UTF-8")+"("+i+")"+"TWSE"+","+"成交張數"+str(int(Stock(i).raw[-1][1]/1000))+","+"殖利率" \ +str(fields()[i][2])+","+"收盤價"+str(close_price)+","+"週均線"+"%.1f"%Bias5+"%"+","+"雙週均價"+"%.1f"%Bias10+"%"\ +","+"月均價"+"%.1f"%Bias20+"%"+","+"發行"+rank_market_value()[i][3]+"萬張"+","+"市值"+rank_market_value()[i][4]+"億"+","+"上市" \ +rank_market_value()[i][5]+"年"+","+rank_market_value()[i][6].encode("UTF-8")+","+"市值排名:"+rank_market_value()[i][0]+"/1548"+"," \ +"週轉率"+"%.3f"%turnover_ration+"%"+","+"政府機構"+vip_other()[i][1]+"%"+"橋外投資"+vip_other()[i][2]+"%"+"本國金融"+vip_other()[i][3]+"%" \ +"本國法人"+vip_other()[i][4]+"%"+"本國個人含董監"+vip_other()[i][5]+"%"+"董監持股"+vip_main()[i][2]+str(one_day)+"\n") except: pass index = index + 1 except: # 回傳為None 或 資料不足導致ValueError pass #===================== fileopen.write('\n\n\n上櫃公司股票篩選'+"\n")
for i in stock_no_list: #print i try: if BestFourPoint(Stock(i,mons=2)).y_v_t_r(): print i,'123' #暴量長紅2天 try: if oneday()[i][1] == '': one_day = "買賣現沖 " elif oneday()[i][1] =='Y': one_day = "先買現沖" else: one_day = "" except: one_day = "" #csv找不到該股票代碼,即不開放買賣現沖 fileopen.write(str(index)+" "+"昨天暴量長紅(昨天量>前天量,昨天收盤價>昨天開盤價),今天又上漲1~2%,今日成交張數要大於1000張"+"-"+Stock_no_name[i].encode("UTF-8")+"-"+i+"-"+"成交張數"+"-"+str(int(Stock(i).raw[-1][1]/1000))+"-"+"殖益率"+str(fields()[i][2])+"-"+one_day+"\n") index = index + 1 except: # 回傳為None 或 資料不足導致ValueError pass #===================== index = 1 for i in OTC_no_list: #print i #print type(i) print i try: if BestFourPoint(Stock(i,mons=2)).y_v_t_r(): print i,'123OTC' #暴量長紅2天 try: if oneday()[i][1] == '':
fileopen.write('上市公司股票篩選\n\n\n') fileopen.write("\n"+"回測n天中,5與10與20日均線總和平均在m%盤整,今天暴nn倍的mm日均量"+"\n\n") #===================== index = 1 for i in stock_no_list: #print i try: if BestFourPoint(Stock(i,mons=3)).breakthrough(20, 1, 1.5, 20): # n, m ,nn, mm # 回測天數, 盤整%數, 暴量nn倍, mm日均量 # 回測n天中,5與10與20日均線總和平均在m%盤整,今天暴nn倍的mm日均量 print i,'twse' #暴量長紅2天 fileopen.write(str(index)+" "+"-"+Stock_no_name[i].encode("UTF-8")+"-"+i+"-"+"殖益率"+str(fields()[i][2])+"\n") index = index + 1 except: # 回傳為None 或 資料不足導致ValueError pass fileopen.close() #關閉檔案
Bias5 = (close_price - MA5) / MA5 * 100 Bias10 = (close_price - MA10) / MA10 * 100 Bias20 = (close_price - MA20) / MA20 * 100 turnover_ration = float(Stock(i).raw[-1][1] / 1000) / ( float(rank_market_value()[i][3]) * 10000) * 100 fileopen.write(str(index)+"."+Stock_no_name[i].encode("UTF-8")+"("+i+")"+"-"+"成交張數"+str(int(Stock(i).raw[-1][1]/1000))+"-"+"殖利率" \ +str(fields()[i][2])+"-"+"收盤價"+str(close_price)+"-"+"週均線"+str(MA5)+"("+"%.1f"%Bias5+"%"+")"+"-"+"雙週均價"+str(MA10)+"("+"%.1f"%Bias10+"%"+")"\ +"-"+"月均價"+str(MA20)+"("+"%.1f"%Bias20+"%"+")"+"-"+"發行"+rank_market_value()[i][3]+"萬張"+"-"+"市值"+rank_market_value()[i][4]+"億"+"-"+"上市" \ +rank_market_value()[i][5]+"年"+"-"+rank_market_value()[i][6].encode("UTF-8")+"-"+"市值排名:"+rank_market_value()[i][0]+"/1548"+"-" \ +"週轉率"+"("+"%.3f"%turnover_ration+"%"+")"+"-"+str(one_day)+"\n") index = index + 1 except: # 回傳為None 或 資料不足導致ValueError pass #===================== fileopen.write('\n\n\n上櫃公司股票篩選' + "\n") index = 1 for i in OTC_no_list: #print i
fileopen = open(attachment, 'w') #開啟檔案,w沒有該檔案就新增 f = open('/home/tim/GMAIL.txt', 'r') #於前一個相對目錄中放置登入GMAIL帳號密碼,目的為了不再GitHub顯示出來. ID = f.readline().strip('\n') #不包含換行符號\n PW = f.readline().strip('\n') fileopen.write('上市公司股票篩選\n\n\n') fileopen.write("\n" + "回測n天中,5與10與20日均線總和平均在m%盤整,今天暴nn倍的mm日均量" + "\n\n") #===================== index = 1 for i in stock_no_list: #print i try: if BestFourPoint(Stock(i, mons=3)).breakthrough(20, 1, 1.5, 20): # n, m ,nn, mm # 回測天數, 盤整%數, 暴量nn倍, mm日均量 # 回測n天中,5與10與20日均線總和平均在m%盤整,今天暴nn倍的mm日均量 print i, 'twse' #暴量長紅2天 fileopen.write( str(index) + " " + "-" + Stock_no_name[i].encode("UTF-8") + "-" + i + "-" + "殖益率" + str(fields()[i][2]) + "\n") index = index + 1 except: # 回傳為None 或 資料不足導致ValueError pass fileopen.close() #關閉檔案
try: if oneday()[i][1] == '': one_day = "買賣現沖 " elif oneday()[i][1] =='Y': one_day = "先買現沖" else: one_day = "" except: one_day = "" #csv找不到該股票代碼,即不開放買賣現沖 # fileopen.write(str(index)+" "+time_now+"-----目前該股累積成交量>週均量"+"-"+Stock_no_name[i].encode("UTF-8")+"-"+i+"-"+"成交張數"+"-"+str(int(Stock(i,mons=1).raw[-1][1]/1000))+"-"+"殖益率"+str(fields()[i][2])+"-"+one_day+"\n") fileopen.write('321') fileopen.write(i+"-"+Stock_no_name[i].encode("UTF-8")+"-"+"目前累積成交量"+","+ \ str(float(realtime_data.data[i]['volume_acc'])/float(Stock(i,mons=3).moving_average_value(5)[0][-2]))+","+"倍週均量"+ \ ","+ "成交張數"+"-"+str(realtime_data.data[i]['volume_acc'])+","+"殖益率"+str(fields()[i][2])+"-"+one_day+ \ ","+str(float(realtime_data.data[i]['volume_acc'])/float(Stock(i,mons=3).moving_average_value(20)[0][-2]))+","+"倍月均量"+ \ "\n") # str(int(Stock(i,mons=1).raw[-1][1]/1000)) index = index + 1 except: # 回傳為None 或 資料不足導致ValueError pass fileopen.close() #關閉檔案 #realtime_data = RealtimeTWSE(1101)