本文整理汇总了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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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'))
示例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
示例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)
示例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')
示例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')