Beispiel #1
0
Datei: c8.py Projekt: fuimaz/abu
def sample_811():
    """
    8.1.1 买入因子的实现
    :return:
    """
    # buy_factors 60日向上突破,42日向上突破两个因子
    buy_factors = [{
        'xd': 60,
        'class': AbuFactorBuyBreak
    }, {
        'xd': 42,
        'class': AbuFactorBuyBreak
    }]
    benchmark = AbuBenchmark()
    capital = AbuCapital(1000000, benchmark)
    kl_pd_manager = AbuKLManager(benchmark, capital)
    # 获取TSLA的交易数据
    kl_pd = kl_pd_manager.get_pick_time_kl_pd('usTSLA')
    abu_worker = AbuPickTimeWorker(capital, kl_pd, benchmark, buy_factors,
                                   None)
    abu_worker.fit()

    orders_pd, action_pd, _ = ABuTradeProxy.trade_summary(abu_worker.orders,
                                                          kl_pd,
                                                          draw=True)

    ABuTradeExecute.apply_action_to_capital(capital, action_pd, kl_pd_manager)
    capital.capital_pd.capital_blance.plot()
    plt.show()
Beispiel #2
0
Datei: c8.py Projekt: 3774257/abu
def sample_811():
    """
    8.1.1 买入因子的实现
    :return:
    """
    # buy_factors 60日向上突破,42日向上突破两个因子
    buy_factors = [{'xd': 60, 'class': AbuFactorBuyBreak},
                   {'xd': 42, 'class': AbuFactorBuyBreak}]
    benchmark = AbuBenchmark()
    capital = AbuCapital(1000000, benchmark)
    kl_pd_manager = AbuKLManager(benchmark, capital)
    # 获取TSLA的交易数据
    kl_pd = kl_pd_manager.get_pick_time_kl_pd('usTSLA')
    abu_worker = AbuPickTimeWorker(capital, kl_pd, benchmark, buy_factors, None)
    abu_worker.fit()

    orders_pd, action_pd, _ = ABuTradeProxy.trade_summary(abu_worker.orders, kl_pd, draw=True)

    ABuTradeExecute.apply_action_to_capital(capital, action_pd, kl_pd_manager)
    capital.capital_pd.capital_blance.plot()
    plt.show()
    buy_factors = [{
        'xd': 60,
        'class': AbuFactorBuyBreak
    }, {
        'xd': 42,
        'class': AbuFactorBuyBreak
    }]
    # 基准利润
    benchmark = AbuBenchmark()

    # 现金和基准利润
    capital = AbuCapital(1000000, benchmark)
    # 多线程管理类
    kl_pd_manager = AbuKLManager(benchmark, capital)
    # 获取TSLA的股票信息
    kl_pd = kl_pd_manager.get_pick_time_kl_pd('usTSLA')
    # 准备开始工作
    abu_worker = AbuPickTimeWorker(capital, kl_pd, benchmark, buy_factors,
                                   None)
    abu_worker.fit()
    # 画出哪几个点可以买入,以及最终的收益情况
    # orders_pd,action_pd,_=ABuTradeProxy.trade_summary(abu_worker.orders,kl_pd,draw=True)
    orders_pd, action_pd, _ = ABuTradeProxy.trade_summary(abu_worker.orders,
                                                          kl_pd,
                                                          draw=False)

    # 上面是从股价角度,下面从我们的资金来看
    # ABuTradeExecute.apply_action_to_capital(capital, action_pd, kl_pd_manager)
    # print(capital.capital_pd.head())
    # capital.capital_pd.capital_blance.plot()
    # plt.show()