TRADING SYSTEMS
Aspects of an ALGORITHMIC TRADING SYSTEM
A trading algorithm consists of several elements. You need to decide which markets you want to trade, develop the logic with which you want to trade them, and define parameters by which the trading logic is triggered. Your system should incorporate the cost of trading and commission, called slippage. There are good reasons why you should start simple and not overfit your system. Read about these aspects here:
Markets You Can Trade
Currently Quantiacs trades in both Stock and Futures markets. A Future is a contract to deliver a specified amount of the underlying product at a certain date. You can learn more about Futures here. Trading in both Stocks and Futures allows for a great degree of diversification and helps you to generate a trading system that is successful in many market environments. You can find the full list of available markets on the Markets Page.
Parameters
Your trading system will most likely depend on the choice of certain parameters. The parameters are for example averages or ratios of price data. The data points are OPEN, HIGH, LOW, CLOSE, VOL, and OPEN INTEREST (for Futures). Look at the sample trading system on github. It uses two parameters smaPeriodLonger and smaPeriodShorter. These are simple moving averages, which smoothen the noisy market signals by averaging over a certain time period. We picked 200 days and 40 days as values for the time periods, but these values are not necessarily the best. In this very simple case we might be able to improve these numbers by computing all combinations of smaPeriodLonger and smaPeriodShorter in a reasonable interval and picking the best solution. As algorithms become more complex, it becomes increasingly challenging to find a stable and optimal set of parameters. We would recommend to keep your model as simple as possible.
Long and Short
Once you’ve picked your markets and defined the parameters you need to decide what your system should do: buy or sell? In trading you can take two positions on a trade, you can either enter the position long or enter the position short. When long in a market, you benefit if the price of the market increases. When short a market, you benefit if the price of the market decreases.
When trading stocks, generally it is easier to find good systems if you are trading only long. The short side is usually harder to predict, since very large moves happen in very little time. However, having a short side onboard might help a great deal in years like 2001, 2002 or 2008. Having a short strategy also helps to reduce the correlation to conventional investment strategies. One important thing to note is that, while your potential losses with a long trade are limited to 100% per position, a short trade may lose more, if the price of the asset more than doubles.
Trading Costs
Trading costs can have a significant effect on the performance of a trading algorithm. The two main contributors to trading costs are commissions and slippage. Commissions are fees charged by the exchange and the broker. You can not avoid them. In most cases they are quite low compared to amount of your trade. Slippage is the price at which you expected or placed your order and the price at which your order was actually filled. Factors like the liquidity and the volatility contribute to the slippage as well as the volume you want to trade. Learn more about slippage here.
In our backtesting toolbox we use a very simple yet conservative approach to estimate slippage and commissions: We take 5% of the daily range as the trading costs. This computes as (HIGHLOW) * 0.05. This covers the assumption, that you’ll have more slippage on days with larger market moves, than on days with smaller. This approximation might overestimate the real trading costs. In this case, it is better to overestimate than underestimate.
Performance of a System
What makes your system a good system? Universally defining the quality of a system is impossible, but a good first approximation is the Sharpe Ratio. The Sharpe Ratio compares the realized performance against the risk (or volatility) taken to achieve that performance. Every investor would prefer systems with high performance and low risk. This is why a higher Sharpe Ratio is usually better.
Overfitting
Overfitting is the natural enemy of trading algorithms. With enough parameters, it’s easy to fit a model perfectly to the past. Mathematically: You can always fit n data points perfectly with a polynomial of degree n1. In other words, you can build extremely complicated algos that perfectly retell the past but have no clue what happens next. So, here are a few rules of thumb how to avoid overfitting:

Don’t use too many parameters. You’ll have a hard time to find the best solution in the parameter space. If you manage to isolate an effect with only a few parameters, it might be more stable.

Test your hypothesis. Don’t use all the data for the development of your algorithm. Save some for a test once you’re done. You’ll have a much higher chance of success on live market data, if your system doesn’t fail your outofsample test.