Financial Python

Studies in Finance and Python

Financial Crisis For Beginners

leave a comment »

Another good resource for the curious, care of Baseline Scenario. The post aggregates a lot of informative links about the current crisis (thank goodness; I wasn’t looking forward to doing it myself). The “This American Life” stories (one of my favorite NPR shows) are a good place to start and do a good job of explaining things to the layperson.

Written by DK

April 19, 2009 at 10:24 pm

Posted in Finance

Tagged with

My Liability Is Your Asset

with one comment

A friend of mine pointed me to a recent article by MIT professor Simon Johnson. A former head economist for the IMF, Johnson compares the US’ current predicament to his experience advising developing nations that are in financial trouble (for those of you who aren’t familiar with the IMF, you only really talk to them when the proverbial $#%* has hit the fan). Johnson’s oligarchy analysis has served as a rallying point for much of the blogosphere since the publication of his article. Given the conspiracy theories surrounding Goldman Sachs and the general frustration with Wall Street’s response to the government bailout, Johnson provides a framework for understanding unfolding events. It should be noted, however, that others have drawn similar parallels (as early as Aug 2007) between the features of the current crisis and other crises (e.g., the Asian Financial Crisis, etc.), though without Johnson’s oligarch perspective.

Johnson’s framing of the problem is now enabling other commentators to focus on the power dynamics between Wall Street and Washington, and has fueled the moral outrage surrounding the government’s bank bailout plan (even among those within the financial industry).

While Johnson’s observations ring true with me (I may be biased because I actually worked in Korea during the Asian Financial Crisis, followed by a few years in the development field), it’s still unclear to me where the bailout lies on the spectrum between “the best we can do given difficult circumstances” and “highway robbery.”  Most of what I’ve read assert a WMD-like fear of financial destabilization if the banks aren’t bailed out, usually citing Lehman Brothers, or (on the other hand) equally vague demands that the government force a GM-style restructuring of the banks that ignore the role legislation and social safety nets must play in such a scenario (I’m willing to be educated, though, if I’m just reading the wrong corners of the InterWeb).

Some questions that always seem glossed over by the administration and the press:

  • What are the specific legal hurdles to more aggressive restructuring? 
  • Is the FDIC equipped to handle a restructuring of the largest banks? (UPDATE 4/23: some commentary)
  • How did the administration determine that the bailout, as currently structured, would be cheaper than a more aggressive bank restructuring? 
  • Even if the liabilities of the banks are restructured, through nationalization or some other means, bank liabilities are assets for someone else (e.g., PIMCO). What’s the likely chain of events if these creditors are made equity holders? 
  • Would such a restructuring cause the same destabilizing collateral calls and liquidations everyone fears? And if the administration plans to bailout the banks and then cap bank size through subsequent legislation, how likely is it the administration will succeed?

Perhaps most importantly, how the heck is Joe Six-Pack (I couldn’t resist) supposed to understand this stuff when the government and the press are so bad at communicating these issues in concrete terms? Even Obama, widely recognized as the best communicator in the administration, rests more on assertion than exposition when he attempts to explain why the bailout will cost less using the current approach.

The US Is A Developing Economy, But With More Money

I’ve heard this crisis described as the unintended outcome of complex network effects, that no one could have predicted the perfect storm that brought about the current crisis. The lessons of the Asian Crisis, however, belie that argument. As I remember it, the Korean crisis featured:

  • Excessive leverage (10x was a big deal back then!)
  • Excessive investment in real estate
  • Asset/Liability term mismatches exacerbated by “hot money” and deregulation
  • Poor governance and fraud
  • Complex and opaque financial relationships (between the companies of the chaebol)
  • A crisis in confidence sparked by a revealing scandal (Hanbo Steel)

Even if you don’t know anything about the elements above, they probably sound familiar. Granted, the Asian Crisis unfolded much more quickly because the financial instruments and corporate issues were probably easier to digest. In contrast, problems with Asset Backed Commercial Paper (ABCP) and Levered Super Senior (LSS) notes surfaced late in 2007, but it took the equity markets almost a year to notice what was going on in credit. Most people didn’t even know what ABCP or a conduit was (and probably still don’t) prior to this disruption. The main take-away is ABCP and LSS were perceived to be rock solid assets and both blew up. I talked to some equity hedge funds that wanted to learn more of what was going on, but they seemed to have a hard time digesting the news. A common refrain: “When I talk to you guys, I feel like the world is coming to an end.”

Anyway, as Johnson rightly recognizes, the irony is many of the suggested solutions to America’s woes are fundamentally identical to the policy prescriptions applied to emerging economies.

Nail Your Budget Expenditures To My Door, Uncle Sam

The transparency initiatives the Obama administration is pursuing echo similar (if lower-tech) initiatives in developing nations. Paul Collier, in his book The Bottom Billion, describes a compelling study in Uganda:

“The story begins with…a survey to track public expenditure…only about 20 percent of the money that the Ministry of Finance released for primary schools, other than for teacher salaries, actually reached the schools. …[The Secretary of Finance and Planning] decided to try a completely different approach: scrutiny from the bottom up. Each time the Ministry of Finance released money it informed the local media, and it also sent a poster to each school setting out what it should be getting…three years later he repeated the tracking survey. Now, instead of 20 percent getting through to the schools, 90 percent was getting through.” (p. 150)

Data.gov anyone? Although the US version is Internet-based, the underlying benefits of added transparency are the same whether you are a emerging market or a mature market. This story underscores the the value of transparency better than a technical discussion about market efficiency, lemon markets (a la Akerlof), etc. Imagine if the Defense Department itemized and published all its expenditures in an intelligible way! In any case, it’s easy to see how the complex web of conduits, SPVs, credit derivatives, structured finance vehicles, and counter-party risk could take time to untangle and comprehend.

I Can’t See Past My Own Self-Interest: Heads I Win, Tails You Lose

Have you ever worked in an office where you always felt like you had to watch your back (welcome to Wall Street!)? Maybe you weren’t part of the in-crowd. Johnson’s argument regarding the oligarchy reminds me of arguments made about the psychology of elites. While I am not familiar with his entire body of work, Princeton professor Ezra Suleiman’s discussion of elites in French society parallels Johnson’s financial oligarchs. He discusses the symbiotic relationship that often develops between private and public institutions. As described in Powers of Theory: Capitalism, the State, and Democracy (Alford, Friedland):

“Suleiman is not arguing that the state controls the economy; rather, he says that the common elite structure shared by both public and private sectors serves the interests of both. And he is not arguing that there is no conflict between the various sectors of the elite. On the contrary, they are in continuous conflict over jurisdictions and turf, but they unite to defend the institutional principle of elite domination…They share a common social psychology: ‘the elite is deeply committed to a certain view of the society – centralized, non-participatory, and fundamentally conservative.'”

France is obviously different than the US, but c’mon, the statement above might as well describe the Bush years. Many fear that missteps by the Obama administration may signal a similar level of “elite encumbrance.” I think its a bit early to make that determination, particularly given Obama’s background, but commentators are already questioning the judgment of those working for him (Geithner, Summers, etc.).

Ugh, it’s getting late, PPIP will have to wait…

Written by DK

April 18, 2009 at 10:26 pm

Taleb Strikes Again

leave a comment »

nice article from Taleb care of the FT.

Written by DK

April 8, 2009 at 10:31 pm

Posted in Finance

Parse Google Reader Files

leave a comment »

I wanted to send a friend a subset of the blogs I subscribe to, but didn’t want to cut and paste a zillion URLs into an email. Instead, I exported all my subscriptions to an opml file (just go to “Settings” in Google Reader) and used OPML, a lightweight python module, to parse the file.

OPML is basically a subset of XML, focusing on subscription “outlines.” The module allows you to slice the file structure as you would a list or list of lists. Let’s go to the interpreter:

>>> import opml
>>> outline = opml.parse(‘google-reader-subscriptions.xml’)
>>> for element in range(len(outline)):
…     print outline[element].title

General Interest
NotesToSelf
Primaries
Finance
Religion
Tech

As you can see, it doesn’t take very much to pull out the top level elements of the file. The code above finds the number of top level elements and loops through them, printing out the element title. FYI, it helps to take a look at the raw opml file, just so you are familiar with the element attributes (e.g. “title”).

You can’t tell, however, just from looking at the interpreter output which elements include nested elements (though you probably will if you are parsing your own subscription file). I know NotesToSelf is actually a feed, and I can inspect the attributes of this feed using normal python slicing syntax:

>>> outline[1].xmlUrl
http://notestoself.posterous.com/rss.xml

>>> outline[1].title
‘NotesToSelf’

You can examine nested elements similarly. The following command references the title of the first feed (“[0]”) in the fourth element (“[3]”, the “Finance” folder):

>>> outline[3][0].title
‘A Credit Trader’

There are probably better ways to share subscriptions, but I look at it as a gentle introduction to XML parsing.


Written by DK

April 8, 2009 at 10:28 pm

Posted in Python

Tagged with ,

AIG Fuels Bank Profits

leave a comment »

Tyler Durden at Zero Hedge publishes a provocative post regarding bank profitability and AIG CDS payouts. In some ways, this should not be a surprise. As described in my previous Soros post, AIG was long lots of credit risk by selling protection to banks. Given how far credit has deteriorated, banks SHOULD be deeply in-the-money on those contracts. Indeed, these contracts are precisely why AIG has been bailed out multiple times by the government. So as these contracts get unwound, a significant amount of P&L should be flowing to the banks.

Nevertheless, Tyler always offers an interesting opinion, so have a look.

Written by DK

March 30, 2009 at 10:56 pm

Posted in Finance

Tagged with , ,

Fixed Coupon CDS is the same as CDX

leave a comment »

Everyone is quoting A Credit Trader these days! Felix Salmon of Portfolio (soon moving to Reuters), attempts to communicate the bottom-line of ACT’s post on the duration risk of CDS. Felix usually does a fantastic job with credit derivatives, but I thought a little helping hand might be useful on this coupon issue. If you understand how the CDX index is quoted, you already understand the fixed coupon, since it’s basically the same idea. The fixed coupon mechanism simply takes standardization a step further.

For example, the CDX index trades at a spread determined by the market, but also features a fixed coupon, or strike. This coupon is set at the beginning of each series (so the IG12 coupon was set when it was launched as the new on-the-run index). I don’t know what the new coupon is at the moment, but let’s say the coupon is set at 250 bps, and the index is trading at 250bps as well. In this case, the index is essentially trading at par since the market spread equals the coupon. Now, let’s assume the index widens to 300 bps and you want to buy protection at this level. There’s obviously a mismatch: the market wants 300 bps but the contract only demands 250 bps. What do you do? You make a small upfront payment to the dealer to clean up the mismatch (basically the present value of the difference between 300 bp and 250 bp payments). Trading upfront eliminates fiddling with duration assumptions and makes the transaction “cleaner.” This can be troublesome when trading the synthetic tranches as well, and there have been proposals to make similar changes to tranche quotes.

The “clean-up” upfront payment can get large when spreads widen a lot, thus introducing a technical slowdown in short trading since a large difference between the coupon and the market spread can make for expensive shorts. The opposite, of course, is also possible. If the index is trading tighter than the coupon, the dealer needs to pay you an upfront payment when you buy protection.

The big bang fixed coupon described by A Credit Trader and Felix follows the same logic as the index, but with standard 100bp/500bp coupons. If you are trading CDS with a 100bp coupon, you could say the CDS is trading at par when the market spread is 100bp (or trading at a discount when the market spread > 100 bp coupon). As a result, the CDS contract has become more bond-like.

See? Easy peasy.

Update: It occurs to me you can see this in action in a previous post. The CDSW screenshot shows IG11 trading at 237bps, with a coupon of 150bps. Looking at the numbers to the left of the green circle, you can see that the CDX is trading at a discount (~96) and that you need to pay ~$300k upfront to clean up the mismatch

Written by DK

March 30, 2009 at 10:32 pm

Posted in Finance

Tagged with , , , ,

Soros Doesn't Understand CDS

leave a comment »

A friend of mine once pointed out to me, years ago, that Warren Buffet was an investor in Dairy Queen. I replied, “Warren may know a lot about stocks, but he doesn’t know $#% about food!”

As the man who broke the pound, multi-billionaire George Soros obviously has nothing to fear from me. His editorial on the WSJ, however, makes it clear he doesn’t understand CDS.

A couple thoughts:

  • What about IRS? If George has problems with CDS, it seems he should be even more concerned with the interest rate swap market. I don’t know exactly how large it is, but I imagine it’s at least an order of magnitude larger than the credit default swap market.
  • Asymmetric Risks? George argues that asymmetric risk profiles promote the shorting of credit risk and speculation. Yet he ignores the fact that AIG got into trouble because it established massively LONG credit risk positions by selling protection during one of the tightest spread environments in history. How then, could one argue that “CDS [was] outrageously overpriced?” Anyone who has done even the most cursory research on CDS understands that the investor is long credit risk when selling protection. That’s why they are called synthetics. You can synthesize/approximate a long bond postion by buying Treasuries and selling credit protection. Furthermore, AIG sold protection on structured products/tranches, not individual corporate names (directly, at least). Single name CDS is governed by standard ISDA agreements and collateral requirements.

I place the blame for AIGs predicament squarely on the executives involved, risk management, and the senior management of the firm. Clearly, those directly responsible were gaming the system and AIG’s rating. Nevertheless, risk management, accountants, and senior management didn’t have to know anything about correlation or complicated structures to recognize AIG was long billions of dollars of unhedged credit risk. That’s what’s most infuriating to me.

It’s also infuriating that some people equate CDS contracts with irresponsible casino gambling because you don’t own the underlying asset. Let’s make this clear: If you own an ETF, trade equity options, or even buy coupons online, you are dealing with derivatives!Even ‘complicated’ index tranches can be described as call spreads on porfolio loss (see the previous post on Delta and Mark To Market).

Written by DK

March 26, 2009 at 10:34 pm

Posted in Finance

Tagged with , ,

Delta, Synthetic Tranches, and Mark to Market

with one comment

A Credit Trader recently posted a very nice exposition of AIGs mistakes in the credit default swap arena. Describing a meeting with AIG at the beginning of the post, he says:

Though mostly unmemorable, there was one moment in the meeting that I will never forget. As the marketing guys were pitching mezz tranches to the PM, I threw in a comment that if credit spreads were to widen the delta of the tranche would go up thus increasing the mark-to-market (MTM) sensitivity, and thus net credit exposure, of the trade. This the PM calmly brushed aside responding “we are not MTM sensitive” as he reached for another piece of fruit.

He goes on to discuss correlation of the underlying assets in CDOs and AIGs inability to appreciate the mark-to-market nature of synthetics. One thing he doesn’t explain, however, is the basic concept of mezzanine tranche deltas increasing as spreads widen. The relationship between tranche deltas and spreads isn’t well-understood (even among those in the credit derivative business), so here’s a shot at providing some intuition.

Expected Loss and Delta

Let’s use the standard IG11 index tranches as an example (though they were never really liquid, but whatever). The IG11 index is based on a portfolio of 125 investment grade credits. The spread of the 5Y index, currently around 237bps, reflects the market’s view of default probability, liquidity, etc. For argument’s sake, let’s just focus on implied default probability. Assuming some recovery rate, we can use the spread and a measure called SDV01 (dollar value of a basis point) to calculate an expected loss (EL) for the portfolio. EL just refers to the amount of money the market expects to lose given current spreads. As the screenshot shows, the SDV01 (circled in green) is about $4035. 237bps x $4035 gives us an expected loss of about $956,295 out of a notional of $10M, or 9.56%. Tuck this number away for later.

Technically speaking, SDV01s decrease as spreads increase, but the important thing to note is expected loss increases as spreads increase. Makes sense, right? Your expected loss should increase if you believe there’s a higher chance of default. Taking it to the extreme, if we assume an aggregate recovery of 40% for the portfolio (just roll with it), the maximum loss is 60%, even if every company in the index defaults.

An index tranche is defined by its attachment and detachment points. The equity tranche covers the first 0-3% of loss, the junior mezz 3-7% of loss, etc. The delta of a tranche describes the leverage of a tranche relative to the underlying portfolio. So if a given tranche has a delta of 3x, a one dollar swing in the underlying portfolio should result in a roughly $3 dollar swing in the value of the tranche.

Now, remember that index expected loss of 9.56% we calculated? You can map this to the attachment and detachment points of each index tranche. Without seeing any runs, we can guess that the 7-10% tranche probably has the highest delta (or close to it). Why? You could call it the “at-the-money tranche” since, intuitively speaking, the value of the 7-10% tranche is most sensitive to spread movements from current levels. Another way to look at it – index spreads are implying that the equity tranche will get wiped out (9.56% > 0-3%). As such, the equity tranche delta should be low as it is pretty much saturated in terms of loss.

If you look back at equity tranche deltas when spreads were low (sub-100bps), you’ll find that the equity tranche actually exhibited the highest delta of all the tranches (in the high teens). This high delta reflects the low level of expected loss implied by the index (<3%). I’m ignoring the impact of correlation right now, but basically all the loss was in the equity tranche. Thus, any change in expected loss would have the greatest impact on the equity tranche.

And that’s why mezz tranches gain sensitivity as spreads widen a lot. The junior-most tranches lose delta as they get saturated with loss while the “at-the-money” tranches gain delta since they are now the “new” first loss slices.

Written by DK

March 17, 2009 at 10:36 pm

Posted in Finance

Tagged with , , , , , ,

Using Google Apps Python Provisioning API

leave a comment »

I’ve gotten my church staff to use Google Apps for email and collaboration (sort of). Unfortunately, the Google Apps admin web tool is a bit inflexible (though it’s improving). In an effort to get more control over the data, I put together a little script that pulls all the users, distribution list names, and distribution list constituents into a google spreadsheet. The program uses two nice python libraries, xlrd and xlwt, to read and write to intermediary excel files since it’s not possible to directly create google spreadsheets (the workaround I used is to upload an xls file).

The documentation for xlrd is quite good. The documentation for Google’s Python Provisioning API is ok, but not particularly well organized. For example, I was trying to figure out the attributes for the different XML feed objects and was told no documentation existed (by a Google employee, no less). After hours of trial and error, I found the PrintFeed function below in a separate piece of Google documentation that made it clear it was possible to use a generic attribute. I accept the possibility I was being a idiot. Anyway, the documentation for xlwt is not good, but the code below should give you a decent start and a few fruitful search terms.

The script basically makes a spreadsheet with a summary tab that lists the name of each distribution list and the number of members in each list. It also creates a tab for each distribution list containing the email addresses of the list. Pretty basic, but handy if people (that aren’t admins) need to know what email lists are available (and their constituents).

I’m sure there are better ways to code this, but what the heck, it worked for me. But I make no guarantees! (UPDATE, see post with updated code.)

Written by DK

March 11, 2009 at 10:39 pm

Posted in Python

Tagged with ,