Oct 13

Pattern matching: a quick look at the last 11 months

John Hussman posted the following pattern on his twitter:

Source: John Hussman’s Twitter

So I thought this would be a great time to see which points in history the Systematic Investor Toolbox pattern matching algorithm would highlight. Instead of looking at the Dow Jones I will use the S&P500 Spyder (SPY). Choosing a window period of approximately 11 months and looking at 20 years of data lets see what happens:

###############################################################################
# Load Systematic Investor Toolbox (SIT)
# http://systematicinvestor.wordpress.com/systematic-investor-toolbox/
###############################################################################
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)

#*****************************************************************
# Load historical data
#****************************************************************** 
load.packages('quantmod')   
tickers = 'SPY'

data = getSymbols(tickers, src = 'yahoo', from = '1950-01-01', auto.assign = F)


#*****************************************************************
# Dynamic time warping distance 
#****************************************************************** 
# http://en.wikipedia.org/wiki/Dynamic_time_warping
# http://dtw.r-forge.r-project.org/
#****************************************************************** 
load.packages('dtw')

obj = bt.matching.find(Cl(data), normalize.fn = normalize.mean, dist.fn = 'dist.DTW', plot=T,, n.query=228,n.reference = 252*20)

matches = bt.matching.overlay(obj, plot.index=1:90, plot=T)

layout(1:2)
matches = bt.matching.overlay(obj, plot=T, layout=T)
bt.matching.overlay.table(obj, matches, plot=T, layout=T)

Source: Time Series Matching with Dynamic Time Warping

Interestingly enough, the runup starting in july 2011 is chosen as the closest match, and we all know how that ended. There are multiple other scenarios however.

The average returns of the top 9 matches seem to under perform the anytime/benchmark return (not shown).

More pattern matching posts to come in the future….

Now back to turkey day…..

Update: I ran the same code for the DJIA diamonds (DIA):


The same conclusions hold true, the runup starting in july 2011 is the closest match and the next week/month return is below average. In the future we will examine more pattern matching methods….

Sep 24

Trahan and Lazar: Buy Domestic Consumer and Industrial stocks

Interesting interview with Francois Trahan and Nancy Lazar. I’ve long been a fan of Trahan and his ‘Inflation is the new fed funds rate’ thesis, and now that he’s moved to a new firm to focus only on macro strategy I’m watching Cornerstone Macro LP very closely. Check out the interview below in which they discuss the outlook for the US:

Source: WealthTrack

Some of the takeaways:
• Macroeconomic influences have an outsized impact on equity market returns
• Dividends will contribute less to equity returns over the next few years. Markets driven mostly by PE expansion
• US has a low cost of energy because of natural gas
• Structural story of inflation being contained in US
• Emerging market bond sell-off and inflation problem: Indonesia yields from 5% to 9%, much worse than change in US yields
• Retail/Consumer stocks will have structural and cyclical outperformance vs materials/energy
• Buy US based industrial companies

I also recently came across this presentation by Trahan to the CFA society which has some great charts. In particular here are two slides that highlight the shift from a fed dominated market cycle to inflation dominated.

Source: Francois Trahan presentation to the CFA

I’ve also mentioned Trahan’s LEI framwork from his book in a previous post.

Sep 10

Beyond Crunching Numbers: How to Have Influence

I wanted to post this panel interview from the 2013 MIT Sloan Sports Analytics conference about how to influence people as a number crunching analyst. Its no secret that good stories influence much more than statistics. You’ll hear some good takeaways from analysts that have been very successful in their careers and have influenced others.

Jun 27

been traveling….

but i’ll be back soon, here’s a peek at what i’ve been up to:

May 18

Gold: Dead cat bounce or double bottom?

Gold is at another interesting inflection point. After the break of support, gold crashed 15% in two days. It has since then staged a bounce and is now retesting support. Is it going to be a dead cat bounce and collapse further or a double bottom and rally?

Source: Stockcharts, PatternSite

Is the great trend over? I’m not sure, but if you’re an intevestor in gold I hope you’ve been double checking your thesis. A great place to start is the Golden Dilemma paper also here and here. In short, it examines the common reasons for holding gold, including:

“gold provides an inflation hedge”
“gold serves as a currency hedge”
“gold is an attractive alternative to assets with low real returns”
“gold a safe haven in times of stress”
“gold should be held because we are returning to a de facto world gold standard”
“gold is underowned”

Examine your own reasons carefully. Most people blindly buy into gold as a religion. I used to believe that gold was a hedge against instability but I’m not so sure anymore, as it trades more like a financial product, commoditized by wall street. Gold’s former role should have thrived in the current environment of intervention and positive feedback loops but it has since lost the qualities that have been described by others:

“The abandonment of the gold standard had broad cultural significance. It is no exaggeration to insist that going off the gold standard was the economic equivalent of the death of God. God functions in religious systems like gold functions in economic systems: God and gold are believed to be the firm foundations that provide a secure anchor for religious, moral, and economic values. When this foundation disappears, meaning and value become unmoored and once trustworthy symbols and signs float freely in turbulent currents that are constantly shifting.” ——Mark C. Taylor

The end of the gold standard (1973) unfettered the dollar from precious metal backing and laid the seeds for unconstrained credit growth. The economic consequences of the movement off of the gold standard have been incalculable, but the psychic effects have been no less profound. In a world in which financial promises are only as good as the counterparties that make them, gold is a promise kept. Gold is the anti-derivative, the anti-credit default swap, the anti-LBO. More important, it is the anti-dollar, the anti-fiat currency. And a fiat currency is the ultimate example of a promise, increasingly, a promise that can’t be kept. Gold is a tangible object in a world that came to overvalue intangible things. It is grounded in a world where few values are grounded. Most important, it is a physical good that is limited in supply. If the end of the world ever comes, gold will be your best friend. And it is indisputable that the end of the world is closer today than it was yesterday, and will be closer tomorrow than it is today

Source: Michael Lewitt

It seemed like the world was a perfect place for the former ‘foundation’ version of gold, with government intervention reaching new extremes in this Keynesian experiment. Positive feedback loops now taking place will have unintended consequences in the future. No one knows how this experiment will end. Gold seemed like the perfect place to hide….

Source: Ineichen Research and Management

As I said before, gold has traded more like a financial product lately than the foundation or hedge it was supposed to provide. Is the trend in financial assets to gold (Tangibles) finally reversing course?

Source: ShareLynx

No one can tell you for sure. As an investor, I don’t like gold under its support line around 1500. Under that line and its much harder to manage risk and know when you’re wrong. We shall see where gold heads in coming days.

May 08

Words from the wise/Things I’m reading

Been busy lately, but I’ve still had time to read. Here are some interesting articles and podcasts:

Ned Davis via PragCap at Big Picture

If you want to know if its worth your time to spend an hour with this legendary technician, consider what Ned calls the four basic traits of successful investors:

1. They look at objective indicators. Removing the emotions from the investing process, they focus on data instead of reacting to events;
2. They are Disciplined: The data drives decision making with pre-established rules. External factors do not influence them;
3. They have Flexibility: The best investors are open-minded to new ideas, or revisiting previous thoughts;
4. They are Risk adverse: Not always obvious to investors, it is a crucial part of successful investing.

via falkenblog

Cliff Asness: An hour interview with Cliff Asness.

It would be hard to improve upon Cliff’s Big 4 Investment Principles:

Cheap stocks beat expensive stocks
High carry beats low carry
Low risk beats high risk
The trend is your friend

Five Steps Toward Becoming Your Own Trading Coach

1) Developing a Framework for Thinking About Markets – The successful traders I’ve known and worked with have developed their own ways of thinking about markets, supply and demand, intermarket relationships, and the like. This framework helps them understand why markets do what they do; they are conceptual lenses through which traders interpret market action. My own framework has developed from an appreciation of Market Profile theory and concrete experience working with various groups of market participants: retail, market makers, investors, etc. That framework sensitizes me to the market behavior of the largest participants, seeking clues from their behavior as to likely near-term price movement.

The Fed and Interest Rates – The Details

long rates are ultimately a function of current economic conditions. The Fed sets short rates based on expectations of future economic conditions and long rates are an extension of short rates. In fact, if the Fed wanted to pin the 10 year t-bond at 0% it would just do it, but that’s a different matter. And bond traders front-run the Fed in trying to outguess the future economic conditions. So, it’s best to think of this whole relationship like a person walking a dog through traffic. The Fed walks the bond market around and the bond market tries to steer the Fed by guessing where traffic is headed. But the Fed can always control the rate and the leash if they want. The dog ultimately knows this and so doesn’t steer too far from its master (though it doesn’t want to be behind its master!). So it’s all a delicate guessing game because there’s no telling when the traffic might become faster or slower than we expect.

Apr 21

Canadian households now the most indebted….

This is an interesting chart from Pragmatic Capitalism. It shows that Canadian households are now the most highly leveraged out of the listed developed markets.


Source: Prag Cap

As I’ve said before, Canada is the last remaining developed country to start private household deleveraging. All signs point to Canada being 3-4 years behind the deleveraging process that other developed nations have started but set to go through the same process given the high level of debt. Hopefully the rest of the world goes through a recovery phase and Canada can use its exports to make up the gap between potential and actual growth instead of leveraging up its public sector to counteract the loss of growth.

One positive of note is that the Canadian corporate sector and federal government remains relatively underleveraged:

What It Means for Canada

Canada has distinguished itself through the debt super cycle (Chart 10), though there are some recent trends that bear watching. Over the past twenty years, our non-financial debt increased less than any other G-7 country. In particular, government indebtedness fell sharply, and corporate leverage is currently at a record low (Chart 11). “


Source: Growth in the age of deleveraging

See Also:

Bears attack Canada
Mark Carney speech highlights

Apr 14

S&P500 tracing out crash pattern

By crash pattern I’m referring to Didier Sornette’s Log Periodic Power Law (LPPL). This is a price trend that has exhibited super exponential price acceleration with log periodic oscillations and mean reverting residuals. This type of pattern does not always lead to a crash but has led to a change in regime in price action. I noticed the pattern forming visually and then John Hussman confirmed a fit to the model on his twitter feed last week. It is an interesting event to consider, although traders should always default to the price action at hand, as patterns and divergences can exist longer than we can remain solvent if we ignore the reality of price action.

A 1590; B -260; Tc 2013.272; beta = 0.55; C = 0.28; omega = 10.2; phi (phase) 2.3. Classic uncorrected, diagonal, high frequency ramp at end
Not convinced that markets obey math, but increasingly shallow corrections at accelerated frequency suggest euphoria
Geek’s Note – Log-periodic Sornette-type bubble in S&P 500 with Tc = 2013.27 just reached its finite-time singularity. Interesting to watch.
Sornette bubbles – increasing volatility at 10-minute intervals is indicative of log-periodic fluctuations => singularity: buying every dip

Source: John Hussman

This pattern got media coverage a couple years ago when it predicted a a drop in the Chinese equity market. I thought the following quote helped explain what the pattern is trying to model in terms of underlying agent dynamics.


Chinese Equity Bubble: Ready To Burst

Patterns emerging from complexity

Due to their very nature, financial markets exist of interacting players that are connected in a network structure. These inter acting players, often referred to as interacting agents, are continuously influencing each other. In scientific literature it is said that such a system is subject to non-linear dynamics. Modeling such a system in full detail is practically impossible to do. That is why the long-term behavior of the global economy or the weather is quite hard to predict.

Recent research, however, has provided new tools to analyze complex non-linear systems without having to go through the simulation of all underlying interactions. When interacting agents are playing in a hierarchical network structure very specific emerging patterns arise. Let us clarify this with an example3. After a concert the audience expresses its appreciation with applause. In the beginning, everybody is handclapping according to their own rhythm. The sound is like random noise. There is no imminence of collective behavior. This can be compared to financial markets operating in a steady-state where prices follow a random walk. All of a sudden something curious happens. All randomness disappears; the audience organizes itself in a synchronized regular beat, each pair of hands is clapping in unison. There is no master of ceremony at play. This collective behaviour emanates endogenously. It is a pattern arising from the underlying interactions. This can be compared to a crash. There is a steady build-up of tension in the system (like with an earthquake or a sand pile) and without any exogenous trigger a massive failure of the system occurs. There is no need for big news events for a crash to happen.

I don’t want to claim this pattern has magical powers in predicting the market but it interesting to watch. Is it nothing more than an acceleration in trend? Is this the same as a rising wedge formation?

In my experience, rising wedge formations have an equal tendency to break upwards or downwards, making the pattern equally bullish and bearish. However, that is in looking at individual stocks. In an index this level of exponential acceleration is unlikely. We shall we what happens….

Update: John Hussman wrote his weekly market commentary and provided some great quotes regarding the LPPL:

It’s important to begin this section clearly: I don’t believe that markets obey math. Markets are complex, adaptive, behavioral systems that reflect the combined behavior and feedback between an enormous number of participants. At the same time, I strongly believe that the results of those interactions often take on observable patterns, and part of the job of investors is to recognize and understand those patterns.

Another pattern that we’ve trained ourselves to identify, with some concern, is an emerging tendency toward increasingly immediate attempts by investors to buy every dip in the market. This tendency reflects a broadening consensus among investors that there is no direction other than up, and that any correction, however small, is a buying opportunity. As investors clamor to buy ever smaller dips at increasing frequency, the slope of the market’s advance becomes diagonal or parabolic. This is one of the warning signs of a bubble. It does not require much of a “catalyst” for these bubbles to burst, other than the retreat of some investors from the unanimous consensus that buying every dip is an act of genius.

Back in July 2008, I observed this dynamic in the parabolic ramp of oil prices, writing “Geek’s Rule o’ Thumb: When you have to fit a sixth-order polynomial to capture price history because exponential growth is too conservative, you’re probably close to a peak” (see The Outlook for Inflation and the Likelihood of $60 Oil).

Indeed, the closest way to describe the price dynamics of oil at the time was to think in terms of a “log-periodic bubble” as described by Didier Sornette. The essential feature here isn’t precision in the fit between the log-periodic wave and the actual price, but rather the tendency of prices to experience a series of increasingly frequent but shallower dips, ending in a nearly uncorrected upward ramp in which virtually every dip is purchased as soon as it emerges. Again, I don’t believe that markets follow math, and Sornette’s approach shouldn’t be taken as implying such precision. For my part, the key feature of log-periodic bubbles is the tendency toward those increasingly frequent and shallow corrections, as investors buy dips with accelerating urgency, ending in a diagonal or parabolic ramp that I’ve identified with the yellow oval. That uncorrected binge at the end of mature, overbought, overbullish advances is a hallmark of bubbles.

Source: Hussman Funds

John Hussman goes on to provide some great examples of the LPPL with charts. you should definitely check out his article.

Apr 03

Defensive rally finally sees a down day

From a pure price action view this market has been flawless, forming a nicely defined trend channel upwards and grinding higher slowly amidst a sea of doubt and bearishness. Under the hood, the intermarket signals have been pretty defensive for quite some time, with healthcare, utilities and consumer stocks outperforming.

The chart below from finviz shows that this defensive out-performance has been occurring on multiple time frames, with the defensive sectors being in the top 3 on the 1 day, 1 week and 1 month time-frames and 3 out of the top 4 in the 3 month. I guess its good advice when Charles Kirk says to be wary of divergences in absence of bearish price action. The time for bearish price action may finally be at hand.

Mar 26

Steve Jobs: The Most Important Thing in Life

via Farnam Street

Well said, now its up to you to take the first step….

When you grow up, you tend to get told that the world is the way it is and your life is just to live your life inside the world, try not to bash into the walls too much, try to have a nice family life, have fun, save a little money.

That’s a very limited life. Life can be much broader, once you discover one simple fact, and that is that everything around you that you call life was made up by people that were no smarter than you. And you can change it, you can influence it, you can build your own things that other people can use. Once you learn that, you’ll never be the same again.

And the minute that you understand that you can poke life and actually something will, you know if you push in, something will pop out the other side, that you can change it, you can mold it. That’s maybe the most important thing. It’s to shake off this erroneous notion that life is there and you’re just gonna live in it, versus embrace it, change it, improve it, make your mark upon it.

I think that’s very important and however you learn that, once you learn it, you’ll want to change life and make it better, cause it’s kind of messed up, in a lot of ways. Once you learn that, you’ll never be the same again

Steve Jobs Solved the Innovator’s Dilemma

Older posts «