My previous article on Finite State Accounting described a quantitative analysis engine that considers a large number of market conditions. The engine does not make buy and sell decisions, but rather accounts for return based on simple above and below states of the technical indicators analyzed. Eight different lengths of five important technical indicators are analyzed.
It is anybody's guess why trading algorithms are generally not publicized. I don't think it is because they make a lot of easy money, but maybe that is just lack of cleverness on my part. In any case, there is less of a need to keep a quantitative algorithm secret; somebody good enough to duplicate it, is good enough to produce something equal or better with the same amount of effort.
This analysis considers 17 important US Equity ETFs, starting on the first trading day of March, 2019 through October 8. January and February are not considered because the strong rally at the beginning of the year is over and there is a concern that that data would distort the current numbers.
Buy and Hold Profit
The column HProf is the buy and hold profit for a $10,000 investment in any of the securities listed. An investor who bought $10,000 worth of each security on March 1, 2019 and held until October 8 would have a profit of $2,110 on the $170,000 investment.
Fixed (FProf) and Reinvested (RProf)
I reduced the number of columns to those items that I sort of understand how to objectively analyze.
Fixed Amount - FProf - An investor invests $10,000, and sells on a state transition. The investor can optionally reinvest $10,000 in the new state or wait for a transition to the favored one to reinvest $10,000.
Reinvest Amount - RProf - the virtual investor maintains a yinyang account with two or more virtual balances. He allocates $10,000 to each state and reinvests whatever the balance is in the appropriate account type on a state transition.
Evaluating the Profit Numbers
The preferred setup for these numbers is HProf should the highest and FProf should be lowest. Anything else is objectively weak. Negative profit numbers are bad.
Note how XLP is the only security with a preferred profit number structure for the period. The other securities with decent profits (SMH, XHB, and XLK) are questionable.
FProf above RProf is an issue because it suggests that favorable action from earlier in the sample period is deteriorating.
The condition the table is analyzing is M21M03. I randomly selected this from the 175 combinations the program analyzes.
The five indicator types are:
- E - Exponential moving average
- L - Least Squares moving average
- M - Simple moving average
- P - Percent in Range (or Stochastic Oscillator)
- R - Rate of change
M21 (21 day simple moving average of the weighted price) is the first indicator type in the condition. M03 (3 day simple moving average of the weighted price) is the second indicator type.
Selection of Combinations
Programming this took me some time to figure out (and I'm not completely there yet). It requires some practical skill in manipulating two dimensional matrices. This analysis looks at each of the 5 different types of 3 day indicators in conjunction with each of the other 7 different lengths (of the 5 indicator types). That makes the 5 x 7 x 5 = 175 different combinations.
The fine points of each indicator type are well worth understanding but they will not be dealt with in this article.
Four State Analysis
Two state analysis tracks above and below states for a single indicator. Four state analysis tracks above and below for two indicators. Eight state analysis (three indicators) is kind of useful but probably farther than most reasonable people want to go.
Four state analysis is useful for swing traders because the states generally transition every few days. This is an important methodology to mitigate time risk. Stops are a bit dubious in my opinion, they are more of a sign that one is betting too much money than anything else.
Each of the 175 indicator combinations are divided into four states:
- AA = Price is above both indicator readings
- AB = Price is above the first indicator and below the second
- BA = Price is below the first indicator and above the second
- BB = Price is below both indicators.
Note: P (Percent in Range) in range considers 50% to be zero, so if price is at the 40% level between the high and low in the range that is considered below.
Some general rules for each state:
- AA and BB are usually profitable.
- AA occurs about 50% of the time, the longer, the better.
- BB occurs about 25% of the time, the shorter the better.
- AB and BA together occur about 25% of the time.
- AB and BA are less reliable than AA and BB.
M21M03 State Accounting
Note how the grand totals crossfoot to the previous table. Any of the 175 combinations will always produce the same buy and hold profits but the accounting of the state profits will be different.
Obviously, it would have behooved a trader to avoid BA situations using this combination on these equities during this time period. Mixed states have questionable performance characteristics. It makes some sense to avoid them, but they can be nice if you play them right.
BA usually happens when the security is in BB and there is a pop to the upside strong enough to change the short term indicator but that doesn't change the state of the longer indicator. The disastrous profit numbers are saying that those pops have had poor follow through in the current environment.
AB is similar. That usually happens when the state is AA and a drop occurs that is strong enough for the shorter term indicator to go negative but not strong enough to reverse the longer. Logically, this can be either a good entry or exit point, depending on one's market forecast.
State Profit Profiles
The table below shows SPY profit during the AA state based on number of days in the state.
This is data that includes October 9.
Notice that if the above state doesn't hold for more than three days a loss will usually result.
There might be a question about whether it is better to wait for a few days before jumping in when AA happens (or BB for that matter). The short answer is not really, it is pretty much turtles all the way down (or up).
Table created with data from Norgate
Notice the profit curve based on days held is backwards compared to AA. If BB doesn't make money in the first three or four days, y pobreci! as Omar says in Scarface.
BA and AB states produce charts that are similar to the short term indicator state (second letter). That is AB, looks like a BB structure and BA looks like AA.
Ranking the States
The simplest way of playing the various combinations is to invest in the highest ranking states with the hope that the favorable behavior will tend to extend into the future. The best performing states can be for a single security or a portfolio. Here is a snapshot of a table showing the best performing states for all 17 ETFs.
Note that mostly longer length BB conditions dominate the top. This analysis has an extra day of data in it, than the first tables. I ran the sample without using lengths of 57 and 73. Both of those lengths do quite well in BB states during the sample.
FProf is positive and below RProf for all of them. AProf is average profit per trade in basis points (100 = 1 percent). AMax is higher than AMin. AMaMi (average exit percent of Max Min Range) is very important. BB has a significant technical advantage over AA in maximizing AMaMi because the target is based on a short term up move. AA crosses below well below the Max. One wants the winning percent to be as high as possible, that is the ratio of CWin to CStat.
The best performing conditions of state AA are listed below:
Profits are lagging BB and objective analysis shows technical issues with many of these conditions, nevertheless some are worth playing.
Some securities perform better at different states. For example IWM and XLV are typically quite profitable in below states, QQQ, SMH, and XLK typically play well above. The best performing states can also be analyzed for each security
The table below shows how my little friends performed with L31R03AA.
Table created with data from Norgate
L (Least Square Moving Average) is generally good for above conditions. This indicator flips between above and below quite often compared to the other indicators. That can be a double edged sword of course.
R43E03BB is analyzed for all securities below:
If R43E03BB is traded with L31R03AA, RProf for the period would be about $23.5K versus $3.6K for buy and hold for the period. That seems decent enough to put some money on but single state results are volatile, so including many of the best performing conditions is well worth analyzing. That will probably be part of the next development steps.
There seems to be little question that this type of analysis vastly improves decision making.
"...and I was considered to be the least among the brotherhood." Ashur to Glabur - Spartacus
I might be a little unusual in that I have enough knowledge of some of the obscure subject matter to develop this concept to where ever it is at the moment. It has taken me about a year of full time work (by my standards) to get the application to where it is now, but the underlying data manipulation structure (downloading prices, reporting results, etc.) was developed and improved over several decades of putzing around with it.
Certainly a small team of specialists could do a lot of damage. One has to wonder how quickly well funded teams from investment banks will be able to implement something that totally revolutionizes economic life as we know it; my guess is that won't be immediately positive. The next decade should be interesting.
Relatively advanced knowledge of mathematics, computer science, and statistics are probably necessary to compete in this field. It is absolutely imperative to be able to exploit computer power effectively. I can sort of get by with watching hundreds of youtubes on math and statistics to go along with 40 some years in systems development.
I develop with Excel VBA. The "in" language, at the moment, is Python. My specialty, such as it is, is doing simultaneous analysis on multiple securities and I think that capability is somewhat tenuous on the more fashionable quantitative development platforms. These are just tools, pretty much a matter of taste.
There are a number of excellent quantitative firms. I like Bespoke which contributes here.
Recently I attended a webinar by Dr. Ernest P. Chan and was impressed with his knowledge. Perhaps I'm flattering myself but think I could skip the beginners class. Anyway, there seems to be excellent educational resources, not least of which is youtube. Personally, there is a lot to be said for figuring things out for oneself - in my case, it avoids a lot of arguments.
This seems to be an excellent career choice, but an actual interest/talent in the relevant academic subjects is required.
Disclosure: I/we have no positions in any stocks mentioned, and no plans to initiate any positions within the next 72 hours. I wrote this article myself, and it expresses my own opinions. I am not receiving compensation for it (other than from Seeking Alpha). I have no business relationship with any company whose stock is mentioned in this article.