System Trader Success
Share It!

Secret Weapon of Stock & ETF System Development

This is the second article in a two-part series where I discuss the top three pitfalls when backtesting Stock & ETF trading systems. In the first article, The Top Three Pitfalls of Stock and ETF System Development, I highlighted the top three issues system developers face. In this article, I’m going to show you how I fixed this problem to give me precise and accurate historical backtested results.

As many of you know, I designed the ETF trading strategies for Tuttle Tactical Management. This firm manages over $200 million in ETFs. I started working with Tuttle in 2007. One of the reasons why I was hired as a consultant was due to my expertise in developing realistic equity backtests. Being aware of the glaring issues of backtesting both Stock and ETFs with traditional trading platforms was the only thing I could do to fix the issue. I created a system development platform that fixes these issues.

Behold! The Secret Weapon

The platform  developed  was TradersStudio 1.0 way back in 2003-2004. I improved the algorithm in 2005 and it has remained the same since. My algorithm requires three different types of data streams for each equity being traded. In order to generate realistic results, TradersStudio needs split-adjusted data. Many data vendors roll split and dividend-adjusted data into one series. This is not an ideal solution as on longer historical data series it just compounds the errors in precision of the split-adjusted data. Next, TradersStudio uses dividend-only adjusted data. This simply means the data series is subtracting out the dividends without any further adjustments. CSI Data is the only vendor which allows you to produce this series because it, in effect, gives away the stock and ETF dividend database. Finally, TradersStudio needs the totally unadjusted data series. I then use my algorithm which allows me to accurately backtest portfolios of stocks and ETFs with any money management strategy you would like and get accurate results. One can see the splits and the dividends in the trade-by-trade reports along with real prices.

TradersStudio is the only product on the market that can produce a table of stock splits and dividends when CSI stock data or data from another vendor allows the data to be outputted in the correct format. Let’s look at the poster child for problems with splits and dividends, Microsoft.

This analysis is shown in the splits and dividends report.

msft

Click to enlarge

This report shows the date of splits and dividends. The number of shares (288) was calculated by multiplying the stock split ratios (2.0 * 2.0 * 1.5 * 2.0 * …). From this report we can also see that Microsoft did not pay dividends until February 19, 2003. This is a valuable report due to the fact that it allows us to audit our testing results to see what has happened. This report is also created when this type of analysis is performed on a portfolio of stocks. For example, if it were run on the S&P500 or NASDAQ 100, you would have this same report, ordered by date, for all stocks included in the portfolio.

Consider now the buy-and-hold calculation. Since the split factor for Microsoft is 288, our formula is (288 * (final price – original split price)).

Since there are issues with “maxbars” back, we need to use the value of the first bar’s open split adjusted price on 4/25/1986. That price was $0.11111. This is “Maxbarsback + 2” bars.  Next we have our final closing price which is $46.29. This is “lastbar – 1” close on 7/29/2015.

288 * ($46.29 [final price]) – $0.11111 [split adjusted open first bar] = $13,299.52

In our buy-and-hold calculation, we also need to adjust for dividends. Since Microsoft had split 288-1 by the time it paid any dividends and has not split during the dividend period, our calculation is easy. Simply add the dividends from the Splits and Dividends report at $10.28 per share and multiply that value by 288. This gives a total of $2,960.64. Add the two numbers together and we get $16,260.16 which matches exactly what is returned on the summary report as the buy-and-hold return.

A TradersStudio stock session has two different Trade-by-Trade Reports. There is the standard report that shows the entry and exit prices with the split-adjusted values. The P/L (profit/loss) from the trade does not represent the P/L that would be calculated by only using split-adjusted data, but the real P/L on the trade. The standard Trade-by-Trade Report used to the entry and exit prices match the prices you see on the chart. The Trade-by-Trade Real Price gives you real-world results. First, let’s look at the standard report. The split-adjusted price of Microsoft is less than $0.12 on June 5, 1986 while the real price is $34!

Click to enlarge

Click to enlarge

The other report is the Trade-by-Trade Real Price Report which shows the real entry and exit prices. For example, on June 5, 1986, Microsoft was purchased at $34.25 and exited at $33.75 on June 6, 1986.

Click to enlarge

Click to enlarge

This demonstrates how buy-and-hold is calculated and how TradersStudio gives you actual entry and exit prices as well as a Splits and Dividend history. There is a problem inherent in this analysis and it’s the reason why it looks like we only made a very small percentage of buy-and-hold with this system (only 376.99 points when buy-and-hold was over $16,000).

The answer is that we should be buying the current number of shares that one original share has become and not just one share to be consistent in our first test. The size of what we are buying should be equal to the current split factor.

To do this, we need to modify our simple system by adding a call to split factor to use for sizing and a flag so that buy-and-hold still represents starting with one share when we started. The code appears as follows.

'Simple ORB system to trade stocks, backtest adjusted for
'splits to create correct comparison to buy and hold
Sub QQQBreakOutStockTest(MULT)
Dim AveTr
Dim Nxtopen
Dim NumLots
NumLots = splitfactor
BuyAndHoldSingle = true
If BarNumber < LastBar Then Nxtopen = NextOpen(0) Else Nxtopen = 0 End If If Close > Open Then
Sell("SellBrk",NumLots,Nxtopen – MULT * TrueRange,Stop,Day)
End If
If Close < Open Then
Buy("BuyBrk",NumLots,Nxtopen + MULT * TrueRange,Stop,Day)
End If
End Substocks

‘ backtest adjusted for splits to create correct comparison
‘ to buy-and-hold
Sub QQQBreakOutStockTest(MULT)
Dim AveTr
Dim Nxtopen
Dim NumLots
NumLots = splitfactor
BuyAndHoldSingle = true
If BarNumber < LastBar Then Nxtopen = NextOpen(0) Else Nxtopen = 0 End If If Close > Open Then
Sell(“SellBrk”,NumLots,Nxtopen – MULT * TrueRange,Stop,Day)
End If
If Close < Open Then
Buy(“BuyBrk”,NumLots,Nxtopen + MULT * TrueRange,Stop,Day)
End If
End Sub

A new function called “splitfactor” is called. This number represents the number of shares that our original single share of stock has become after multiple splits. There is also a flag called “BuyAndHoldSingle” which is set to true. This bases buy-and-hold analysis on one original share and not the original number of shares that were purchased. For example if our analysis was started with 100 shares, buy-and-hold would be calculated based on 100 original shares if “BuyAndHoldSingle” was set to false. This means that the number of shares of Microsoft to buy and sell will change when there are signals based on the following schedule. Before September 21, 1987, only one share would be purchased.

MSFT_Table

By making this significant change, the analysis is now correctly comparing apples to apples and we see how the QQQBreakout system has done.

Click to enlarge

Click to enlarge

Indeed, our original system which looked like a joke $376.99 points versus over $16k now looks more respectable at $8,651.23 which is a little more than half of buy-and-hold. I am not arguing that this is a good system, but you can see how ensuring that we are truly comparing apples to apples which can change a system that looks dismal at first to something that actually makes sense.

When working with a stock database, the calculations should be to 4 decimal places including the time before decimalization to increase accuracy. Some stock database vendors have maintained their database calculations at only two decimal places even after decimalization occurred. This oversight serves to destroy the accuracy of the data. Using CSI Data avoids this issue entirely as they have done a good job overall of maintaining their data accurately.

The purpose of this example was not to give out a great system but to illustrate and explain the issues that are related to trading stocks with stock splits and dividends. In our next installments we will look more closely at some of the other reports involved in stock trading.

Next week I will be giving a live webinar, hosted by Jeff Swanson, where I will show you how I use TradersStudio when building trading systems. I will show you how to get accurate backtested results and avoid the three big pitfalls when developing system for ETFs and stocks.

About the Author Murray Ruggiero

Murray Ruggiero is the chief systems designer, and market analyst at TTM. He is one of the world’s foremost experts on the use of intermarket and trend analysis in locating and confirming developing price moves in the markets. Murray is often referred to in the industry as the Einstein of Wall Street. He is a sought-after speaker at IEEE engineering conventions and symposiums on artificial intelligence. IEEE, the Institute of Electrical and Electronics Engineers, is the largest professional association in the world advancing innovation and technological excellence for the benefit of humanity. Due to his work on mechanical trading systems, Murray has also has been featured on John Murphy’s CNBC show Tech Talk, proving John’s chart-based trading theories by applying backtested mechanical strategies. (Murphy is known as the father of inter-market analysis.) After earning his degree in astrophysics, Murray pioneered work on neural net and artificial intelligence (AI) systems for applications in the investment arena. He was subsequently awarded a patent for the process of embedding a neural network into a spreadsheet. Murray’s first book, Cybernetic Trading, revealed details of his market analysis and systems testing to a degree seldom seen in the investment world. Reviewers were universal in their praise of the book, and it became a best seller among systems traders, analysts and money managers. He has also co-written the book Traders Secrets, interviewing relatively unknown but successful traders and analyzing their trading methodologies. Murray has been a contributing editor to Futures magazine since 1994, and has written over 160 articles. As chief systems designer, Murray digs into the depths of niche and sub-markets, developing very specialized programs to take advantage of opportunities that often escape the public eye, and even experienced high level money managers.

Leave a Comment: