Exemple #1
0
 def load_tushare_bars(self, pcontract, dt_start, dt_end):
     import tushare as ts
     print "load stock data with tushare... (start=%s,end=%s)" % (dt_start, dt_end)
     if(pcontract.period._type == 'Minute' ):
         data = tick2period(pcontract.contract.code,
                            str(pcontract.period)[:-3].replace('.',''),
                            start=dt_start,
                            end=dt_end)
     elif(pcontract.period._type == 'Second' ):
         data = tick2period(pcontract.contract.code,
                            str(pcontract.period)[:-5].replace('.',''),
                            start=dt_start,
                            end=dt_end)
     else:
             
         #日线直接调用
         data = ts.get_hist_data(pcontract.contract.code,
                                 start=dt_start,
                                 end=dt_end)
         data.open = data.open.astype(float)
         data.close = data.close.astype(float)
         data.high = data.high.astype(float)
         data.low = data.low.astype(float)
         ## @todo bug: data.volume 里面有浮点值!
         data.volume = data.volume.astype(float)
         data.index.names = ['datetime']
         data.index = pd.to_datetime(data.index)
         return data
Exemple #2
0
 def load_tushare_bars(self, pcontract, dt_start, dt_end):
     import tushare as ts
     print "load stock data with tushare... (start=%s,end=%s)" % (dt_start,
                                                                  dt_end)
     if (pcontract.period._type == 'Minute'):
         data = tick2period(pcontract.contract.code,
                            str(pcontract.period)[:-3].replace('.', ''),
                            start=dt_start,
                            end=dt_end)
     elif (pcontract.period._type == 'Second'):
         data = tick2period(pcontract.contract.code,
                            str(pcontract.period)[:-5].replace('.', ''),
                            start=dt_start,
                            end=dt_end)
     else:
         #日线直接调用
         data = ts.get_hist_data(pcontract.contract.code,
                                 start=dt_start,
                                 end=dt_end)
         data.open = data.open.astype(float)
         data.close = data.close.astype(float)
         data.high = data.high.astype(float)
         data.low = data.low.astype(float)
         ## @todo bug: data.volume 里面有浮点值!
         data.volume = data.volume.astype(float)
         data.index.names = ['datetime']
         data.index = pd.to_datetime(data.index)
         return data