Blog Topics...

3D plotting (1) Academic Life (2) ACE (18) Adaptive Behavior (2) Agglomeration (1) Aggregation Problems (1) Asset Pricing (1) Asymmetric Information (2) Behavioral Economics (1) Breakfast (4) Business Cycles (8) Business Theory (4) China (1) Cities (2) Clustering (1) Collective Intelligence (1) Community Structure (1) Complex Systems (42) Computational Complexity (1) Consumption (1) Contracting (1) Credit constraints (1) Credit Cycles (6) Daydreaming (2) Decision Making (1) Deflation (1) Diffusion (2) Disequilibrium Dynamics (6) DSGE (3) Dynamic Programming (6) Dynamical Systems (9) Econometrics (2) Economic Growth (5) Economic Policy (5) Economic Theory (1) Education (4) Emacs (1) Ergodic Theory (6) Euro Zone (1) Evolutionary Biology (1) EVT (1) Externalities (1) Finance (29) Fitness (6) Game Theory (3) General Equilibrium (8) Geopolitics (1) GitHub (1) Graph of the Day (11) Greatest Hits (1) Healthcare Economics (1) Heterogenous Agent Models (2) Heteroskedasticity (1) HFT (1) Housing Market (2) Income Inequality (2) Inflation (2) Institutions (2) Interesting reading material (2) IPython (1) IS-LM (1) Jerusalem (7) Keynes (1) Kronecker Graphs (3) Krussel-Smith (1) Labor Economics (1) Leverage (2) Liquidity (11) Logistics (6) Lucas Critique (2) Machine Learning (2) Macroeconomics (45) Macroprudential Regulation (1) Mathematics (23) matplotlib (10) Mayavi (1) Micro-foundations (10) Microeconomic of Banking (1) Modeling (8) Monetary Policy (4) Mountaineering (9) MSD (1) My Daily Show (3) NASA (1) Networks (46) Non-parametric Estimation (5) NumPy (2) Old Jaffa (9) Online Gaming (1) Optimal Growth (1) Oxford (4) Pakistan (1) Pandas (8) Penn World Tables (1) Physics (2) Pigouvian taxes (1) Politics (6) Power Laws (10) Prediction Markets (1) Prices (3) Prisoner's Dilemma (2) Producer Theory (2) Python (29) Quant (4) Quote of the Day (21) Ramsey model (1) Rational Expectations (1) RBC Models (2) Research Agenda (36) Santa Fe (6) SciPy (1) Shakshuka (1) Shiller (1) Social Dynamics (1) St. Andrews (1) Statistics (1) Stocks (2) Sugarscape (2) Summer Plans (2) Systemic Risk (13) Teaching (16) Theory of the Firm (4) Trade (4) Travel (3) Unemployment (9) Value iteration (2) Visualizations (1) wbdata (2) Web 2.0 (1) Yale (1)

Wednesday, June 8, 2011

More on Smoothing Splines...

Chalk yesterday's post up as a learning experience...following a very helpful comment left on yesterday's blog post, I made two changes to my code:
  1. I am now calculate the confidence bands by bootstrapping the residuals (instead of the data points themselves).  The confidence bands yesterday were huge.  The reason why the confidence bands were so wide was because the bootstrap method I implemented scrambled the dataset during each iteration, which destroyed the time series nature of the underlying data.  Bootstrapping over the smoothing spline's residuals should preserve the times series nature of the data (which should narrow the confidence bands considerably). 
  2. I am now using generalized cross validation (GCV) to pick the penalty for the curvature( for those following at home that is setting cv=FALSE using the function smooth.spline().
Here are the relevant plots using daily, weekly, and monthly returns:

Daily Returns:
Weekly Returns:
Monthly Returns:
Both the daily and monthly plots exhibit significant asymmetry between the left and right tails of the data.  Although I still wonder about the sensitivity of the results to certain outliers (particularly with the daily data).  Recall the EMH implies that returns should follow random walk with a drift, and the red-dotted line represents the EMH null prediction (ignoring the drift...feel free to mentally shift the dotted-red line up or down as you see fit). 

My (not very enlightening) interpretation of the above plots is that EMH works pretty well for the "body" of the data (all three plots are roughly "flat" where most of the data lies), but there is something fundamentally different governing the dynamics for large returns (and that whatever is governing the dynamics must effect large negative returns differently than large positive returns).  Note that the robust asymmetry is much harder (maybe impossible) to detect using a linear model. 

Tuesday, June 7, 2011

Today's Distraction...

For the past month or so I have been working my way through Cosma Shalizi's excellent course on data analysis.  Today I distracted myself from my own research by playing with Smoothing Splines (Cosma's Lecture 11).  Everything below was done in R.

First, I grabbed some historical data for the S&P 500 from Yahoo finance using the get.hist.quote() function from the tseries library.  I pulled down daily, weekly, and monthly data starting on 3 January 1950 and ending 31 Dec 2010 (start and end dates are for daily data).  I then constructed S&P 500 returns by taking the first-difference of the logarithm of the S&P 500 Adjusted Closing Price.   Here are (probably familiar) time series plots of the daily returns and a density plot...
Note that stock returns exhibit clustered volatility and are negatively skewed with significantly heavier tails than one would expect if returns were Gaussian.  On a side note (related to my current research), a couple of years ago some researchers at the Santa Fe Institute (specifically Stefan Thurner, J. Farmer, and John Geanakoplos) published a paper titled "Leverage Causes Fat Tails and Clustered Volatility."  Their model also predicts that returns should be negatively skewed (a point I think they should have included in the title).

Back to learning about splines! Is today's S&P 500 return useful in predicting tomorrow's S&P 500 return?  For the null hypothesis, I take a strongish form of the Efficient Market Hypothesis (EMH):
  • Ho: Stock prices follow a random walk with a drift (i.e., returns should be mean zero white noise)
For alternative hypotheses, I use a brutally simple parametric model, and then what ever functional form the smoothing spline finds
  • HA,1: rt+1 = β0 + β1 rt + εt
  • HA,2: Whatever the smoothing spline kicks out
To test the null against the parametric alternative, we simply need to test the joint restriction that β0=β1=0.  Presumably to test the smoothing spline, we need to calculate some 95% confidence bands for the fitted spline and then look to see if the confidence bands contain the curve (really a line) predicted by the null hypothesis.  This is my first time using splines, so if anyone out there knows whether a better way (or a book) about how to do hypothesis testing with smoothing splines, I would be interested in hearing from you.

Here is a scatter plot of tomorrow's return against today's return.  I fit a simple linear regression to the data and plotted the curve in gray.  While both the slope and intercept terms are very significant (p-values essentially zero for both), it is worth noting that the standard confidence intervals are not valid (much too narrow) given the blatant violation of Gauss-Markov assumptions for the regression.  More work needs to be done before we can take this as evidence against the EMH null (since this post is about smoothing splines I am going to simply state that I would be surprised if, after calculating appropriate standard errors (either using bootstrapping, or some type of heteroskedastic robust standard errors, etc), the parameter results were still significant...but maybe!)

The smoothing spline is in orange.  I used the smooth.spline() function in R to fit the spline (using leave-one-out cross-validation to pick the optimal penalty for the curvature).  
If stock prices reflect all relevant information about the value of the stock, then one would expect that today's return should be pretty useless in predicting tomorrow's return (thus under the null the true regression line should be the dotted red line in the above scatter).

But what about the smoothing spline?  A few things:
  1. While the regression line is positively sloped, the smoothing spline is negatively sloped for larger negative and large  positive values of today's return.
  2. The asymmetry.  The slope of the smoothing spline is more negative for large negative values of today's return (compared with the slope of the smoothing spline for large positive values of today's return).
  3. Outliers:  The October 1987 stock market crash looms large in the data. How sensitive is the estimated smoothing spline to these 1-2 observations?
  4. Is the asymmetry of the smoothing spline a statistical artifact?
  5. Most importantly, despite the dramatic appearance, is the smoothing spline significantly different than the dotted red line?
I am going to focus on point 5 for the rest of the post.  I calculated 95% confidence bands for the smoothing spline using a bootstrap re-sampling of the data points.  Basically, I re-sampled (with replacement) the stock return data creating a new synthetic data set, fit a smoothing spline to this new data set, and then repeated the process a bunch of times to build up a distribution that I could use to create the confidence bands.
For the most part, the dotted-red line lies entirely within the 95% confidence band for the smoothing spline (if you squint you can kind of see a small portion of the dotted-red line that lies outside the bands).  So despite the dramatic appearance of the smoothing spline I would say that we can not statistically distinguish it from the dotted-red line.

I was curious to see what the above plot might look like if I used weekly and monthly S&P 500 returns instead of daily returns...

Weekly Returns:


Monthly Returns:

I was surprised at how different the daily, weekly, and monthly smoothing splines turned out to be...still in all three cases the 95% confidence bands for the smoothing spline contain (almost completely) the red-dotted line.  I will have a think as to why they are so different, and perhaps follow up with another post.  My R code will be posted as soon as I have time to get my Google Code page up and running...until then feel free to email me (or leave email in a comment) and I will send it to you.

Update: As pointed out in a comment below, EMH predicts stock returns should follow a random walk with a drift...which implies that the dotted-red line doesn't necessarily need to have a zero intercept.  One would hope that the drift is slightly positive! 

Monday, May 23, 2011

The yield curve as a recession indicator...

According to a couple of recent papers from the N.Y. Federal Reserve, the magnitude of the yield curve at the end of monetary policy tightening cycles is an excellent predictor of whether or not the economy will end up in recession within 24 months following the end of the tightening cycle. 

The earlier paper (Adrian and Estrella, 2009) documents the empirical result, while the later paper (Adrian, Estrella, and Shin, 2010) provides a plausible causal mechanism that has its roots in balance sheet management by financial intermediaries.  The idea in (Adrian, Estrella, and Shin, 2010) is that when monetary tightening is associated with a flattening of the term spread (i.e., the gap between yields on 10 year U.S. government bonds and short-term Treasury bills becomes sufficiently small), it reduces net interest margins (NIM) for financial intermediaries.  This reduction in NIM makes lending less profitable, which leads to a contraction in the supply of credit. 

The plot above is slightly different than the one reproduced in both of the above papers.  The difference is that I used the difference between GS10, 10-year U.S. government bonds (constant maturity), and TB3MS, 3-month T-bills (secondary market rate), to construct my yield curve. 

The authors above use a constant maturity 3-month T-bill rate.  I choose the secondary market rate because the data series went back further.  It is possible (likely) that the secondary market rates are systematically higher than the corresponding constant maturity rates.  So compared with the authors measure,  my measure of the term spread is likely to be narrower.

I don't know which method of constructing the term spread is preferable...but Greg Mankiw uses the same method!   I will post my R-code (and data) for constructing the above plots soon...

Monday, May 16, 2011

Asset Price Cycles and Collateral...

Some intuition on how borrowing constraints can lead to cycles in asset prices.  My explanation below is heavily influenced by Geanakoplos (1997), and Kiyotaki and Moore (1997).  First I will explain why asset prices will be more volatile in a world where investors can buy on margin, and then I will provide some intuition as to why this process can lead to cycles in assets prices.

Suppose that you are an investor, and that you have the ability to buy assets on margin (i.e., you are allowed to use the asset that you wish to purchase as collateral to borrow the funds necessary to make the purchase).  Note, in passing, that because the borrower keeps position of the collateral during the period of repayment, a fairly sophisticated courts system is a prerequisite for buying on margin.

Buying on margin will allow those agents with the most optimistic view of the future value of those assets (in the Geanakoplos (1997) framework optimistic agents are those agents whose marginal utility of holding the asset is the highest) can hold a larger fraction of those assets in their portfolio than would have been possible absent the ability to buy on margin.  This will lead (initially) to an increase in asset prices because:
  1. Asset prices will be higher because every agent can now afford to buy more assets (because of the ability to buy on margin)
  2. The marginal buyer of the assets will be an agent with strictly higher marginal utility (compared to a world without the ability to buy on margin).
The ability to buy on margin leads the optimistic agents to have high levels of leverage.  It is the leverage that creates the volatility in asset prices.  To see the leverage effect consider the effects of "bad news" on the price of an asset:
  1. Every agent now values the asset less than before the arrival of the "bad news"
  2. The lower valuation redistributes wealth from optimistic agents to the pessimistic agents (who did not purchase the asset on margin).  This redistribution of wealth can be very large depending on the leverage of the optimistic agents.  
Now if we are willing to assume that enough optimistic agents survived the fire sale (i.e., that at least some of the optimistic agents were not so levered up that they completely defaulted on their debts following the revaluation of asset prices), then these agents will find the assets that they value highly available for purchase at extremely low prices.  Now is an excellent time for then to buy.  The optimistic agents will begin to bid up the price, and voila we have the makings of a cycle!

Friday, May 13, 2011

Thoughts?

At some point I would like to know (with high probability at least) whether or not the following statement is true:
By spreading risk to those most able to bear it, creating new markets for financial assets (i.e, market completion) increases the productive capacity of the economy.
I came across the statement in a very nice paper by John Geanakoplos.  To provide a bit of context, the quote was lifted from a section of the paper where Geanakoplos was discussing ways in which splitting mortgage promises (i.e., tranching) into collateralized mortgage obligations (CMOs) increase the number of buyers.  The first way is the effectively the above quote.

The second way is that tranching allows investor to speculate on the movements of things like interest rates.  The utility of CMOs as a speculative hedge, raises the value of the CMO to the bank because the bank knows that it will be easier to sell the mortgage on after it has been tranched.  This encourages banks to lower interest rates (or credit standards! or both!) in order to create the CMOs to sell to speculators.  Not surprisingly, Geanakoplos points out that this whole process is not necessarily welfare enhancing. 

Thursday, May 5, 2011

Complexity Economics

I embed the videos of the Complexity Economics Panel from the recent INET conference in Bretton Woods for those interested. On a related note, I am wondering what (if any) connections exist between the complex systems notion of the economy as a disequilibrium system, and the existing economic literature on disequilibrium dynamics...

Introduction by Eric Beinhocker:


Brian Arthur:


Ian Goldin:


Thomas Homer Dixon:


Moderated Q/A:

Wednesday, May 4, 2011

The Use of Knowledge in Society...

I first came across this paper while doing a bit of outside reading during the MSc.  It is one of my all-time favorites, and has strongly influenced my interests in the complex systems approach to economics in general, and networks in particular. 

I quote my favorite passage:
"The problem is in no way solved if we can show that all the facts, if they were known to a single mind (as we hypothetically assume them to be given to the observing economist), would uniquely determine the solution; instead we must show how a solution is produced by the interactions of people each of whom possess only partial knowledge.  To assume that all the knowledge to be given to us as the explaining economists is to assume the problem away and to disregard everything that is important and significant in the real world."
What I take from the above passage is that it is not enough to show that an equilibrium exists, what is needed is to show a process of dynamic adjustment that describes how such an equilibrium can be reached given that agents have only partial knowledge of the world.  I remember as an MSc student being deeply skeptical of the utility of the Arrow-Debreu general equilibrium framework because it showed only that an equilibrium existed and did not specify a dynamic process of through which that equilibrium was obtained.  Needless to say, I was very excited when I came across this paper as it indicated to me that I was not alone in my concern. 

On a related note, for those interested in a another way of modeling the price system, I highly recommend Growing Artificial Societies.  The book is slightly dated now (most of the work was done in the late 1980's early 1990's).  The authors use a computational model/simulation to show how (and under what conditions) market prices in an economy consisting of heterogeneous agents, operating under only limited knowledge of their environment, can converge to something resembling an equilibrium prices.  Perhaps even more interestingly they delve into when prices should not be expected to converge.  NetLogo has a version of the model that replicates most (all?) of the results from the book.

Upon reflection, I think the economics of Keynes and Hayek are in many respects closer than people think.  This is particularly true if one's knowledge of the differences between Keynes and Hayek comes from the following two rap videos from YouTube.