Graphing Fed Data

The quantmod package is great for grabbing various financial data series from online sources like Google, Yahoo, Oanda, and the Federal Reserve. It also has some nifty technical charts that look very nice but are rather difficult to modify. One such problem is charting multiple data series. In quantmod, you could do this:

variables=c(“INDPRO”,”TCU”); names=c(“Industrial Production”,”Capacity Utilization SA”)
recent=120 #Set number of most recent observations

It works but doesn’t really give you a result that you would want to publish. While there are probably ways to clean this up and make it presentable, it starts to become more work than it is worth.

The ggplot2 package does not really take advantage of xts and zoo class objects but it is fairly simple to transform them into a dataframe to use with ggplot. The same exercise as above can be done with greater control and what I would consider to be better quality graphics in ggplot.

variables=c(“INDPRO”,”TCU”); names=c(“Industrial Production”,”Capacity Utilization SA”)
recent=120 #Set number of most recent observations[1]),recent),last(get(variables[2]),recent)))
temp$Date=as.Date(row.names(temp)); temp=melt(temp,id=”Date”,measure=c(“TCU”,”INDPRO”))

Is it longer? Yes. Is it worth the extra effort? I certainly think so.

Correlation Graph

Earlier this week, I saw a message in my Twitter feed talking about an unusual correlation pattern between the S&P 500 and the Dow. Unfortunately, the graph produced by the Greg Mankiw recommended site was grossly inaccurate showing periods of zero correlation between the indices. A few lines of code using the Quantmod package in R can easily replicate the functionality of the site and a prudent analyst can simply load a more reliable data source before arriving at any conclusions. This script takes data from Yahoo finance but you can easily use Google finance or load your own data.

Quant N00bs

Boys go through a dinosaur phase, girls go through a horse phase, and it seems that many engineers and computer programmers go through a quant phase. Having studied some nonlinear dynamics, they believe that with so many numbers, the market is just another system that can be tamed with a few well written equations. Despite my somewhat condescending tone, I do not wish to dissuade any more whiz kids from daytrading. I made good money beating these guys on the buy side in the equity markets and I would have made far more on commissions if I were a broker. The one thing I would ask is that you not keep comparing the market to a casino.

I know you hear the media often referring to “gambling” with other people’s money but having played some on your own, you should now know the difference between Knightian risk and Knightian uncertainty. If you manage to stay solvent long enough, you will likely come to the conclusion that markets exhibit less Knightian risk than Knightian uncertainty despite what you may have read about VaR, Bachelier, GARP, or A Random Walk Down Wall Street. (And no, Taleb was not the first one to think of this though he was the first to make the watered down version accessible to the general public and make far more money than he is worth in speaking fees.)

Does this mean that the distinction between Knightian risk and uncertainty should not exist? Ask any entrepreneur or manager with real operational responsibility and they will tell you how much time they spend trying to develop an organizational structure that handles the usual problems while keeping the organization flexible enough to deal with unknown problems. By assuming that all problems cannot be anticipated, the organization is not prepared to handle any problem whether expected or unexpected and is equivalent to sticking your head in the sand. The same is true in investing. By trading stocks when you don’t understand how the company makes money, you are exposing yourself to the same total risk as the skilled investor as you enter the position but increasing your risk as you stay invested since you have less information than the skilled investor. The access to information comes not from reports,  insider trading, or the latest rumor; it comes from not being able to interpret the information that you already have access to. The longer you stay invested, the more the interpretation of information matters.

Given that last statement you may be wondering if you don’t know anything about a company, why shouldn’t you stick to technical analysis and trade frequently. The reason is simple. Long time horizons are made up of many short time horizons. Like VaR, the fact that there is a 99% chance of not losing greater than x amount of your portfolio in the next 10 days does not mean that the probability of losing more than x amount in the next 10 days is 1% because assumptions on methodology will be proven wrong when you need them most. When the market moves against you, there is not always a forward looking indicator and when there is, it may not have been reliable in the past. Even understanding the fact that this time is not different does not necessarily mean that historic data will help you because history rhymes but doesn’t repeat itself.

Now, before you show me the massive amounts of money you have made, please learn how to compute compound time-weighted returns and include all operating costs such as commissions, leverage, and information access. If you need help, look up GIPS. Understand that telling me you made 800% on your favorite trade does not constitute any meaningful performance information.