Example #1
0
File: c8.py Project: fuimaz/abu
def sample_817():
    """
    8.1.7 使用并行来提升择时运行效率
    :return:
    """
    # 要关闭沙盒数据环境,因为沙盒里就那几个股票的历史数据, 下面要随机做50个股票
    from abupy import EMarketSourceType
    abupy.env.g_market_source = EMarketSourceType.E_MARKET_SOURCE_tx

    abupy.env.disable_example_env_ipython()

    # 关闭沙盒后,首先基准要从非沙盒环境换取,否则数据对不齐,无法正常运行
    benchmark = AbuBenchmark()
    # 当传入choice_symbols为None时代表对整个市场的所有股票进行回测
    # noinspection PyUnusedLocal
    choice_symbols = None
    # 顺序获取市场后300支股票
    # noinspection PyUnusedLocal
    choice_symbols = ABuMarket.all_symbol()[-50:]
    # 随机获取300支股票
    choice_symbols = ABuMarket.choice_symbols(50)
    capital = AbuCapital(1000000, benchmark)

    sell_factor1 = {'xd': 120, 'class': AbuFactorSellBreak}
    sell_factor2 = {
        'stop_loss_n': 0.5,
        'stop_win_n': 3.0,
        'class': AbuFactorAtrNStop
    }
    sell_factor3 = {'class': AbuFactorPreAtrNStop, 'pre_atr_n': 1.0}
    sell_factor4 = {'class': AbuFactorCloseAtrNStop, 'close_atr_n': 1.5}
    sell_factors = [sell_factor1, sell_factor2, sell_factor3, sell_factor4]
    buy_factors = [{
        'xd': 60,
        'class': AbuFactorBuyBreak
    }, {
        'xd': 42,
        'class': AbuFactorBuyBreak
    }]

    orders_pd, action_pd, _ = AbuPickTimeMaster.do_symbols_with_same_factors_process(
        choice_symbols, benchmark, buy_factors, sell_factors, capital)

    metrics = AbuMetricsBase(orders_pd, action_pd, capital, benchmark)
    metrics.fit_metrics()
    metrics.plot_returns_cmp(only_show_returns=True)

    abupy.env.enable_example_env_ipython()
Example #2
0
File: c8.py Project: fuimaz/abu
def sample_823():
    """
    8.2.3 使用并行来提升回测运行效率
    :return:
    """
    from abupy import EMarketSourceType
    abupy.env.g_market_source = EMarketSourceType.E_MARKET_SOURCE_tx
    abupy.env.disable_example_env_ipython()

    benchmark = AbuBenchmark()
    capital = AbuCapital(1000000, benchmark)

    # 首先随抽取50支股票
    choice_symbols = ABuMarket.choice_symbols(50)
    # 股价在15-50之间
    stock_pickers = [{
        'class': AbuPickStockPriceMinMax,
        'threshold_price_min': 15.0,
        'threshold_price_max': 50.0,
        'reversed': False
    }]
    cs = AbuPickStockMaster.do_pick_stock_with_process(capital, benchmark,
                                                       stock_pickers,
                                                       choice_symbols)
    print('len(cs):', len(cs))
    print('cs:\n', cs)
Example #3
0
File: c8.py Project: 3774257/abu
def sample_817():
    """
    8.1.7 使用并行来提升择时运行效率
    :return:
    """
    # 要关闭沙盒数据环境,因为沙盒里就那几个股票的历史数据, 下面要随机做50个股票
    from abupy import EMarketSourceType
    abupy.env.g_market_source = EMarketSourceType.E_MARKET_SOURCE_tx

    abupy.env.disable_example_env_ipython()

    # 关闭沙盒后,首先基准要从非沙盒环境换取,否则数据对不齐,无法正常运行
    benchmark = AbuBenchmark()
    # 当传入choice_symbols为None时代表对整个市场的所有股票进行回测
    # noinspection PyUnusedLocal
    choice_symbols = None
    # 顺序获取市场后300支股票
    # noinspection PyUnusedLocal
    choice_symbols = ABuMarket.all_symbol()[-50:]
    # 随机获取300支股票
    choice_symbols = ABuMarket.choice_symbols(50)
    capital = AbuCapital(1000000, benchmark)

    sell_factor1 = {'xd': 120, 'class': AbuFactorSellBreak}
    sell_factor2 = {'stop_loss_n': 0.5, 'stop_win_n': 3.0, 'class': AbuFactorAtrNStop}
    sell_factor3 = {'class': AbuFactorPreAtrNStop, 'pre_atr_n': 1.0}
    sell_factor4 = {'class': AbuFactorCloseAtrNStop, 'close_atr_n': 1.5}
    sell_factors = [sell_factor1, sell_factor2, sell_factor3, sell_factor4]
    buy_factors = [{'xd': 60, 'class': AbuFactorBuyBreak},
                   {'xd': 42, 'class': AbuFactorBuyBreak}]

    orders_pd, action_pd, _ = AbuPickTimeMaster.do_symbols_with_same_factors_process(
        choice_symbols, benchmark, buy_factors, sell_factors,
        capital)

    metrics = AbuMetricsBase(orders_pd, action_pd, capital, benchmark)
    metrics.fit_metrics()
    metrics.plot_returns_cmp(only_show_returns=True)

    abupy.env.enable_example_env_ipython()
Example #4
0
File: c8.py Project: 3774257/abu
def sample_823():
    """
    8.2.3 使用并行来提升回测运行效率
    :return:
    """
    from abupy import EMarketSourceType
    abupy.env.g_market_source = EMarketSourceType.E_MARKET_SOURCE_tx
    abupy.env.disable_example_env_ipython()

    benchmark = AbuBenchmark()
    capital = AbuCapital(1000000, benchmark)

    # 首先随抽取50支股票
    choice_symbols = ABuMarket.choice_symbols(50)
    # 股价在15-50之间
    stock_pickers = [
        {'class': AbuPickStockPriceMinMax, 'threshold_price_min': 15.0,
         'threshold_price_max': 50.0, 'reversed': False}]
    cs = AbuPickStockMaster.do_pick_stock_with_process(capital, benchmark,
                                                       stock_pickers,
                                                       choice_symbols)
    print('len(cs):', len(cs))
    print('cs:\n', cs)