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.

416

)

self.events_queue.put(

SignalEvent(

self.tickers[0],

"SLD", self.cur_hedge_qty

)

)

self.invested = None

# kalman_qstrader_backtest.py

import click

from qstrader import settings

from qstrader.compat import queue

from qstrader.price_parser import PriceParser

from qstrader.price_handler.yahoo_daily_csv_bar import \

YahooDailyCsvBarPriceHandler

from qstrader.strategy import Strategies, DisplayStrategy

from qstrader.position_sizer.naive import NaivePositionSizer

from qstrader.risk_manager.example import ExampleRiskManager

from qstrader.portfolio_handler import PortfolioHandler

from qstrader.compliance.example import ExampleCompliance

from qstrader.execution_handler.ib_simulated import \

IBSimulatedExecutionHandler

from qstrader.statistics.tearsheet import TearsheetStatistics

from qstrader.trading_session.backtest import Backtest

from kalman_qstrader_strategy import KalmanPairsTradingStrategy

def run(config, testing, tickers, filename):

# Set up variables needed for backtest

events_queue = queue.Queue()

csv_dir = config.CSV_DATA_DIR

initial_equity = PriceParser.parse(100000.00)

# Use Yahoo Daily Price Handler

price_handler = YahooDailyCsvBarPriceHandler(

csv_dir, events_queue, tickers

)

# Use the KalmanPairsTrading Strategy

strategy = KalmanPairsTradingStrategy(tickers, events_queue)

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

Saved successfully!

Ooh no, something went wrong!