BacktestTradingSessionBuilder

class qf_lib.backtesting.trading_session.backtest_trading_session_builder.BacktestTradingSessionBuilder(settings: Settings, pdf_exporter: PDFExporter, excel_exporter: ExcelExporter)[source]

Bases: object

Class used to build a Trading Session with all necessary elements, connections and dependencies. By default it uses the following settings:

  • backtest name is set to “Backtest Results”

  • initial cash is set to 10000000

  • SimulatedContractTickerMapper is used to map contracts to tickers

  • no commissions are introduced (FixedCommissionModel(0.0))

  • no slippage is introduced (PriceBasedSlippage(0.0))

  • SimplePositionSizer is used

Parameters:
  • settings (Settings) – object containing all necessary settings, used for example for connection purposes

  • pdf_exporter (PDFExporter) – used to export all trading statistics to PDF

  • excel_exporter (ExcelExporter) – used to export trading data to Excel

Methods:

build(start_date, end_date)

Builds a backtest trading session.

set_benchmark_tms(benchmark_tms)

Sets the benchmark timeseries.

build(start_date: datetime, end_date: datetime) BacktestTradingSession[source]

Builds a backtest trading session.

Parameters:
  • start_date (datetime) – starting date of the backtest

  • end_date (datetime) – last date of the backtest

Returns:

trading session containing all the necessary parameters

Return type:

BacktestTradingSession

set_benchmark_tms(benchmark_tms: QFSeries)[source]

Sets the benchmark timeseries. If set, the TearsheetWithBenchamrk will be generated.

Parameters:

benchmark_tms (QFSeries) – timeseries of the benchmark