예제 #1
0
def get_live(sec_id, block_size=400):
    """
    :param sec_id: list, wind股票代码,如果是全市场,可输入'fulla'或者'ashare'
    :param block_size: 内部调用wsq接口一次提取的数量,默认400支
    :return: pd.DataFrame, index=sec id, header = [rt_open,rt_high,rt_low,rt_last,rt_vol,rt_amt,rt_vol_ratio,rt_pct_chg_5min]
    """
    factor = FactorLoader(start_date=None,
                          end_date=None,
                          factor_name='LIVE',
                          sec_id=sec_id,
                          block_size=block_size)
    ret = factor.load_data()
    return ret
예제 #2
0
파일: api.py 프로젝트: zion302/WindAdapter
def factor_load(start_date, end_date, factor_name, save_file=None, **kwargs):
    """
    :param start_date: str, 读取因子数据的开始日期
    :param end_date: str, 读取因子数据的结束日期
    :param factor_name: str, 因子名称,不区分大小写
    :param save_file: str, optional, 保存数据的文件名,可写成 '*.csv' 或者 '*.pkl'
    :param kwargs: dict, optional

            freq: str, optional, 因子数据的频率, 可选'M', 'W', 'Q', 'S', 'Y', 参见enums.py - FreqType
            tenor: str, optional, 因子数据的周期, 对于截面数据(如换手率,收益率),需要给定数据区间(向前), 可选数字+FreqType, 如'1Q'
            sec_id, str/list, optional, 股票代码或者是指数代码
            output_data_format: enum, optional, 参见enums.py - FreqType
                                MULTI_INDEX_DF: multi-index DataFrame, index=[date, secID], value = factor
                                PITVOT_TABLE_DF: DataFrame, index=date, columns = secID
            is_index: bool, optional, True: 输入的sec_id是指数,实际需要读取的是该指数成分股的因子数据,
                                      False: 直接读取sec_id的因子数据
            date_format: str, optional, 日期的格式, 默认'%Y-%m-%d'
    :return: pd.DataFrame 整理好的因子数据
    """
    if isinstance(factor_name, list):
        kwargs = merge(kwargs,
                       {'output_data_format': OutputFormat.MULTI_INDEX_DF})
        factor_names = factor_name
    else:
        factor_names = [factor_name]

    ret = pd.DataFrame()
    for factor_name in factor_names:
        LOGGER.info('Loading factor data {0}'.format(factor_name))
        factor_loader = FactorLoader(start_date=start_date,
                                     end_date=end_date,
                                     factor_name=factor_name,
                                     **kwargs)
        factor_data = factor_loader.load_data()
        LOGGER.info('factor data {0} is loaded '.format(factor_name))
        ret = pd.concat([ret, factor_data], axis=1)
    if kwargs.get('reset_col_names'):
        ret.columns = factor_names
    if save_file:
        save_data_to_file(ret, save_file)
        LOGGER.critical('Data saved in {0}'.format(save_file))
    return ret