多因子合成¶
内建对因子合成算法¶
- hikyuu.trade_sys.MF_EqualWeight(inds, stks, query, ref_stk[, ic_n=5])¶
等权重合成因子
- 参数:
- 返回类型:
- hikyuu.trade_sys.MF_ICWeight(inds, stks, query, ref_stk[, ic_n=5, ic_rolling_n=120])¶
滚动IC权重合成因子
- 参数:
- 返回类型:
- hikyuu.trade_sys.MF_ICIRWeight(inds, stks, query, ref_stk[, ic_n=5, ic_rolling_n=120])¶
滚动ICIR权重合成因子
- 参数:
- 返回类型:
自定义多因子合成算法基类¶
自定义多因子合成算法接口:
MultiFactorBase._calculate()
- 【必须】计算合成因子
多因子合成算法基类¶
- class hikyuu.trade_sys.MultiFactorBase¶
多因子合成基类
- name 名称
- __init__(self)¶
初始化构造函数
- 参数:
name (str) – 名称
- get_param(self, name)¶
获取指定的参数
- 参数:
name (str) – 参数名称
- 返回:
参数值
- 抛出:
out_of_range – 无此参数
- set_param(self, name, value)¶
设置参数
- 参数:
name (str) – 参数名称
value (int | bool | float | string) – 参数值
- 抛出:
logic_error – Unsupported type! 不支持的参数类型
- clone(self)¶
克隆操作
- get_query(self)¶
查询条件范围
- get_ref_stock(self)¶
获取参考证券
- get_stock_list(self)¶
获取创建时指定的证券列表
- get_stock_list_num(self)¶
获取创建时指定的证券列表中证券数量
- get_datetime_list(self)¶
获取参考日期列表(由参考证券通过查询条件获得)
- get_ref_indicators(self)¶
获取创建时输入的原始因子列表
- get_all_factors(self)¶
获取所有证券合成后的因子列表
- 返回:
[factor1, factor2, …] 顺序与参考证券顺序相同
- get_ic(self[, ndays=0])¶
获取合成因子的IC, 长度与参考日期同
ndays 对于使用 IC/ICIR 加权的新因子,最好保持好 ic_n 一致, 但对于等权计算的新因子,不一定非要使用 ic_n 计算。 所以,ndays 增加了一个特殊值 0, 表示直接使用 ic_n 参数计算 IC
- 参数:
ndays (int) – ic 的 ndays 日收益率
- 返回类型:
- get_icir(self, ir_n[, ic_n=0])¶
获取合成因子的 ICIR
- 参数:
ir_n (int) – 计算 IR 的 n 窗口
ic_n (int) – 计算 IC 的 n 窗口 (同 get_ic 中的 ndays)
- get_score(self, date[, start=0, end=Null])¶
获取指定日期截面的所有因子值,已经降序排列,相当于各证券日期截面评分。
- 参数:
date (Datetime) – 指定日期
start (int) – 取当日排名开始
end (int) – 取当日排名结束(不包含本身)
- 返回类型:
ScoreRecordList
- get_all_scores(self)¶
获取所有日期的所有评分,长度与参考日期相同
- 返回:
每日 ScoreRecordList 结果的 list
- _calculate(self, stks_inds)¶
计算每日证券合成因子,输入参数由上层函数计算后传入,如:
待计算的证券列表 - stk1, stk2 原始因子列表 - ind1, ind2 则传入的 stks_inds 为:[IndicatorList(stk1)[ind1, ind2], IndicatorList(stk2)[ind1, ind2]]
- 参数:
stks_inds (list) – 与证券列表顺序相同已经计算好的所有证券的原始因子列表
- 返回:
按证券列表顺序存放的所有新的因子