コード例 #1
0
def factor_analysis(f_name):
    from alphamind.api import SqlEngine, Universe, alpha_logger
    engine = SqlEngine()
    universe = Universe('custom', ['zz800'])
    base1 = LAST('Alpha60')
    base2 = CSRes('roe_q', base1)
    base3 = CSRes(CSRes('ep_q', base1), base2)
    factor = CSRes(CSRes(CSRes(LAST(f_name), base1), base2), base3)
    res = factor_residue_analysis('2010-01-01', '2018-01-26', f_name, factor,
                                  '10b', universe, engine)
    alpha_logger.info('{0} is done'.format(f_name))
    return f_name, res
コード例 #2
0
def worker_func_negative(factor_name):
    from alphamind.api import SqlEngine, Universe
    neutralize_factors = ['roe_q', 'ep_q']
    engine = SqlEngine()
    benchmark_code = 905
    universe_name = ['zz500']
    universe = Universe('custom', universe_name)
    return factor_analysis(engine,
                           factor_name,
                           universe,
                           benchmark_code,
                           positive=False,
                           neutralize_factors=neutralize_factors)
コード例 #3
0
    factor = CSRes(CSRes(CSRes(LAST(f_name), base1), base2), base3)
    res = factor_residue_analysis('2010-01-01', '2018-01-26', f_name, factor,
                                  '10b', universe, engine)
    alpha_logger.info('{0} is done'.format(f_name))
    return f_name, res


if __name__ == '__main__':
    from dask.distributed import Client
    client = Client('10.63.6.176:8786')

    engine = SqlEngine()
    df = engine.fetch_factor_coverage()
    df = df[df.universe == 'zz800'].groupby('factor').mean()
    df = df[df.coverage >= 0.98]
    universe = Universe('custom', ['zz800'])

    factor_df = pd.DataFrame()

    tasks = client.map(factor_analysis, df.index.tolist())
    res = client.gather(tasks)

    for f_name, df in res:
        factor_df[f_name] = df['$top1 - bottom1$']

    # for i, f_name in enumerate(df.index):
    #     base1 = LAST('Alpha60')
    #     base2 = CSRes('roe_q', base1)
    #     base3 = CSRes(CSRes('ep_q', base1), base2)
    #     factor = CSRes(CSRes(CSRes(LAST(f_name), base1), base2), base3)
    #     res = factor_residue_analysis('2010-01-01',
コード例 #4
0
    from alphamind.api import industry_list
    from alphamind.api import winsorize_normal
    from alphamind.api import standardize

    from matplotlib import pyplot as plt
    from matplotlib.pylab import mpl

    plt.style.use('seaborn-whitegrid')
    mpl.rcParams['font.sans-serif'] = ['SimHei']
    mpl.rcParams['axes.unicode_minus'] = False

    start_date = '2017-01-01'
    end_date = '2018-05-17'
    freq = '10b'
    neutralized_risk = None
    universe = Universe('zz800')
    dask_client = Client('10.63.6.176:8786')

    alpha_factors = {
        'f1':
        CSQuantiles(LAST('ILLIQUIDITY') * LAST('NegMktValue'),
                    groups='sw1_adj'),
        'f2':
        CSQuantiles('con_pe', groups='sw1_adj')
    }

    weights = {'f1': 1., 'f2': 0.}

    # alpha_model = XGBTrainer(objective='reg:linear',
    #                          booster='gbtree',
    #                          n_estimators=300,
コード例 #5
0
    from matplotlib import pyplot as plt
    from PyFin.api import *
    from dask.distributed import Client
    from alphamind.api import Universe
    from alphamind.api import ConstLinearModel
    from alphamind.api import XGBTrainer
    from alphamind.api import DataMeta
    from alphamind.api import industry_list
    from alphamind.api import winsorize_normal
    from alphamind.api import standardize

    start_date = '2011-01-01'
    end_date = '2018-05-04'
    freq = '20b'
    neutralized_risk = None
    universe = Universe("custom", ['zz800'])
    dask_client = Client('10.63.6.176:8786')

    factor = CSQuantiles(LAST('NetProfitRatio'), groups='sw1_adj')
    alpha_factors = {
        str(factor): factor,
    }

    weights = {str(factor): 1.}

    # alpha_model = XGBTrainer(objective='reg:linear',
    #                          booster='gbtree',
    #                          n_estimators=300,
    #                          eval_sample=0.25,
    #                          features=alpha_factors)
コード例 #6
0
    from alphamind.api import industry_list
    from alphamind.api import winsorize_normal
    from alphamind.api import standardize

    from matplotlib import pyplot as plt
    from matplotlib.pylab import mpl

    plt.style.use('seaborn-whitegrid')
    mpl.rcParams['font.sans-serif'] = ['SimHei']
    mpl.rcParams['axes.unicode_minus'] = False
    """
    Back test parameter settings
    """

    benchmark_code = 905
    universe = Universe('zz800') + Universe('cyb')

    start_date = '2011-01-01'
    end_date = '2011-05-04'
    freq = '10b'
    neutralized_risk = None

    alpha_factors = {'ep_q_cs': CSQuantiles(LAST('ep_q'), groups='sw1_adj')}

    weights = dict(ep_q_cs=1.)

    alpha_model = ConstLinearModel(features=alpha_factors, weights=weights)

    data_meta = DataMeta(freq=freq,
                         universe=universe,
                         batch=1,
コード例 #7
0
    industry_matrix = engine.fetch_industry_matrix(ref_date, codes, 'sw_adj',
                                                   1)
    dx_returns = engine.fetch_dx_return(ref_date,
                                        codes,
                                        horizon=horizon,
                                        offset=1)

    return cs_impl(ref_date, factor_data, factor_name, risk_exposure,
                   constraint_risk, industry_matrix, dx_returns)


if __name__ == '__main__':
    from alphamind.api import SqlEngine, Universe, risk_styles, industry_styles

    factor_name = 'SIZE'
    data_source = 'postgres+psycopg2://postgres:[email protected]/alpha'
    engine = SqlEngine(data_source)
    risk_names = list(set(risk_styles).difference({factor_name}))
    industry_names = list(set(industry_styles).difference({factor_name}))
    constraint_risk = risk_names + industry_names
    universe = Universe('custom', ['ashare_ex'])
    horizon = 9

    x = cross_section_analysis('2018-02-08',
                               factor_name,
                               universe,
                               horizon,
                               constraint_risk,
                               engine=engine)
    print(x)