BacktestTradingSessionBuilder

class qf_lib.backtesting.trading_session.backtest_trading_session_builder.BacktestTradingSessionBuilder(settings: qf_lib.settings.Settings, pdf_exporter: qf_lib.documents_utils.document_exporting.pdf_exporter.PDFExporter, excel_exporter: qf_lib.documents_utils.excel.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

Methods

build(start_date, end_date)

Builds a backtest trading session.

set_benchmark_tms(benchmark_tms)

Sets the benchmark timeseries.

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

build(start_date: datetime.datetime, end_date: datetime.datetime)qf_lib.backtesting.trading_session.backtest_trading_session.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: qf_lib.containers.series.qf_series.QFSeries)[source]

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

Parameters

benchmark_tms (QFSeries) – timeseries of the benchmark