当前位置: 首页>>代码示例>>Python>>正文


Python tushare.get_k_data函数代码示例

本文整理汇总了Python中tushare.get_k_data函数的典型用法代码示例。如果您正苦于以下问题:Python get_k_data函数的具体用法?Python get_k_data怎么用?Python get_k_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_k_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process

 def process(self):
     fo = open('shrink_code', 'w')
     oversold = open('oversold', 'w')
     week_shrink = open('week_shrink','w')
     #raw_data = TS.memchaced_data(ts.get_stock_basics,'get_stock_basics')
     raw_data = ts.get_stock_basics()
     raw_data['earn_ratio'] = raw_data['esp'] / raw_data['bvps']
     for code in raw_data.index:
         if code in bad_container:
             continue
         try:
             daydata = ts.get_k_data(code, ktype='D')
             ratio = judge_oversold(daydata)
             if ratio < -0.45:
                 oversold.write("{0}\t{1}\n".format(code, ratio))
                 weekdata = ts.get_k_data(code, ktype='W')
             if judge_week_shrinkage(code, 0.02):
                 week_shrink.write(code + '\n')
             if ratio > -0.3:
                 continue
             #if raw_data.ix[code]['earn_ratio'] < 0.05:
             #    continue
             totals = raw_data.ix[code]['totals']
             close = np.array(daydata['close'])[-1]
             if close < 6.5:
                 continue
             if close * totals > 360:
                 continue
             flag,mean = judge_shrinkage(daydata,0.02)
             if ratio > -0.3:
                 continue
             if flag != -1:
                 fo.write("{0}\t{1}\t{2:.1%}\n".format(flag,code, mean))
         except Exception, e:
                 print e
开发者ID:qyqbird,项目名称:stock_work,代码行数:35,代码来源:shrinkage.py

示例2: download_kline_by_date_range

def download_kline_by_date_range(code, date_start, date_end):
    """
    根据日期范围下载股票行情
    :param code:股票代码,即6位数字代码,或者指数代码(sh=上证指数 sz=深圳成指 hs300=沪深300指数 sz50=上证50 zxb=中小板 cyb=创业板)
    :param date_start:
    :param date_end:
    :return:
    """
    try:
        if len(code)==6:
            df_qfq = ts.get_k_data(str(code), start=date_start, end=date_end, autype='qfq') # 前复权
            df_hfq = ts.get_k_data(str(code), start=date_start, end=date_end, autype='hfq')  # 后复权
        else:
            df_qfq = ts.get_k_data(str(code), start=date_start, end=date_end)
        if len(df_qfq)==0 or (len(code)==6 and len(df_hfq)==0):
            return pd.DataFrame()

        if len(code)==6:
            df_qfq['close_hfq'] = df_hfq['close']
        else:
            df_qfq['close_hfq'] = df_qfq['close']  # 指数后复权=前复权

        print(df_qfq.head())

        return df_qfq
    except Exception as e:
        print(str(e))
        return pd.DataFrame()
开发者ID:cbbing,项目名称:stock,代码行数:28,代码来源:data_download.py

示例3: tang_process

    def tang_process(self):
        badarea = set(['黑龙江','辽宁','吉林'])
        raw_data = self.foundmental_data
        month_writer = open('month_health', 'w')
        week_writer = open('week_health', 'w')
        day_writer = open('day_health', 'w')
        for code in raw_data.index:
            earn_ratio = raw_data.ix[code]['earn_ratio']
            if raw_data.ix[code]['area'] in badarea:
                continue
            monthdata = ts.get_k_data(code, ktype='M')
            weekdata = ts.get_k_data(code, ktype='W')
            daydata = ts.get_k_data(code, ktype='D')

            if tang_method(monthdata, -0.8, 1.5):
                month_writer.write(code + '\t' + str(earn_ratio) + '\n')
                if tang_method(weekdata, -0.5, 0.8):
                    week_writer.write(code + '\t' + str(earn_ratio) + '\n')
                    if tang_method(daydata,-0.2, 0.6):
                        day_writer.write(code + '\t' + str(earn_ratio) + '\n')
                        print code
            sys.stdout.flush()

        month_writer.close()
        week_writer.close()
        day_writer.close()
开发者ID:qyqbird,项目名称:stock_work,代码行数:26,代码来源:tang_director.py

示例4: baseAPI

def baseAPI():
    # 通过tushare获取股票信息
    df = ts.get_k_data('300580', start='2017-01-12', end='2017-05-26')
    # 提取收盘价
    closed = df['close'].values
    # 获取均线的数据,通过timeperiod参数来分别获取 5,10,20 日均线的数据。
    ma5 = talib.SMA(closed, timeperiod=5)
    ma10 = talib.SMA(closed, timeperiod=10)
    ma20 = talib.SMA(closed, timeperiod=20)

    # 打印出来每一个数据
    print(closed)
    print(ma5)
    print(ma10)
    print(ma20)

    # 通过plog函数可以很方便的绘制出每一条均线
    plt.plot(closed)
    plt.plot(ma5)
    plt.plot(ma10)
    plt.plot(ma20)
    # 添加网格,可有可无,只是让图像好看点
    plt.grid()
    # 记得加这一句,不然不会显示图像
    plt.show()
开发者ID:Rockyzsu,项目名称:base_function,代码行数:25,代码来源:talib_testcase.py

示例5: ma_type_test

def ma_type_test():
    # MA_Type: 0=SMA, 1=EMA, 2=WMA, 3=DEMA, 4=TEMA, 5=TRIMA, 6=KAMA, 7=MAMA, 8=T3 (Default=SMA)
    df = ts.get_k_data('300580', start='2017-01-12', end='2017-05-26')
    closed = df['close'].values
    sma = talib.MA(closed, timeperiod=10, matype=0)
    ema = talib.MA(closed, timeperiod=10, matype=1)
    wma = talib.MA(closed, timeperiod=10, matype=2)
    dema = talib.MA(closed, timeperiod=10, matype=3)
    tema = talib.MA(closed, timeperiod=10, matype=4)
    trima = talib.MA(closed, timeperiod=10, matype=5)
    kma = talib.MA(closed, timeperiod=10, matype=6)
    mama = talib.MA(closed, timeperiod=10, matype=7)
    t3 = talib.MA(closed, timeperiod=10, matype=8)
    # ouput=talib.MA(closed,timeperiod=5,matype=0)
    print(closed)
    plt.ylim([0, 40])
    plt.plot(sma, 'r--')
    plt.plot(ema, 'g-*')
    plt.plot(wma)
    plt.plot(dema)
    plt.plot(tema)
    plt.plot(trima)
    plt.plot(kma)
    plt.plot(mama)
    plt.plot(t3)
    plt.grid()
    plt.text(7, 30, 'BST')

    plt.show()
开发者ID:Rockyzsu,项目名称:base_function,代码行数:29,代码来源:talib_testcase.py

示例6: prepare_stock_data

def prepare_stock_data(stock):
    stock_data = ts.get_k_data(stock)
    stock_data = stock_data.sort_values("date")
    stock_data = stock_data.set_index(["date"])
    stock_data = calculate_macd(stock_data)
    stock_data = calculate_change_aver(stock_data)
    return stock_data
开发者ID:ericsolo,项目名称:python,代码行数:7,代码来源:util.py

示例7: QA_fetch_get_stock_day

def QA_fetch_get_stock_day(name, startDate='', endDate='', if_fq='01', type_='json'):
    if (len(name) != 6):
        name = str(name)[0:6]

    if str(if_fq) in ['qfq', '01']:
        if_fq = 'qfq'
    elif str(if_fq) in ['hfq', '02']:
        if_fq = 'hfq'
    elif str(if_fq) in ['bfq', '00']:
        if_fq = 'bfq'
    else:
        QA_util_log_info('wrong with fq_factor! using qfq')
        if_fq = 'qfq'

    data = QATs.get_k_data(str(name), startDate, endDate,
                           ktype='D', autype=if_fq, retry_count=200, pause=0.005).sort_index()
    
    data['date_stamp'] = data['date'].apply(lambda x: QA_util_date_stamp(x))
    data['fqtype'] = if_fq
    if type_ in ['json']:
        data_json = QA_util_to_json_from_pandas(data)
        return data_json
    elif type_ in ['pd', 'pandas', 'p']:
        data['date'] = pd.to_datetime(data['date'])
        data = data.set_index('date',drop=False)
        data['date'] = data['date'].apply(lambda x: str(x)[0:10])
        return data
开发者ID:imsimplise,项目名称:QUANTAXIS,代码行数:27,代码来源:QATushare.py

示例8: calc_open_day

    def calc_open_day(self,code):
        cont=100000000
        #total_vol=self.bases[self.bases['code']==code]['totals'].values[0]
        acutal_vol=self.bases[self.bases['code']==code]['outstanding'].values[0]
        all_vol= acutal_vol*cont
        #df= ts.get_hist_data(code)
        df1=ts.get_k_data(code)
        if len(df1)<3:
            return None
        #print(df1.info())
        #df1=df.reset_index()
        #print(df1)
        start=df1['date'].values[0]
        print('Start day:', start)
        df2= df1[(df1['close']==df1['low']) & (df1['high']==df1['low'])]
        print(self.bases[self.bases['code']==code]['name'].values[0])
        end=df2['date'].values[-1]
        print("Break day" , end)

        df3=df1[(df1['date']>=start) & (df1['date']<=end)]
        v_total_break=df3['volume'].sum()
        l=len(df3)
        print(l)
        print(v_total_break)
        rate=v_total_break*100*100.00/all_vol #手和股 注意
        print(round(rate,6))
        return rate,l
开发者ID:Rockyzsu,项目名称:stock,代码行数:27,代码来源:new_stock_break.py

示例9: calc_open_by_percent

    def calc_open_by_percent(self,code):
        cont=100000000
        #total_vol=self.bases[self.bases['code']==code]['totals'].values[0]
        acutal_vol=self.bases[self.bases['code']==code]['outstanding'].values[0]
        all_vol= acutal_vol*cont
        df1=ts.get_k_data(code)
        i=1
        while 1:
            s=df1.ix[i]
            if s['high']!=s['low']:
                #date=s['date']
                break
            i=i+1

        j=i-1
        date_end=df1.ix[j]['date']
        date_start=df1.ix[0]['date']
        df3=df1[(df1['date']>=date_start) & (df1['date']<=date_end)]
        v_total_break=df3['volume'].sum()
        l=len(df3)
        print(l)
        print(v_total_break)
        rate=v_total_break*100*100.00/all_vol #手和股 注意
        print(round(rate,6))
        return rate,l
开发者ID:Rockyzsu,项目名称:stock,代码行数:25,代码来源:new_stock_break.py

示例10: gen_zz800_market_index_price_and_ratio

def gen_zz800_market_index_price_and_ratio(start, end):
    zz800_market_ratio = ts.get_k_data('000906', start=start, end=end, index=True)
    zz800_market_ratio.columns = zz800_market_ratio.columns.str.upper()
    file_path = '/data/gen_data/' + start + '_' + end + '_zz800_market_ratio' + '.csv'

    zz800_market_ratio['RATIO'] = zz800_market_ratio['CLOSE'].rolling(window=2).apply(lambda x: (x[1] - x[0]) / x[0])
    zz800_market_ratio[['DATE', 'CLOSE', 'RATIO']].to_csv(config.rootPath + file_path, index=False, header=True)
开发者ID:cheersyouran,项目名称:quantization,代码行数:7,代码来源:gen_data.py

示例11: process

 def process(self):
     week_shrink = open('week_shrink','w')
     raw_data = ts.get_stock_basics()
     raw_data['earn_ratio'] = raw_data['esp'] / raw_data['bvps']
     container = defaultdict(list)
     for code in raw_data.index:
         if code in bad_container:
             continue
         weekdata = ts.get_k_data(code, ktype='W')
         try:
             info = compute_foundation_info(code, weekdata, 36)
             if info['ratio'] > 0.2:
                 continue
             if not info['cross_flag'] and not info['nearcross_flag']:
                 continue
             if info['macdmean'] > 0.3:
                 continue
             assment = info['close'] * raw_data.ix[code]['totals']
             if info['week_shrink'] < 2 or info['close'] < 6 or assment > 1800:
                 continue
             for feature in features:
                 feature_value = info[feature]
                 container[feature].append(feature_value)
         except Exception,e:
             print "ERROR:{0}".format(code)
开发者ID:qyqbird,项目名称:stock_work,代码行数:25,代码来源:ModelSearch.py

示例12: _load_data

 def _load_data(self, code, dt_start, dt_end):
     dts = _process_ts_dt(dt_start)
     dte = _process_ts_dt(dt_end)
     data = ts.get_k_data(code, start=dts, end=dte)
     data.set_index('date',drop=True,inplace=True)
     data.index.names = ['datetime']
     return data.iloc[::-1]
开发者ID:QuantFans,项目名称:quantdigger,代码行数:7,代码来源:tushare_source.py

示例13: relation

 def relation(self):
     sh_index=ts.get_k_data('000001',index=True,start='2012-01-01')
     sh=sh_index['close'].values
     print sh
     vol_close=sh_index.corr()
     print vol_close
     '''
开发者ID:LiYinglin-Bruce-Lee,项目名称:stock,代码行数:7,代码来源:select_stock.py

示例14: k_15min_one_stock

def k_15min_one_stock(_stock_id, _db):
    # log_info("k_15min_one_stock begin")


    # get from web(by tushare)
    begin = get_micro_second()

    try:
        df = ts.get_k_data(_stock_id, ktype='15', autype='qfq')
    except Exception:
        log_error("warn:error: %s get_k_data exception!", _stock_id)
        return -4

    # calc cost time
    log_info("get_k_data [%s] costs %d ms", _stock_id, (get_micro_second()-begin)/1000)

    if df is None :
        log_error("warn: stock %s is None, next", _stock_id)
        return -1

    if df.empty:
        log_error("warn: stock %s is empty, next", _stock_id)
        return -2

    df.sort_index(ascending=False, inplace=True)

    begin = get_micro_second()

    k_15min_one_to_db(_stock_id, df, _db)

    log_info("one_to_db costs %d ms", (get_micro_second() - begin)/1000)

    # log_info("function k_15min_one_stock end")

    return 
开发者ID:saibye,项目名称:project,代码行数:35,代码来源:k_15min.py

示例15: macd

 def macd(self):
     # df=self.fetch_new_ipo(writeable=True)
     # all_code=df['code'].values
     # all_code=self.get_all_code()
     # print all_code
     result = []
     for each_code in self.all_code:
         print each_code
         try:
             df_x = ts.get_k_data(code=each_code, start='2017-03-01')
         # 只找最近一个月的,所以no item的是停牌。
         except:
             print "Can't get k_data"
             continue
         if len(df_x) < 11:
             # return
             print "no item"
             continue
         ma5 = df_x['close'][-5:].mean()
         ma10 = df_x['close'][-10:].mean()
         if ma5 > ma10:
             # print "m5>m10: ",each_code," ",self.base[self.base['code']==each_code]['name'].values[0], "ma5: ",ma5,' m10: ',ma10
             temp = [each_code, self.base[self.base['code'] == each_code]['name'].values[0]]
             print temp
             result.append(temp)
     print result
     print "Done"
     return result
开发者ID:LiYinglin-Bruce-Lee,项目名称:stock,代码行数:28,代码来源:select_stock.py


注:本文中的tushare.get_k_data函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。