Introducing Analyzing Technical Analysis

I’m happy to announce a new series of pages: Analyzing Technical Analysis.

I frequently read people talking about Moving Average Crossovers, Bollinger Bands, Relative Strength Indexes and other indicators that allegedly allow traders to beat the market. The default algorithm at QuantConnect uses volume-weighted moving averges to beat the market. A few weeks ago, my Uber driver told me he uses Average True Ranges to trade the currency market.

It’s hard to believe all these strategies are being discussed if there’s nothing there. Then again, it’s also hard to believe a successful currency trader would drive Uber.

This series of posts is an attempt to rigorously and thoroughly check the effectiveness of technical analysis indicators through a series of iPython notebooks. In the notebooks, I’ll do my best to set my biases aside and objectively test the facts. In posts such as these, I’ll share my conclusions.

In the initial block of posts, I tested how returns react in the days after moving averages cross each other and when prices “bounce” off moving averages. (Click here for results and here for a guide to interpreting results.) In every strategy for every horizon, nothing close to statistically significant returns are observed. The strategies failed so spectacularly, I almost felt guilty about making my computer subset white noise so many times.

Regardless, it has been a good exercise. The past two weeks haven’t taught me how to beat the market, but I did finally have a good excuse to make the jump from R to Python, I learned how to perform bash scripting and I developed an objective way to test trading strategies.

With some luck, the next strategy I try will make me fabulously wealthy.

Quora Question: What are the strengths of Coasian Bargaining?

I recently answered the following question on Quora:

What are the strengths of Coasian Bargaining?

Coasian Bargaining says that agents can negotiate away the effects of externalities if transaction costs are sufficiently low. Ideally, this will lead to an efficient outcome.

wellwellwellSuppose you want to drill an oil well that will make you $100. Suppose it’ll make the lives of 20 neighbors $1 worse. How is this problem approached in different countries?

  • In Non-Coasian Anacapistan, you drill the well and create $100 of personal utility and $80 of total utility. The twenty neighbors are $1 worse off, but they all read Ayn Rand, flex their forearms, and carry on with their grim resolve to build the kind of buildings they want to build.
  • In Coastopia, the neighbors say you can drill the well iff you pay them $2 each. You drill the well and gain $60 of value. The neighbors gain $1 of value each.
  • In Coasistan, the neighbors demand $6 each. The well doesn’t get drilled. No one wins except for the lawyers who negotiated the failed deal.
  • In StatusQuoVille, the neighbors all vote on whether or not the well should be drilled. Depending on who shows up to the polls, it’s either drilled or not. The winner takes all, and everyone hates each other.

Coastopia is clearly an unrealistic fantasy, but it has some enviable features and real-world take-aways. In my experience, those who spend time thinking about Coasian Bargaining are more likely to be impartial when assessing real-world externalitites. While some are quick to say that fracking should be outlawed because it disturbs the locals, those from the Coasian school of thought will consider other possibilities. Maybe oil companies should pay money to the locals. Maybe locals should pay oil companies to not drill. Maybe oil companies should pay locals to move. Coasian bargainers are more likely to consider creative solutions rather than simply banning productive economic activity of which they disapprove. This leads to more economically efficient outcomes. In my toy example, the drilling clearly should happen. Any outcome that doesn’t result in a new well misses out on $80 of total utility.

All that said, I wouldn’t want to live in Coastopia. Incentives work both ways, and you wouldn’t want to live in a world where the prevalence of Coasian Bargaining encourages potential externalizers to seek out situations to threaten. “That’s an awfully nice stream you have there. It’d be a shame if someone were to dump runoff into it. Perhaps you should pay me to threaten someone from the next town instead.” On net, the average man’s distaste of naked Coasian Bargaining may be a good thing.

In DanielMorganTopia, all questions like these are solved through Pigovian Taxes, an approach which doesn’t require perfect bargaining and has decent efficiency if the government is reasonably competent. But I don’t rule the world. Not yet.

Grand Theft Autocorrelation

Michael-Counting-Money-16_RGBIn my last post, I discussed the concept of correlation. In my free time since then, I’ve been playing a lot of Grand Theft Auto V. It’s time to merge these noble pursuits.

As you may know, GTA V includes an online stock market that allows players to invest their ill-gotten gains in fictitious companies. Naturally, a Reddit user has created an updating database of Stock Market prices. I play on a 360, so I’ve analyzed the Xbox prices. I’ve developed a strategy that will earn money in the long-run, but first let’s do some learning.

As we previously discussed, correlation is a measure of how well the highs of one series line up with the highs of another series. Autocorrelation is a measure of how well highs of a series line up with the highs of the previous observation of the same series. Continue reading →

Using Game Theory to Predict if the U.S. will Bomb Syria

predatorDrone21I’m good at some things, and foreign policy isn’t one of them. I have no idea if Syria actually used chemical weapons, how the U.S. should respond to any potential attack or the probability of attacks spilling over into larger conflicts. I don’t understand Russia’s incentives or how they will react to any acts of aggression. However, I have created an excel book that calculates mixed strategy equilibria, and I will use this as a game theory example.

As a study, game theory uses mathematical models to predict the actions of rational decision-makers. The world is complex and noisy. If we want to know anything, we must make simplifying assumptions. People aren’t actually rational, but we can measure where they fail and model imperfect agents. A simpler first-pass is to assume they rationally maximize “utility” and assign utility to all possible outcomes.

As a simple model of the situation, let’s assume that the U.S. and Russia can either Waver or Stand Firm. Let’s assume they make this decision simultaneously and once. Their payoff is defined by the following table:


As an example on how to read this, if both countries waver, then the U.S. will receive -20 utility and Russia will receive 40 utility. If the U.S. stands firm and Russia wavers, then Russia will receive a payoff of 0 and the U.S. will receive a payoff of 30.

All of these values are editable in the excel file attached below. These are subjective estimates that I admittedly just made up. A bit of reasoning on the choices I made.

  • I’ve assumed the U.S. wants to give Iran a strong example of what happens to countries that use WMD’s of any sort. This means the U.S. would rather stand firm than waver, assuming Russia would not escalate the conflict.
  • I’ve read speculation claiming Russia has an economic interest in keeping Assad in power, as his government has made it more difficult for Qatar to sell natural gas to Europe.
  • To make the solution more interesting, I made these payoffs asymmetrical.
  • I’ve made the outcome of both countries going to war large and negative under the assumption that even a proxy war in Syria would be very bad for both sides.

The first thing my workbook does is check to see if any strategies weakly dominate the other. A strategy weakly dominates another strategy if a strategy is always as good or better than the alternatives regardless of how the opponent plays. In this game, each country would rather stand firm if the other wavers or waver if the other stands firm, so no strategies dominate.

Next, the workbook looks for Nash equilibria. A Nash equilibrium is a situation where neither player would unilaterally change his position. In this case, there are two Nash equilibria at the top right and bottom left. In these boxes, neither player can improve their outcome by changing their strategy. The top right equilibrium is better for the U.S. and the bottom left is better for Russia. But which equilibrium will we likely end up in?

In this case, probably neither. The next thing my workbook does is, if no strategies weakly dominate each other, then it will solve for the mixed Nash equilibrium. A mixed strategy is when a player chooses a probability distribution across all possible strategies. In the mixed Nash equilibrium, each player chooses a distribution of strategies that leaves the opponent indifferent between their strategies. Feel free to play with the payoffs and watch as the mixed solution changes.

In this case, the U.S. will waver from conflict roughly 96 percent of the time and Russia will waver roughly 91 percent of the time. In equilibrium, Russia and the U.S. will fight over Syria less than half a percent of the time.


The final sheet of the workbook analyzes the outcome for both players, including the expected value of the outcome. Based on this simplistic analysis, it looks like the U.S. will not bomb Syria and, even if it does, it is unlikely Russia will escalate the conflict. This is a good thing for the world’s total utility.

This analysis could be furthered by having the U.S. and Russia play several rounds where they choose to Waver or stand Firm. Any improved utility estimates are welcomed.

Here’s a link to the excel book that generated these reports. Of course, this workbook can be used in other contexts such as pricing decisions in a duopoly, figuring out how to make your roommate do the dishes, analyzing the read option, modeling evolutionary equilibria or solving your Game Theory homework.

Cruising with Minimal Wallet Bruising

How fast should you drive on long road trips?

One common piece of financial advice is to drive slowly. Per, “gas mileage usually decreases rapidly at speeds above 50 mph. You can assume that each 5 mph you drive over 50 mph is like paying an additional $0.25 per gallon for gas.”

That’s a big deal, and it can lead to some significant savings. However, this piece of advice ignores a giant cost of driving slowly: it takes more time. Therefore, I’ve created back-of-the-envelope cost estimates at various speeds. This is part of my ongoing quest to optimize literally everything.

Without further ado, here’s a graph of the total cost of driving 500 miles at a sustained cruising speed. I’ve assumed leisure time is worth $30 per hour, and I’ve used the same fuel assumptions specified at the above link. With these parameters, the cost of the entire trip is minimized at 95 miles per hour.


All of these can be adjusted in the workbook attached below. For instance, changing the value of leisure time to $10 per hour changes the optimal speed to 67 miles per hour.


I was somewhat surprised to see the cost of time completely dominate the cost of fuel at the interstate speed limit. Fuel is expensive, but you can always buy more of it.

Amusingly, one can use Excel’s goalseek function to back into the value of time of the losers you pass in the right hand lane. Someone driving at 55 miles per hour is implicitly valuing their time at $5.64 an hour. As a persistent leadfoot, I was comforted by this analysis. However, I can already hear my mother begging me to exercise caution. Those who drive quickly are more likely to get into an accident, and that’s worth considering.

Fortunately, I’m not the only person to ask this question. Wikipedia led me to a discussion of the Solomon Curve, a graphical representation of driving risk. Apparently, the log of crash risk has a quadratic relationship with driving speed. Drive either above or below the median speed, and your risk of crashing exponentially increases.


Table 7 of the original paper presented a fairly detailed risk of injury and death depending on the driving speed and the time of day (day vs night). I used this data, the aforementioned relationship and two regressions to develop risk curves for day-time and night-time driving. This is old data, and someone else could probably improve the results by looking at more contemporary sources. However, it suits my back-of-the-napkin purposes.

To translate the risks of crashes into the expected value of crashes, I had to assume costs for both injuries and deaths. For injuries, I assumed $50,000. After insurance, that’s probably a little high, but it’s good enough for our purposes.

The next assumption I had to make is slightly more complicated. How does one value the threat of losing their life? What cost do you assign to daylights, sunsets, midnights and cups of coffee forever squandered in a driver’s overzealous haste to get to the next red light? Sure, in 1999, the EPA estimated a life’s value at $5.5 million while calculating the value of air regulations, but just because I’m an economist doesn’t mean I’m a monster. Who am I to blindly annoint a dollar value to an anonymous other’s very existence? It would go against everything I hold dear to say lives are worth $5.5 million each.

First, we must adjust it for inflation. In 2013 dollars, one life is worth roughly $7.7 million. Moving on…

Due to the quadratic and exponential nature of speed and collisions, the right side of the graph quickly balloons. With the original assumptions, the back of my envelope recommends going 65 miles per hour in the day and 60 miles per hour at night. For my non-American readers, that’s roughly 105 kmh and 97 kmh, respectively. For my pirate readers, that’s 56 and 52 knots, respectively.

The day chart is provided below. Please note that the x-axis has been restricted to 90 miles per hour, unlike the prior graphs.


Of course, all of this assumes you have a radar detector, an average driving ability and an average love of life. The Solomon Curve is anchored on the speed of your fellow travelers, not the speed of an old data set. Take everything into account, and don’t be afraid to disregard

My model can be downloaded here:

Total Cost of Trip

Edit to add: A friend of mine let me know another potential ending. The other possible moral of this story is that everyone should drive at 95 miles per hour. Balloonfoots are imposing a negative externality. How did I miss that?

Are Equities Riskier than Bonds?

Because individual companies are inherently riskier than entire nations, investors will apply a greater discount to future cash flows. This means that, if the business plan works out, investors will achieve a higher return on their invested capital. That’s why it is common to assume an equity risk premium when building a discount rate for companies. Valuators usually start with yields on government bonds and then add an additional risk premium for securities. A simple model suggested in the 2012 Ibbotson Valuation Yearbook is a 2.48 percent riskless discount rate (20-year U.S. Treasury Coupon Bond Yield) and a 6.62 percent equity premium (large company stock total returns minus long-term government bond income returns) with additional premiums that can be added for size, risk, industry, et cetera.

An article in February’s print copy of The Economist challenged this standard formulation. It is entitled Beware of the bias: Investors may have developed too rosy a view of equity returns. I’m open to the idea that investors are too rosy about equity returns, but I find almost every example cited spurious. I’ll quote liberally from the article and proceed point by point. Emphasis added throughout. Continue reading →

Quora Question: Money – Inflation Relationship

I recently answered the following question on Quora:

How is it that the United States has tripled the money in circulation over the last five years, but inflation is only at 2 percent?

This is a great question, and there’s a lot to be said on this issue.

For starters, let’s look at the Equation of exchange:

M * V = P * Y

Where P is the price level, Y is real GDP, M is the money supply and V is the velocity, the average amount of times the average dollar trades hand per year.

Change in P is called inflation (or deflation), and change in Y is called growth. Continue reading →