This article shows how to develop and execute a long/short equity strategy for Dow 30 stocks in the weekly timeframe with DLPAL LS software.
Long/short equity strategies take both long and short positions so that a net profit is realized while market exposure is minimized. The objective is to profit during both uptrends and downtrends and also limit losses during choppy markets.
In addition to being long/short stocks from the DOW 30 group, the strategy presented in this article also “exits and reverses” positions and therefore it is always long or short individual stocks. Below are the step involved in developing, testing and executing this long/short strategy:
- Data preparation
- Feature engineering
- Results import in Amibroker
- Strategy backtesting
- Weekly execution
- Feature updating
1. Data preparation
This is always an important step in strategy development. Irrelevant data usually lead to irrelevant models. We use weekly data for all DOW 30 stocks in current composition of the index starting on 01/2000 or latter. The reasons for the starting date is that after 2000 there was a major regime shift in equity markets as was shown in several articles in this blog. Data before 2000 can skew results and cause a bias that does not correspond to prevailing market conditions. Still, the data series after 01/2000 include two major downtrends and several minor corrections.
2. Feature engineering
The historical values of the features are calculated by DLPAL LS software. We use the “Create Features History” option from Tools, as follows:
In the above setup we first select a directory with the DOW 30 weekly data. We also select a T/S file with 5% profit target and stop-loss for feature classification purposes. This is a reasonable reward/risk for weekly stock data.
We also select the Normal major cluster but any other cluster can be used and then results compared. The history length is set to 253 bars so that calculation of features will start on 01/2013. The data history before that is used for the calculations. There are a total of 931 weekly bars since 01/2000 and this leaves 678 bars for feature calculations.
We also elect to have the results adjusted for trend by checking the option “Detrend All Results.”
DLPAL LS takes the original historical data files of the stocks as input and creates new files with extension .pih that include the feature values for each instance (row). An example is shown below for AAPL.
PLong and PShort are the long and short directions probabilities, respectively, Pdelta is their difference and S is the significance of the results.
3. Results import in Amibroker
The generated .pih files for each stock are imported in Amibroker. We use Amibroker because of the ease of importing historical data with additional fields, something that is not straightforward with other platforms. The four indicators are imported as follows: PLong is assigned to Volume, PShort is assigned to Open Interest, Pdelta is assigned to Aux1 and S to Aux2. A typical chart of the stock with the indicators is shown below. The chart also included the product Aux1*Aux2 because this is what is used in the strategy.
4. Strategy backtesting
Time-frame: Weekly (adjusted data)
Strategy type: Long/short, exit and reverse
Universe: All Dow stocks from current composition
Backtest period: 01/04/2013 – 11/03/2017
Features calculation period: 01/03/2000 – 12/31/2012
Maximum open positions: 30
Position size per stock: Equity/30
Position entry and exit: Open of next bar
Commission per share: $0.01
Buy if AUX1 × AUX2 > 50 (this is equivalent to Pdelta × S > 50
Short if AUX1 × AUX2 < -50 (this is equivalent to Pdelta × S < -50
We use a bias of 50 to limit the number of trades and reduce commission cost. The bias results in longer holding periods for positions.
|Parameter||Strategy||SPY TR B&H|
|Avg. bars in trades||19.8||931|
MAR (CAGR/Max. DD) for the strategy is 2.90 versus 1.12 for SPY total return in the same period. The strategy has low drawdown and can be leveraged to generate returns in excess of SPY total return.
Below are the equity curve, underwater equity curve, monthly returns table and results of a Monte Carlo simulation. (Click on images to enlarge.)
There is less than 5% probability of 4.5% or higher drawdown according to the simulation. The probability of drawdown exceeding 8% is about 1%.
5. Weekly Execution
Weekly execution involves updating data files and ranking stocks according to score. This is done in DLPAL LS with a few clicks. An example as of 11/03/2017 is shown below:
The bias is specified in the field labeled N. Then the original results for all stocks are scored for PDelta*S to get the final results above.
A CSV file of the results is also generated for use with an API for executing trades automatically through a broker platform.
6. Feature updating
Features can be updated automatically from “Create Feature History” tool. In addition, train and score files can be generated for use with machine leaning classifiers. Some of our customers prefer to let the classifiers identify the model or make the final selection of stocks to trade. Support Vector Machines (SVM) or even Binary Logistic Regression (BLS) can be used for this purpose. Additional features of choice can be added by the user to the files for more sophisticated models.
Click here for more details of how hedge funds can download a free fully-functional demo of DLPAL LS to test for a month.
If you have any questions or comments, happy to connect on Twitter: @priceactionlab