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


Python tushare.get_k_data方法代码示例

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


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

示例1: getSingleStockByTime

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def getSingleStockByTime(symbol, from_date, till_date):
    start = from_date.split('-')
    start_y, start_m, start_d = start[0], start[1], start[2] # starting date

    end = till_date.split('-')
    end_y, end_m, end_d = end[0], end[1], end[2] # until now
    
    repeat_times = 1
    message = ""
    df = pd.DataFrame()

    for _ in range(repeat_times): 
        try:
            data = ts.get_k_data(symbol)#, from_date, till_date)
            data.sort_index(ascending=True, inplace=True)
            return data, ""
        except Exception as e:
            message = symbol + " fetch exception: " + str(e)
            continue   
    return df, message 
开发者ID:doncat99,项目名称:StockRecommendSystem,代码行数:22,代码来源:Fetch_Data_Stock_CHN_Daily.py

示例2: getSingleStockByTime

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def getSingleStockByTime(symbol, from_date, till_date):
    start = from_date.split('-')
    start_y, start_m, start_d = start[0], start[1], start[2] # starting date

    end = till_date.split('-')
    end_y, end_m, end_d = end[0], end[1], end[2] # until now
    
    repeat_times = 1
    message = ""
    df = pd.DataFrame()

    for _ in range(repeat_times): 
        try:
            data = ts.get_k_data(symbol, ktype='M')
            data.sort_index(ascending=True, inplace=True)
            return data, ""
        except Exception as e:
            message = symbol + " fetch exception: " + str(e)
            continue   
    return df, message 
开发者ID:doncat99,项目名称:StockRecommendSystem,代码行数:22,代码来源:Fetch_Data_Stock_CHN_Monthly.py

示例3: dptb

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def dptb(df, n=7):
    """
    大盘同步指标	dptb(7)
    DPTB=(统计N天中个股收盘价>开盘价,且指数收盘价>开盘价的天数或者个股收盘价<开盘价,且指数收盘价<开盘价)/N
    """
    ind = ts.get_k_data("sh000001", start=df.date.iloc[0], end=df.date.iloc[-1])
    sd = df.copy()
    sd.set_index('date', inplace=True)  # 可能出现停盘等情况,所以将date设为index
    ind.set_index('date', inplace=True)
    _dptb = pd.DataFrame(index=df.date)
    q = ind.close - ind.open
    _dptb['p'] = sd.close - sd.open
    _dptb['q'] = q
    _dptb['m'] = _dptb.apply(lambda x: 1 if (x.p > 0 and x.q > 0) or (x.p < 0 and x.q < 0) else np.nan, axis=1)
    _dptb['jdrs'] = _dptb.m.rolling(n).count() / n
    _dptb.drop(columns=['p', 'q', 'm'], inplace=True)
    _dptb.reset_index(inplace=True)
    return _dptb 
开发者ID:waditu,项目名称:tushare,代码行数:20,代码来源:trendline.py

示例4: jdqs

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def jdqs(df, n=20):
    """
    阶段强势指标	jdqs(20)
    JDQS=(统计N天中个股收盘价>开盘价,且指数收盘价<开盘价的天数)/(统计N天中指数收盘价<开盘价的天数)
    """
    ind = ts.get_k_data("sh000001", start=df.date.iloc[0], end=df.date.iloc[-1])
    sd = df.copy()
    sd.set_index('date', inplace=True)   # 可能出现停盘等情况,所以将date设为index
    ind.set_index('date', inplace=True)
    _jdrs = pd.DataFrame(index=df.date)
    q = ind.close - ind.open
    _jdrs['p'] = sd.close - sd.open
    _jdrs['q'] = q
    _jdrs['m'] = _jdrs.apply(lambda x: 1 if (x.p > 0 and x.q < 0) else np.nan, axis=1)
    q[q > 0] = np.nan
    _jdrs['t'] = q
    _jdrs['jdrs'] = _jdrs.m.rolling(n).count() / _jdrs.t.rolling(n).count()
    _jdrs.drop(columns=['p', 'q', 'm', 't'], inplace=True)
    _jdrs.reset_index(inplace=True)
    return _jdrs 
开发者ID:waditu,项目名称:tushare,代码行数:22,代码来源:trendline.py

示例5: jdrs

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def jdrs(df, n=20):
    """
    阶段弱势指标	jdrs(20)
    JDRS=(统计N天中个股收盘价<开盘价,且指数收盘价>开盘价的天数)/(统计N天中指数收盘价>开盘价的天数)
    """
    ind = ts.get_k_data("sh000001", start=df.date.iloc[0], end=df.date.iloc[-1])
    sd = df.copy()
    sd.set_index('date', inplace=True)
    ind.set_index('date', inplace=True)
    _jdrs = pd.DataFrame(index=df.date)
    q = ind.close - ind.open
    _jdrs['p'] = sd.close - sd.open
    _jdrs['q'] = q
    _jdrs['m'] = _jdrs.apply(lambda x: 1 if (x.p < 0 and x.q > 0) else np.nan, axis=1)
    q[q < 0] = np.nan
    _jdrs['t'] = q
    _jdrs['jdrs'] = _jdrs.m.rolling(n).count() / _jdrs.t.rolling(n).count()
    _jdrs.drop(columns=['p', 'q', 'm', 't'], inplace=True)
    _jdrs.reset_index(inplace=True)
    return _jdrs 
开发者ID:waditu,项目名称:tushare,代码行数:22,代码来源:trendline.py

示例6: _load_from_api

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def _load_from_api(self, code, start, end, ktype, autype, index):
        d = dict(code=code, ktype=ktype)

        if start:
            d["start"] = start

        if end:
            d["end"] = end

        df = ts.get_k_data(**d)
        df.reset_index(drop=True, inplace=True)
        j = df.to_json()
        data = json.loads(j)

        df_len = len(df)

        return data, df_len 
开发者ID:Chandlercjy,项目名称:OnePy,代码行数:19,代码来源:tushare_saver.py

示例7: getSingleStock

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def getSingleStock(symbol):
    repeat_times = 1
    message = ""
    df = pd.DataFrame()

    for _ in range(repeat_times): 
        try:
            data = ts.get_k_data(symbol)
            data.sort_index(ascending=True, inplace=True)
            return data, ""
        except Exception as e:
            message = symbol + " fetch exception: " + str(e)
            continue   
    return df, message 
开发者ID:doncat99,项目名称:StockRecommendSystem,代码行数:16,代码来源:Fetch_Data_Stock_CHN_Daily.py

示例8: getSingleStock

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def getSingleStock(symbol):
    repeat_times = 1
    message = ""
    df = pd.DataFrame()

    for _ in range(repeat_times): 
        try:
            data = ts.get_k_data(symbol, ktype='M')
            data.sort_index(ascending=True, inplace=True)
            return data, ""
        except Exception as e:
            message = symbol + " fetch exception: " + str(e)
            continue   
    return df, message 
开发者ID:doncat99,项目名称:StockRecommendSystem,代码行数:16,代码来源:Fetch_Data_Stock_CHN_Monthly.py

示例9: getSingleStock

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def getSingleStock(symbol):
    repeat_times = 1
    message = ""
    df = pd.DataFrame()

    for _ in range(repeat_times): 
        try:
            data = ts.get_k_data(symbol, ktype='W')
            data.sort_index(ascending=True, inplace=True)
            return data, ""
        except Exception as e:
            message = symbol + " fetch exception: " + str(e)
            continue   
    return df, message 
开发者ID:doncat99,项目名称:StockRecommendSystem,代码行数:16,代码来源:Fetch_Data_Stock_CHN_Weekly.py

示例10: get_single_stock_data_daily

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def get_single_stock_data_daily(root_path, symbol):
    '''
    All data is from quandl wiki dataset
    Feature set: [Open  High    Low  Close    Volume  Ex-Dividend  Split Ratio Adj. Open  Adj. High  Adj. Low
    Adj. Close  Adj. Volume]
    '''
    #df, lastUpdateTime = queryStock(root_path, "DB_STOCK", "SHEET_CHN", "_DAILY", symbol, "daily_update")
    try:
        df = ts.get_k_data(symbol)
        df.set_index('date', inplace=True)
        df.sort_index(ascending=True, inplace=True)
    except:
        print("stock delisted", symbol)
        return pd.DataFrame()

    if df.empty:
        print("stock delisted", symbol)
        return pd.DataFrame()

    out_path = root_path + "/Data/CSV/symbols/"

    if os.path.exists(out_path) == False:
        os.mkdir(out_path)

    out_file = out_path + symbol + ".csv"
    df.to_csv(out_file)

    return df 
开发者ID:doncat99,项目名称:StockRecommendSystem,代码行数:30,代码来源:Filter_Stock_Cashflow_CHN.py

示例11: get_tushare_k_data

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def get_tushare_k_data(instrument, start_dt, end_dt):
        order_book_id = instrument.order_book_id
        code = order_book_id.split(".")[0]

        if instrument.type == 'CS':
            index = False
        elif instrument.type == 'INDX':
            index = True
        else:
            return None

        return ts.get_k_data(code, index=index, start=start_dt.strftime('%Y-%m-%d'), end=end_dt.strftime('%Y-%m-%d')) 
开发者ID:ricequant,项目名称:rqalpha-mod-tushare,代码行数:14,代码来源:data_source.py

示例12: tapi

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def tapi(df, n=6):
    """ # TODO: 由于get_k_data返回数据中没有amount,可以用get_h_data中amount,算法是正确的
    加权指数成交值	tapi(6)
    TAPI=每日成交总值/当日加权指数=a/PI;A表示每日的成交金额,PI表示当天的股价指数即指收盘价
    """
    _tapi = pd.DataFrame()
    # _tapi['date'] = df.date
    _tapi['tapi'] = df.amount / df.close
    _tapi['matapi'] = _ma(_tapi.tapi, n)
    return _tapi 
开发者ID:waditu,项目名称:tushare,代码行数:12,代码来源:trendline.py

示例13: test_plot_all

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def test_plot_all(self):
        data = ts.get_k_data("601398", start="2018-01-01", end="2018-05-27")

        data = data.sort_values(by=["date"], ascending=True)

        idx.plot_all(data, is_show=True, output=None) 
开发者ID:waditu,项目名称:tushare,代码行数:8,代码来源:indictor_test.py

示例14: k_data

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def k_data(index,mode='D'):

    if mode == 'D':
        df_to_mysql('anack_d_k_data',ts.get_k_data(index))
    elif mode == 'M':
        df_to_mysql('anack_m_k_data',ts.get_k_data(index,ktype='M'))
        
#------------------------------------------------------------------------------
#create_k_table()
#k_data('600660') 
#k_data('600660','M') 
开发者ID:YinChao126,项目名称:anack,代码行数:13,代码来源:k_data_to_sql.py

示例15: k_day

# 需要导入模块: import tushare [as 别名]
# 或者: from tushare import get_k_data [as 别名]
def k_day(index,mode='D'):

    if mode == 'D':
        return ts.get_k_data(index)
    elif mode == 'M':
        return ts.get_k_data(index,ktype='M') 
开发者ID:YinChao126,项目名称:anack,代码行数:8,代码来源:basic.py


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