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.

477

pickle_path = "/path/to/your/model/hmm_model_spy.pkl"

..

..

# Use Yahoo Daily Price Handler

start_date = datetime.datetime(2005, 1, 1)

end_date = datetime.datetime(2014, 12, 31)

price_handler = YahooDailyCsvBarPriceHandler(

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 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()

To run the backtest it is necessary to open up the Terminal and type the following:

$ python regime_hmm_backtest.py --tickers=SPY

The truncated output is as follows:

..

..

---------------------------------

Backtest complete.

Sharpe Ratio: 0.518857928421

Max Drawdown: 0.356537705234

Max Drawdown Pct: 0.356537705234

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

Saved successfully!

Ooh no, something went wrong!