def get_nav_close(fund_type='all', sub_type='all'): """ 获取封闭型基金净值数据 Parameters ------ type:string 封闭基金类型: 1. all 所有封闭型基金 2. fbqy 封闭-权益 3. fbzq 封闭债券 sub_type:string 基金子类型: 1. type=all sub_type无效 2. type=fbqy 封闭-权益 *all 全部封闭权益 *ct 传统封基 *cx 创新封基 3. type=fbzq 封闭债券 *all 全部封闭债券 *wj 稳健债券型 *jj 激进债券型 *cz 纯债债券型 return ------- DataFrame 开放型基金净值数据(DataFrame): symbol 基金代码 sname 基金名称 per_nav 单位净值 total_nav 累计净值 nav_rate 增长率(%) discount_rate 折溢价率(%) nav_date 净值日期 start_date 成立日期 end_date 到期日期 fund_manager 基金经理 jjlx 基金类型 jjzfe 基金总份额 """ ct._write_head() nums = _get_fund_num(ct.SINA_NAV_COUNT_URL % (ct.P_TYPE['http'], ct.DOMAINS['vsf'], ct.NAV_CLOSE_KEY, ct.NAV_CLOSE_API, ct.NAV_CLOSE_T2[fund_type], ct.NAV_CLOSE_T3[sub_type])) fund_df = _parse_fund_data(ct.SINA_NAV_DATA_URL % (ct.P_TYPE['http'], ct.DOMAINS['vsf'], ct.NAV_OPEN_KEY, ct.NAV_CLOSE_API, ct.NAV_DEFAULT_PAGE, nums, ct.NAV_CLOSE_T2[fund_type], ct.NAV_CLOSE_T3[sub_type]), 'close') return fund_df
def get_nav_open(fund_type='all', retry_count=3, pause=0.01, timeout=10): """ 获取开放型基金净值数据 Parameters ------ type:string 开放基金类型: 1. all 所有开放基金 2. equity 股票型开放基金 3. mix 混合型开放基金 4. bond 债券型开放基金 5. monetary 货币型开放基金 6. qdii QDII型开放基金 return ------- DataFrame 开放型基金净值数据(DataFrame): symbol 基金代码 sname 基金名称 per_nav 单位净值 total_nav 累计净值 yesterday_nav 前一日净值 nav_a 涨跌额 nav_rate 增长率(%) nav_date 净值日期 fund_manager 基金经理 jjlx 基金类型 jjzfe 基金总份额 """ if ct._check_nav_oft_input(fund_type) is True: ct._write_head() nums = _get_fund_num(ct.SINA_NAV_COUNT_URL % (ct.P_TYPE['http'], ct.DOMAINS['vsf'], ct.NAV_OPEN_KEY[fund_type], ct.NAV_OPEN_API[fund_type], ct.NAV_OPEN_T2[fund_type], ct.NAV_OPEN_T3), retry_count=retry_count, pause=pause, timeout=timeout) pages = 2 # 分两次请求数据 limit_cnt = int(nums/pages)+1 # 每次取的数量 fund_dfs = [] for page in range(1, pages+1): fund_dfs = _parse_fund_data(ct.SINA_NAV_DATA_URL % (ct.P_TYPE['http'], ct.DOMAINS['vsf'], ct.NAV_OPEN_KEY[fund_type], ct.NAV_OPEN_API[fund_type], page, limit_cnt, ct.NAV_OPEN_T2[fund_type], ct.NAV_OPEN_T3), retry_count=retry_count, pause=pause, timeout=timeout) return fund_dfs
def get_nav_close(fund_type='all', sub_type='all'): """ 获取封闭型基金净值数据 Parameters ------ type:string 封闭基金类型: 1. all 所有封闭型基金 2. fbqy 封闭-权益 3. fbzq 封闭债券 sub_type:string 基金子类型: 1. type=all sub_type无效 2. type=fbqy 封闭-权益 *all 全部封闭权益 *ct 传统封基 *cx 创新封基 3. type=fbzq 封闭债券 *all 全部封闭债券 *wj 稳健债券型 *jj 激进债券型 *cz 纯债债券型 return ------- DataFrame 开放型基金净值数据(DataFrame): symbol 基金代码 sname 基金名称 per_nav 单位净值 total_nav 累计净值 nav_rate 增长率(%) discount_rate 折溢价率(%) nav_date 净值日期 start_date 成立日期 end_date 到期日期 fund_manager 基金经理 jjlx 基金类型 jjzfe 基金总份额 """ ct._write_head() nums = _get_fund_num(ct.SINA_NAV_COUNT_URL % (ct.P_TYPE['http'], ct.DOMAINS['vsf'], ct.NAV_CLOSE_KEY, ct.NAV_CLOSE_API, ct.NAV_CLOSE_T2[fund_type], ct.NAV_CLOSE_T3[sub_type])) fund_df = _parse_fund_data(ct.SINA_NAV_DATA_URL % (ct.P_TYPE['http'], ct.DOMAINS['vsf'], ct.NAV_OPEN_KEY, ct.NAV_CLOSE_API, nums, ct.NAV_CLOSE_T2[fund_type], ct.NAV_CLOSE_T3[sub_type]), 'close') return fund_df
def get_nav_grading(fund_type='all', sub_type='all'): """ 获取分级子基金净值数据 Parameters ------ type:string 封闭基金类型: 1. all 所有分级基金 2. fjgs 分级-固收 3. fjgg 分级-杠杆 sub_type:string 基金子类型(type=all sub_type无效): *all 全部分级债券 *wjzq 稳健债券型 *czzq 纯债债券型 *jjzq 激进债券型 *gp 股票型 *zs 指数型 return ------- DataFrame 开放型基金净值数据(DataFrame): symbol 基金代码 sname 基金名称 per_nav 单位净值 total_nav 累计净值 nav_rate 增长率(%) discount_rate 折溢价率(%) nav_date 净值日期 start_date 成立日期 end_date 到期日期 fund_manager 基金经理 jjlx 基金类型 jjzfe 基金总份额 """ ct._write_head() nums = _get_fund_num(ct.SINA_NAV_COUNT_URL % (ct.P_TYPE['http'], ct.DOMAINS['vsf'], ct.NAV_GRADING_KEY, ct.NAV_GRADING_API, ct.NAV_GRADING_T2[fund_type], ct.NAV_GRADING_T3[sub_type])) fund_df = _parse_fund_data(ct.SINA_NAV_DATA_URL % (ct.P_TYPE['http'], ct.DOMAINS['vsf'], ct.NAV_GRADING_KEY, ct.NAV_GRADING_API, ct.NAV_DEFAULT_PAGE, nums, ct.NAV_GRADING_T2[fund_type], ct.NAV_GRADING_T3[sub_type]), 'grading') return fund_df
def get_nav_open(fund_type='all'): """ 获取开放型基金净值数据 Parameters ------ type:string 开放基金类型: 1. all 所有开放基金 2. equity 股票型开放基金 3. mix 混合型开放基金 4. bond 债券型开放基金 5. monetary 货币型开放基金 6. qdii QDII型开放基金 return ------- DataFrame 开放型基金净值数据(DataFrame): symbol 基金代码 sname 基金名称 per_nav 单位净值 total_nav 累计净值 yesterday_nav 前一日净值 nav_a 涨跌额 nav_rate 增长率(%) nav_date 净值日期 fund_manager 基金经理 jjlx 基金类型 jjzfe 基金总份额 """ if ct._check_nav_oft_input(fund_type) is True: ct._write_head() nums = _get_fund_num(ct.SINA_NAV_COUNT_URL % (ct.P_TYPE['http'], ct.DOMAINS['vsf'], ct.NAV_OPEN_KEY[fund_type], ct.NAV_OPEN_API[fund_type], ct.NAV_OPEN_T2[fund_type], ct.NAV_OPEN_T3)) pages = 2 # 分两次请求数据 limit_cnt = int(nums/pages)+1 # 每次取的数量 fund_dfs = [] for page in range(1, pages+1): fund_dfs = _parse_fund_data(ct.SINA_NAV_DATA_URL % (ct.P_TYPE['http'], ct.DOMAINS['vsf'], ct.NAV_OPEN_KEY[fund_type], ct.NAV_OPEN_API[fund_type], page, limit_cnt, ct.NAV_OPEN_T2[fund_type], ct.NAV_OPEN_T3)) return pd.concat(fund_dfs, ignore_index=True)
def get_nav_history(code, start=None, end=None, retry_count=3, pause=0.001, timeout=10): ''' 获取历史净值数据 Parameters ------ code:string 基金代码 e.g. 000001 start:string 开始日期 format:YYYY-MM-DD 为空时取当前日期 end:string 结束日期 format:YYYY-MM-DD 为空时取去年今日 retry_count : int, 默认 3 如遇网络等问题重复执行的次数 pause : int, 默认 0 重复请求数据过程中暂停的秒数,防止请求间隔时间太短出现的问题 timeout: int 默认 10s 请求大量数据时的网络超时 return ------- DataFrame date 发布日期 (index) value 基金净值(股票/混合/QDII型基金) / 年华收益(货币/债券基金) total 累计净值(股票/混合/QDII型基金) / 万分收益(货币/债券基金) change 净值增长率(股票/混合/QDII型基金) ''' start = du.today_last_year() if start is None else start end = du.today() if end is None else end # 判断基金类型 ismonetary = False # 是否是债券型和货币型基金 df_fund = get_fund_info(code) fund_type = df_fund.ix[0]['Type2Name'] if fund_type is not None: if (fund_type.find(u'债券型') != -1) or (fund_type.find(u'货币型') != -1): ismonetary = True ct._write_head() nums = _get_nav_histroy_num(code, start, end, ismonetary) data = _parse_nav_history_data(code, start, end, nums, ismonetary, retry_count, pause, timeout) return data
def get_nav_open(fund_type='all'): """ 获取开放型基金净值数据 Parameters ------ type:string 开放基金类型: 1. all 所有开放基金 2. equity 股票型开放基金 3. mix 混合型开放基金 4. bond 债券型开放基金 5. monetary 货币型开放基金 6. qdii QDII型开放基金 return ------- DataFrame 开放型基金净值数据(DataFrame): symbol 基金代码 sname 基金名称 per_nav 单位净值 total_nav 累计净值 yesterday_nav 前一日净值 nav_a 涨跌额 nav_rate 增长率(%) nav_date 净值日期 fund_manager 基金经理 jjlx 基金类型 jjzfe 基金总份额 """ if ct._check_nav_oft_input(fund_type) is True: ct._write_head() nums = _get_fund_num(ct.SINA_NAV_COUNT_URL % (ct.P_TYPE['http'], ct.DOMAINS['vsf'], ct.NAV_OPEN_KEY[fund_type], ct.NAV_OPEN_API[fund_type], ct.NAV_OPEN_T2[fund_type], ct.NAV_OPEN_T3)) fund_df = _parse_fund_data(ct.SINA_NAV_DATA_URL % (ct.P_TYPE['http'], ct.DOMAINS['vsf'], ct.NAV_OPEN_KEY[fund_type], ct.NAV_OPEN_API[fund_type], nums, ct.NAV_OPEN_T2[fund_type], ct.NAV_OPEN_T3)) return fund_df
def get_nav_history(code, start=None, end=None, retry_count=3, pause=0.001, timeout=10): ''' 获取历史净值数据 Parameters ------ code:string 基金代码 e.g. 000001 start:string 开始日期 format:YYYY-MM-DD 为空时取当前日期 end:string 结束日期 format:YYYY-MM-DD 为空时取去年今日 retry_count : int, 默认 3 如遇网络等问题重复执行的次数 pause : int, 默认 0 重复请求数据过程中暂停的秒数,防止请求间隔时间太短出现的问题 timeout: int 默认 10s 请求大量数据时的网络超时 return ------- DataFrame date 发布日期 (index) value 基金净值(股票/混合/QDII型基金) / 年华收益(货币/债券基金) total 累计净值(股票/混合/QDII型基金) / 万分收益(货币/债券基金) change 净值增长率(股票/混合/QDII型基金) ''' start = du.today_last_year() if start is None else start end = du.today() if end is None else end # 判断基金类型 ismonetary = False # 是否是债券型和货币型基金 df_fund = get_fund_info(code) fund_type = df_fund.ix[0]['Type2Name'] if (fund_type.find(u'债券型') != -1) or (fund_type.find(u'货币型') != -1): ismonetary = True ct._write_head() nums = _get_nav_histroy_num(code, start, end, ismonetary) data = _parse_nav_history_data( code, start, end, nums, ismonetary, retry_count, pause, timeout) return data