13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

409

# Use the Naive Position Sizer (suggested quantities are followed)

position_sizer = NaivePositionSizer()

# Use an example Risk Manager

risk_manager = ExampleRiskManager()

# Use the default Portfolio Handler

portfolio_handler = PortfolioHandler(

initial_equity, events_queue, price_handler,

position_sizer, risk_manager

)

# Use the ExampleCompliance component

compliance = ExampleCompliance(config)

# Use a simulated IB Execution Handler

execution_handler = IBSimulatedExecutionHandler(

events_queue, price_handler, compliance

)

# Use the Tearsheet Statistics

title = ["Kalman Filter Pairs Trade on TLT/IEI"]

statistics = TearsheetStatistics(

config, portfolio_handler, title

)

# Set up the backtest

backtest = Backtest(

price_handler, strategy,

portfolio_handler, execution_handler,

position_sizer, risk_manager,

statistics, initial_equity

)

results = backtest.simulate_trading(testing=testing)

statistics.save(filename)

return results

@click.command()

@click.option(

’--config’, default=settings.DEFAULT_CONFIG_FILENAME,

help=’Config filename’

)

@click.option(

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!