From Back Test to Paper Trading

By:

Chief Technology Officer

Atreyu Trading

See Part I for instructions to setup the development and trading environment, Part II for using IBKR historical data within Backtrader and Part III for using various types of real-time data to run trading strategies.

In this section we look at the steps in developing a simple strategy and back testing it with historical data from IBKR. We then modify it to Paper Trader in the TWS frontend.

When running a strategy within the live market, many things can happen that may not have been encountered whilst back testing using historical data. For example, orders may not have filled, prices may have spiked, there may have been network instability resulting in disconnects and reconnects etc.

Hence it is important during the strategy development process to test for and mitigate as many problems as possible in advance of live deployment.

An Example of a Simple Buy/Sell Strategy

Note that in this strategy we generate Buy and Sell market orders related to a simple moving average calculation. This strategy has been adapted from (https://www.backtrader.com/docu/quickstart/quickstart) with minor updates.

Back Test Strategy Using IBKR Historical Data

Output

Paper Trading on IBKR

Once a strategy has been back tested for basic operation, it should be paper traded i.e. where simulated trades are generated and marked using live data to gain confidence in your overall trading strategy and goal.

Note that in this instance paper trading in TWS works the same way as live trading end to end – except the order is not routed a live exchange. Instead, the IBKR simulates the order filling based on the real-time quotes.

Although paper trading is not a substitute for live trading, it provides a good approximation for what one might expect in real trading. Performance may differ a little or a lot depending on the assumptions made in the strategy. Specifically, paper trading does not account for factors such as:

  • Market impact
  • Price slippage
  • Market microstructure
  • Price improvements
  • Regulatory fees
  • Dividends

Be careful to login to TWS using the Paper Trading option (see arrow):

In addition to selecting “Paper Trading” the execution of the strategy also needs to be changed to use IBKR as the broker to place orders and update positions. (see code below)

Output

Once the strategy is started the orders start appearing in TWS.

Stay tuned for the next installment in this series to learn how to transition from Paper Trading to Real Trading.

Visit Atreyu Trading Services https://www.atreyutrading.com/ for additional insight on Backtrader.

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from Atreyu Trading Services and is being posted with its permission. The views expressed in this material are solely those of the author and/or Atreyu Trading Services and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

Disclosure: API Examples Discussed

Throughout the lesson, please keep in mind that the examples discussed are purely for technical demonstration purposes, and do not constitute trading advice. Also, it is important to remember that placing trades in a paper account is recommended before any live trading.

Disclosure: Order Types / TWS

The order types available through Interactive Brokers LLC’s Trader Workstation are designed to help you limit your loss and/or lock in a profit. Market conditions and other factors may affect execution. In general, orders guarantee a fill or guarantee a price, but not both. In extreme market conditions, an order may either be executed at a different price than anticipated or may not be filled in the marketplace.