# FactorList = []  #输入因子合成阶段要使用的因子

from jaqs_fxdayu.research.signaldigger import process
dv.add_field('sw1')
factor_dict = dict()
index_member = ~mask
for name in FactorList:
    print(name)
    signal = -1 * dv.get_ts(name)  # 调整符号

    signal = process.winsorize(factor_df=signal, alpha=0.05, index_member=index_member)  # 去极值

    # 行业中性化
    signal = process.neutralize(signal,
                                group=dv.get_ts("sw1"),  # 行业分类标准
                                )

    signal = process.standardize(signal, index_member)  # z-score标准化 保留排序信息和分布信息
    #     signal = process.rank_standardize(signal,index_member) #因子在截面排序并归一化到0-1(只保留排序信息)
    print('OK!')
    factor_dict[name] = signal

# 因子间存在较强同质性时,使用施密特正交化方法对因子做正交化处理,用得到的正交化残差作为因子
new_factors = multi_factor.orthogonalize(factors_dict=factor_dict,
                           standardize_type="z_score",#输入因子标准化方法,有"rank"(排序标准化),"z_score"(z-score标准化)两种("rank"/"z_score")
                           winsorization=False,#是否对输入因子去极值
                           index_member=index_member) # 是否只处理指数成分股

# rollback_period代表滚动窗口所用到的天数,即用前多少期的数据来计算现阶段的因子权重。 通常建议设置时间在半年以上,可以获得相对稳定的预期结果
예제 #2
0
    return can_enter, can_exit


can_enter, can_exit = limit_up_down()
import numpy as np

price = dv.get_ts('close_adj')
sw1 = sw1_name
enter = can_enter
exit = can_exit
mask = mask
from jaqs_fxdayu.research.signaldigger.process import neutralize
neutralize_dict = {}
i = 0
for a in alpha_signal:
    neutralize_dict[a] = neutralize(factor_df=dv.get_ts(a),
                                    group=dv.get_ts("sw1"))  #行业中性化处理
    i = i + 1
    print('处理进度%s' % (i / len(alpha_signal)))
    print('总体进度%s' % (i / (3 * len(alpha_signal))))
#     except:
#         print(str(a)+'异常')

import matplotlib.pyplot as plt
from jaqs_fxdayu.research import SignalDigger
from jaqs_fxdayu.research.signaldigger import analysis


def cal_obj(signal, name, period, quantile):
    #     price_bench = dv.data_benchmark
    obj = SignalDigger(output_folder="FACTORS/%s" % name, output_format='pdf')
    obj.process_signal_before_analysis(signal,
예제 #3
0
def test_multi_factor():
    from jaqs_fxdayu.research.signaldigger import multi_factor, process
    dv = DataView()
    dv.load_dataview(dataview_folder)
    dv.add_formula("momentum",
                   "Return(close_adj, 20)",
                   is_quarterly=False,
                   add_data=True)

    mask = mask_index_member(dv)
    can_enter, can_exit = limit_up_down(dv)

    ic = dict()
    factors_dict = {
        signal: dv.get_ts(signal)
        for signal in ["pb", "pe", "ps", "momentum"]
    }
    for period in [5, 15]:
        ic[period] = multi_factor.get_factors_ic_df(
            factors_dict,
            price=dv.get_ts("close_adj"),
            high=dv.get_ts("high_adj"),  # 可为空
            low=dv.get_ts("low_adj"),  # 可为空
            n_quantiles=5,  # quantile分类数
            mask=mask,  # 过滤条件
            can_enter=can_enter,  # 是否能进场
            can_exit=can_exit,  # 是否能出场
            period=period,  # 持有期
            benchmark_price=dv.
            data_benchmark,  # 基准价格 可不传入,持有期收益(return)计算为绝对收益
            commission=0.0008,
        )
    factor_dict = dict()
    index_member = dv.get_ts("index_member")
    for name in ["pb", "pe", "ps", "momentum"]:
        signal = -1 * dv.get_ts(name)  # 调整符号
        process.winsorize(factor_df=signal,
                          alpha=0.05,
                          index_member=index_member)  # 去极值
        signal = process.rank_standardize(
            signal, index_member)  # 因子在截面排序并归一化到0-1(只保留排序信息)
        signal = process.standardize(signal,
                                     index_member)  # z-score标准化 保留排序信息和分布信息
        # 行业市值中性化
        signal = process.neutralize(
            signal,
            group=dv.get_ts("sw1"),
            float_mv=dv.get_ts("float_mv"),
            index_member=index_member,  # 是否只处理时只考虑指数成份股
        )
        factor_dict[name] = signal

    # 因子间存在较强同质性时,使用施密特正交化方法对因子做正交化处理,用得到的正交化残差作为因子
    new_factors = multi_factor.orthogonalize(
        factors_dict=factor_dict,
        standardize_type="rank",
        # 输入因子标准化方法,有"rank"(排序标准化),"z_score"(z-score标准化)两种("rank"/"z_score")
        winsorization=False,  # 是否对输入因子去极值
        index_member=index_member)  # 是否只处理指数成分股

    #  多因子组合-动态加权参数配置
    props = {
        'price': dv.get_ts("close_adj"),
        'high': dv.get_ts("high_adj"),  # 可为空
        'low': dv.get_ts("low_adj"),  # 可为空
        'ret_type':
        'return',  # 可选参数还有upside_ret/downside_ret 则组合因子将以优化潜在上行、下行空间为目标
        'benchmark_price': dv.data_benchmark,  # 为空计算的是绝对收益 不为空计算相对收益
        'period': 30,  # 30天的持有期
        'mask': mask,
        'can_enter': can_enter,
        'can_exit': can_exit,
        'forward': True,
        'commission': 0.0008,
        "covariance_type": "shrink",  # 协方差矩阵估算方法 还可以为"simple"
        "rollback_period": 120
    }  # 滚动窗口天数

    comb_factors = dict()
    for method in [
            "equal_weight", "ic_weight", "ir_weight", "max_IR", "max_IC",
            "factors_ret_weight"
    ]:
        comb_factors[method] = multi_factor.combine_factors(
            factor_dict,
            standardize_type="rank",
            winsorization=False,
            weighted_method=method,
            props=props)
    return can_enter, can_exit


can_enter, can_exit = limit_up_down()
alpha_signal = [
    'gainvariance120', 'alpha46', 'alpha48', 'alpha85', "vema12", "ir60",
    'adminiexpenserate', 'ssctol'
]
price = dv.get_ts('close_adj')
sw1 = sw1_name
enter = can_enter
exit = can_exit
mask = mask
from jaqs_fxdayu.research.signaldigger.process import neutralize
neutralize_dict = {
    a: neutralize(factor_df=dv.get_ts(a), group=dv.get_ts("sw1"))
    for a in alpha_signal
}

#分析因子所在行业特点
import matplotlib.pyplot as plt
from jaqs_fxdayu.research import SignalDigger
from jaqs_fxdayu.research.signaldigger import analysis


def cal_obj(signal, name, period, quantile):
    #     price_bench = dv.data_benchmark
    obj = SignalDigger(output_folder="hs300/%s" % name, output_format='pdf')
    obj.process_signal_before_analysis(signal,
                                       price=price,
                                       n_quantiles=quantile,
예제 #5
0
id_zz800 = dp.daily_index_cons(api, "000906.SH", start, end)

import pandas as pd
id_zz800 = dp.daily_index_cons(api, "000906.SH", start, end)
index_member = pd.concat([id_zz800],axis=1)

dv.add_field('float_mv')
for name in ["alpha1","alpha2","alpha3","alpha4","alpha5","alpha6","alpha7"]:
    signal = dv.get_ts(name)
    process.winsorize(factor_df=signal, alpha=0.05, index_member=index_member)  # 去极值
    #signal = process.standardize(signal, index_member)  # z-score标准化 保留排序信息和分布信息
    #     signal = process.rank_standardize(signal,index_member) #因子在截面排序并归一化到0-1(只保留排序信息)
         # 行业市值中性化
    signal = process.neutralize(factor_df=signal,
                                    group=dv.get_ts("sw1"),# 行业分类标准
                                    float_mv = dv.get_ts("float_mv"), #流通市值 可为None 则不进行市值中性化
                                    index_member=index_member,# 是否只处理时只考虑指数成份股
                                    )
    factor_dict[name] = signal

new_factors = multi_factor.orthogonalize(factors_dict=factor_dict,
                           standardize_type="rank",#输入因子标准化方法,有"rank"(排序标准化),"z_score"(z-score标准化)两种("rank"/"z_score")
                           winsorization=False,#是否对输入因子去极值
                           index_member=index_member) # 是否只处理指数成分股

props = {
    'price':dv.get_ts("close_adj"),
    'high':dv.get_ts("high_adj"), # 可为空
    'low':dv.get_ts("low_adj"),# 可为空
    'ret_type': 'return',#可选参数还有upside_ret/downside_ret 则组合因子将以优化潜在上行、下行空间为目标
    'benchmark_price': dv.data_benchmark,  # 为空计算的是绝对收益 不为空计算相对收益