13.08.2022 Views

advanced-algorithmic-trading

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

487

)

csv_dir, events_queue, tickers,

start_date=start_date, end_date=end_date,

calc_adj_returns=True

# Use the Moving Average Crossover trading strategy

base_quantity = 10000

strategy = MovingAverageCrossStrategy(

tickers, events_queue, base_quantity,

short_window=10, long_window=30

)

strategy = Strategies(strategy, DisplayStrategy())

# Use the Naive Position Sizer

# where suggested quantities are followed

position_sizer = NaivePositionSizer()

# Use regime detection HMM risk manager

hmm_model = pickle.load(open(pickle_path, "rb"))

risk_manager = RegimeHMMRiskManager(hmm_model)

# 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 = ["Trend Following Regime Detection with HMM"]

statistics = TearsheetStatistics(

config, portfolio_handler, title,

benchmark="SPY"

)

# Set up the backtest

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

Saved successfully!

Ooh no, something went wrong!