├── README.md ├── py语音合成 测试源码 ├── bat-ftnn-hk.bat ├── ftnn_api_test.py ├── ftnn_api_us.py ├── ftnn_api_hongkong.py ├── ftnn_api_us_hongkong.py ├── index_and_stock.py └── XiangGuanDu /README.md: -------------------------------------------------------------------------------- 1 | # FTNN 2 | 富途牛牛自动化,py示例 3 | -------------------------------------------------------------------------------- /py语音合成 测试源码: -------------------------------------------------------------------------------- 1 | #coding:utf-8 2 | import win32com.client 3 | import time 4 | spk = win32com.client.Dispatch("SAPI.SpVoice") 5 | for i in range(100): 6 | spk.Speak("triple 3 UP") 7 | spk.Speak("000333 UP") 8 | time.sleep(1) 9 | -------------------------------------------------------------------------------- /bat-ftnn-hk.bat: -------------------------------------------------------------------------------- 1 | set m=%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2% 2 | set file=ftnn_api_hk_log_%m%.txt 3 | D:\Anaconda2\python.exe C:\\IBM-9\\FTNN_HK\\ftnn_api_hongkong.py >> C:\IBM-9\FTNN_HK\%file% 4 | rem pause 5 | -------------------------------------------------------------------------------- /ftnn_api_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2.6 2 | # -*- coding: utf-8 -*- 3 | ''' 4 | Created on 2015年8月26日 5 | @author: futu 6 | ''' 7 | 8 | import socket 9 | import json 10 | import string 11 | import sys 12 | 13 | #futnn plubin会开启本地监听服务端 14 | # 请求及发送数据都是jason格式, 具体详见插件的协议文档 15 | host="localhost" 16 | port=11111 17 | 18 | s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) 19 | s.connect((host,port)) 20 | 21 | print "test quote price 00700" 22 | print "-------------------------------------" 23 | #发送报价请求 24 | req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'00700'},'Version':'1'} 25 | #req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'01585'},'Version':'1'} 26 | str = json.dumps(req) + "\n" 27 | print str 28 | s.send(str) 29 | rsp = "" 30 | while True: 31 | buf = s.recv(1024) 32 | rsp = rsp + buf 33 | #找到"\n"就认为结束了 34 | try: 35 | rsp.index('\n') 36 | break; 37 | except Exception, e: 38 | print "recving..." 39 | print rsp 40 | 41 | print "test trade buy 0700\n" 42 | print "-------------------------------------" 43 | #发送交易请求 44 | #req = {'Protocol':'6003','ReqParam':{'Cookie':'123456', 'EnvType':'0', 'OrderSide':'0','OrderType':'1','Price':'150','Qty':'22200','StockCode':'00700'},'Version':'1'} 45 | 46 | #实盘 'EnvType':'0'买入腾讯控股,100@163.00,务必价格够低无法成交 47 | #req = {'Protocol':'6003','ReqParam':{'Cookie':'123456', 'EnvType':'0', 'OrderSide':'0','OrderType':'0','Price':'163000','Qty':'100','StockCode':'00700'},'Version':'1'} 48 | 49 | #模拟盘( 'EnvType':'1')买入腾讯控股,100@163.00,务必价格够低无法成交 50 | #模拟盘可以在富途“交易”---“港股仿真”看到 51 | req = {'Protocol':'6003','ReqParam':{'Cookie':'123456', 'EnvType':'1', 'OrderSide':'0','OrderType':'0','Price':'163000','Qty':'100','StockCode':'00700'},'Version':'1'} 52 | 53 | str = json.dumps(req) + "\n" 54 | print str 55 | s.send(str) 56 | rsp = "" 57 | while True: 58 | buf = s.recv(1024) 59 | rsp = rsp + buf 60 | #找到"\n"就认为结束了 61 | try: 62 | rsp.index('\n') 63 | break; 64 | except Exception, e: 65 | print "recving..." 66 | print rsp 67 | print "-----------------over----------------" 68 | 69 | s.close() 70 | -------------------------------------------------------------------------------- /ftnn_api_us.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2.6 2 | # -*- coding: utf-8 -*- 3 | ''' 4 | Created on 2015年8月26日 5 | @author: futu 6 | ''' 7 | 8 | #如果这个分钟内没有一笔成交,这个是 9 | 10 | import socket 11 | import json 12 | import string 13 | import sys 14 | from time import sleep 15 | import time 16 | import os 17 | import pandas as pd 18 | 19 | def MA(MA_x,Latest_Value): 20 | global file_souji_fengzhong 21 | df_tmp=pd.read_csv(file_souji_fengzhong,index_col=0) 22 | value_tmp=(df_tmp.ix[:,3].tail(MA_x-1).sum()+Latest_Value)/MA_x 23 | return value_tmp 24 | 25 | def MACD(Latest_Value): 26 | #使用通达信的MACD计算方法: 27 | #第一天:EMA_12=收盘价;EMA_26=收盘价;DIF=0;DEA=0;MACD=0(不套用公式) 28 | #第二天-第N天:套用公式 29 | #EMA(12)= 前一日EMA(12)×11/13+今日收盘价×2/13 30 | #EMA(26)= 前一日EMA(26)×25/27+今日收盘价×2/27 31 | #DIFF=今日EMA(12)- 今日EMA(26) 32 | #DEA(MACD)= 前一日DEA×8/10+今日DIF×2/10 33 | #BAR=2×(DIFF-DEA) 34 | #参考http://blog.sina.com.cn/s/blog_5938eb510100fz89.html 35 | 36 | global file_souji_fengzhong 37 | MACD_EMA_SHORT_POSITION=10 38 | 39 | short = 12 40 | long = 26 41 | mid = 9 42 | df_tmp=pd.read_csv(file_souji_fengzhong,index_col=0) 43 | 44 | if len(df_tmp)==0: 45 | MACD_EMA_short=Latest_Value 46 | MACD_EMA_long =Latest_Value 47 | MACD_DIF = 0 48 | MACD_DEA = 0 49 | MACD_MACD = 0 50 | 51 | else: 52 | Last_Trade_4_MACD=df_tmp.tail(1) 53 | MACD_EMA_short=Last_Trade_4_MACD.ix[0,MACD_EMA_SHORT_POSITION]*(short-1)/(short+1)+\ 54 | Latest_Value*2/(short+1) 55 | 56 | MACD_EMA_long=Last_Trade_4_MACD.ix[0,MACD_EMA_SHORT_POSITION+1]*(long-1)/(long+1)+\ 57 | Latest_Value*2/(long+1) 58 | 59 | MACD_DIF = MACD_EMA_short - MACD_EMA_long 60 | 61 | MACD_DEA =Last_Trade_4_MACD.ix[0,MACD_EMA_SHORT_POSITION+3]*(mid-1)/(mid+1)+\ 62 | MACD_DIF*2/(mid+1) 63 | 64 | MACD_MACD = (MACD_DIF - MACD_DEA) * 2 65 | 66 | return MACD_EMA_short,MACD_EMA_long,MACD_DIF,MACD_DEA,MACD_MACD 67 | 68 | 69 | # 上一分钟信息 70 | LastMinute=None 71 | LastTradeOrderTime=None 72 | 73 | file_souji_tmp="c:\\9\\ftnn_souji_ASHR_6.csv" 74 | file_souji_all="c:\\9\\ftnn_souji_all_ASHR_6.csv" 75 | file_souji_fengzhong="c:\\9\\ftnn_souji_ASHR_6_fengzhong.csv" 76 | 77 | df_4=pd.DataFrame() 78 | df_5=pd.DataFrame() 79 | df_6=pd.DataFrame() 80 | 81 | #futnn plubin会开启本地监听服务端 82 | # 请求及发送数据都是jason格式, 具体详见插件的协议文档 83 | host="localhost" 84 | port=11111 85 | 86 | 87 | local_date=time.strftime('%Y-%m-%d',time.localtime(time.time()-24*60*60)) 88 | 89 | s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) 90 | s.connect((host,port)) 91 | 92 | #需要确认电脑时区是香港时区 93 | now_time=time.localtime(time.time()-24*60*60) 94 | while (now_timetime.strptime(local_date+" "+"09:30:00", "%Y-%m-%d %H:%M:%S")): 96 | #发送报价请求,Market为2表示是美股 97 | req = {'Protocol':'1001', 'ReqParam':{'Market':'2','StockCode':'ASHR'},'Version':'1'} 98 | #req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'00700'},'Version':'1'} 99 | #req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'01585'},'Version':'1'} 100 | str_1 = json.dumps(req) + "\n" 101 | print str_1 102 | s.send(str_1) 103 | rsp = "" 104 | while True: 105 | buf = s.recv(1024) 106 | rsp = rsp + buf 107 | #找到"\n"就认为结束了 108 | try: 109 | rsp.index('\n') 110 | break; 111 | except Exception, e: 112 | print "recving..." 113 | print rsp 114 | 115 | rsp_current_price_str=rsp.split(',')[4] 116 | current_price=rsp_current_price_str.split('"')[3] 117 | 118 | #输出的时间是按秒计算的,现在距离0点0分0秒多长时间 119 | rsp_current_time_str=rsp.split(',')[11] 120 | current_time=rsp_current_time_str.split('"')[3] 121 | trade_order_time=current_time 122 | current_hour=int(current_time)/3600 123 | current_minute=(int(current_time)-current_hour*3600)/60 124 | current_second=int(current_time)-current_hour*3600-current_minute*60 125 | 126 | actual_minute=time.strftime("%M",now_time) 127 | actual_hour=time.strftime("%H",now_time) 128 | 129 | print current_hour 130 | print current_minute 131 | print current_second 132 | print current_price 133 | print "------" 134 | print actual_minute 135 | print actual_hour 136 | 137 | print "LastMinute:",LastMinute 138 | print "actual_minute:",actual_minute 139 | print "current_minute:",current_minute 140 | 141 | if LastMinute!=None: 142 | if ( (int(actual_minute)<=int(LastMinute) and int(actual_hour)==int(LastHour)) or int(actual_hour)>f,"Date,Price" 158 | f.close() 159 | 160 | if os.path.exists(file_souji_all)==False: 161 | f=open(file_souji_all,"w") 162 | print>>f,"Date,Price" 163 | f.close() 164 | 165 | if os.path.exists(file_souji_fengzhong)==False: 166 | f=open(file_souji_fengzhong,"w") 167 | print>>f," ,open,high,low,close,MA5,MA10,MA20,MA30,MA60,MA120,MACD_EMA_12,MACD_EMA_26,MACD_DIF,MACD_DEA,MACD_MACD" 168 | f.close() 169 | 170 | f=open(file_souji_tmp,"a") 171 | print>>f,local_date+" "+str(current_hour)+":"+str(current_minute)+":"+str(current_second)+","+str(current_price) 172 | f.close() 173 | 174 | else: 175 | df_1=pd.read_csv(file_souji_tmp) 176 | df_4=pd.read_csv(file_souji_all) 177 | df_4=df_4.append(df_1,ignore_index=True) 178 | df_4.to_csv(file_souji_all,index=False) 179 | 180 | df_1.index=pd.tseries.index.DatetimeIndex(df_1.ix[:,0]) 181 | df_2=df_1.ix[:,1] 182 | df_3=df_2.resample('1min',how='ohlc') 183 | 184 | df_5=pd.read_csv(file_souji_fengzhong,index_col=0) 185 | #df_tmp=df_3.ix[0] 186 | 187 | 188 | if len(df_5)==0: 189 | df_tmp=df_3.tail(1) 190 | elif df_3.head(1).index>pd.tseries.index.DatetimeIndex(df_5.tail(1).index): 191 | df_tmp=df_3.head(1) 192 | elif df_3.tail(1).index>pd.tseries.index.DatetimeIndex(df_5.tail(1).index): 193 | df_tmp=df_3.tail(1) 194 | else: 195 | #就是为了更换一个index,需要这么麻烦吗 196 | if int(actual_minute)==0: 197 | #针对整点,分钟为0的场景,减1分钟应该是59分,而不是-1 198 | str_tmp=time.strftime("%Y-%m-%d ",now_time)+str(int(actual_hour)-1)+':59' 199 | else: 200 | str_tmp=time.strftime("%Y-%m-%d %H:",now_time)+str(int(actual_minute)-1) #就是为了更换一个index,需要这么麻烦吗 201 | df_7 = pd.DataFrame(df_tmp.ix[0].open, index=[str_tmp],columns=['open']) 202 | df_7['high']=df_tmp['high'].ix[0] 203 | df_7['low'] =df_tmp['low'].ix[0] 204 | df_7['close'] =df_tmp['close'].ix[0] 205 | df_tmp=df_7 206 | 207 | print df_tmp 208 | print "------" 209 | print df_3 210 | print "*****" 211 | print actual_minute 212 | 213 | #trade_order_time!=LastTradeOrderTime 214 | 215 | #df_tmp=df_3.tail(1) 216 | 217 | MA5_tmp=MA(5,df_tmp.ix[0,3]) 218 | MA10_tmp=MA(10,df_tmp.ix[0,3]) 219 | MA20_tmp=MA(20,df_tmp.ix[0,3]) 220 | MA30_tmp=MA(30,df_tmp.ix[0,3]) 221 | MA60_tmp=MA(60,df_tmp.ix[0,3]) 222 | MA120_tmp=MA(120,df_tmp.ix[0,3]) 223 | 224 | df_tmp['MA5']=MA5_tmp 225 | df_tmp['MA10']=MA10_tmp 226 | df_tmp['MA20']=MA20_tmp 227 | df_tmp['MA30']=MA30_tmp 228 | df_tmp['MA60']=MA60_tmp 229 | df_tmp['MA120']=MA120_tmp 230 | 231 | #增加MACD 232 | MACD_EMA_short,MACD_EMA_long,MACD_DIF,MACD_DEA,MACD_MACD=MACD(df_tmp.ix[0,3]) 233 | 234 | df_tmp['MACD_EMA_12']=MACD_EMA_short 235 | df_tmp['MACD_EMA_26']=MACD_EMA_long 236 | df_tmp['MACD_DIF']=MACD_DIF 237 | df_tmp['MACD_DEA']=MACD_DEA 238 | df_tmp['MACD_MACD']=MACD_MACD 239 | 240 | df_5=df_5.append(df_tmp) 241 | 242 | df_5.to_csv(file_souji_fengzhong) 243 | 244 | os.remove(file_souji_tmp) 245 | #写入新分钟的成交数据 246 | f=open(file_souji_tmp,"w") 247 | print>>f,"Date,Price" 248 | print>>f,local_date+" "+str(current_hour)+":"+str(current_minute)+":"+str(current_second)+","+str(current_price) 249 | f.close() 250 | #似乎还要往前 251 | LastTradeOrderTime=trade_order_time 252 | #caculate_zhibiao(df_3.ix[0,0],) 253 | #caculate_MACD(df_3) 254 | 255 | if int(actual_hour)> int(current_hour): 256 | LastHour=actual_hour 257 | LastMinute=actual_minute 258 | elif int(actual_hour)== int(current_hour): 259 | LastHour=current_hour 260 | LastMinute=max(int(actual_minute),int(current_minute)) 261 | elif int(actual_hour)< int(current_hour): 262 | LastHour=current_hour 263 | LastMinute=current_minute 264 | 265 | sleep(0.5) 266 | now_time=time.localtime(time.time()-24*60*60) 267 | -------------------------------------------------------------------------------- /ftnn_api_hongkong.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2.6 2 | # -*- coding: utf-8 -*- 3 | ''' 4 | Created on 2015年8月26日 5 | @author: futu 6 | ''' 7 | 8 | #时区采用的是汉城时区 9 | 10 | #如果这个分钟内没有一笔成交,这个是 11 | 12 | import socket 13 | import json 14 | import string 15 | import sys 16 | from time import sleep 17 | import time 18 | import os 19 | import pandas as pd 20 | import math 21 | import numpy as np 22 | 23 | import winsound 24 | 25 | def Example_Analysis(): 26 | global file_souji_fengzhong 27 | global local_date_4_file 28 | wav_file_up="C:\\Windows\\Media\\StarWar_force.wav" 29 | wav_file_down="C:\\Windows\\Media\\StarWar_nuclear.wav" 30 | file_result_example="C:\\IBM-9\\FTNN_HK\\Analysis_out_example"+"_"+local_date_4_file+".csv" 31 | 32 | if os.path.exists(file_result_example)==False: 33 | f=open(file_result_example,"w") 34 | print >>f,"MA Up/Down,Time,MA5,MA10,MA20,MA30,MA60" 35 | f.close() 36 | 37 | df_tmp=pd.read_csv(file_souji_fengzhong) 38 | last_line_data=df_tmp.tail(1) 39 | #if len(df_tmp)>0 and math.isnan(last_line_data.ix[:,8])==False: 40 | 41 | if len(df_tmp)>20: 42 | if (last_line_data.ix[:,4] > last_line_data.ix[:,5]).bool() and \ 43 | (last_line_data.ix[:,5] > last_line_data.ix[:,6]).bool(): 44 | #last_line_data.ix[0,6] > last_line_data.ix[0,7] and \ 45 | #last_line_data.ix[0,7] > last_line_data.ix[0,8] : 46 | winsound.PlaySound(wav_file_up, winsound.SND_NODEFAULT) 47 | f=open(file_result_example,"a") 48 | print >>f,"Up,"+str(list(last_line_data.ix[:,0]).pop())+","\ 49 | +str(list(last_line_data.ix[:,4]).pop())+","\ 50 | +str(list(last_line_data.ix[:,5]).pop())+","\ 51 | +str(list(last_line_data.ix[:,6]).pop())+","\ 52 | +str(list(last_line_data.ix[:,7]).pop())+","\ 53 | +str(list(last_line_data.ix[:,8]).pop()) 54 | f.close() 55 | 56 | elif (last_line_data.ix[:,4] < last_line_data.ix[:,5]).bool() and \ 57 | (last_line_data.ix[:,5] < last_line_data.ix[:,6]).bool(): 58 | #last_line_data.ix[0,6] < last_line_data.ix[0,7] and \ 59 | #last_line_data.ix[0,7] < last_line_data.ix[0,8] : 60 | winsound.PlaySound(wav_file_down, winsound.SND_NODEFAULT) 61 | f=open(file_result_example,"a") 62 | print >>f,"Down,"+str(list(last_line_data.ix[:,0]).pop())+","\ 63 | +str(list(last_line_data.ix[:,4]).pop())+","\ 64 | +str(list(last_line_data.ix[:,5]).pop())+","\ 65 | +str(list(last_line_data.ix[:,6]).pop())+","\ 66 | +str(list(last_line_data.ix[:,7]).pop())+","\ 67 | +str(list(last_line_data.ix[:,8]).pop()) 68 | f.close() 69 | 70 | def MA_xielv(XieLv_Num,MA5,MA10,MA20,MA30,MA60,MA120): 71 | global df_5 72 | df_tmp=df_5.tail(XieLv_Num-1).head(1) 73 | lenth_df_tmp=len(df_5) 74 | if lenth_df_tmp>5 and math.isnan(df_tmp.ix[:,4])==False: 75 | MA5_xielv=(MA5-list(df_tmp.ix[:,4]).pop())/list(df_tmp.ix[:,4]).pop() 76 | else: 77 | MA5_xielv=np.nan 78 | 79 | if lenth_df_tmp>10 and math.isnan(df_tmp.ix[:,5])==False: 80 | MA10_xielv=(MA10-list(df_tmp.ix[:,5]).pop())/list(df_tmp.ix[:,5]).pop() 81 | else: 82 | MA10_xielv=np.nan 83 | 84 | if lenth_df_tmp>20 and math.isnan(df_tmp.ix[:,6])==False: 85 | MA20_xielv=(MA20-list(df_tmp.ix[:,6]).pop())/list(df_tmp.ix[:,6]).pop() 86 | else: 87 | MA20_xielv=np.nan 88 | 89 | if lenth_df_tmp>30 and math.isnan(df_tmp.ix[:,7])==False: 90 | MA30_xielv=(MA30-list(df_tmp.ix[:,7]).pop())/list(df_tmp.ix[:,7]).pop() 91 | else: 92 | MA30_xielv=np.nan 93 | 94 | if lenth_df_tmp>60 and math.isnan(df_tmp.ix[:,8])==False: 95 | MA60_xielv=(MA60-list(df_tmp.ix[:,8]).pop())/list(df_tmp.ix[:,8]).pop() 96 | else: 97 | MA60_xielv=np.nan 98 | 99 | if lenth_df_tmp>120 and math.isnan(df_tmp.ix[:,9])==False: 100 | MA120_xielv=(MA120-list(df_tmp.ix[:,9]).pop())/list(df_tmp.ix[:,9]).pop() 101 | else: 102 | MA120_xielv=np.nan 103 | 104 | return MA5_xielv,MA10_xielv,MA20_xielv,MA30_xielv,MA60_xielv,MA120_xielv 105 | 106 | 107 | def MA(MA_x,Latest_Value): 108 | global file_souji_fengzhong 109 | df_tmp=pd.read_csv(file_souji_fengzhong,index_col=0) 110 | value_tmp=(df_tmp.ix[:,3].tail(MA_x-1).sum()+Latest_Value)/MA_x 111 | return value_tmp 112 | 113 | def MACD(Latest_Value): 114 | #使用通达信的MACD计算方法: 115 | #第一天:EMA_12=收盘价;EMA_26=收盘价;DIF=0;DEA=0;MACD=0(不套用公式) 116 | #第二天-第N天:套用公式 117 | #EMA(12)= 前一日EMA(12)×11/13+今日收盘价×2/13 118 | #EMA(26)= 前一日EMA(26)×25/27+今日收盘价×2/27 119 | #DIFF=今日EMA(12)- 今日EMA(26) 120 | #DEA(MACD)= 前一日DEA×8/10+今日DIF×2/10 121 | #BAR=2×(DIFF-DEA) 122 | #参考http://blog.sina.com.cn/s/blog_5938eb510100fz89.html 123 | 124 | global file_souji_fengzhong 125 | 126 | short = 12 127 | long = 26 128 | mid = 9 129 | df_tmp=pd.read_csv(file_souji_fengzhong,index_col=0) 130 | MACD_EMA_SHORT_POSITION=df_tmp.columns.searchsorted('MACD_EMA_12') 131 | 132 | if len(df_tmp)==0: 133 | MACD_EMA_short=Latest_Value 134 | MACD_EMA_long =Latest_Value 135 | MACD_DIF = 0 136 | MACD_DEA = 0 137 | MACD_MACD = 0 138 | 139 | else: 140 | Last_Trade_4_MACD=df_tmp.tail(1) 141 | MACD_EMA_short=Last_Trade_4_MACD.ix[0,MACD_EMA_SHORT_POSITION]*(short-1)/(short+1)+\ 142 | Latest_Value*2/(short+1) 143 | 144 | MACD_EMA_long=Last_Trade_4_MACD.ix[0,MACD_EMA_SHORT_POSITION+1]*(long-1)/(long+1)+\ 145 | Latest_Value*2/(long+1) 146 | 147 | MACD_DIF = MACD_EMA_short - MACD_EMA_long 148 | 149 | MACD_DEA =Last_Trade_4_MACD.ix[0,MACD_EMA_SHORT_POSITION+3]*(mid-1)/(mid+1)+\ 150 | MACD_DIF*2/(mid+1) 151 | 152 | MACD_MACD = (MACD_DIF - MACD_DEA) * 2 153 | 154 | return MACD_EMA_short,MACD_EMA_long,MACD_DIF,MACD_DEA,MACD_MACD 155 | 156 | 157 | # 上一分钟信息 158 | LastMinute=None 159 | LastTradeOrderTime=None 160 | 161 | #local_date_4_file=time.strftime('%Y%m%d_%H%M%S',time.localtime(time.time()-24*60*60)) 162 | local_date_4_file=time.strftime('%Y%m%d',time.localtime(time.time()-24*60*60)) 163 | 164 | file_souji_tmp="C:\\IBM-9\\FTNN_HK\\ftnn_souji_00700_8"+"_"+local_date_4_file+".csv" 165 | file_souji_all="C:\IBM-9\FTNN_HK\\ftnn_souji_all_00700_8"+"_"+local_date_4_file+".csv" 166 | file_souji_fengzhong="C:\IBM-9\FTNN_HK\\ftnn_souji_00700_8_fengzhong"+"_"+local_date_4_file+".csv" 167 | 168 | df_4=pd.DataFrame() 169 | df_5=pd.DataFrame() 170 | df_6=pd.DataFrame() 171 | 172 | #futnn plubin会开启本地监听服务端 173 | # 请求及发送数据都是jason格式, 具体详见插件的协议文档 174 | host="localhost" 175 | port=11111 176 | 177 | 178 | local_date=time.strftime('%Y-%m-%d',time.localtime(time.time()-24*60*60)) 179 | 180 | s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) 181 | s.connect((host,port)) 182 | 183 | #需要确认电脑时区是香港时区 184 | now_time=time.localtime(time.time()-24*60*60) 185 | while (now_timetime.strptime(local_date+" "+"9:30:00", "%Y-%m-%d %H:%M:%S")): 187 | #发送报价请求,Market为2表示是美股 188 | req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'00700'},'Version':'1'} 189 | #req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'00700'},'Version':'1'} 190 | #req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'01585'},'Version':'1'} 191 | str_1 = json.dumps(req) + "\n" 192 | print str_1 193 | s.send(str_1) 194 | rsp = "" 195 | while True: 196 | buf = s.recv(1024) 197 | rsp = rsp + buf 198 | #找到"\n"就认为结束了 199 | try: 200 | rsp.index('\n') 201 | break; 202 | except Exception, e: 203 | print "recving..." 204 | print rsp 205 | 206 | rsp_current_price_str=rsp.split(',')[4] 207 | current_price=rsp_current_price_str.split('"')[3] 208 | 209 | #输出的时间是按秒计算的,现在距离0点0分0秒多长时间 210 | rsp_current_time_str=rsp.split(',')[11] 211 | current_time=rsp_current_time_str.split('"')[3] 212 | trade_order_time=current_time 213 | current_hour=int(current_time)/3600 214 | current_minute=(int(current_time)-current_hour*3600)/60 215 | current_second=int(current_time)-current_hour*3600-current_minute*60 216 | 217 | actual_minute=time.strftime("%M",now_time) 218 | actual_hour=time.strftime("%H",now_time) 219 | 220 | print current_hour 221 | print current_minute 222 | print current_second 223 | print current_price 224 | print "------" 225 | print actual_minute 226 | print actual_hour 227 | 228 | print "LastMinute:",LastMinute 229 | print "actual_minute:",actual_minute 230 | print "current_minute:",current_minute 231 | 232 | if LastMinute!=None: 233 | if ( (int(actual_minute)<=int(LastMinute) and int(actual_hour)==int(LastHour)) or int(actual_hour)>f,"Date,Price" 249 | f.close() 250 | 251 | if os.path.exists(file_souji_all)==False: 252 | f=open(file_souji_all,"w") 253 | print>>f,"Date,Price" 254 | f.close() 255 | 256 | if os.path.exists(file_souji_fengzhong)==False: 257 | f=open(file_souji_fengzhong,"w") 258 | print>>f," ,open,high,low,close,MA5,MA10,MA20,MA30,MA60,MA120,MA5_XieLv_0,MA10_XieLv_0,MA20_XieLv_0,MA30_XieLv_0,MA60_XieLv_0,MA120_XieLv_0,MACD_EMA_12,MACD_EMA_26,MACD_DIF,MACD_DEA,MACD_MACD" 259 | f.close() 260 | 261 | f=open(file_souji_tmp,"a") 262 | print>>f,local_date+" "+str(current_hour)+":"+str(current_minute)+":"+str(current_second)+","+str(current_price) 263 | f.close() 264 | 265 | else: 266 | df_1=pd.read_csv(file_souji_tmp) 267 | df_4=pd.read_csv(file_souji_all) 268 | df_4=df_4.append(df_1,ignore_index=True) 269 | df_4.to_csv(file_souji_all,index=False) 270 | 271 | df_1.index=pd.tseries.index.DatetimeIndex(df_1.ix[:,0]) 272 | df_2=df_1.ix[:,1] 273 | df_3=df_2.resample('1min',how='ohlc') 274 | 275 | df_5=pd.read_csv(file_souji_fengzhong,index_col=0) 276 | #df_tmp=df_3.ix[0] 277 | 278 | 279 | if len(df_5)==0: 280 | df_tmp=df_3.tail(1) 281 | elif df_3.head(1).index>pd.tseries.index.DatetimeIndex(df_5.tail(1).index): 282 | df_tmp=df_3.head(1) 283 | elif df_3.tail(1).index>pd.tseries.index.DatetimeIndex(df_5.tail(1).index): 284 | df_tmp=df_3.tail(1) 285 | else: 286 | #就是为了更换一个index,需要这么麻烦吗 287 | if int(actual_minute)==0: 288 | #针对整点,分钟为0的场景,减1分钟应该是59分,而不是-1 289 | str_tmp=time.strftime("%Y-%m-%d ",now_time)+str(int(actual_hour)-1)+':59' 290 | else: 291 | str_tmp=time.strftime("%Y-%m-%d %H:",now_time)+str(int(actual_minute)-1) #就是为了更换一个index,需要这么麻烦吗 292 | df_7 = pd.DataFrame(df_tmp.ix[0].open, index=[str_tmp],columns=['open']) 293 | df_7['high']=df_tmp['high'].ix[0] 294 | df_7['low'] =df_tmp['low'].ix[0] 295 | df_7['close'] =df_tmp['close'].ix[0] 296 | df_tmp=df_7 297 | 298 | print df_tmp 299 | print "------" 300 | print df_3 301 | print "*****" 302 | print actual_minute 303 | 304 | #trade_order_time!=LastTradeOrderTime 305 | 306 | #df_tmp=df_3.tail(1) 307 | 308 | MA5_tmp=MA(5,df_tmp.ix[0,3]) 309 | MA10_tmp=MA(10,df_tmp.ix[0,3]) 310 | MA20_tmp=MA(20,df_tmp.ix[0,3]) 311 | MA30_tmp=MA(30,df_tmp.ix[0,3]) 312 | MA60_tmp=MA(60,df_tmp.ix[0,3]) 313 | MA120_tmp=MA(120,df_tmp.ix[0,3]) 314 | 315 | df_tmp['MA5']=MA5_tmp 316 | df_tmp['MA10']=MA10_tmp 317 | df_tmp['MA20']=MA20_tmp 318 | df_tmp['MA30']=MA30_tmp 319 | df_tmp['MA60']=MA60_tmp 320 | df_tmp['MA120']=MA120_tmp 321 | 322 | #计算各个MA斜率 323 | XieLv_Num=3 324 | MA5_xielv,MA10_xielv,MA20_xielv,MA30_xielv,MA60_xielv,MA120_xielv=MA_xielv(XieLv_Num,MA5_tmp,MA10_tmp,MA20_tmp,MA30_tmp,MA60_tmp,MA120_tmp) 325 | 326 | df_tmp['MA5_XieLv_0']= MA5_xielv 327 | df_tmp['MA10_XieLv_0']= MA10_xielv 328 | df_tmp['MA20_XieLv_0']= MA20_xielv 329 | df_tmp['MA30_XieLv_0']= MA30_xielv 330 | df_tmp['MA60_XieLv_0']= MA60_xielv 331 | df_tmp['MA120_XieLv_0']= MA120_xielv 332 | 333 | 334 | #增加MACD 335 | MACD_EMA_short,MACD_EMA_long,MACD_DIF,MACD_DEA,MACD_MACD=MACD(df_tmp.ix[0,3]) 336 | 337 | df_tmp['MACD_EMA_12']=MACD_EMA_short 338 | df_tmp['MACD_EMA_26']=MACD_EMA_long 339 | df_tmp['MACD_DIF']=MACD_DIF 340 | df_tmp['MACD_DEA']=MACD_DEA 341 | df_tmp['MACD_MACD']=MACD_MACD 342 | 343 | df_5=df_5.append(df_tmp) 344 | 345 | df_5.to_csv(file_souji_fengzhong) 346 | 347 | os.remove(file_souji_tmp) 348 | #写入新分钟的成交数据 349 | f=open(file_souji_tmp,"w") 350 | print>>f,"Date,Price" 351 | print>>f,local_date+" "+str(current_hour)+":"+str(current_minute)+":"+str(current_second)+","+str(current_price) 352 | f.close() 353 | 354 | # Example:To Analysis Data 355 | Example_Analysis() 356 | 357 | #似乎还要往前 358 | LastTradeOrderTime=trade_order_time 359 | #caculate_zhibiao(df_3.ix[0,0],) 360 | #caculate_MACD(df_3) 361 | 362 | if int(actual_hour)> int(current_hour): 363 | LastHour=actual_hour 364 | LastMinute=actual_minute 365 | elif int(actual_hour)== int(current_hour): 366 | LastHour=current_hour 367 | LastMinute=max(int(actual_minute),int(current_minute)) 368 | elif int(actual_hour)< int(current_hour): 369 | LastHour=current_hour 370 | LastMinute=current_minute 371 | 372 | 373 | sleep(1.2) 374 | now_time=time.localtime(time.time()-24*60*60) 375 | -------------------------------------------------------------------------------- /ftnn_api_us_hongkong.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2.6 2 | # -*- coding: utf-8 -*- 3 | ''' 4 | Created on 2015年8月26日 5 | @author: futu 6 | ''' 7 | 8 | #时区采用的是汉城时区 9 | 10 | #如果这个分钟内没有一笔成交,这个是 11 | 12 | import socket 13 | import json 14 | import string 15 | import sys 16 | from time import sleep 17 | import time 18 | import os 19 | import pandas as pd 20 | import math 21 | import numpy as np 22 | 23 | import winsound 24 | 25 | def Example_Analysis(): 26 | global file_souji_fengzhong 27 | global local_date_4_file 28 | 29 | global stock_number 30 | global market_name 31 | 32 | wav_file_up="C:\\Windows\\Media\\StarWar_force.wav" 33 | wav_file_down="C:\\Windows\\Media\\StarWar_nuclear.wav" 34 | file_result_example="C:\\IBM-9\\FTNN_HK\\Analysis_out_example"+"_"+market_name+"_"+stock_number+"_"+local_date_4_file+".csv" 35 | 36 | if os.path.exists(file_result_example)==False: 37 | f=open(file_result_example,"w") 38 | print >>f,"MA Up/Down,Time,MA5,MA10,MA20,MA30,MA60" 39 | f.close() 40 | 41 | df_tmp=pd.read_csv(file_souji_fengzhong) 42 | last_line_data=df_tmp.tail(1) 43 | #if len(df_tmp)>0 and math.isnan(last_line_data.ix[:,8])==False: 44 | 45 | if len(df_tmp)>20: 46 | if (last_line_data.ix[:,4] > last_line_data.ix[:,5]).bool() and \ 47 | (last_line_data.ix[:,5] > last_line_data.ix[:,6]).bool(): 48 | #last_line_data.ix[0,6] > last_line_data.ix[0,7] and \ 49 | #last_line_data.ix[0,7] > last_line_data.ix[0,8] : 50 | winsound.PlaySound(wav_file_up, winsound.SND_NODEFAULT) 51 | f=open(file_result_example,"a") 52 | print >>f,"Up,"+str(list(last_line_data.ix[:,0]).pop())+","\ 53 | +str(list(last_line_data.ix[:,4]).pop())+","\ 54 | +str(list(last_line_data.ix[:,5]).pop())+","\ 55 | +str(list(last_line_data.ix[:,6]).pop())+","\ 56 | +str(list(last_line_data.ix[:,7]).pop())+","\ 57 | +str(list(last_line_data.ix[:,8]).pop()) 58 | f.close() 59 | 60 | elif (last_line_data.ix[:,4] < last_line_data.ix[:,5]).bool() and \ 61 | (last_line_data.ix[:,5] < last_line_data.ix[:,6]).bool(): 62 | #last_line_data.ix[0,6] < last_line_data.ix[0,7] and \ 63 | #last_line_data.ix[0,7] < last_line_data.ix[0,8] : 64 | winsound.PlaySound(wav_file_down, winsound.SND_NODEFAULT) 65 | f=open(file_result_example,"a") 66 | print >>f,"Down,"+str(list(last_line_data.ix[:,0]).pop())+","\ 67 | +str(list(last_line_data.ix[:,4]).pop())+","\ 68 | +str(list(last_line_data.ix[:,5]).pop())+","\ 69 | +str(list(last_line_data.ix[:,6]).pop())+","\ 70 | +str(list(last_line_data.ix[:,7]).pop())+","\ 71 | +str(list(last_line_data.ix[:,8]).pop()) 72 | f.close() 73 | 74 | def MA_xielv(XieLv_Num,MA5,MA10,MA20,MA30,MA60,MA120): 75 | global df_5 76 | df_tmp=df_5.tail(XieLv_Num-1).head(1) 77 | lenth_df_tmp=len(df_5) 78 | if lenth_df_tmp>5 and math.isnan(df_tmp.ix[:,4])==False: 79 | MA5_xielv=(MA5-list(df_tmp.ix[:,4]).pop())/list(df_tmp.ix[:,4]).pop() 80 | else: 81 | MA5_xielv=np.nan 82 | 83 | if lenth_df_tmp>10 and math.isnan(df_tmp.ix[:,5])==False: 84 | MA10_xielv=(MA10-list(df_tmp.ix[:,5]).pop())/list(df_tmp.ix[:,5]).pop() 85 | else: 86 | MA10_xielv=np.nan 87 | 88 | if lenth_df_tmp>20 and math.isnan(df_tmp.ix[:,6])==False: 89 | MA20_xielv=(MA20-list(df_tmp.ix[:,6]).pop())/list(df_tmp.ix[:,6]).pop() 90 | else: 91 | MA20_xielv=np.nan 92 | 93 | if lenth_df_tmp>30 and math.isnan(df_tmp.ix[:,7])==False: 94 | MA30_xielv=(MA30-list(df_tmp.ix[:,7]).pop())/list(df_tmp.ix[:,7]).pop() 95 | else: 96 | MA30_xielv=np.nan 97 | 98 | if lenth_df_tmp>60 and math.isnan(df_tmp.ix[:,8])==False: 99 | MA60_xielv=(MA60-list(df_tmp.ix[:,8]).pop())/list(df_tmp.ix[:,8]).pop() 100 | else: 101 | MA60_xielv=np.nan 102 | 103 | if lenth_df_tmp>120 and math.isnan(df_tmp.ix[:,9])==False: 104 | MA120_xielv=(MA120-list(df_tmp.ix[:,9]).pop())/list(df_tmp.ix[:,9]).pop() 105 | else: 106 | MA120_xielv=np.nan 107 | 108 | return MA5_xielv,MA10_xielv,MA20_xielv,MA30_xielv,MA60_xielv,MA120_xielv 109 | 110 | 111 | def MA(MA_x,Latest_Value): 112 | global file_souji_fengzhong 113 | df_tmp=pd.read_csv(file_souji_fengzhong,index_col=0) 114 | value_tmp=(df_tmp.ix[:,3].tail(MA_x-1).sum()+Latest_Value)/MA_x 115 | return value_tmp 116 | 117 | def MACD(Latest_Value): 118 | #使用通达信的MACD计算方法: 119 | #第一天:EMA_12=收盘价;EMA_26=收盘价;DIF=0;DEA=0;MACD=0(不套用公式) 120 | #第二天-第N天:套用公式 121 | #EMA(12)= 前一日EMA(12)×11/13+今日收盘价×2/13 122 | #EMA(26)= 前一日EMA(26)×25/27+今日收盘价×2/27 123 | #DIFF=今日EMA(12)- 今日EMA(26) 124 | #DEA(MACD)= 前一日DEA×8/10+今日DIF×2/10 125 | #BAR=2×(DIFF-DEA) 126 | #参考http://blog.sina.com.cn/s/blog_5938eb510100fz89.html 127 | 128 | global file_souji_fengzhong 129 | 130 | short = 12 131 | long = 26 132 | mid = 9 133 | df_tmp=pd.read_csv(file_souji_fengzhong,index_col=0) 134 | MACD_EMA_SHORT_POSITION=df_tmp.columns.searchsorted('MACD_EMA_12') 135 | 136 | if len(df_tmp)==0: 137 | MACD_EMA_short=Latest_Value 138 | MACD_EMA_long =Latest_Value 139 | MACD_DIF = 0 140 | MACD_DEA = 0 141 | MACD_MACD = 0 142 | 143 | else: 144 | Last_Trade_4_MACD=df_tmp.tail(1) 145 | MACD_EMA_short=Last_Trade_4_MACD.ix[0,MACD_EMA_SHORT_POSITION]*(short-1)/(short+1)+\ 146 | Latest_Value*2/(short+1) 147 | 148 | MACD_EMA_long=Last_Trade_4_MACD.ix[0,MACD_EMA_SHORT_POSITION+1]*(long-1)/(long+1)+\ 149 | Latest_Value*2/(long+1) 150 | 151 | MACD_DIF = MACD_EMA_short - MACD_EMA_long 152 | 153 | MACD_DEA =Last_Trade_4_MACD.ix[0,MACD_EMA_SHORT_POSITION+3]*(mid-1)/(mid+1)+\ 154 | MACD_DIF*2/(mid+1) 155 | 156 | MACD_MACD = (MACD_DIF - MACD_DEA) * 2 157 | 158 | return MACD_EMA_short,MACD_EMA_long,MACD_DIF,MACD_DEA,MACD_MACD 159 | 160 | which_market='2' 161 | stock_number='BABA' 162 | if which_market=="1": 163 | market_name="hk" 164 | elif which_market=="2": 165 | market_name="us" 166 | else: 167 | market_name="XX" 168 | 169 | # 上一分钟信息 170 | LastMinute=None 171 | LastTradeOrderTime=None 172 | 173 | #local_date_4_file=time.strftime('%Y%m%d_%H%M%S',time.localtime(time.time()-24*60*60)) 174 | local_date_4_file=time.strftime('%Y%m%d',time.localtime(time.time()-24*60*60)) 175 | 176 | file_souji_tmp="C:\\IBM-9\\FTNN_HK\\ftnn_souji_"+market_name+"_"+stock_number+"_"+local_date_4_file+".csv" 177 | file_souji_all="C:\IBM-9\FTNN_HK\\ftnn_souji_all_"+market_name+"_"+stock_number+"_"+local_date_4_file+".csv" 178 | file_souji_fengzhong="C:\IBM-9\FTNN_HK\\ftnn_souji_fengzhong_"+market_name+"_"+stock_number+"_"+local_date_4_file+".csv" 179 | 180 | df_4=pd.DataFrame() 181 | df_5=pd.DataFrame() 182 | df_6=pd.DataFrame() 183 | 184 | #futnn plubin会开启本地监听服务端 185 | # 请求及发送数据都是jason格式, 具体详见插件的协议文档 186 | host="localhost" 187 | port=11111 188 | 189 | 190 | local_date=time.strftime('%Y-%m-%d',time.localtime(time.time()-24*60*60)) 191 | 192 | s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) 193 | s.connect((host,port)) 194 | 195 | #需要确认电脑时区是香港时区 196 | now_time=time.localtime(time.time()-24*60*60) 197 | if which_market=='1': 198 | if (now_time>time.strptime(local_date+" "+"9:30:00", "%Y-%m-%d %H:%M:%S") and \ 199 | now_timetime.strptime(local_date+" "+"13:00:00", "%Y-%m-%d %H:%M:%S") and \ 201 | now_timetime.strptime(local_date+" "+"9:30:00", "%Y-%m-%d %H:%M:%S") and \ 207 | now_time0: 215 | actual_second=time.strftime("%S",now_time) 216 | if int(actual_second)%2!=0: 217 | #发送报价请求,Market为2表示是美股 218 | #req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'00700'},'Version':'1'} 219 | req = {'Protocol':'1001', 'ReqParam':{'Market':which_market,'StockCode':stock_number},'Version':'1'} 220 | #req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'00700'},'Version':'1'} 221 | #req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'01585'},'Version':'1'} 222 | str_1 = json.dumps(req) + "\n" 223 | print str_1 224 | s.send(str_1) 225 | rsp = "" 226 | while True: 227 | buf = s.recv(1024) 228 | rsp = rsp + buf 229 | #找到"\n"就认为结束了 230 | try: 231 | rsp.index('\n') 232 | break; 233 | except Exception, e: 234 | print "recving..." 235 | print rsp 236 | 237 | rsp_current_price_str=rsp.split(',')[4] 238 | current_price=rsp_current_price_str.split('"')[3] 239 | 240 | #输出的时间是按秒计算的,现在距离0点0分0秒多长时间 241 | rsp_current_time_str=rsp.split(',')[11] 242 | current_time=rsp_current_time_str.split('"')[3] 243 | trade_order_time=current_time 244 | current_hour=int(current_time)/3600 245 | current_minute=(int(current_time)-current_hour*3600)/60 246 | current_second=int(current_time)-current_hour*3600-current_minute*60 247 | 248 | actual_minute=time.strftime("%M",now_time) 249 | actual_hour=time.strftime("%H",now_time) 250 | 251 | print current_hour 252 | print current_minute 253 | print current_second 254 | print current_price 255 | print "------" 256 | print actual_hour 257 | print actual_minute 258 | print actual_second 259 | 260 | 261 | print "LastMinute:",LastMinute 262 | print "actual_minute:",actual_minute 263 | print "current_minute:",current_minute 264 | 265 | if LastMinute!=None: 266 | if ( (int(actual_minute)<=int(LastMinute) and int(actual_hour)==int(LastHour)) or int(actual_hour)>f,"Date,Price" 282 | f.close() 283 | 284 | if os.path.exists(file_souji_all)==False: 285 | f=open(file_souji_all,"w") 286 | print>>f,"Date,Price" 287 | f.close() 288 | 289 | if os.path.exists(file_souji_fengzhong)==False: 290 | f=open(file_souji_fengzhong,"w") 291 | print>>f," ,open,high,low,close,MA5,MA10,MA20,MA30,MA60,MA120,MA5_XieLv_0,MA10_XieLv_0,MA20_XieLv_0,MA30_XieLv_0,MA60_XieLv_0,MA120_XieLv_0,MACD_EMA_12,MACD_EMA_26,MACD_DIF,MACD_DEA,MACD_MACD" 292 | f.close() 293 | 294 | f=open(file_souji_tmp,"a") 295 | print>>f,local_date+" "+str(current_hour)+":"+str(current_minute)+":"+str(current_second)+","+str(current_price) 296 | f.close() 297 | 298 | else: 299 | df_1=pd.read_csv(file_souji_tmp) 300 | df_4=pd.read_csv(file_souji_all) 301 | df_4=df_4.append(df_1,ignore_index=True) 302 | df_4.to_csv(file_souji_all,index=False) 303 | 304 | df_1.index=pd.tseries.index.DatetimeIndex(df_1.ix[:,0]) 305 | df_2=df_1.ix[:,1] 306 | df_3=df_2.resample('1min',how='ohlc') 307 | 308 | df_5=pd.read_csv(file_souji_fengzhong,index_col=0) 309 | #df_tmp=df_3.ix[0] 310 | 311 | 312 | if len(df_5)==0: 313 | df_tmp=df_3.tail(1) 314 | elif df_3.head(1).index>pd.tseries.index.DatetimeIndex(df_5.tail(1).index): 315 | df_tmp=df_3.head(1) 316 | elif df_3.tail(1).index>pd.tseries.index.DatetimeIndex(df_5.tail(1).index): 317 | df_tmp=df_3.tail(1) 318 | else: 319 | #就是为了更换一个index,需要这么麻烦吗 320 | if int(actual_minute)==0: 321 | #针对整点,分钟为0的场景,减1分钟应该是59分,而不是-1 322 | str_tmp=time.strftime("%Y-%m-%d ",now_time)+str(int(actual_hour)-1)+':59' 323 | else: 324 | str_tmp=time.strftime("%Y-%m-%d %H:",now_time)+str(int(actual_minute)-1) #就是为了更换一个index,需要这么麻烦吗 325 | df_7 = pd.DataFrame(df_tmp.ix[0].open, index=[str_tmp],columns=['open']) 326 | df_7['high']=df_tmp['high'].ix[0] 327 | df_7['low'] =df_tmp['low'].ix[0] 328 | df_7['close'] =df_tmp['close'].ix[0] 329 | df_tmp=df_7 330 | 331 | print df_tmp 332 | print "------" 333 | print df_3 334 | print "*****" 335 | print actual_minute 336 | 337 | #trade_order_time!=LastTradeOrderTime 338 | 339 | #df_tmp=df_3.tail(1) 340 | 341 | MA5_tmp=MA(5,df_tmp.ix[0,3]) 342 | MA10_tmp=MA(10,df_tmp.ix[0,3]) 343 | MA20_tmp=MA(20,df_tmp.ix[0,3]) 344 | MA30_tmp=MA(30,df_tmp.ix[0,3]) 345 | MA60_tmp=MA(60,df_tmp.ix[0,3]) 346 | MA120_tmp=MA(120,df_tmp.ix[0,3]) 347 | 348 | df_tmp['MA5']=MA5_tmp 349 | df_tmp['MA10']=MA10_tmp 350 | df_tmp['MA20']=MA20_tmp 351 | df_tmp['MA30']=MA30_tmp 352 | df_tmp['MA60']=MA60_tmp 353 | df_tmp['MA120']=MA120_tmp 354 | 355 | #计算各个MA斜率 356 | XieLv_Num=3 357 | MA5_xielv,MA10_xielv,MA20_xielv,MA30_xielv,MA60_xielv,MA120_xielv=MA_xielv(XieLv_Num,MA5_tmp,MA10_tmp,MA20_tmp,MA30_tmp,MA60_tmp,MA120_tmp) 358 | 359 | df_tmp['MA5_XieLv_0']= MA5_xielv 360 | df_tmp['MA10_XieLv_0']= MA10_xielv 361 | df_tmp['MA20_XieLv_0']= MA20_xielv 362 | df_tmp['MA30_XieLv_0']= MA30_xielv 363 | df_tmp['MA60_XieLv_0']= MA60_xielv 364 | df_tmp['MA120_XieLv_0']= MA120_xielv 365 | 366 | 367 | #增加MACD 368 | MACD_EMA_short,MACD_EMA_long,MACD_DIF,MACD_DEA,MACD_MACD=MACD(df_tmp.ix[0,3]) 369 | 370 | df_tmp['MACD_EMA_12']=MACD_EMA_short 371 | df_tmp['MACD_EMA_26']=MACD_EMA_long 372 | df_tmp['MACD_DIF']=MACD_DIF 373 | df_tmp['MACD_DEA']=MACD_DEA 374 | df_tmp['MACD_MACD']=MACD_MACD 375 | 376 | df_5=df_5.append(df_tmp) 377 | 378 | df_5.to_csv(file_souji_fengzhong) 379 | 380 | os.remove(file_souji_tmp) 381 | #写入新分钟的成交数据 382 | f=open(file_souji_tmp,"w") 383 | print>>f,"Date,Price" 384 | print>>f,local_date+" "+str(current_hour)+":"+str(current_minute)+":"+str(current_second)+","+str(current_price) 385 | f.close() 386 | 387 | # Example:To Analysis Data 388 | Example_Analysis() 389 | 390 | #似乎还要往前 391 | LastTradeOrderTime=trade_order_time 392 | #caculate_zhibiao(df_3.ix[0,0],) 393 | #caculate_MACD(df_3) 394 | 395 | if int(actual_hour)> int(current_hour): 396 | LastHour=actual_hour 397 | LastMinute=actual_minute 398 | elif int(actual_hour)== int(current_hour): 399 | LastHour=current_hour 400 | LastMinute=max(int(actual_minute),int(current_minute)) 401 | elif int(actual_hour)< int(current_hour): 402 | LastHour=current_hour 403 | LastMinute=current_minute 404 | 405 | # noinspection PyUnboundLocalVariable,PyUnboundLocalVariable 406 | sleep(1) 407 | 408 | now_time=time.localtime(time.time()-24*60*60) 409 | if which_market=='1': 410 | if (now_time>time.strptime(local_date+" "+"9:30:00", "%Y-%m-%d %H:%M:%S") and \ 411 | now_timetime.strptime(local_date+" "+"13:00:00", "%Y-%m-%d %H:%M:%S") and \ 413 | now_timetime.strptime(local_date+" "+"9:30:00", "%Y-%m-%d %H:%M:%S") and \ 419 | now_time>f,"MA Up/Down,Time,MA5,MA10,MA20,MA30,MA60" 61 | f.close() 62 | 63 | df_tmp=pd.read_csv(file_souji_fengzhong) 64 | last_line_data=df_tmp.tail(1) 65 | #if len(df_tmp)>0 and math.isnan(last_line_data.ix[:,8])==False: 66 | 67 | if len(df_tmp)>20: 68 | if (last_line_data.ix[:,4] > last_line_data.ix[:,5]).bool() and \ 69 | (last_line_data.ix[:,5] > last_line_data.ix[:,6]).bool(): 70 | #last_line_data.ix[0,6] > last_line_data.ix[0,7] and \ 71 | #last_line_data.ix[0,7] > last_line_data.ix[0,8] : 72 | if stock_number==stock_number_1 or stock_number==stock_number_2: 73 | speak_str=stock_number+" UP" 74 | p1 = multiprocessing.Process(target = speak_string, args = (speak_str,)) 75 | p1.start() 76 | else: 77 | p2 = multiprocessing.Process(target = play_wav_sound, args = (wav_file_up,)) 78 | p2.start() 79 | 80 | f=open(file_result_example,"a") 81 | print >>f,"Up,"+str(list(last_line_data.ix[:,0]).pop())+","\ 82 | +str(list(last_line_data.ix[:,4]).pop())+","\ 83 | +str(list(last_line_data.ix[:,5]).pop())+","\ 84 | +str(list(last_line_data.ix[:,6]).pop())+","\ 85 | +str(list(last_line_data.ix[:,7]).pop())+","\ 86 | +str(list(last_line_data.ix[:,8]).pop()) 87 | f.close() 88 | 89 | elif (last_line_data.ix[:,4] < last_line_data.ix[:,5]).bool() and \ 90 | (last_line_data.ix[:,5] < last_line_data.ix[:,6]).bool(): 91 | #last_line_data.ix[0,6] < last_line_data.ix[0,7] and \ 92 | #last_line_data.ix[0,7] < last_line_data.ix[0,8] : 93 | 94 | if stock_number==stock_number_1 or stock_number==stock_number_2: 95 | speak_str=stock_number+" DOWN" 96 | p1 = multiprocessing.Process(target = speak_string, args = (speak_str,)) 97 | p1.start() 98 | else: 99 | p2 = multiprocessing.Process(target = play_wav_sound, args = (wav_file_down,)) 100 | p2.start() 101 | 102 | f=open(file_result_example,"a") 103 | print >>f,"Down,"+str(list(last_line_data.ix[:,0]).pop())+","\ 104 | +str(list(last_line_data.ix[:,4]).pop())+","\ 105 | +str(list(last_line_data.ix[:,5]).pop())+","\ 106 | +str(list(last_line_data.ix[:,6]).pop())+","\ 107 | +str(list(last_line_data.ix[:,7]).pop())+","\ 108 | +str(list(last_line_data.ix[:,8]).pop()) 109 | f.close() 110 | 111 | def MA_xielv(XieLv_Num,MA5,MA10,MA20,MA30,MA60,MA120): 112 | global df_5 113 | df_tmp=df_5.tail(XieLv_Num-1).head(1) 114 | lenth_df_tmp=len(df_5) 115 | if lenth_df_tmp>5 and math.isnan(df_tmp.ix[:,4])==False: 116 | MA5_xielv=(MA5-list(df_tmp.ix[:,4]).pop())/list(df_tmp.ix[:,4]).pop() 117 | else: 118 | MA5_xielv=np.nan 119 | 120 | if lenth_df_tmp>10 and math.isnan(df_tmp.ix[:,5])==False: 121 | MA10_xielv=(MA10-list(df_tmp.ix[:,5]).pop())/list(df_tmp.ix[:,5]).pop() 122 | else: 123 | MA10_xielv=np.nan 124 | 125 | if lenth_df_tmp>20 and math.isnan(df_tmp.ix[:,6])==False: 126 | MA20_xielv=(MA20-list(df_tmp.ix[:,6]).pop())/list(df_tmp.ix[:,6]).pop() 127 | else: 128 | MA20_xielv=np.nan 129 | 130 | if lenth_df_tmp>30 and math.isnan(df_tmp.ix[:,7])==False: 131 | MA30_xielv=(MA30-list(df_tmp.ix[:,7]).pop())/list(df_tmp.ix[:,7]).pop() 132 | else: 133 | MA30_xielv=np.nan 134 | 135 | if lenth_df_tmp>60 and math.isnan(df_tmp.ix[:,8])==False: 136 | MA60_xielv=(MA60-list(df_tmp.ix[:,8]).pop())/list(df_tmp.ix[:,8]).pop() 137 | else: 138 | MA60_xielv=np.nan 139 | 140 | if lenth_df_tmp>120 and math.isnan(df_tmp.ix[:,9])==False: 141 | MA120_xielv=(MA120-list(df_tmp.ix[:,9]).pop())/list(df_tmp.ix[:,9]).pop() 142 | else: 143 | MA120_xielv=np.nan 144 | 145 | return MA5_xielv,MA10_xielv,MA20_xielv,MA30_xielv,MA60_xielv,MA120_xielv 146 | 147 | 148 | def MA(MA_x,Latest_Value,file_souji_fengzhong): 149 | df_tmp=pd.read_csv(file_souji_fengzhong,index_col=0) 150 | value_tmp=(df_tmp.ix[:,3].tail(MA_x-1).sum()+Latest_Value)/MA_x 151 | return value_tmp 152 | 153 | def MACD(Latest_Value,file_souji_fengzhong): 154 | #使用通达信的MACD计算方法: 155 | #第一天:EMA_12=收盘价;EMA_26=收盘价;DIF=0;DEA=0;MACD=0(不套用公式) 156 | #第二天-第N天:套用公式 157 | #EMA(12)= 前一日EMA(12)×11/13+今日收盘价×2/13 158 | #EMA(26)= 前一日EMA(26)×25/27+今日收盘价×2/27 159 | #DIFF=今日EMA(12)- 今日EMA(26) 160 | #DEA(MACD)= 前一日DEA×8/10+今日DIF×2/10 161 | #BAR=2×(DIFF-DEA) 162 | #参考http://blog.sina.com.cn/s/blog_5938eb510100fz89.html 163 | 164 | short = 12 165 | long = 26 166 | mid = 9 167 | df_tmp=pd.read_csv(file_souji_fengzhong,index_col=0) 168 | MACD_EMA_SHORT_POSITION=df_tmp.columns.searchsorted('MACD_EMA_12') 169 | 170 | if len(df_tmp)==0: 171 | MACD_EMA_short=Latest_Value 172 | MACD_EMA_long =Latest_Value 173 | MACD_DIF = 0 174 | MACD_DEA = 0 175 | MACD_MACD = 0 176 | 177 | else: 178 | Last_Trade_4_MACD=df_tmp.tail(1) 179 | MACD_EMA_short=Last_Trade_4_MACD.ix[0,MACD_EMA_SHORT_POSITION]*(short-1)/(short+1)+\ 180 | Latest_Value*2/(short+1) 181 | 182 | MACD_EMA_long=Last_Trade_4_MACD.ix[0,MACD_EMA_SHORT_POSITION+1]*(long-1)/(long+1)+\ 183 | Latest_Value*2/(long+1) 184 | 185 | MACD_DIF = MACD_EMA_short - MACD_EMA_long 186 | 187 | MACD_DEA =Last_Trade_4_MACD.ix[0,MACD_EMA_SHORT_POSITION+3]*(mid-1)/(mid+1)+\ 188 | MACD_DIF*2/(mid+1) 189 | 190 | MACD_MACD = (MACD_DIF - MACD_DEA) * 2 191 | 192 | return MACD_EMA_short,MACD_EMA_long,MACD_DIF,MACD_DEA,MACD_MACD 193 | 194 | 195 | def GetValue(req,stock_number): 196 | global s 197 | global local_date_4_file 198 | global LastMinute 199 | global LastHour 200 | 201 | global df_5 202 | 203 | file_souji_tmp="C:\\IBM-9\\FTNN_HK\\ftnn_souji_"+market_name+"_"+stock_number+"_"+local_date_4_file+".csv" 204 | file_souji_all="C:\IBM-9\FTNN_HK\\ftnn_souji_all_"+market_name+"_"+stock_number+"_"+local_date_4_file+".csv" 205 | file_souji_fengzhong="C:\IBM-9\FTNN_HK\\ftnn_souji_fengzhong_"+market_name+"_"+stock_number+"_"+local_date_4_file+".csv" 206 | 207 | str_1 = json.dumps(req) + "\n" 208 | print str_1 209 | s.send(str_1) 210 | rsp = "" 211 | while True: 212 | buf = s.recv(1024) 213 | rsp = rsp + buf 214 | #找到"\n"就认为结束了 215 | try: 216 | rsp.index('\n') 217 | break; 218 | except Exception, e: 219 | print "recving..." 220 | print rsp 221 | 222 | rsp_current_price_str=rsp.split(',')[4] 223 | current_price=rsp_current_price_str.split('"')[3] 224 | 225 | #输出的时间是按秒计算的,现在距离0点0分0秒多长时间 226 | rsp_current_time_str=rsp.split(',')[11] 227 | current_time=rsp_current_time_str.split('"')[3] 228 | trade_order_time=current_time 229 | current_hour=int(current_time)/3600 230 | current_minute=(int(current_time)-current_hour*3600)/60 231 | current_second=int(current_time)-current_hour*3600-current_minute*60 232 | 233 | actual_minute=time.strftime("%M",now_time) 234 | actual_hour=time.strftime("%H",now_time) 235 | 236 | print current_hour 237 | print current_minute 238 | print current_second 239 | print current_price 240 | print "------" 241 | print actual_hour 242 | print actual_minute 243 | print actual_second 244 | 245 | 246 | print "LastMinute:",LastMinute 247 | print "actual_minute:",actual_minute 248 | print "current_minute:",current_minute 249 | 250 | if LastMinute!=None: 251 | if ( (int(actual_minute)<=int(LastMinute) and int(actual_hour)==int(LastHour)) or int(actual_hour)>f,"Date,Price" 268 | f.close() 269 | 270 | if os.path.exists(file_souji_all)==False: 271 | f=open(file_souji_all,"w") 272 | print>>f,"Date,Price" 273 | f.close() 274 | 275 | if os.path.exists(file_souji_fengzhong)==False: 276 | f=open(file_souji_fengzhong,"w") 277 | print>>f," ,open,high,low,close,MA5,MA10,MA20,MA30,MA60,MA120,MA5_XieLv_0,MA10_XieLv_0,MA20_XieLv_0,MA30_XieLv_0,MA60_XieLv_0,MA120_XieLv_0,MACD_EMA_12,MACD_EMA_26,MACD_DIF,MACD_DEA,MACD_MACD" 278 | f.close() 279 | 280 | f=open(file_souji_tmp,"a") 281 | print>>f,local_date+" "+str(current_hour)+":"+str(current_minute)+":"+str(current_second)+","+str(current_price) 282 | f.close() 283 | 284 | else: 285 | df_1=pd.read_csv(file_souji_tmp) 286 | df_4=pd.read_csv(file_souji_all) 287 | df_4=df_4.append(df_1,ignore_index=True) 288 | df_4.to_csv(file_souji_all,index=False) 289 | 290 | df_1.index=pd.tseries.index.DatetimeIndex(df_1.ix[:,0]) 291 | df_2=df_1.ix[:,1] 292 | df_3=df_2.resample('1min',how='ohlc') 293 | 294 | df_5=pd.read_csv(file_souji_fengzhong,index_col=0) 295 | #df_tmp=df_3.ix[0] 296 | 297 | 298 | if len(df_5)==0: 299 | df_tmp=df_3.tail(1) 300 | elif df_3.head(1).index>pd.tseries.index.DatetimeIndex(df_5.tail(1).index): 301 | df_tmp=df_3.head(1) 302 | elif df_3.tail(1).index>pd.tseries.index.DatetimeIndex(df_5.tail(1).index): 303 | df_tmp=df_3.tail(1) 304 | else: 305 | #就是为了更换一个index,需要这么麻烦吗 306 | if int(actual_minute)==0: 307 | #针对整点,分钟为0的场景,减1分钟应该是59分,而不是-1 308 | str_tmp=time.strftime("%Y-%m-%d ",now_time)+str(int(actual_hour)-1)+':59' 309 | else: 310 | str_tmp=time.strftime("%Y-%m-%d %H:",now_time)+str(int(actual_minute)-1) #就是为了更换一个index,需要这么麻烦吗 311 | #20160713,df_tmp修改为df_3 ??? 312 | df_7 = pd.DataFrame(df_3.ix[0].open, index=[str_tmp],columns=['open']) 313 | df_7['high']=df_3['high'].ix[0] 314 | df_7['low'] =df_3['low'].ix[0] 315 | df_7['close'] =df_3['close'].ix[0] 316 | df_tmp=df_7 317 | 318 | print df_tmp 319 | print "------" 320 | print df_3 321 | print "*****" 322 | print actual_minute 323 | 324 | #trade_order_time!=LastTradeOrderTime 325 | 326 | #df_tmp=df_3.tail(1) 327 | 328 | MA5_tmp=MA(5,df_tmp.ix[0,3],file_souji_fengzhong) 329 | MA10_tmp=MA(10,df_tmp.ix[0,3],file_souji_fengzhong) 330 | MA20_tmp=MA(20,df_tmp.ix[0,3],file_souji_fengzhong) 331 | MA30_tmp=MA(30,df_tmp.ix[0,3],file_souji_fengzhong) 332 | MA60_tmp=MA(60,df_tmp.ix[0,3],file_souji_fengzhong) 333 | MA120_tmp=MA(120,df_tmp.ix[0,3],file_souji_fengzhong) 334 | 335 | df_tmp['MA5']=MA5_tmp 336 | df_tmp['MA10']=MA10_tmp 337 | df_tmp['MA20']=MA20_tmp 338 | df_tmp['MA30']=MA30_tmp 339 | df_tmp['MA60']=MA60_tmp 340 | df_tmp['MA120']=MA120_tmp 341 | 342 | #计算各个MA斜率 343 | XieLv_Num=3 344 | MA5_xielv,MA10_xielv,MA20_xielv,MA30_xielv,MA60_xielv,MA120_xielv=MA_xielv(XieLv_Num,MA5_tmp,MA10_tmp,MA20_tmp,MA30_tmp,MA60_tmp,MA120_tmp) 345 | 346 | df_tmp['MA5_XieLv_0']= MA5_xielv 347 | df_tmp['MA10_XieLv_0']= MA10_xielv 348 | df_tmp['MA20_XieLv_0']= MA20_xielv 349 | df_tmp['MA30_XieLv_0']= MA30_xielv 350 | df_tmp['MA60_XieLv_0']= MA60_xielv 351 | df_tmp['MA120_XieLv_0']= MA120_xielv 352 | 353 | 354 | #增加MACD 355 | MACD_EMA_short,MACD_EMA_long,MACD_DIF,MACD_DEA,MACD_MACD=MACD(df_tmp.ix[0,3],file_souji_fengzhong) 356 | 357 | df_tmp['MACD_EMA_12']=MACD_EMA_short 358 | df_tmp['MACD_EMA_26']=MACD_EMA_long 359 | df_tmp['MACD_DIF']=MACD_DIF 360 | df_tmp['MACD_DEA']=MACD_DEA 361 | df_tmp['MACD_MACD']=MACD_MACD 362 | 363 | df_5=df_5.append(df_tmp) 364 | 365 | df_5.to_csv(file_souji_fengzhong) 366 | 367 | os.remove(file_souji_tmp) 368 | #写入新分钟的成交数据 369 | f=open(file_souji_tmp,"w") 370 | print>>f,"Date,Price" 371 | print>>f,local_date+" "+str(current_hour)+":"+str(current_minute)+":"+str(current_second)+","+str(current_price) 372 | f.close() 373 | 374 | # Example:To Analysis Data 375 | Example_Analysis(file_souji_fengzhong,stock_number) 376 | 377 | #似乎还要往前 378 | LastTradeOrderTime=trade_order_time 379 | #caculate_zhibiao(df_3.ix[0,0],) 380 | #caculate_MACD(df_3) 381 | 382 | if int(actual_hour)> int(current_hour): 383 | temp_LastHour=actual_hour 384 | temp_LastMinute=actual_minute 385 | elif int(actual_hour)== int(current_hour): 386 | temp_LastHour=current_hour 387 | temp_LastMinute=max(int(actual_minute),int(current_minute)) 388 | elif int(actual_hour)< int(current_hour): 389 | temp_LastHour=current_hour 390 | temp_LastMinute=current_minute 391 | 392 | return temp_LastHour,temp_LastMinute 393 | 394 | if __name__ == '__main__': 395 | #1 = 港股 396 | #2 = 美股 397 | #3 = 沪股 398 | #4 = 深股 399 | which_market='2' 400 | stock_number_1='ASHR' 401 | stock_number_2='CHAD' 402 | if which_market=="1": 403 | market_name="hk" 404 | market_index_number='800000' 405 | elif which_market=="2": 406 | market_name="us" 407 | market_index_number='DJI' 408 | elif which_market=="3": 409 | market_name="sh" 410 | market_index_number='000001' 411 | elif which_market=="4": 412 | market_name="sz" 413 | market_index_number='399001' 414 | else: 415 | market_name="XX" 416 | 417 | # 上一分钟信息 418 | LastMinute=None 419 | LastTradeOrderTime=None 420 | 421 | #local_date_4_file=time.strftime('%Y%m%d_%H%M%S',time.localtime(time.time()-24*60*60)) 422 | local_date_4_file=time.strftime('%Y%m%d',time.localtime(time.time()-24*60*60)) 423 | 424 | df_4=pd.DataFrame() 425 | df_5=pd.DataFrame() 426 | df_6=pd.DataFrame() 427 | 428 | #futnn plubin会开启本地监听服务端 429 | # 请求及发送数据都是jason格式, 具体详见插件的协议文档 430 | host="localhost" 431 | port=11111 432 | 433 | local_date=time.strftime('%Y-%m-%d',time.localtime(time.time()-24*60*60)) 434 | 435 | s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) 436 | s.connect((host,port)) 437 | 438 | #需要确认电脑时区是香港时区 439 | now_time=time.localtime(time.time()-24*60*60) 440 | if which_market=='1': 441 | if (now_time>time.strptime(local_date+" "+"9:30:00", "%Y-%m-%d %H:%M:%S") and \ 442 | now_timetime.strptime(local_date+" "+"13:00:00", "%Y-%m-%d %H:%M:%S") and \ 444 | now_timetime.strptime(local_date+" "+"9:30:00", "%Y-%m-%d %H:%M:%S") and \ 450 | now_timetime.strptime(local_date+" "+"9:30:00", "%Y-%m-%d %H:%M:%S") and \ 456 | now_timetime.strptime(local_date+" "+"13:00:00", "%Y-%m-%d %H:%M:%S") and \ 458 | now_time0: 466 | actual_second=time.strftime("%S",now_time) 467 | if int(actual_second)>-1: 468 | #发送报价请求,Market为2表示是美股 469 | #req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'00700'},'Version':'1'} 470 | stock_number=stock_number_1 471 | req = {'Protocol':'1001', 'ReqParam':{'Market':which_market,'StockCode':stock_number},'Version':'1'} 472 | #req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'00700'},'Version':'1'} 473 | #req = {'Protocol':'1001', 'ReqParam':{'Market':'1','StockCode':'01585'},'Version':'1'} 474 | temp_LastHour,temp_LastMinute=GetValue(req,stock_number) 475 | 476 | stock_number=stock_number_2 477 | req = {'Protocol':'1001', 'ReqParam':{'Market':which_market,'StockCode':stock_number},'Version':'1'} 478 | temp_LastHour,temp_LastMinute=GetValue(req,stock_number) 479 | 480 | if which_market==str(1) or which_market==str(3) or which_market==str(4) : 481 | req = {'Protocol':'1001', 'ReqParam':{'Market':which_market,'StockCode':market_index_number},'Version':'1'} 482 | #美国股指在富途中是以.(点)开头 483 | elif which_market==str(2): 484 | req = {'Protocol':'1001', 'ReqParam':{'Market':which_market,'StockCode':'.'+market_index_number},'Version':'1'} 485 | stock_number=market_index_number 486 | temp_LastHour,temp_LastMinute=GetValue(req,stock_number) 487 | #使用指数查询时间作为本次交易(一次交易包括查询一次股票,一次指数)的最新时间 488 | LastHour=temp_LastHour 489 | LastMinute=temp_LastMinute 490 | 491 | now_time=time.localtime(time.time()-24*60*60) 492 | if which_market=='1': 493 | if (now_time>time.strptime(local_date+" "+"9:30:00", "%Y-%m-%d %H:%M:%S") and \ 494 | now_timetime.strptime(local_date+" "+"13:00:00", "%Y-%m-%d %H:%M:%S") and \ 496 | now_timetime.strptime(local_date+" "+"9:30:00", "%Y-%m-%d %H:%M:%S") and \ 502 | now_timetime.strptime(local_date+" "+"9:30:00", "%Y-%m-%d %H:%M:%S") and \ 508 | now_timetime.strptime(local_date+" "+"13:00:00", "%Y-%m-%d %H:%M:%S") and \ 510 | now_timedatetime.datetime(date_from_which_year,1,1)].ix[:,0]) 44 | columns_len=len(df_temp.columns) 45 | 46 | Y1_name=df_temp.columns[columns_len-1] 47 | df_temp_2=df_temp.ix[:,columns_len-1] 48 | #之前已经对NAN使用了ffill的填充,这里是对一开始就是NAN的替代,将其数值为空 49 | df_temp_2[df_temp_2.isnull()==True]=' ' 50 | Y1_Value=str(list(df_temp_2)) 51 | Y1_Value=Y1_Value.replace('\'','') 52 | 53 | Y2_name=df_temp.columns[columns_len-2] 54 | df_temp_2=df_temp.ix[:,columns_len-2] 55 | df_temp_2[df_temp_2.isnull()==True]=' ' 56 | Y2_Value=str(list(df_temp_2)) 57 | Y2_Value=Y2_Value.replace('\'','') 58 | 59 | Y3_name=df_temp.columns[columns_len-3] 60 | df_temp_2=df_temp.ix[:,columns_len-3] 61 | df_temp_2[df_temp_2.isnull()==True]=' ' 62 | Y3_Value=str(list(df_temp_2)) 63 | Y3_Value=Y3_Value.replace('\'','') 64 | 65 | Y4_name=df_temp.columns[columns_len-4] 66 | df_temp_2=df_temp.ix[:,columns_len-4] 67 | df_temp_2[df_temp_2.isnull()==True]=' ' 68 | Y4_Value=str(list(df_temp_2)) 69 | Y4_Value=Y4_Value.replace('\'','') 70 | 71 | Y5_name=df_temp.columns[columns_len-5] 72 | df_temp_2=df_temp.ix[:,columns_len-5] 73 | df_temp_2[df_temp_2.isnull()==True]=' ' 74 | Y5_Value=str(list(df_temp_2)) 75 | Y5_Value=Y5_Value.replace('\'','') 76 | 77 | Y6_name=df_temp.columns[columns_len-6] 78 | df_temp_2=df_temp.ix[:,columns_len-6] 79 | df_temp_2[df_temp_2.isnull()==True]=' ' 80 | Y6_Value=str(list(df_temp_2)) 81 | Y6_Value=Y6_Value.replace('\'','') 82 | 83 | Y7_name=df_temp.columns[columns_len-7] 84 | df_temp_2=df_temp.ix[:,columns_len-7] 85 | df_temp_2[df_temp_2.isnull()==True]=' ' 86 | Y7_Value=str(list(df_temp_2)) 87 | Y7_Value=Y7_Value.replace('\'','') 88 | 89 | Y8_name=df_temp.columns[columns_len-8] 90 | df_temp_2=df_temp.ix[:,columns_len-8] 91 | df_temp_2[df_temp_2.isnull()==True]=' ' 92 | Y8_Value=str(list(df_temp_2)) 93 | Y8_Value=Y8_Value.replace('\'','') 94 | 95 | Y9_name=df_temp.columns[columns_len-9] 96 | df_temp_2=df_temp.ix[:,columns_len-9] 97 | df_temp_2[df_temp_2.isnull()==True]=' ' 98 | Y9_Value=str(list(df_temp_2)) 99 | Y9_Value=Y9_Value.replace('\'','') 100 | 101 | Y10_name=df_temp.columns[columns_len-10] 102 | df_temp_2=df_temp.ix[:,columns_len-10] 103 | df_temp_2[df_temp_2.isnull()==True]=' ' 104 | Y10_Value=str(list(df_temp_2)) 105 | Y10_Value=Y10_Value.replace('\'','') 106 | 107 | return title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 108 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value 109 | 110 | 111 | 112 | def Analysis_Var_2_display_in_html(stock_name,merge_filepath,date_from_which_year): 113 | df_temp=pd.read_csv(merge_filepath) 114 | df_temp.index=pd.tseries.index.DatetimeIndex(df_temp.ix[:,0]) 115 | title_str='\''+stock_name+' Latest Date:'+df_temp.tail(1).ix[:,0].max()+'\'' 116 | 117 | Date_X_axis=list(df_temp[df_temp.index>datetime.datetime(date_from_which_year,1,1)].ix[:,0]) 118 | columns_len=len(df_temp.columns) 119 | Y1_name=df_temp.columns[columns_len-1] 120 | df_temp_2=df_temp.ix[:,columns_len-1] 121 | df_temp_2[df_temp_2.isnull()==True]=' ' 122 | Y1_Value=str(list(df_temp_2[df_temp_2.index>datetime.datetime(date_from_which_year,1,1)])) 123 | Y1_Value=Y1_Value.replace('\'','') 124 | 125 | #格式变成了2016涨幅,2016涨幅Z分数,2015涨幅,2015涨幅Z分数,2014涨幅,2014涨幅Z分数, 126 | Y2_name=df_temp.columns[columns_len-1-2] 127 | df_temp_2=df_temp.ix[:,columns_len-1-2] 128 | df_temp_2[df_temp_2.isnull()==True]=' ' 129 | Y2_Value=str(list(df_temp_2[df_temp_2.index>datetime.datetime(date_from_which_year,1,1)])) 130 | Y2_Value=Y2_Value.replace('\'','') 131 | 132 | Y3_name=df_temp.columns[columns_len-1-2-2] 133 | df_temp_2=df_temp.ix[:,columns_len-1-2-2] 134 | df_temp_2[df_temp_2.isnull()==True]=' ' 135 | Y3_Value=str(list(df_temp_2[df_temp_2.index>datetime.datetime(date_from_which_year,1,1)])) 136 | Y3_Value=Y3_Value.replace('\'','') 137 | 138 | return title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value 139 | 140 | 141 | def Write_2_html(*x): 142 | global ERROR_String 143 | #(写入文件名,标题,X横坐标,Y1变量名,Y1变量值,Y2变量名,Y2变量值...... ) 144 | 145 | write_2_html_part_1_session_0=""" 146 | 147 | 148 | 149 | """ 150 | 151 | write_2_html_part_1_session_1=""" 152 | 153 | 154 |
155 | 156 | 315 | 316 | """ 317 | print >>f,write_2_html_part_7 318 | f.close() 319 | 320 | 321 | 322 | 323 | 324 | def GetValue(stock_name,symbol,filepath,analysis_filepath): 325 | global year_analysis_number 326 | global ERROR_String 327 | global error_file_path 328 | 329 | data_sina=requests.get('http://hq.sinajs.cn/list='+symbol) 330 | if symbol.find('sh') >= 0 or symbol.find('sz') >= 0: 331 | data_stock=data_sina.text.split(',') 332 | data_stock_Open=data_stock[1] 333 | data_stock_Close=data_stock[3] 334 | data_stock_High=data_stock[4] 335 | data_stock_Low=data_stock[5] 336 | data_stock_Date=data_stock[30] 337 | data_stock_volume=data_stock[8] 338 | 339 | month=str(data_stock[30]).split("-")[1] 340 | day=str(data_stock[30]).split("-")[2] 341 | year=time.strftime('%Y') 342 | 343 | stock_date_string=" "+year+"/"+month+"/"+day 344 | stock_date=time.strptime(stock_date_string," %Y/%m/%d") 345 | 346 | df=pd.read_csv(filepath) 347 | former_day=time.strptime(df.tail(1).ix[:,0].max()," %Y/%m/%d") 348 | former_close=df.tail(1).ix[:,4].max() 349 | 350 | elif symbol.find('hk') >= 0: 351 | data_stock=data_sina.text.split(',') 352 | data_stock_Open=data_stock[2] 353 | data_stock_Close=data_stock[6] 354 | data_stock_High=data_stock[4] 355 | data_stock_Low=data_stock[5] 356 | data_stock_Date=data_stock[17] 357 | data_stock_volume=str(int(data_stock[12])/100) 358 | 359 | month=str(data_stock_Date).split("/")[1] 360 | day=str(data_stock_Date).split("/")[2] 361 | year=time.strftime('%Y') 362 | 363 | stock_date_string=" "+year+"/"+month+"/"+day 364 | ##注意这里为了下面的香港变态数据格式保持一致,故意多了一个空格! 365 | stock_date=time.strptime(stock_date_string," %Y/%m/%d") 366 | 367 | df=pd.read_csv(filepath) 368 | #注意这里香港数据变态得多了一个空格! 369 | former_day=time.strptime(df.tail(1).ix[:,0].max()," %Y/%m/%d") 370 | former_close=df.tail(1).ix[:,4].max() 371 | 372 | #加多限制条件,满足才写入---2016.10.29 373 | #增加float(data_stock_Open),否则如果这样data_stock_Open!='0':当data_stock_Open采集到0.000时,data_stock_Open!='0'为True,而不是预期的为False---20161223 374 | if former_day!=stock_date and float(data_stock_Open)!=0 and float(data_stock_High)!=0 and float(data_stock_Low)!=0 and float(data_stock_Close)!=0: 375 | today_percent=( float(data_stock_Close)-float(former_close) )/float(former_close) 376 | #c2=stock_date_string+','+data_stock_Open+','+data_stock_High+','+data_stock_Low+','+data_stock_Close+','+data_stock_volume+','+str(today_percent)+'\r' 377 | #针对通达信格式,否则使用UltraEdit可以看到奇怪的格式! 378 | c2=stock_date_string+','+data_stock_Open+','+data_stock_High+','+data_stock_Low+','+data_stock_Close+','+data_stock_volume+','+str(today_percent)+'\n' 379 | 380 | f=open(filepath,"a") 381 | f.write(c2) 382 | f.close() 383 | 384 | #增加float(data_stock_Open),否则如果这样data_stock_Open!='0':当data_stock_Open采集到0.000时,data_stock_Open!='0'为True,而不是预期的为False---20161223 385 | if not(float(data_stock_Open)!=0 and float(data_stock_High)!=0 and float(data_stock_Low)!=0 and float(data_stock_Close)!=0): 386 | ERROR_String=ERROR_String+stock_name+"," 387 | 388 | Error_Message_2_txt="\n"+stock_date_string+","+stock_name 389 | 390 | f=open(error_file_path,"a") 391 | f.write(Error_Message_2_txt) 392 | f.close() 393 | 394 | #20161227改进:对于停牌的沿用上一天数据(成交量为0是最明显标志),否则最后结果输出会因为一颗老鼠屎坏了一锅粥,最终的结果因为这个永远停留在停牌那天 395 | #获取文件最后一行信息 396 | f=open(filepath,"r") 397 | lines=f.readlines() 398 | f.close() 399 | 400 | tmp_last_day_value=lines[-1].split(",") 401 | #OHLC都等于上一天的收盘价 402 | data_stock_Close=tmp_last_day_value[4] 403 | data_stock_Open=data_stock_Close 404 | data_stock_High=data_stock_Close 405 | data_stock_Low=data_stock_Close 406 | data_stock_volume="0" 407 | today_percent="0" 408 | 409 | if former_day!=stock_date: 410 | c2=stock_date_string+','+data_stock_Open+','+data_stock_High+','+data_stock_Low+','+data_stock_Close+','+data_stock_volume+','+str(today_percent)+'\n' 411 | f=open(filepath,"a") 412 | f.write(c2) 413 | f.close() 414 | #20161227改进结束 415 | 416 | #计算每天到初始值的涨幅 417 | df=pd.read_csv(filepath) 418 | df.index=pd.tseries.index.DatetimeIndex(df.ix[:,0]) 419 | #计算累计涨幅 420 | today_percent_position=6 421 | df['1+x%']=df.ix[:,today_percent_position]+1 422 | #这里计算近3年的涨幅,因为现在是2016年,则计算2016(基准值是2015最后一天),2015(基准值是2014最后一天),2014(基准值是2013最后一天)到现在的累计涨幅 423 | 424 | to_now_ZhangFu='_2now_ZhangFu' 425 | for tmp in range(0,year_analysis_number): 426 | #因为1月1日香港美国大陆均放假,因此这个>xxxx年1月1日肯定包含了所有的交易日数据 427 | #使用累计乘积cumprod() 428 | 429 | #20170108 强制让年份为2016;如果以2017新开始计算的话,至少半年内的数据(因为太少)基本无法使用 430 | #如果数据样本足够多,2014,2015,2016以来的曲线应该会逐渐重合在一起吧 431 | year=2016 432 | df[str(int(year)-tmp)+to_now_ZhangFu]=df[df.index>datetime.datetime(int(year)-tmp,1,1)].ix[:,today_percent_position+1].cumprod() 433 | 434 | df.to_csv(analysis_filepath,index=False) 435 | 436 | 437 | 438 | def Merge_data(stock_name,A_filepath,HK_filepath,merge_filepath): 439 | global year_analysis_number 440 | 441 | global df_1_all 442 | global df_2_all 443 | global df_3_all 444 | 445 | A_df=pd.read_csv(A_filepath) 446 | A_df.index=pd.tseries.index.DatetimeIndex(A_df.ix[:,0]) 447 | 448 | HK_df=pd.read_csv(HK_filepath) 449 | HK_df.index=pd.tseries.index.DatetimeIndex(HK_df.ix[:,0]) 450 | 451 | df=pd.merge(A_df,HK_df,left_index=True,right_index=True,how='inner') 452 | 453 | to_now_ZhangFu='_2now_ZhangFu' 454 | to_now_ZhangFu_pairtrade='_2now_ZhangFu_Z_Score' 455 | year=time.strftime('%Y') 456 | last_year_ZhangFu_position=8 457 | 458 | for tmp in range(0,year_analysis_number): 459 | 460 | #20170108 强制让年份为2016;如果以2017新开始计算的话,至少半年内的数据(因为太少)基本无法使用 461 | #如果数据样本足够多,2014,2015,2016以来的曲线应该会逐渐重合在一起吧 462 | year=2016 463 | df_all_tmp=pd.DataFrame() 464 | 465 | #Date_x O_x H_x L_x C_x Volume_x today_percent 1+x% 2016_2now_ZhangFu_x 2015_2now_ZhangFu_x 2014_2now_ZhangFu_x Date_y O_y H_y L_y C_y Volume_y today_ZhangFu 2016_2now_ZhangFu_y 2015_2now_ZhangFu_y 2014_2now_ZhangFu_y 466 | df[stock_name+"_"+str(int(year)-tmp)+to_now_ZhangFu]=df.ix[:,last_year_ZhangFu_position+tmp]-df.ix[:,last_year_ZhangFu_position+(year_analysis_number-1)+(last_year_ZhangFu_position+1)+tmp] 467 | 468 | #计算配对交易Z_score 469 | tmp_df=df[stock_name+"_"+str(int(year)-tmp)+to_now_ZhangFu][df.index>datetime.datetime(int(year)-tmp,1,1)] 470 | tmp_mean=tmp_df.mean() 471 | tmp_std=np.std(tmp_df) 472 | tmp_result=(tmp_df-tmp_mean)/tmp_std 473 | 474 | df[stock_name+"_"+str(int(year)-tmp)+to_now_ZhangFu_pairtrade]=tmp_result 475 | df_all_tmp[stock_name+"_"+str(int(year)-tmp)+to_now_ZhangFu_pairtrade]=tmp_result 476 | 477 | #使用最原始暴力合并,即各个股票的最近3年(2016、2015、2014年)的统计数据整合在一起 478 | if tmp==0: 479 | if len(df_1_all)==0: 480 | df_1_all[stock_name+"_"+str(int(year)-tmp)+to_now_ZhangFu_pairtrade]=tmp_result 481 | else: 482 | #df_1_all=pd.merge(df_1_all,df[stock_name+"_"+str(int(year)-tmp)+to_now_ZhangFu],left_index=True,right_index=True,how='outer') 483 | df_1_all=pd.concat([df_1_all,df_all_tmp],axis=1) 484 | 485 | if tmp==1: 486 | if len(df_2_all)==0: 487 | df_2_all[stock_name+"_"+str(int(year)-tmp)+to_now_ZhangFu_pairtrade]=tmp_result 488 | else: 489 | #df_2_all=pd.concat([df_2_all,df[stock_name+"_"+str(int(year)-tmp)+to_now_ZhangFu_pairtrade]],axis=1) 490 | df_2_all=pd.concat([df_2_all,df_all_tmp],axis=1) 491 | 492 | if tmp==2: 493 | if len(df_3_all)==0: 494 | df_3_all[stock_name+"_"+str(int(year)-tmp)+to_now_ZhangFu_pairtrade]=tmp_result 495 | else: 496 | df_3_all=pd.concat([df_3_all,df_all_tmp],axis=1) 497 | 498 | df.to_csv(merge_filepath,index=False) 499 | 500 | 501 | #东江环保 502 | DJHB_A_filepath="C:\IBM-9\A_HK_XiangGuan\DJHB\A.csv" 503 | DJHB_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\DJHB\A_analysis.csv" 504 | DJHB_HK_filepath="C:\IBM-9\A_HK_XiangGuan\DJHB\HK.csv" 505 | DJHB_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\DJHB\HK_analysis.csv" 506 | DJHB_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\DJHB\Merge.csv" 507 | GetValue('DJHB','sz002672',DJHB_A_filepath, DJHB_A_analysis_filepath) 508 | GetValue('DJHB','hk00895', DJHB_HK_filepath,DJHB_HK_analysis_filepath) 509 | Merge_data('DJHB',DJHB_A_analysis_filepath,DJHB_HK_analysis_filepath,DJHB_HK_merge_filepath) 510 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\DJHB\Visual.html" 511 | #2014年以来的数据 512 | date_from_which_year=2014 513 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('DJHB',DJHB_HK_merge_filepath,date_from_which_year) 514 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 515 | #(写入文件名,标题,X横坐标,Y1变量名,Y1变量值,Y2变量名,Y2变量值...... ) 516 | 517 | 518 | #建设银行 519 | JSYH_A_filepath="C:\IBM-9\A_HK_XiangGuan\JSYH\A.csv" 520 | JSYH_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\JSYH\A_analysis.csv" 521 | JSYH_HK_filepath="C:\IBM-9\A_HK_XiangGuan\JSYH\HK.csv" 522 | JSYH_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\JSYH\HK_analysis.csv" 523 | JSYH_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\JSYH\Merge.csv" 524 | GetValue('JSYH','sh601939',JSYH_A_filepath, JSYH_A_analysis_filepath) 525 | GetValue('JSYH','hk00939', JSYH_HK_filepath,JSYH_HK_analysis_filepath) 526 | Merge_data('JSYH',JSYH_A_analysis_filepath,JSYH_HK_analysis_filepath,JSYH_HK_merge_filepath) 527 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\JSYH\Visual.html" 528 | #2014年以来的数据 529 | date_from_which_year=2014 530 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('JSYH',JSYH_HK_merge_filepath,date_from_which_year) 531 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 532 | 533 | 534 | 535 | #中集集团 536 | ZJJT_A_filepath="C:\IBM-9\A_HK_XiangGuan\ZJJT\A.csv" 537 | ZJJT_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZJJT\A_analysis.csv" 538 | ZJJT_HK_filepath="C:\IBM-9\A_HK_XiangGuan\ZJJT\HK.csv" 539 | ZJJT_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZJJT\HK_analysis.csv" 540 | ZJJT_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\ZJJT\Merge.csv" 541 | GetValue('ZJJT','sz000039',ZJJT_A_filepath, ZJJT_A_analysis_filepath) 542 | GetValue('ZJJT','hk02039', ZJJT_HK_filepath,ZJJT_HK_analysis_filepath) 543 | Merge_data('ZJJT',ZJJT_A_analysis_filepath,ZJJT_HK_analysis_filepath,ZJJT_HK_merge_filepath) 544 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\ZJJT\Visual.html" 545 | #2014年以来的数据 546 | date_from_which_year=2014 547 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('ZJJT',ZJJT_HK_merge_filepath,date_from_which_year) 548 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 549 | 550 | 551 | #中联重科 552 | ZLZK_A_filepath="C:\IBM-9\A_HK_XiangGuan\ZLZK\A.csv" 553 | ZLZK_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZLZK\A_analysis.csv" 554 | ZLZK_HK_filepath="C:\IBM-9\A_HK_XiangGuan\ZLZK\HK.csv" 555 | ZLZK_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZLZK\HK_analysis.csv" 556 | ZLZK_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\ZLZK\Merge.csv" 557 | GetValue('ZLZK','sz000157',ZLZK_A_filepath, ZLZK_A_analysis_filepath) 558 | GetValue('ZLZK','hk01157', ZLZK_HK_filepath,ZLZK_HK_analysis_filepath) 559 | Merge_data('ZLZK',ZLZK_A_analysis_filepath,ZLZK_HK_analysis_filepath,ZLZK_HK_merge_filepath) 560 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\ZLZK\Visual.html" 561 | #2014年以来的数据 562 | date_from_which_year=2014 563 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('ZLZK',ZLZK_HK_merge_filepath,date_from_which_year) 564 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 565 | 566 | #东北电气 567 | DBDQ_A_filepath="C:\IBM-9\A_HK_XiangGuan\DBDQ\A.csv" 568 | DBDQ_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\DBDQ\A_analysis.csv" 569 | DBDQ_HK_filepath="C:\IBM-9\A_HK_XiangGuan\DBDQ\HK.csv" 570 | DBDQ_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\DBDQ\HK_analysis.csv" 571 | DBDQ_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\DBDQ\Merge.csv" 572 | GetValue('DBDQ','sz000585',DBDQ_A_filepath, DBDQ_A_analysis_filepath) 573 | GetValue('DBDQ','hk00042', DBDQ_HK_filepath,DBDQ_HK_analysis_filepath) 574 | Merge_data('DBDQ',DBDQ_A_analysis_filepath,DBDQ_HK_analysis_filepath,DBDQ_HK_merge_filepath) 575 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\DBDQ\Visual.html" 576 | #2014年以来的数据 577 | date_from_which_year=2014 578 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('DBDQ',DBDQ_HK_merge_filepath,date_from_which_year) 579 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 580 | 581 | 582 | #海信科龙 583 | HXKL_A_filepath="C:\IBM-9\A_HK_XiangGuan\HXKL\A.csv" 584 | HXKL_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\HXKL\A_analysis.csv" 585 | HXKL_HK_filepath="C:\IBM-9\A_HK_XiangGuan\HXKL\HK.csv" 586 | HXKL_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\HXKL\HK_analysis.csv" 587 | HXKL_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\HXKL\Merge.csv" 588 | GetValue('HXKL','sz000921',HXKL_A_filepath, HXKL_A_analysis_filepath) 589 | GetValue('HXKL','hk00921', HXKL_HK_filepath,HXKL_HK_analysis_filepath) 590 | Merge_data('HXKL',HXKL_A_analysis_filepath,HXKL_HK_analysis_filepath,HXKL_HK_merge_filepath) 591 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\HXKL\Visual.html" 592 | #2014年以来的数据 593 | date_from_which_year=2014 594 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('HXKL',HXKL_HK_merge_filepath,date_from_which_year) 595 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 596 | 597 | #新华制药 598 | XHZY_A_filepath="C:\IBM-9\A_HK_XiangGuan\XHZY\A.csv" 599 | XHZY_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\XHZY\A_analysis.csv" 600 | XHZY_HK_filepath="C:\IBM-9\A_HK_XiangGuan\XHZY\HK.csv" 601 | XHZY_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\XHZY\HK_analysis.csv" 602 | XHZY_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\XHZY\Merge.csv" 603 | GetValue('XHZY','sz000756',XHZY_A_filepath, XHZY_A_analysis_filepath) 604 | GetValue('XHZY','hk00719', XHZY_HK_filepath,XHZY_HK_analysis_filepath) 605 | Merge_data('XHZY',XHZY_A_analysis_filepath,XHZY_HK_analysis_filepath,XHZY_HK_merge_filepath) 606 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\XHZY\Visual.html" 607 | #2014年以来的数据 608 | date_from_which_year=2014 609 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('XHZY',XHZY_HK_merge_filepath,date_from_which_year) 610 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 611 | 612 | #山东墨龙 613 | SDML_A_filepath="C:\IBM-9\A_HK_XiangGuan\SDML\A.csv" 614 | SDML_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\SDML\A_analysis.csv" 615 | SDML_HK_filepath="C:\IBM-9\A_HK_XiangGuan\SDML\HK.csv" 616 | SDML_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\SDML\HK_analysis.csv" 617 | SDML_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\SDML\Merge.csv" 618 | GetValue('SDML','sz002490',SDML_A_filepath, SDML_A_analysis_filepath) 619 | GetValue('SDML','hk00568', SDML_HK_filepath,SDML_HK_analysis_filepath) 620 | Merge_data('SDML',SDML_A_analysis_filepath,SDML_HK_analysis_filepath,SDML_HK_merge_filepath) 621 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\SDML\Visual.html" 622 | #2014年以来的数据 623 | date_from_which_year=2014 624 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('SDML',SDML_HK_merge_filepath,date_from_which_year) 625 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 626 | 627 | #浙江世宝 628 | ZJSB_A_filepath="C:\IBM-9\A_HK_XiangGuan\ZJSB\A.csv" 629 | ZJSB_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZJSB\A_analysis.csv" 630 | ZJSB_HK_filepath="C:\IBM-9\A_HK_XiangGuan\ZJSB\HK.csv" 631 | ZJSB_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZJSB\HK_analysis.csv" 632 | ZJSB_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\ZJSB\Merge.csv" 633 | GetValue('ZJSB','sz002703',ZJSB_A_filepath, ZJSB_A_analysis_filepath) 634 | GetValue('ZJSB','hk01057', ZJSB_HK_filepath,ZJSB_HK_analysis_filepath) 635 | Merge_data('ZJSB',ZJSB_A_analysis_filepath,ZJSB_HK_analysis_filepath,ZJSB_HK_merge_filepath) 636 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\ZJSB\Visual.html" 637 | #2014年以来的数据 638 | date_from_which_year=2014 639 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('ZJSB',ZJSB_HK_merge_filepath,date_from_which_year) 640 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 641 | 642 | #工商银行 643 | GSYH_A_filepath="C:\IBM-9\A_HK_XiangGuan\GSYH\A.csv" 644 | GSYH_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\GSYH\A_analysis.csv" 645 | GSYH_HK_filepath="C:\IBM-9\A_HK_XiangGuan\GSYH\HK.csv" 646 | GSYH_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\GSYH\HK_analysis.csv" 647 | GSYH_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\GSYH\Merge.csv" 648 | GetValue('GSYH','sh601398',GSYH_A_filepath, GSYH_A_analysis_filepath) 649 | GetValue('GSYH','hk01398', GSYH_HK_filepath,GSYH_HK_analysis_filepath) 650 | Merge_data('GSYH',GSYH_A_analysis_filepath,GSYH_HK_analysis_filepath,GSYH_HK_merge_filepath) 651 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\GSYH\Visual.html" 652 | #2014年以来的数据 653 | date_from_which_year=2014 654 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('GSYH',GSYH_HK_merge_filepath,date_from_which_year) 655 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 656 | 657 | #中国银行 658 | ZGYH_A_filepath="C:\IBM-9\A_HK_XiangGuan\ZGYH\A.csv" 659 | ZGYH_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZGYH\A_analysis.csv" 660 | ZGYH_HK_filepath="C:\IBM-9\A_HK_XiangGuan\ZGYH\HK.csv" 661 | ZGYH_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZGYH\HK_analysis.csv" 662 | ZGYH_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\ZGYH\Merge.csv" 663 | GetValue('ZGYH','sh601988',ZGYH_A_filepath, ZGYH_A_analysis_filepath) 664 | GetValue('ZGYH','hk03988', ZGYH_HK_filepath,ZGYH_HK_analysis_filepath) 665 | Merge_data('ZGYH',ZGYH_A_analysis_filepath,ZGYH_HK_analysis_filepath,ZGYH_HK_merge_filepath) 666 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\ZGYH\Visual.html" 667 | #2014年以来的数据 668 | date_from_which_year=2014 669 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('ZGYH',ZGYH_HK_merge_filepath,date_from_which_year) 670 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 671 | 672 | #交通银行 673 | JTYH_A_filepath="C:\IBM-9\A_HK_XiangGuan\JTYH\A.csv" 674 | JTYH_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\JTYH\A_analysis.csv" 675 | JTYH_HK_filepath="C:\IBM-9\A_HK_XiangGuan\JTYH\HK.csv" 676 | JTYH_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\JTYH\HK_analysis.csv" 677 | JTYH_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\JTYH\Merge.csv" 678 | GetValue('JTYH','sh601328',JTYH_A_filepath, JTYH_A_analysis_filepath) 679 | GetValue('JTYH','hk03328', JTYH_HK_filepath,JTYH_HK_analysis_filepath) 680 | Merge_data('JTYH',JTYH_A_analysis_filepath,JTYH_HK_analysis_filepath,JTYH_HK_merge_filepath) 681 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\JTYH\Visual.html" 682 | #2014年以来的数据 683 | date_from_which_year=2014 684 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('JTYH',JTYH_HK_merge_filepath,date_from_which_year) 685 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 686 | 687 | 688 | #民生银行 689 | MSYH_A_filepath="C:\IBM-9\A_HK_XiangGuan\MSYH\A.csv" 690 | MSYH_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\MSYH\A_analysis.csv" 691 | MSYH_HK_filepath="C:\IBM-9\A_HK_XiangGuan\MSYH\HK.csv" 692 | MSYH_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\MSYH\HK_analysis.csv" 693 | MSYH_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\MSYH\Merge.csv" 694 | GetValue('MSYH','sh600016',MSYH_A_filepath, MSYH_A_analysis_filepath) 695 | GetValue('MSYH','hk01988', MSYH_HK_filepath,MSYH_HK_analysis_filepath) 696 | Merge_data('MSYH',MSYH_A_analysis_filepath,MSYH_HK_analysis_filepath,MSYH_HK_merge_filepath) 697 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\MSYH\Visual.html" 698 | #2014年以来的数据 699 | date_from_which_year=2014 700 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('MSYH',MSYH_HK_merge_filepath,date_from_which_year) 701 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 702 | 703 | 704 | #中国太保 705 | ZGTB_A_filepath="C:\IBM-9\A_HK_XiangGuan\ZGTB\A.csv" 706 | ZGTB_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZGTB\A_analysis.csv" 707 | ZGTB_HK_filepath="C:\IBM-9\A_HK_XiangGuan\ZGTB\HK.csv" 708 | ZGTB_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZGTB\HK_analysis.csv" 709 | ZGTB_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\ZGTB\Merge.csv" 710 | GetValue('ZGTB','sh601601',ZGTB_A_filepath, ZGTB_A_analysis_filepath) 711 | GetValue('ZGTB','hk02601', ZGTB_HK_filepath,ZGTB_HK_analysis_filepath) 712 | Merge_data('ZGTB',ZGTB_A_analysis_filepath,ZGTB_HK_analysis_filepath,ZGTB_HK_merge_filepath) 713 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\ZGTB\Visual.html" 714 | #2014年以来的数据 715 | date_from_which_year=2014 716 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('ZGTB',ZGTB_HK_merge_filepath,date_from_which_year) 717 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 718 | 719 | #中国人寿 720 | ZGRS_A_filepath="C:\IBM-9\A_HK_XiangGuan\ZGRS\A.csv" 721 | ZGRS_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZGRS\A_analysis.csv" 722 | ZGRS_HK_filepath="C:\IBM-9\A_HK_XiangGuan\ZGRS\HK.csv" 723 | ZGRS_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZGRS\HK_analysis.csv" 724 | ZGRS_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\ZGRS\Merge.csv" 725 | GetValue('ZGRS','sh601628',ZGRS_A_filepath, ZGRS_A_analysis_filepath) 726 | GetValue('ZGRS','hk02628', ZGRS_HK_filepath,ZGRS_HK_analysis_filepath) 727 | Merge_data('ZGRS',ZGRS_A_analysis_filepath,ZGRS_HK_analysis_filepath,ZGRS_HK_merge_filepath) 728 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\ZGRS\Visual.html" 729 | #2014年以来的数据 730 | date_from_which_year=2014 731 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('ZGRS',ZGRS_HK_merge_filepath,date_from_which_year) 732 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 733 | 734 | #新华保险 735 | XHBX_A_filepath="C:\IBM-9\A_HK_XiangGuan\XHBX\A.csv" 736 | XHBX_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\XHBX\A_analysis.csv" 737 | XHBX_HK_filepath="C:\IBM-9\A_HK_XiangGuan\XHBX\HK.csv" 738 | XHBX_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\XHBX\HK_analysis.csv" 739 | XHBX_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\XHBX\Merge.csv" 740 | GetValue('XHBX','sh601336',XHBX_A_filepath, XHBX_A_analysis_filepath) 741 | GetValue('XHBX','hk01336', XHBX_HK_filepath,XHBX_HK_analysis_filepath) 742 | Merge_data('XHBX',XHBX_A_analysis_filepath,XHBX_HK_analysis_filepath,XHBX_HK_merge_filepath) 743 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\XHBX\Visual.html" 744 | #2014年以来的数据 745 | date_from_which_year=2014 746 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('XHBX',XHBX_HK_merge_filepath,date_from_which_year) 747 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 748 | 749 | #广深铁路 750 | GSTL_A_filepath="C:\IBM-9\A_HK_XiangGuan\GSTL\A.csv" 751 | GSTL_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\GSTL\A_analysis.csv" 752 | GSTL_HK_filepath="C:\IBM-9\A_HK_XiangGuan\GSTL\HK.csv" 753 | GSTL_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\GSTL\HK_analysis.csv" 754 | GSTL_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\GSTL\Merge.csv" 755 | GetValue('GSTL','sh601333',GSTL_A_filepath, GSTL_A_analysis_filepath) 756 | GetValue('GSTL','hk00525', GSTL_HK_filepath,GSTL_HK_analysis_filepath) 757 | Merge_data('GSTL',GSTL_A_analysis_filepath,GSTL_HK_analysis_filepath,GSTL_HK_merge_filepath) 758 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\GSTL\Visual.html" 759 | #2014年以来的数据 760 | date_from_which_year=2014 761 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('GSTL',GSTL_HK_merge_filepath,date_from_which_year) 762 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 763 | 764 | #中信银行 765 | ZXYH_A_filepath="C:\IBM-9\A_HK_XiangGuan\ZXYH\A.csv" 766 | ZXYH_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZXYH\A_analysis.csv" 767 | ZXYH_HK_filepath="C:\IBM-9\A_HK_XiangGuan\ZXYH\HK.csv" 768 | ZXYH_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZXYH\HK_analysis.csv" 769 | ZXYH_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\ZXYH\Merge.csv" 770 | GetValue('ZXYH','sh601998',ZXYH_A_filepath, ZXYH_A_analysis_filepath) 771 | GetValue('ZXYH','hk00998', ZXYH_HK_filepath,ZXYH_HK_analysis_filepath) 772 | Merge_data('ZXYH',ZXYH_A_analysis_filepath,ZXYH_HK_analysis_filepath,ZXYH_HK_merge_filepath) 773 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\ZXYH\Visual.html" 774 | #2014年以来的数据 775 | date_from_which_year=2014 776 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('ZXYH',ZXYH_HK_merge_filepath,date_from_which_year) 777 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 778 | 779 | #晨鸣纸业 780 | CMZY_A_filepath="C:\IBM-9\A_HK_XiangGuan\CMZY\A.csv" 781 | CMZY_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\CMZY\A_analysis.csv" 782 | CMZY_HK_filepath="C:\IBM-9\A_HK_XiangGuan\CMZY\HK.csv" 783 | CMZY_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\CMZY\HK_analysis.csv" 784 | CMZY_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\CMZY\Merge.csv" 785 | GetValue('CMZY','sz000488',CMZY_A_filepath, CMZY_A_analysis_filepath) 786 | GetValue('CMZY','hk01812', CMZY_HK_filepath,CMZY_HK_analysis_filepath) 787 | Merge_data('CMZY',CMZY_A_analysis_filepath,CMZY_HK_analysis_filepath,CMZY_HK_merge_filepath) 788 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\CMZY\Visual.html" 789 | #2014年以来的数据 790 | date_from_which_year=2014 791 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('CMZY',CMZY_HK_merge_filepath,date_from_which_year) 792 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 793 | 794 | 795 | #金风科技 796 | JFKJ_A_filepath="C:\IBM-9\A_HK_XiangGuan\JFKJ\A.csv" 797 | JFKJ_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\JFKJ\A_analysis.csv" 798 | JFKJ_HK_filepath="C:\IBM-9\A_HK_XiangGuan\JFKJ\HK.csv" 799 | JFKJ_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\JFKJ\HK_analysis.csv" 800 | JFKJ_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\JFKJ\Merge.csv" 801 | GetValue('JFKJ','sz002202',JFKJ_A_filepath, JFKJ_A_analysis_filepath) 802 | GetValue('JFKJ','hk02208', JFKJ_HK_filepath,JFKJ_HK_analysis_filepath) 803 | Merge_data('JFKJ',JFKJ_A_analysis_filepath,JFKJ_HK_analysis_filepath,JFKJ_HK_merge_filepath) 804 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\JFKJ\Visual.html" 805 | #2014年以来的数据 806 | date_from_which_year=2014 807 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('JFKJ',JFKJ_HK_merge_filepath,date_from_which_year) 808 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 809 | 810 | #中兴通讯 811 | ZXTX_A_filepath="C:\IBM-9\A_HK_XiangGuan\ZXTX\A.csv" 812 | ZXTX_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZXTX\A_analysis.csv" 813 | ZXTX_HK_filepath="C:\IBM-9\A_HK_XiangGuan\ZXTX\HK.csv" 814 | ZXTX_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZXTX\HK_analysis.csv" 815 | ZXTX_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\ZXTX\Merge.csv" 816 | GetValue('ZXTX','sz000063',ZXTX_A_filepath, ZXTX_A_analysis_filepath) 817 | GetValue('ZXTX','hk00763', ZXTX_HK_filepath,ZXTX_HK_analysis_filepath) 818 | Merge_data('ZXTX',ZXTX_A_analysis_filepath,ZXTX_HK_analysis_filepath,ZXTX_HK_merge_filepath) 819 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\ZXTX\Visual.html" 820 | #2014年以来的数据 821 | date_from_which_year=2014 822 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('ZXTX',ZXTX_HK_merge_filepath,date_from_which_year) 823 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 824 | 825 | 826 | NYYH_A_filepath="C:\\IBM-9\\A_HK_XiangGuan\\NYYH\\A.csv" 827 | NYYH_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\NYYH\A_analysis.csv" 828 | NYYH_HK_filepath="C:\IBM-9\A_HK_XiangGuan\NYYH\HK.csv" 829 | NYYH_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\NYYH\HK_analysis.csv" 830 | NYYH_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\NYYH\Merge.csv" 831 | GetValue('NYYH','sh601288',NYYH_A_filepath, NYYH_A_analysis_filepath) 832 | GetValue('NYYH','hk01288', NYYH_HK_filepath,NYYH_HK_analysis_filepath) 833 | Merge_data('NYYH',NYYH_A_analysis_filepath,NYYH_HK_analysis_filepath,NYYH_HK_merge_filepath) 834 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\NYYH\Visual.html" 835 | #2014年以来的数据 836 | date_from_which_year=2014 837 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('NYYH',NYYH_HK_merge_filepath,date_from_which_year) 838 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 839 | 840 | NHGS_A_filepath="C:\IBM-9\A_HK_XiangGuan\NHGS\A.csv" 841 | NHGS_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\NHGS\A_analysis.csv" 842 | NHGS_HK_filepath="C:\IBM-9\A_HK_XiangGuan\NHGS\HK.csv" 843 | NHGS_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\NHGS\HK_analysis.csv" 844 | NHGS_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\NHGS\Merge.csv" 845 | GetValue('NHGS','sh600377',NHGS_A_filepath, NHGS_A_analysis_filepath) 846 | GetValue('NHGS','hk00177', NHGS_HK_filepath,NHGS_HK_analysis_filepath) 847 | Merge_data('NHGS',NHGS_A_analysis_filepath,NHGS_HK_analysis_filepath,NHGS_HK_merge_filepath) 848 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\NHGS\Visual.html" 849 | #2014年以来的数据 850 | date_from_which_year=2014 851 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('NHGS',NHGS_HK_merge_filepath,date_from_which_year) 852 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 853 | 854 | HLSN_A_filepath="C:\IBM-9\A_HK_XiangGuan\HLSN\A.csv" 855 | HLSN_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\HLSN\A_analysis.csv" 856 | HLSN_HK_filepath="C:\IBM-9\A_HK_XiangGuan\HLSN\HK.csv" 857 | HLSN_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\HLSN\HK_analysis.csv" 858 | HLSN_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\HLSN\Merge.csv" 859 | GetValue('HLSN','sh600585',HLSN_A_filepath, HLSN_A_analysis_filepath) 860 | GetValue('HLSN','hk00914', HLSN_HK_filepath,HLSN_HK_analysis_filepath) 861 | Merge_data('HLSN',HLSN_A_analysis_filepath,HLSN_HK_analysis_filepath,HLSN_HK_merge_filepath) 862 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\HLSN\Visual.html" 863 | #2014年以来的数据 864 | date_from_which_year=2014 865 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('HLSN',HLSN_HK_merge_filepath,date_from_which_year) 866 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 867 | 868 | ZGPA_A_filepath="C:\IBM-9\A_HK_XiangGuan\ZGPA\A.csv" 869 | ZGPA_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZGPA\A_analysis.csv" 870 | ZGPA_HK_filepath="C:\IBM-9\A_HK_XiangGuan\ZGPA\HK.csv" 871 | ZGPA_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\ZGPA\HK_analysis.csv" 872 | ZGPA_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\ZGPA\Merge.csv" 873 | GetValue('ZGPA','sh601318',ZGPA_A_filepath, ZGPA_A_analysis_filepath) 874 | GetValue('ZGPA','hk02318', ZGPA_HK_filepath,ZGPA_HK_analysis_filepath) 875 | Merge_data('ZGPA',ZGPA_A_analysis_filepath,ZGPA_HK_analysis_filepath,ZGPA_HK_merge_filepath) 876 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\ZGPA\Visual.html" 877 | #2014年以来的数据 878 | date_from_which_year=2014 879 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('ZGPA',ZGPA_HK_merge_filepath,date_from_which_year) 880 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 881 | 882 | GFZQ_A_filepath="C:\IBM-9\A_HK_XiangGuan\GFZQ\A.csv" 883 | GFZQ_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\GFZQ\A_analysis.csv" 884 | GFZQ_HK_filepath="C:\IBM-9\A_HK_XiangGuan\GFZQ\HK.csv" 885 | GFZQ_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\GFZQ\HK_analysis.csv" 886 | GFZQ_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\GFZQ\Merge.csv" 887 | GetValue('GFZQ','sz000776',GFZQ_A_filepath, GFZQ_A_analysis_filepath) 888 | GetValue('GFZQ','hk01776', GFZQ_HK_filepath,GFZQ_HK_analysis_filepath) 889 | Merge_data('GFZQ',GFZQ_A_analysis_filepath,GFZQ_HK_analysis_filepath,GFZQ_HK_merge_filepath) 890 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\GFZQ\Visual.html" 891 | #2014年以来的数据 892 | date_from_which_year=2014 893 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('GFZQ',GFZQ_HK_merge_filepath,date_from_which_year) 894 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 895 | 896 | WCDL_A_filepath="C:\IBM-9\A_HK_XiangGuan\WCDL\A.csv" 897 | WCDL_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\WCDL\A_analysis.csv" 898 | WCDL_HK_filepath="C:\IBM-9\A_HK_XiangGuan\WCDL\HK.csv" 899 | WCDL_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\WCDL\HK_analysis.csv" 900 | WCDL_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\WCDL\Merge.csv" 901 | GetValue('WCDL','sz000338',WCDL_A_filepath, WCDL_A_analysis_filepath) 902 | GetValue('WCDL','hk02338', WCDL_HK_filepath,WCDL_HK_analysis_filepath) 903 | Merge_data('WCDL',WCDL_A_analysis_filepath,WCDL_HK_analysis_filepath,WCDL_HK_merge_filepath) 904 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\WCDL\Visual.html" 905 | #2014年以来的数据 906 | date_from_which_year=2014 907 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('WCDL',WCDL_HK_merge_filepath,date_from_which_year) 908 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 909 | 910 | AGGF_A_filepath="C:\IBM-9\A_HK_XiangGuan\AGGF\A.csv" 911 | AGGF_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\AGGF\A_analysis.csv" 912 | AGGF_HK_filepath="C:\IBM-9\A_HK_XiangGuan\AGGF\HK.csv" 913 | AGGF_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\AGGF\HK_analysis.csv" 914 | AGGF_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\AGGF\Merge.csv" 915 | GetValue('AGGF','sz000898',AGGF_A_filepath, AGGF_A_analysis_filepath) 916 | GetValue('AGGF','hk00347', AGGF_HK_filepath,AGGF_HK_analysis_filepath) 917 | Merge_data('AGGF',AGGF_A_analysis_filepath,AGGF_HK_analysis_filepath,AGGF_HK_merge_filepath) 918 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\AGGF\Visual.html" 919 | #2014年以来的数据 920 | date_from_which_year=2014 921 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('AGGF',AGGF_HK_merge_filepath,date_from_which_year) 922 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 923 | 924 | BYD_A_filepath="C:\IBM-9\A_HK_XiangGuan\BYD\A.csv" 925 | BYD_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\BYD\A_analysis.csv" 926 | BYD_HK_filepath="C:\IBM-9\A_HK_XiangGuan\BYD\HK.csv" 927 | BYD_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\BYD\HK_analysis.csv" 928 | BYD_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\BYD\Merge.csv" 929 | GetValue('BYD','sz002594',BYD_A_filepath, BYD_A_analysis_filepath) 930 | GetValue('BYD','hk01211', BYD_HK_filepath,BYD_HK_analysis_filepath) 931 | Merge_data('BYD',BYD_A_analysis_filepath,BYD_HK_analysis_filepath,BYD_HK_merge_filepath) 932 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\BYD\Visual.html" 933 | #2014年以来的数据 934 | date_from_which_year=2014 935 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('BYD',BYD_HK_merge_filepath,date_from_which_year) 936 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 937 | 938 | LZJT_A_filepath="C:\IBM-9\A_HK_XiangGuan\LZJT\A.csv" 939 | LZJT_A_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\LZJT\A_analysis.csv" 940 | LZJT_HK_filepath="C:\IBM-9\A_HK_XiangGuan\LZJT\HK.csv" 941 | LZJT_HK_analysis_filepath="C:\IBM-9\A_HK_XiangGuan\LZJT\HK_analysis.csv" 942 | LZJT_HK_merge_filepath="C:\IBM-9\A_HK_XiangGuan\LZJT\Merge.csv" 943 | GetValue('LZJT','sz000513',LZJT_A_filepath, LZJT_A_analysis_filepath) 944 | GetValue('LZJT','hk01513', LZJT_HK_filepath,LZJT_HK_analysis_filepath) 945 | Merge_data('LZJT',LZJT_A_analysis_filepath,LZJT_HK_analysis_filepath,LZJT_HK_merge_filepath) 946 | write_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\LZJT\Visual.html" 947 | #2014年以来的数据 948 | date_from_which_year=2014 949 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value=Analysis_Var_2_display_in_html('LZJT',LZJT_HK_merge_filepath,date_from_which_year) 950 | Write_2_html(write_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value) 951 | 952 | 953 | #测试后应该放在源码最后面 954 | df_1_all.to_csv("c:\9\df_1_all.csv") 955 | df_2_all.to_csv("c:\9\df_2_all.csv") 956 | df_3_all.to_csv("c:\9\df_3_all.csv") 957 | 958 | Top_N=10 959 | 960 | #如果前面有数值,然后碰到停牌什么的,可以使用之前的数据来替代NAN,这是可以说的过去的 961 | #但是对于一开始就是NAN的,建议取值为空更能反映问题 962 | df_1_all=df_1_all.fillna(method='ffill') 963 | df_2_all=df_2_all.fillna(method='ffill') 964 | df_3_all=df_3_all.fillna(method='ffill') 965 | 966 | n=len(df_1_all) 967 | df_1_all_ReadytoUP=df_1_all.T.sort_index(by=df_1_all.index[n-1]).head(Top_N).T 968 | df_1_all_ReadytoUP.to_csv(df_1_all_ReadytoUP_path) 969 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 970 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value=Analysis_Top10_Var_2_display_in_html(df_1_all_ReadytoUP_path,2016) 971 | write_TopN_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\df_1_all_ReadytoUP.html" 972 | Write_2_html(write_TopN_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 973 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value) 974 | 975 | n=len(df_2_all) 976 | df_2_all_ReadytoUP=df_2_all.T.sort_index(by=df_2_all.index[n-1]).head(Top_N).T 977 | df_2_all_ReadytoUP.to_csv(df_2_all_ReadytoUP_path) 978 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 979 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value=Analysis_Top10_Var_2_display_in_html(df_2_all_ReadytoUP_path,2015) 980 | write_TopN_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\df_2_all_ReadytoUP.html" 981 | Write_2_html(write_TopN_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 982 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value) 983 | 984 | n=len(df_3_all) 985 | df_3_all_ReadytoUP=df_3_all.T.sort_index(by=df_3_all.index[n-1]).head(Top_N).T 986 | df_3_all_ReadytoUP.to_csv(df_3_all_ReadytoUP_path) 987 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 988 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value=Analysis_Top10_Var_2_display_in_html(df_3_all_ReadytoUP_path,2014) 989 | write_TopN_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\df_3_all_ReadytoUP.html" 990 | Write_2_html(write_TopN_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 991 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value) 992 | 993 | n=len(df_1_all) 994 | df_1_all_ReadytoDown=df_1_all.T.sort_index(by=df_1_all.index[n-1]).tail(Top_N).T 995 | df_1_all_ReadytoDown.to_csv(df_1_all_ReadytoDown_path) 996 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 997 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value=Analysis_Top10_Var_2_display_in_html(df_1_all_ReadytoDown_path,2016) 998 | write_TopN_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\df_1_all_ReadytoDown.html" 999 | Write_2_html(write_TopN_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 1000 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value) 1001 | 1002 | n=len(df_2_all) 1003 | df_2_all_ReadytoDown=df_2_all.T.sort_index(by=df_2_all.index[n-1]).head(Top_N).T 1004 | df_2_all_ReadytoDown.to_csv(df_2_all_ReadytoDown_path) 1005 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 1006 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value=Analysis_Top10_Var_2_display_in_html(df_2_all_ReadytoDown_path,2015) 1007 | write_TopN_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\df_2_all_ReadytoDown.html" 1008 | Write_2_html(write_TopN_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 1009 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value) 1010 | 1011 | 1012 | n=len(df_3_all) 1013 | df_3_all_ReadytoDown=df_3_all.T.sort_index(by=df_3_all.index[n-1]).head(Top_N).T 1014 | df_3_all_ReadytoDown.to_csv(df_3_all_ReadytoDown_path) 1015 | title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 1016 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value=Analysis_Top10_Var_2_display_in_html(df_3_all_ReadytoDown_path,2014) 1017 | write_TopN_2_html_filepath="C:\IBM-9\A_HK_XiangGuan\df_3_all_ReadytoDown.html" 1018 | Write_2_html(write_TopN_2_html_filepath,title_str,Date_X_axis,Y1_name,Y1_Value,Y2_name,Y2_Value,Y3_name,Y3_Value,Y4_name,Y4_Value,Y5_name,Y5_Value,\ 1019 | Y6_name,Y6_Value,Y7_name,Y7_Value,Y8_name,Y8_Value,Y9_name,Y9_Value,Y10_name,Y10_Value) 1020 | --------------------------------------------------------------------------------