Beginner’s Guide to Quantitative Trading II: Developing Automated Trading Systems

Auquan
auquan
Published in
5 min readAug 13, 2017

In part I of this guide, we talked about math programming, data and ML skills that come in handy while building your own trading strategies. Hopefully you’re already an expert at those and are ready to dive into building your own automated trading system.

An Automated Trading System consists of several elements. You need to decide which markets you want to trade, create features to identify a trading logic and develop a strategy to implement this logic to buy or sell stocks. Your system should decide when to enter and exit a trade, account for trading costs and be optimized via backtesting (but not overfit). You can watch a detailed video on the key elements of a trading system here.

Let’s get started:

1. FIND THE RIGHT MARKET TO TRADE

Choose your market and instruments to trade. Then find historical data for those instruments to develop and test your model. We provide data for 600 stocks listed on NASDAQ which are (or were) a part of the S&P 500 since 2001. The full list of stocks is here.

Stocks are usually a good place to start for beginners and allow for a great degree of diversification. Don’t understand what financial instruments like stocks, futures and options mean? Learn more here.

2. BUILD YOUR FEATURES AND TRADING SIGNAL

You will need a set of features to identify a trading signal/logic. The features can be moving averages or ratios of price data, correlations or more complex signals. We provide daily OPEN, CLOSE, HIGH, LOW and VOLUME data for the stocks. You can combine these in many ways to create new features. Once you have your set of features, you need to generate a trading signal using these features, i.e which instruments are a buy, a sell or neutral.

If you need a refresher on the math, read more here.

Sample features for a stock

You can start by experimenting with simple mean-reversion or momentum systems, building up to slightly complex pair or long-short trades. You can check out our beginner series on these (with tutorial IPython notebooks) on simple trading strategies.

3. TRADE EXECUTION STRATEGY

Next you’ll need a strategy which tells your system what to do based on the signal generated by your features. This is the final order you send to the broker.

You can enter a trade in two positions — long or short. When long a stock, you benefit if price increases. Similarly, when short you benefit if price decreases. Once you enter a trade, you can choose to increase or decrease your position size based on the strength of your signal, and finally exit the position if you meet your profit criteria, if you think the signal has reversed or if you hit your stop loss.

Therefore, your trade execution strategy should decide a) how to enter a position(buy or sell) b) what size to trade c) how to subsequently size up or down and d) when to exit, both in case of profits or losses.

4. TRADING COSTS

Trading costs significantly alter the performance of strategy. High trading costs can eat up into an otherwise profitable strategy significantly. Our backtester automatically accounts for trading costs. We apply a commission (fees charged by the exchange and the broker to facilitate trades) and slippage (the difference in price at which you placed your order and the price at which you actually traded.) to every order.
We use $0.10 per stock as commission and 5% of the stock’s daily range as an estimate of slippage. Therefore, total cost to trade (in$) = 0.10 + (HIGH — LOW) * 0.05

5. BACKTESTING AND PERFORMANCE METRICS

Finally you have to test your system on historical data to see how your strategy would have performed in the past. This helps you optimize your system for the markets you are trading. It also provides you with an expectation how your strategy is expected to do in the future.

How do you compare two systems? Our backtester provides you with the following metrics to quantify your system’s performance. These set of metrics are not exhaustive, but they’re a good place to start:

  1. Total Return
  2. Annualized Return
  3. Annualized Volatility
  4. Sharpe Ratio
  5. Sortino Ratio
  6. Maximum Drawdown
  7. % Profitability
  8. Profit Factor

You can read in detail about them here.

There is no correct target value for these metrics. Every investor looks for systems with high performance and low risk but different investors may have varying thresholds for what’s considered acceptable based on their risk profile and trading styles.

Sample Backtesting Result from our toolbox

6. BE WARNED AGAINST OVERFITTING AND BIASES

Similar to any data science problem, the abundance of available data means there is a natural tendency to overfit systems.

Overfitting is the most dangerous pitfall of a trading strategy. You might create a complex algorithm which performs wonderfully on a backtest but fails miserably on new unseen data. This system has not really uncovered any trend in data and no real predictive power. A few tips to avoid overfitting:

  • Keep your systems as simple as possible. If you find yourself using too many or extremely complex features, you’re probably overfitting, not catching a trend.
  • Divide available data into training and test data. Don’t use all the data to optimize your strategy algorithm, use the test data to validate your strategy. Systems that perform well on out-of-sample test are more likely to be successful on live market data.
  • Avoid biases, especially lookahead bias. Make sure your strategy isn’t using any knowledge from the future while backtesting. This information won’t be available to you when trading on live market data. You can find a list of common backtesting biases here.

That’s it. You’re ready to start writing some strategies of your own. You can read our follow-up post on a systematic approach to identifying the trading logic and developing a strategy.

For some hands-on experience, try developing your own strategies using our toolbox.

--

--

Auquan
auquan

Building Tools and Platform to solve finance problems using Data Science