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.

430

IQFeedIntradayCsvBarPriceHandler

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 intraday_ml_strategy import \

IntradayMachineLearningPredictionStrategy

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

# Set up variables needed for backtest

events_queue = queue.Queue()

csv_dir = "/path/to/your/data/"

initial_equity = PriceParser.parse(500000.00)

# Use DTN IQFeed Intraday Bar Price Handler

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

price_handler = IQFeedIntradayCsvBarPriceHandler(

csv_dir, events_queue, tickers, start_date=start_date

)

# Use the IntradayMachineLearningPredictionStrategy

model_pickle_file = ’/path/to/your/ml_model_rf.pkl’

strategy = IntradayMachineLearningPredictionStrategy(

tickers, events_queue, model_pickle_file, lags=5

)

strategy = Strategies(strategy, DisplayStrategy())

# 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

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

Saved successfully!

Ooh no, something went wrong!