Example #1
0
def sample_821_1():
    """
    8.2.1_1 选股使用示例
    :return:
    """
    # 选股条件threshold_ang_min=0.0, 即要求股票走势为向上上升趋势
    stock_pickers = [{'class': AbuPickRegressAngMinMax,
                      'threshold_ang_min': 0.0, 'reversed': False}]

    # 从这几个股票里进行选股,只是为了演示方便
    # 一般的选股都会是数量比较多的情况比如全市场股票
    choice_symbols = ['usNOAH', 'usSFUN', 'usBIDU', 'usAAPL', 'usGOOG',
                      'usTSLA', 'usWUBA', 'usVIPS']
    benchmark = AbuBenchmark()
    capital = AbuCapital(1000000, benchmark)
    kl_pd_manager = AbuKLManager(benchmark, capital)
    stock_pick = AbuPickStockWorker(capital, benchmark, kl_pd_manager,
                                    choice_symbols=choice_symbols,
                                    stock_pickers=stock_pickers)
    stock_pick.fit()
    # 打印最后的选股结果
    print('stock_pick.choice_symbols:', stock_pick.choice_symbols)

    # 从kl_pd_manager缓存中获取选股走势数据,注意get_pick_stock_kl_pd为选股数据,get_pick_time_kl_pd为择时
    kl_pd_noah = kl_pd_manager.get_pick_stock_kl_pd('usNOAH')
    # 绘制并计算角度
    deg = ABuRegUtil.calc_regress_deg(kl_pd_noah.close)
    print('noah 选股周期内角度={}'.format(round(deg, 3)))
Example #2
0
def sample_b3_4():
    """
    【示例4】abu量化系统选股结合相关性,编写相关性选股策略
    AbuPickSimilarNTop源代码请自行阅读,只简单示例使用。
    :return:
    """
    from abupy import AbuPickSimilarNTop
    from abupy import AbuPickStockWorker
    from abupy import AbuBenchmark, AbuCapital, AbuKLManager

    benchmark = AbuBenchmark()

    # 选股因子AbuPickSimilarNTop, 寻找与usTSLA相关性不低于0.95的股票
    # 这里内部使用以整个市场作为观察者方式计算,即取值范围0-1
    stock_pickers = [{
        'class': AbuPickSimilarNTop,
        'similar_stock': 'usTSLA',
        'threshold_similar_min': 0.95
    }]

    # 从这几个股票里进行选股,只是为了演示方便,一般的选股都会是数量比较多的情况比如全市场股票
    choice_symbols = [
        'usNOAH', 'usSFUN', 'usBIDU', 'usAAPL', 'usGOOG', 'usTSLA', 'usWUBA',
        'usVIPS'
    ]

    capital = AbuCapital(1000000, benchmark)
    kl_pd_manager = AbuKLManager(benchmark, capital)
    stock_pick = AbuPickStockWorker(capital,
                                    benchmark,
                                    kl_pd_manager,
                                    choice_symbols=choice_symbols,
                                    stock_pickers=stock_pickers)
    stock_pick.fit()
    print('stock_pick.choice_symbols:\n', stock_pick.choice_symbols)
    """
        通过选股因子first_choice属性执行批量优先选股操作,具体阅读源代码
    """
    # 选股因子AbuPickSimilarNTop, 寻找与usTSLA相关性不低于0.95的股票
    # 通过设置'first_choice':True,进行优先批量操作,默认从对应市场选股
    stock_pickers = [{
        'class': AbuPickSimilarNTop,
        'first_choice': True,
        'similar_stock': 'usTSLA',
        'threshold_similar_min': 0.95
    }]
    benchmark = AbuBenchmark()
    capital = AbuCapital(1000000, benchmark)
    kl_pd_manager = AbuKLManager(benchmark, capital)
    stock_pick = AbuPickStockWorker(capital,
                                    benchmark,
                                    kl_pd_manager,
                                    choice_symbols=None,
                                    stock_pickers=stock_pickers)
    stock_pick.fit()
    print('stock_pick.choice_symbols:\n', stock_pick.choice_symbols)
Example #3
0
File: extB.py Project: 3774257/abu
def sample_b3_4():
    """
    【示例4】abu量化系统选股结合相关性,编写相关性选股策略
    AbuPickSimilarNTop源代码请自行阅读,只简单示例使用。
    :return:
    """
    from abupy import AbuPickSimilarNTop
    from abupy import AbuPickStockWorker
    from abupy import AbuBenchmark, AbuCapital, AbuKLManager

    benchmark = AbuBenchmark()

    # 选股因子AbuPickSimilarNTop, 寻找与usTSLA相关性不低于0.95的股票
    # 这里内部使用以整个市场作为观察者方式计算,即取值范围0-1
    stock_pickers = [{'class': AbuPickSimilarNTop,
                      'similar_stock': 'usTSLA', 'threshold_similar_min': 0.95}]

    # 从这几个股票里进行选股,只是为了演示方便,一般的选股都会是数量比较多的情况比如全市场股票
    choice_symbols = ['usNOAH', 'usSFUN', 'usBIDU', 'usAAPL', 'usGOOG', 'usTSLA', 'usWUBA', 'usVIPS']

    capital = AbuCapital(1000000, benchmark)
    kl_pd_manager = AbuKLManager(benchmark, capital)
    stock_pick = AbuPickStockWorker(capital, benchmark, kl_pd_manager, choice_symbols=choice_symbols,
                                    stock_pickers=stock_pickers)
    stock_pick.fit()
    print('stock_pick.choice_symbols:\n', stock_pick.choice_symbols)

    """
        通过选股因子first_choice属性执行批量优先选股操作,具体阅读源代码
    """
    # 选股因子AbuPickSimilarNTop, 寻找与usTSLA相关性不低于0.95的股票
    # 通过设置'first_choice':True,进行优先批量操作,默认从对应市场选股
    stock_pickers = [{'class': AbuPickSimilarNTop, 'first_choice': True,
                      'similar_stock': 'usTSLA', 'threshold_similar_min': 0.95}]
    benchmark = AbuBenchmark()
    capital = AbuCapital(1000000, benchmark)
    kl_pd_manager = AbuKLManager(benchmark, capital)
    stock_pick = AbuPickStockWorker(capital, benchmark, kl_pd_manager, choice_symbols=None,
                                    stock_pickers=stock_pickers)
    stock_pick.fit()
    print('stock_pick.choice_symbols:\n', stock_pick.choice_symbols)
Example #4
0
    # 一般而言,我们是遍历整个股市来选股,这里我们就选择以下几个股票来做演示
    choice_symbols = [
        'usNOAH', 'usSFUN', 'usBIDU', 'usAAPL', 'usGOOG', 'usTSLA', 'usWUBA',
        'usVIPS'
    ]

    # 开始执行
    benchmark = AbuBenchmark()
    capital = AbuCapital(1000000, benchmark)
    kl_pd_manager = AbuKLManager(benchmark, capital)
    stock_pick = AbuPickStockWorker(capital,
                                    benchmark,
                                    kl_pd_manager,
                                    choice_symbols=choice_symbols,
                                    stock_pickers=stock_pickers)
    stock_pick.fit()

    print(stock_pick.choice_symbols)

    # 绘图
    kl_pd_SFUN = kl_pd_manager.get_pick_stock_kl_pd('usNOAH')
    deg = ABuRegUtil.calc_regress_deg(kl_pd_SFUN.close)
    print(deg)

    # 上面使用worker的操作太麻烦,下面可以直接使用executer
    stock_pickers = [{
        'class': AbuPickRegressAngMinMax,
        'threshold_ang_min': 0.0,
        'threshold_ang_max': 10.0,
        'reversed': False
    }]