예제 #1
0
        "RWE.TRADES",
        "RWE.NEWS",
    ]

    # TODO: SELECT DATE RANGE. Please use format 'YYYY-MM-DD'.

    start_date = "2016-01-01"
    end_date = "2016-03-31"

    # TODO: INSTANTIATE YOUR TRADING AGENT. You may submit multiple agents.

    agent = Agent(name="test_agent", )

    # TODO: INSTANTIATE YOUR ML MODEL. Only if you need to make predictions.

    model = Model(name="test_model", )

    # insantiate generator
    generator = Generator(
        sources=sources,
        start_date=start_date,
        end_date=end_date,
    )
    # instantiate backtest
    backtest = Backtest(
        agent=agent,
        generator=generator,
    )
    # run backtest
    results = backtest.run()
예제 #2
0
    start_date = "2016-03-01"
    end_date = "2016-03-31"

    # TODO: INSTANTIATE YOUR TRADING AGENT. You may submit multiple agents.

    agent = Agent(
        name="agent_example_2",
        default_quantity=100,
        model=model,
        steps=SEQUENCE_LENGTH,
    )

    # instantiate generator
    generator = Generator(
        sources=sources,
        start_date=start_date,
        end_date=end_date,
    )
    # instantiate backtest
    backtest = Backtest(
        agent=agent,
        generator=generator,
    )

    # run backtest
    results = backtest.run(
        verbose=True,
        interval=1_000,  # report every 1_000 events
    )
예제 #3
0
    if strategy == "regime-filter" or strategy == "new-regime-filter":
        trained_hmm_model = pickle.load(open(args.pickle_path, 'rb'))
        variances = trained_hmm_model.covars_
        flattened_variances = variances.flatten()
        high_regime = 0
        if numpy.argmax(flattened_variances) == 1:
            high_regime = 1
        elif numpy.argmax(flattened_variances) == 2:
            high_regime = 2
        else:
            high_regime = 0

        backtest = Backtest(daily_prices, daily_returns, strategy,
                            backtest_start_date, backtest_end_date,
                            high_regime, trained_hmm_model)
        backtested_portfolio = backtest.run()
    else:
        backtest = Backtest(daily_prices,
                            daily_returns,
                            strategy,
                            backtest_start_date,
                            backtest_end_date,
                            high_regime=None,
                            hmm_model=None)
        backtested_portfolio = backtest.run()

    # Print dates, portfolio equity, and current state if using regime-filter strategy
    DATE = 0
    EQUITY = 1
    REGIME = 2
    for day in backtested_portfolio: