def shibor_ma_data(year=None): """ 获取Shibor均值数据 Parameters ------ year:年份(int) Return ------ date:日期 其它分别为各周期5、10、20均价 """ year = du.get_year() if year is None else year lab = ct.SHIBOR_TYPE['Tendency'] lab = lab.encode('utf-8') if ct.PY3 else lab try: df = pd.read_excel( ct.SHIBOR_DATA_URL % (ct.P_TYPE['http'], ct.DOMAINS['shibor'], ct.PAGES['dw'], 'Shibor_Tendency', year, lab, year), skiprows=[0]) df.columns = ct.SHIBOR_MA_COLS df['date'] = df['date'].map(lambda x: x.date()) df['date'] = df['date'].astype(np.datetime64) return df except: return None
def shibor_data(year=None): """ 获取上海银行间同业拆放利率(Shibor) Parameters ------ year:年份(int) Return ------ date:日期 ON:隔夜拆放利率 1W:1周拆放利率 2W:2周拆放利率 1M:1个月拆放利率 3M:3个月拆放利率 6M:6个月拆放利率 9M:9个月拆放利率 1Y:1年拆放利率 """ year = du.get_year() if year is None else year lab = ct.SHIBOR_TYPE['Shibor'] lab = lab.encode('utf-8') if ct.PY3 else lab try: df = pd.read_excel(ct.SHIBOR_DATA_URL % (ct.P_TYPE['http'], ct.DOMAINS['shibor'], ct.PAGES['dw'], 'Shibor', year, lab, year)) df.columns = ct.SHIBOR_COLS df['date'] = df['date'].map(lambda x: x.date()) df['date'] = df['date'].astype(np.datetime64) return df except: return None
def lpr_data(year=None): """ 获取贷款基础利率(LPR) Parameters ------ year:年份(int) Return ------ date:日期 1Y:1年贷款基础利率 """ year = du.get_year() if year is None else year lab = ct.SHIBOR_TYPE['LPR'] lab = lab.encode('utf-8') if ct.PY3 else lab try: df = pd.read_excel(ct.SHIBOR_DATA_URL % (ct.P_TYPE['http'], ct.DOMAINS['shibor'], ct.PAGES['dw'], 'LPR', year, lab, year)) df.columns = ct.LPR_COLS df['date'] = df['date'].map(lambda x: x.date()) df['date'] = df['date'].astype(np.datetime64) return df except: return None
def xsg_data(year=None, month=None, retry_count=3, pause=0.001): """ 获取限售股解禁数据 Parameters -------- year:年份,默认为当前年 month:解禁月份,默认为当前月 retry_count : int, 默认 3 如遇网络等问题重复执行的次数 pause : int, 默认 0 重复请求数据过程中暂停的秒数,防止请求间隔时间太短出现的问题 Return ------ DataFrame code:股票代码 name:名称 date:解禁日期 count:解禁数量(万股) ratio:占总盘比率 """ year = dt.get_year() if year is None else year month = dt.get_month() if month is None else month for _ in range(retry_count): time.sleep(pause) try: request = Request(rv.XSG_URL%(ct.P_TYPE['http'], ct.DOMAINS['em'], ct.PAGES['emxsg'], year, month)) lines = urlopen(request, timeout = 10).read() lines = lines.decode('utf-8') if ct.PY3 else lines except Exception as e: print(e) else: da = lines[3:len(lines)-3] list = [] for row in da.split('","'): list.append([data for data in row.split(',')]) df = pd.DataFrame(list) df = df[[1, 3, 4, 5, 6]] for col in [5, 6]: df[col] = df[col].astype(float) df[5] = df[5]/10000 df[6] = df[6]*100 df[5] = df[5].map(ct.FORMAT) df[6] = df[6].map(ct.FORMAT) df.columns = rv.XSG_COLS return df raise IOError(ct.NETWORK_URL_ERROR_MSG)
def shibor_quote_data(year=None): """ 获取Shibor银行报价数据 Parameters ------ year:年份(int) Return ------ date:日期 bank:报价银行名称 ON:隔夜拆放利率 ON_B:隔夜拆放买入价 ON_A:隔夜拆放卖出价 1W_B:1周买入 1W_A:1周卖出 2W_B:买入 2W_A:卖出 1M_B:买入 1M_A:卖出 3M_B:买入 3M_A:卖出 6M_B:买入 6M_A:卖出 9M_B:买入 9M_A:卖出 1Y_B:买入 1Y_A:卖出 """ year = du.get_year() if year is None else year lab = ct.SHIBOR_TYPE['Quote'] lab = lab.encode('utf-8') if ct.PY3 else lab try: df = pd.read_excel(ct.SHIBOR_DATA_URL % (ct.P_TYPE['http'], ct.DOMAINS['shibor'], ct.PAGES['dw'], 'Quote', year, lab, year), skiprows=[0]) df.columns = ct.QUOTE_COLS df['date'] = df['date'].map(lambda x: x.date()) df['date'] = df['date'].astype(np.datetime64) return df except: return None