To keep our portfolio market neutral, we can include short signals for stocks likely to get delisted. We could short these stocks at market close each time the S&P updates its list. We can build an algorithm that maintains a list of the 10 to 25 stocks with the highest market cap outside of the S&P 500, along with a list of the 10 to 25 stocks with the lowest market cap within the index.
When the model is created, we decide how to allocate our capital in the safest, most efficient and productive way possible. This is the role of portfolio construction. Portfolio construction models decide how many shares of each asset to purchase, allocating our available margin. In our case, we might have 20 candidates that would be listed; allowing us to allocate 5% of the portfolio in each, or 2.5% with an equivalent short. Sometimes there are risk controls baked into portfolio construction code that would adjust this target to be in balance with an overall portfolio, or weighted based on the likelihood of inclusion.
At this point, the algorithm knows which shares to purchase and how many shares it would like to purchase. We send the decision to the execution model. This code decides the right order types and times to send the order. Often in brokerages they have premade execution algorithms you can use without any effort. For large hedge funds, they often break up their trades into thousands of smaller trades to hide the strategy. For the purposes of this algorithm, a simple market-on-close should be sufficient.
Once the trade is placed, the algorithm should employ risk management code to keep an eye on volatility, or purchase options to hedge exposure when risk exceeds our comfort level. This is called the risk management model.
During this process, algorithms are backtested — simulated over historical data to see how they would have performed. There are many backtesting engines to help with this process. Of course, we would be using past data in terms of the index components.
Once a strategy has been identified, it is necessary to obtain the historical data through which to carry out testing and optimization. There are a significant number of data vendors across all asset classes. Their costs generally scale with the quality, depth, and timeliness of the data. The traditional starting point for beginning quant traders (at least at the retail level) is to use the free dataset from Yahoo! Finance.
Several firms provide free algorithm backtesting tools and financial data so engineers can design algorithmic trading strategies. Traders can build algorithms in a browser IDE, use template strategies and free data and design and test their own strategy.
Who is the ideal user?
Algorithmic trading isn’t easy and there are many ways for novices to expose themselves to danger without realizing the risk. When backtesting a system, one must be able to quantify how well it is performing. The industry standard metrics for quantitative strategies are the maximum drawdown and the Sharpe ratio. The maximum drawdown characterizes the largest peak-to-trough drop in the account equity curve over a particular time period. This is most often quoted as a percentage. It is always good to remember the adage that your worst drawdown is always ahead of you, so this number should include some breathing room and not be assumed to be your worst-case scenario.
A historical backtest will show the past maximum drawdown, which is a good guide for the future drawdown performance of the strategy. The second measurement is the Sharpe ratio, which is heuristically defined as the average of the excess returns divided by the standard deviation of those excess returns. Here, excess returns refer to the return of the strategy above a predetermined benchmark, such as the S&P 500 or a three-month Treasury bill. Note that annualized return is not a measure usually utilized, as it does not take into account the volatility of the strategy.
Once a strategy has been backtested and is deemed to be free of biases (in as much as that is possible) with a good Sharpe and manageable drawdowns, it is time to build an execution system.