# Stephen J. Barr

We are here to help Payday loans UK What if your application is declined

## Permanent and Transitory Shocks in Capital Structure

NOTE: This page is intentionally heavily focused on the computational aspect of the problem.

## Quick Introduction

One of my U of R projects has been research into dynamic capital structure, meaning how firms mix debt and equity. Firms make decisions about capital structure in the face of uncertainty. One of the sources of uncertainty they face comes in the form of the return on their investment. Firms transform investment into profits through their use of capital (raw materials, machines, and so forth), and the rate at which investment turns into profitability is called the firm’s productivity of capital.

For various reasons, the same amount of productivity can produce different amounts of profit in different periods. This can be due to some multiplier to the productivity function, a productivity shock, which can be either positive or negative, and examples exist for each (e.g. worker strikes, favorable weather, etc). The productivity shock process can be thought of as a process which evolves over time in a somewhat predictable manner.

In the academic finance literature, the productivity shock process is almost always thought of as a mean reverting process. This means that the process has some fundamental level and although at any given time may differ from that level, the firm expects that the shock will fluctuate around a known mean. My line of research breaks this assumption, and thinks of the firm as receiving a combination of mean-reverting shocks and permanent shocks. The difference between a mean-reverting (also called transitory) shock and a permanent shock has to do with the firm’s expectation about the future values of the shock. In a permanent shock, there is no expectation of mean reversion.

There are two main sections to this post. Section A bit more theory and math, and even a model contains a description of the model. Section How to solve talks about the solution and numerical methods used to find this example. Since this forum is not strictly academic, I am freely mixing methods, explanations, and code. I think that this may be useful, as often papers, even one that use complex solution methods, describe the entirety of these methods with a tiny appendix. By describing my solution methods in detail, it

• Helps me clarify my understanding
• Allows other people to find any errors in my logic or code
• Helps others in their own work

## Some theory

Capital structure refers to how firms utilize both debt and capital to fund investment. Firms work to maximize the sum of present and expected future value of equity value. They make investments, and can fund them by issuing corporate debt, or issuing equity. The decision to do this is complicated and is influenced by many factors including the current and expected future value of capital.

Assume that your profit is given by equation $z * k^\theta$ where $z$ is productivity, $k$ is capital stock, and $\theta$ is the curvature of the production function. The general style of these productions are called Cobb-Douglas production functions. I am interested in the dynamics of $z$. $z$ is a stochastic process where at each time $t$ it takes a value $z_t$. $z_t$ is typically assumed to follow an autoregressive process of type AR(1). An equation for an AR(1) process $x_t$ is:

$z^T_t = \rho + z^T_{t-1} + \epsilon_t$

where the 1 refers to the 1-period lag on the right side of the equation. $\rho$ is the autoregressive coefficient. AR(1) processes are by definition mean-reverting, meaning that over time, $z_t$ will approach some mean value.

Firms in reality receive shocks to their productivity from a variety of sources – changes in legislation, technology, relations with suppliers and labor, etc, and the nature of these shocks differ with regard to their expected permanence or transience. E.g., a new technology may be seen as a permanent shock while a supply chain concern or labor dispute may be more transient in nature. An AR(1) process is by definition transient when the autoregressive parameter is less than one, and thus using this process as part of a model of firm production assumes that all shocks are of the latter type. A permanent shock looks like:

$z^P_t = z^P_{t-1} + \epsilon_t$

## How to solve

After reading or skimming the above section, you may be thinking “that’s great. How do I solve it?”. That is the purpose of this section.

### Grids

The first step is to stop and think about what “solving the model” means in this context. From a perspective of a firm that wants to maximize its equity value, a solution to this model means that for any current state ($k,p$) of the firm and any combination of permanent and transitory shocks ($z_t = \{z^P_t, z^T_t\}$), the firm understands how to adjust its debt and capital levels such that the response maximizes their current plus expected future equity value. Said succinctly, for any state of the world, what is the value-maximizing choice?

One way to go about solving these models is to make enumerate the states. Say for example, firm capital stock could take values 5,10, or 15. Lets refer to this as the K-grid (or $\mathcal{K}$ in math notation). Similarly, let debt be 2 or 4, the P-grid. To get the possible states, we take the Cartesian product of the grids. Let $s_i$ refer to any element of set $S$, the Cartesian product.

Enumerated State Spaces
s# K P
0 5 2
1 5 4
2 10 2
3 10 4
4 15 2
5 15 4

Thus, we have 6 states, labeled $s_0$ to $s_5$. Thinking back to the model, we have quantities suck as debt $\equiv p' - (1+r(1-\tau_c)*p)$ that depend on both the current and 1-period future (alternatively, previous and current) choices of debt. To evaluate these and all of the other intertemporal equations, it quickly becomes clear that we need to evaluate these choices for every combination of $k,p,k',p'$.

We can do this with 4 different $6 \times 6$ matrices.

k

0 1 2 3 4 5
0 5 5 5 5 5 5
1 5 5 5 5 5 5
2 10 10 10 10 10 10
3 10 10 10 10 10 10
4 15 15 15 15 15 15
5 15 15 15 15 15 15

k prime

0 1 2 3 4 5
0 5 5 10 10 15 15
1 5 5 10 10 15 15
2 5 5 10 10 15 15
3 5 5 10 10 15 15
4 5 5 10 10 15 15
5 5 5 10 10 15 15

p

0 1 2 3 4 5
0 2 2 2 2 2 2
1 4 4 4 4 4 4
2 2 2 2 2 2 2
3 4 4 4 4 4 4
4 2 2 2 2 2 2
5 4 4 4 4 4 4

p prime

0 1 2 3 4 5
0 2 4 2 4 2 4
1 2 4 2 4 2 4
2 2 4 2 4 2 4
3 2 4 2 4 2 4
4 2 4 2 4 2 4
5 2 4 2 4 2 4

Let $i$ index time the rows and $j$ index the columns of these matrices. Then, each $(i,j)$ combination refers to the idea of being in state $i$ and choosing state $j$. And, to get a function of these variables, we can do this in C++:

int Nstates = 6;
for(int i = 0; i < Nstates; i++) {
for(int j = 0; j < Nstates; j++) {
value[i][j] = some_function(k[i][j], k_prime[i][j], p[i][j], p_prime[i][j]);
}
}


My grid for $k$, denoted $\mathcal{K}$, has 71 points, whereas my grid for $p$ has 29 points. Thus, there are 71*29 = 2059 combinations of current $k$ and current $p$, and an equal amount of future $k$ and future $p$. Thus, a $2059 \times 2059$ matrix can describe the combinations of current and futures states. However, a firm must also consider the shock. I am using a grid of $19$ points for my transient shock and $17$ points for permanent shock. For each $2059 \times 2059$ matrix, I need to evaluate the Bellman equation for $19 \times 17 = 323$ shocks. This leads to a $665057 \times 2059$ over which I must iterate to get the solution to my model.

### Solving the Model

Before getting into the mechanics of solving the model, it is important to clarify what the solution looks like. The question I am trying to answer is How will the firm adjust its debt and capital levels in the face of uncertainty in the productivity shock? The answer to this question is a policy function which, for any combination of the state of the firm and possible shock gives the optimal response.

Lets define some terminology.

• control variables / control states: variables that firm can control, in this case debt and capital. Call this state $\mathcal{S} = \mathcal{P} \times \mathcal{K}$ where $\mathcal{P}$ has $M$ elements and $\mathcal{K}$ has $N$ elements, and $\times$ is the Cartesian product operator, yielding every possible combination of the set elements..
• shock states: exogenous shocks to the system. In this case the permanent and transitory shocks. Let $z^T \in \mathcal{Z}^T$ denote a transitory shock and $z^P \in \mathcal{Z}^P$ denote a permanent shock. The entire state space is then $\mathcal{Z} \equiv \mathcal{Z}^T \times \mathcal{Z}^P$
• policy function: a mapping between all control states, shock states, and decisions the firm can make. In math notation, $F: \{ \mathcal{S} \times \mathcal{Z} \} \rightarrow \mathcal{S}$
• value function: a mapping similar to the policy function, but rather than saying the optimal choice of $k', p'$, it says the expected value of making that optimal choice

Value function iteration uses the contraction mapping theorem to find the value function. The algorithm works by starting with an initial guess (which can be simply random), iteratively improving the guess to find a fixed point, which under certain conditions is guaranteed to exist. The “contraction” part of contraction mapping means that every iteration leads closer to the fixed point. See HERE for a quick explanation, or these books for a long one.

### Estimating the Model

After being able to solve the model for one set of parameters, an interesting question could be “What is the set of parameters that leads to simulated firms which behave closest to the actual firms?”. This general way of thinking is called “indirect inference” because the parameters are inferred indirectly through simulations based on a certain parameterization of the model. One particular technique for doing this is called simulated method of moments (SMM). The details of this are the subject of a future blog post.

## Appendix: Software and Hardware

### My software and hardware environment:

• My solver is written in highly optimized C++ code.
• Intel’s Math Kernel Library, which is optimized for Intel CPUs.
• Compiler: Intel icpc version 12.1.3 20120212
• Amazon’s cc2.8xlarge instance types. These feature the new Intel Sandy Bridge-EP Xeon processors with the Intel Advanced Vector Extensions, which allow computations on 256-bit wide registers (meaning matrix math SCREAMS on these boxes)
• For manipulating matrices, I use Eigen, a C++ templating library for matrix multiplication. I am using a new version of Eigen which links against MKL

## csvfix is cool

I have been manipulating some data files in comma separated value format. I have been finding the tool, csvfix to be extremely cool.

For example, I have recently been working with some COMPUSTAT data. The data files are a few hundred megabytes and have several hundred columns, and hundreds of thousands of rows. I wanted all the rows, but only 30 or 40 of the columns, so I had subsetted the large files into much smaller ones. However, I forgot to get the SIC codes. So, rather than open all the files again, I used csvfix.

csvfix order -fn cusip,SIC *.csv | csvfix unique -o quarterly_cusip_SIC.csv


The first command grabbed the cusip and SIC columns from all the .csv files in the current directory. The output of this is redirected to the second command which takes the incoming csv data, separates out just the unique rows, then outputs them to the file quarterly_cusip_SIC.csv.

csvfix seems to be able to do much more than this. The manual looks pretty good – RTFM.

## Leverage Ratio’s, Part 1

Using R, it is really easy to make a nice plot of leverage ratios. Using a data.table with Compustat annual fundamentals data, you can do the following calculation:

btdt <- transform(btdt, debt =  DLTT + DLC)
btdt <- transform(btdt, book_assets = AT)
btdt <- addVars(btdt, isAnnual = TRUE)
btdt <- transform(btdt, bl2 = debt/book_assets)


Then, you can plot it with ggplot2, like this:

x <- ggplot(data=firm.dt, aes(x=date, y=bl2)) + geom_line() + theme_bw()
x <- x + opts(title =  paste(firmname, "Leverage"))
x <- x + ylab("Debt / Total Assets")
print(x)
fname <- paste("plots/", firm, "_bookleverage.png", sep="")
ggsave(filename=fname, plot = x, dpi=600)


This is the result:

## Leverage Ratio’s, Part 2

I have been doing quite a bit of research into firm leverage ratios. Therefore, I spent the last few days looking at corporate leverage among a variety of dimensions. The data is entirely from the Compustat database.

### Along what dimension?

A very simple first question to ask is, along what dimension am I looking at leverage?

There are actually quite a few possibilities:

1. Take the average, pooled over all firms and time periods. However, it seems that there is more to say about the entire data set of corporate leverage ratios than can be expressed by one number.
2. At every distinct point in time, pool all firms. This would create a 1-dimensional time series. This is doing a little better.
3. For every period, compute means by industry. This creates a panel. However, doing this naievely creates a few problems (see the next section for help). At any given time, some firms enter the sample and some firms are leaving the sample. One way to mitigate this is take a slice of the data set known as a balanced panel, where the firms are chosen such that they exist for the entire window of time of interest. But, this introduces survivorship bias, because the sample is biased towards firms which endure all the economic woes of throughout the timeframe and do not leave the sample.
4. Look at leverage by leverage decile, year by year. This is an interesting way to see what the bottom, top, and middle leverage levels are doing. It is important to realize that this does not necessarily capture what the firms at each level are doing. This is because firms are free to change their leverage and thus their relative usage of leverage may change over time.
5. As a response to #4, At time period 1, sort leverage by decile and see which firms are in each decile. Then track these firms over time. This can be very interesting, taking caution that picking different starting time periods will most definitely change the groupings of firms.

There are plenty more.

### Show me some results

#### A plot showing the subsetting as described in #5

Looking at this plot, we see some interesting behaviour. The firms that were at an extremely high leverage ratio (book leverage > 0.6) they tended to delever to some extent, but still settled at a relatively high average when viewed as a group, where it seems like it took about 8 years to stabilize. Firms with relatively low leverage ratios seemed to, as a group, have very stable leverage ratios.

#### A plot showing the subsetting over time by industry

This plot is a bit harder to read. Construction and retail seem to have delevered, where mining seems to have increased in leverage. Definitely more investigation is needed.

### Code

I wrote some code to detect the largest balanced panels in the Compustat database. That code is coming tomorrow. I picked a balanced panel that started in the mid 1980′s for this analysis. I used the data.table package to hold the data, as it allows for keyed data tables that allow extremely fast, in-place subsetting.

For the first plot, the code was as follows.

Subset the data to get just the first time period. Using cut2 from Hmisc library, divide into deciles and label them A..J.

min.date = min(dt.t$date); dt.tmin = subset(dt.t, date == min.date); dt.tmin$initialDEC = with(dt.tmin, cut2(book_lev, g=10), labels=1:10);
dt.tmin$initialDEC = factor(dt.tmin$initialDEC, labels = LETTERS[1:10]);

initialDEC is a factor representing the initial decile. The merge does exactly what you think it should, meaning add a column called initialDEC to the the original data set, dt.t, merging on the column cusip.

## prepare to merge
setkey(dt.tmin, cusip);
setkey(dt.t, cusip);

## do the merge
dt.t = dt.t[dt.tmin]

Create a factor called timedec, which is the interaction of the initial decile (initialDEC) and each time period. There should be 10 * (max(dt.t$year) - min(dt.t$year) + 1) distinct values of this factor. Then, set this as they key, and take the means according to this group.

dt.t$timedec = paste(dt.t$date, "--", dt.t$initialDEC, sep="") setkey(dt.t, timedec) td.means = dt.t[,list(tdmean=mean(book_lev)), by=timedec] This unwraps the data. td.means becomes a nice little data.table with 10 * (max(dt.t$year) - min(dt.t$year) + 1) rows. timedate = strsplit(as.vector(td.means$timedec), "--")
tddf = as.data.frame(matrix(unlist(timedate), ncol=2, byrow=TRUE))
colnames(tddf) = c("DATE", "iDEC");
td.means$date = tddf$DATE;
td.means$iDEC = tddf$iDEC;
td.means$year = extractyear(td.means$date)

Then, use ggplot2 to do the plotting:

p = ggplot(td.means, aes(x=year, y=tdmean, group=iDEC))
p = p + geom_line(aes(colour=iDEC))
p = p + opts(title = expression("Firm leverage at t=0 decile sort"))
p = p + scale_y_continuous('Book leverage')
print(p)

### Coming next

How to use R (and lots of cores) to find all possible balanced panels in a ragged data set.

## ess-remote, so useful!

An extremely useful command Emacs command for ESS (Emacs Speaks Statistics) is ess-remote.

Quoting the documentation:

Execute this command from within a buffer running a process. It runs ess-add-ess-process’ to add the process to ess-process-name-alist’ and to make it the ess-current-process-name’. It then prompts the user for an ESS language and sets the editing characteristics appropriately.

Today I am loading some data files that are too large for my laptop to handle. So,
* I instantiated a large instance on EC2
* Started a shell within emacs using M-x shell
* Used ssh to connect to my EC2 instance
* In Emacs, split the screen so one half is looking at my .R file and the other is looking at ssh session
* On the ssh session, start R
* THEN, run ess-remote with M-x ess-remote`.

Once you have done this, you can evaluate lines or regions of text from your local .R script, but have the execution all take place on the EC2 machine.

* http://www.marketwatch.com/story/imf-rescue-of-italy-will-spark-global-uprising-2011-11-30?Link=obinsite “But whatever it is called, it is not going to work. Why not? Because it puts too much financial strain on the rest of the world. Indeed, if the IMF goes ahead with the plan, it might well finish itself off as a serious custodian of the worldâ€™s financial stability.”
* http://www.npr.org/templates/story/story.php?storyId=143015809

Both are good articles. I believe I heard the NPR one while running an errand this evening.

My personal opinion: I am glad that Angela Merkel is not backing the idea of a Eurobond. It seems clear that that scenario would eventually degernate into a borrowing contest. This would be much the same situation as a group of people agreeing beforehand to evenly split a restaurant bill before everyone orders their dinner. In both cases, social pressures aside, it is to the advantage of each party to rack up an above average bill. And, everyone can’t be above average at the same time.

## My Dynamic Program Solver

My dynamic program solver is available on my bitbucket repository here. The code should self-documented. More official documentation coming soon.

I am working on reviewing a somewhat large body of literature in preparation for a big paper. And, in the process, I decided to make sure to more properly manage my bibtex database. If you are working in LaTeX and don’t know what bibtex is, google and find out. It is the way to manage references for LaTeX papers.

The tool I am currently using for this is http://jabref.sourceforge.net/. It seems to be doing what I want it to do.

Important shortcut keys

• C-n new entry
• C-g clean up pasted in bibtex

My workflow then is typically, find paper. Most cites that host papers export BibTex. Get that. C-[TAB] to JabRef, and paste in the BibTex. Then C-g to clean up and automatically set the key name.

Also, if you download a PDF paper, you can drag it into JabRef and it makes the creation of an entry fairly easy. There is plenty more that JabRef does, but so far I have found it useful

## Parallel Computing for Econometricians with Amazon Web Services

This past quarter, I had two fantastic class. One was corporate finance with Toni Whited. The other was advanced econometrics with Sanjog Misra. In both classes, I heavily used EC2. The first one I would like to document is a presentation I made for Sanjog’s class. The title of the presentation was “Parallel Computing for Econometricians with Amazon Web Services”, available in PDF.

I really enjoyed the opening:

The presentation documents using EC2 with either Segue or Elastic Map Reduce to demonstrate Monte Carlo simulations and evaluating large likelihood functions using EC2 and R. I have some sample code up here. Usage is described in the presentation. The technique is simulated maximum likelihood.

In the near future, I plan to more neatly package this demonstration and perhaps add a screencast. But, this should get you started.