How to Paper Trade Quantpedia Backtests

Quantpedia’s mission is simple – we want to analyze and process academic research related to quant/algo trading and simplify it into a more user-friendly form to help everyone who looks for new trading strategy ideas. It also means that we are a highly focused quant-research company, not an asset manager, and we do not manage any clients’ funds or managed accounts. But sometimes, our readers contact us with a request to help them to translate strategy backtests performed in Quantconnect into paper trading or real-trading environment. The following article is a short case study that contains a few useful tips on how to do it.

Introduction

QuantConnect Paper Trading provides the ability to run live, real-time data feeds into your algorithm and execute trades using fictional capital. Instead of your orders being routed to an exchange when you’re paper trading, your order fills are simulated. Use paper trading to test your algorithm without risking real money and to ensure your backtest wasn’t overfit before deploying with real money. You can use paper trading brokerage without needing to sign up for a real brokerage account.

https://www.quantconnect.com/docs/v2/our-platform/live-trading/getting-started

QuantConnect Paper Trading Assets Available: Equities, Crypto, Forex, CFD, Futures, Futures Options.

Paper trading algorithm pre-deployment tips:

  • Use minute data resolution, preferably for precise market order timing. If daily bar resolution is used, orders will be executed on the next market open. In general, the more granular the data resolution, the better.
  • Make sure you are using the SetWarmup function to get indicators ready and populated with historical data (if any indicators are used). Alternatively, the History function can be used for other historical data population purposes.
  • Make sure your custom signal data are regularly updated. Custom data can be directly parsed in your Initialize function as a single static reference file, but by using this approach, you will lose the ability to use regularly updated data.
  • Create a custom type and then create a data subscription for your regularly updated custom data feed, which help you specify the source and the way LEAN should read it. More on custom data imports: https://www.quantconnect.com/docs/v1/algorithm-reference/importing-custom-data
  • Use the SetWarmup function for your custom data feed also.
  • If you are using custom data, be cautious about how often you need the custom data to be updated and parsed. The frequency at which Quantconnect’s LEAN checks the data source depends on the resolution argument. You can see the polling frequency of each resolution at: https://www.quantconnect.com/docs/v2/writing-algorithms/importing-data/streaming-data/custom-securities/key-concepts
  • The most common remote file providers to use are Dropbox, GitHub, and Google Sheets. You can even use your own API endpoint (even with authorization) or local files. Common data formats are CSV, JSON, and XML, but you can use any file type that can be read over the internet.
  • Use the Log function to print out the internal algorithm state, variables of interest, and pre-execution states, …
  • If you don’t set a brokerage model in your algorithm with the SetBrokerageModel method, the paper trading brokerage uses the DefaultBrokerageModel to simulate trades.
  • Use supported Order types for a selected brokerage. For example, Interactive Brokers equity brokerage would support much more order types than any crypto exchange. Also, make sure that you are aware of available asset classes, fees, and margin options for the brokerage you want to trade on. More information about the topic: https://www.quantconnect.com/docs/v2/our-platform/live-trading/brokerages

Side note – this article is written in the mid of November 2022 and reflects the current situation. Some of the functions and methods can change over time…

Examples

In the following section, we will give you two examples of how the research backtest written in the Quantconnect framework can be translated into a paper trading strategy.

Example Nbr.1 – Strategy ID #2 – Asset Class Momentum – Rotational System

Strategy description – trading rules recapitulation:

Use 5 ETFs (SPY – US stocks, EFA – foreign stocks, IEF – bonds, VNQ – REITs, GSG – commodities). Pick 3 ETFs with strongest 12-month momentum into your portfolio and weight them equally. Hold for 1 month and then rebalance.

Backtest/Paper Trading embedded backtest:

https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_e80efd4bb520f73e7837646238bcef41.html

Paper trading equity:

Strategy gained 0.84% during two trading day test period for this particular strategy algorithm.

Logs:

Minute data resolution bars are used in order to time order execution timed properly after the market opens at 9:31. Log messages provide us with the internal algorithm state information, and we are able to identify what code is being executed at the given moment. Regular market orders are used for trade execution.

Example Nbr.2 – Strategy ID #75 – Federal Open Market Committee Meeting Effect in Stocks

Strategy description – trading rules recapitulation:

The investor is invested in stocks during FOMC meetings (going long S&P 500 ETF, fund, future, or FD on a close one day before the meeting and closing position on close after the meeting). Otherwise, he is invested in cash during the remaining days. The strategy has very low exposure to the stock market (8 days during the average year); but it can be easily leveraged to gain higher returns.

Short note – this example shows how to use a dataset (in this case, calendar data with FOMC meeting dates) that’s not in Quantconnect’s data library. If you want to use 3rd party data feed, this is one of the ways of how you can do it. 

Backtest/Paper Trading embedded backtest:

https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_f15221e9c8f581a073a65ecd2d77093e.html

Paper trading equity:

Strategy lost 0.76% during one trading day period during the “fake” FOMC meeting day (that we plugged into data).

Logs:

Again, minute data resolution bars are used. Log messages provides us with the information about the algorithm state and new FOMC calendar data arrival, as well as new order event. Custom data type FedDays was introduced to receive custom calendar data into the OnData function. FOMC calendar data are subscribed using custom type where source of the data is declared with the way the source file should be parsed. All custom data types must extend the PythonData class (python version) and override the GetSource and Reader functions.

Variable isLive is key element within GetSource function. This flag is set internally by LEAN and lets you specify two different data sources for live (paper) and backtest execution. Internal FOMC calendar remote JSON file is used in this example. More on importing data topic: https://www.quantconnect.com/docs/v2/writing-algorithms/importing-data/key-concepts

Strategy trades only 8 times a year. For the sake of showcasing ability to trade this algorithm on paper trading servers, file fed_days_edited.json was edited in a way that it contains one fake FOMC meeting date (16th of November, 2022). Therefore, we are able to demonstrate new order execution without misleading change of algorithm logic. Every new original FOMC meeting day data point that comes in OnData function is shifted by one business day back and its time is set to 15:31 AM NY, so we can submit new MarketOnClose order (MOC submission limit is at least 16 minutes before US market open). Properties Time and Value have to be set for custom data to be valid and subscribed successfully. Resolution of custom data is set to Daily, therefore live custom JSON data feed will be parsed once every 30 minutes, as you can see in logs. (polling frequency of each resolution differs based on the subscribed custom data resolution). GetSource function is also regularly called during the warmup period.

Paper Trading Algorithm Deployment

The following picture shows how to deploy live paper trading algorithms:

Paper Trading brokerage and available trading node is selected. Order events’ or insights’ notifications could be set via email, webhooks, SMS or Telegram.

More information about paper trading algorithm deployment:

https://www.quantconnect.com/docs/v2/our-platform/live-trading/getting-started


Are you looking for more strategies to read about? Visit our Blog or Screener.

Do you want to learn more about Quantpedia Pro service? Check its description, watch videos, review reporting capabilities and visit our pricing offer.

Do you want to know more about us? Check how Quantpedia works and our mission.

Are you looking for historical data or backtesting platforms? Check our list of Algo Trading Discounts.


Or follow us on:

Facebook Group, Facebook Page, Twitter, Linkedin, Medium or Youtube

Share onRefer to a friend

Subscribe for Newsletter

Be first to know, when we publish new content


    logo
    The Encyclopedia of Quantitative Trading Strategies

    Log in

    MORE INFO
    We boasts a total prize pool of $15,000
    Gain a Share of a Total Prize Pool of $15.000
    MORE INFO
    $15.000
    Gain a Share of a Total Prize Pool
    SUBSCRIBE TO NEWSLETTER AND GET:
    - bi-weekly research insights -
    - tips on new trading strategies -
    - notifications about offers & promos -
    Subscribe