當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。