Skip to content

research.research_runner

research.research_runner

ResearchRunner

Runs backtest research & computes metrics for a Strategy.

run staticmethod

run(config: RunConfig[TConfig], verbose_iterating: bool = True) -> list[BacktestExperimentResult]

Downloads data and runs experiments with the given config.

Parameters:

Name Type Description Default
config RunConfig[TConfig]

The configuration object to derive all data from when running experiments.

required
verbose_iterating bool

Whether to print the experiments that are currently being processed.

True

Returns:

Type Description
list[BacktestExperimentResult]

A list of experiment result instances for further analysis.

Source code in src\contango\research\research_runner.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
@staticmethod
def run(config: RunConfig[TConfig], verbose_iterating: bool = True) -> list[BacktestExperimentResult]:
    """
    Downloads data and runs experiments with the given config.

    Args:
        config: The configuration object to derive all data from when running experiments.
        verbose_iterating: Whether to print the experiments that are currently being processed.

    Returns:
        A list of experiment result instances for further analysis.
    """
    data = ResearchRunner._load_data(config)
    experiments = ResearchRunner._create_experiments(data, config)
    results = BacktestExperimentRunner.run(experiments, verbose_iterating=verbose_iterating)

    return results

RunConfig

Bases: NamedTuple, Generic[TConfig]

Holds the configuration parameters for a ResearchRunner.

Attributes:

Name Type Description
broker HistoricalBroker[TConfig]

The historical broker to use when polling for OHLCV data.

broker_config TConfig

The config matching to the broker to determine what type of data to derive.

strategy_factory Callable[..., Strategy]

A callable that returns the underlying Strategy to test.

param_space dict[str, list[Any]]

A dictionary mapping each possible parameter in the strategy to a list of the desired parameters to test.

initial_cash USD

The initial cash for the backtester to start with for every test.

initial_position units

The initial units for the backtester to start with for every test.

fill_behavior FillBehavior

The behavior determining when trades will be filled across every backtest.

slippage percent

The percent difference beteween the expected price & filled price.

commission_per_unit USD

The price taxed per unit bought.