Financial Python

Studies in Finance and Python

Posts Tagged ‘cds

Parsing DTCC Part 1: PITA

leave a comment »

In a previous post, I complained about the DTCC’s CDS data website and the one week lifespan of the data published there. For those of you who don’t know, the DTCC clears and settles a massive number of transactions every day for multiple asset classes. It’s one of those financial institutions that doesn’t get much press but underpins the entire capital market.

Anyway, the recent crisis motivated the DTCC to publish weekly CDS (single name, index, and tranche) exposure data. A good idea, until one realizes the data goes up in smoke when the next week’s data arrives. Although DTCC recently added links to data for “a week ago”, “a month ago”, and “a year ago,” it’s still pretty inconvenient. So, if you want the data, you have to parse it yourself. I originally wanted to write a smart parser that would dynamically react to whatever format it encountered…I came to my senses and adopted a simpler approach.

The approach thus far:

  • Download the raw html pages/files via “curl.” Urllib2 is the preferred method to pull web pages, but I didn’t have the patience to figure out how to handle redirects. Curl is a utility included with OS X that, for whatever reason, ignores redirects automatically. As such, I created a short python script to download the html for all the tables of interest weekly.
  • Use BeautifulSoup to parse the html. Other libraries, such as html5lib and lxml seem to be gaining ground on BeautifulSoup, particularly as it’s author wants to get out of the parsing game altogether. Nevertheless, I couldn’t be bothered to figure out the unicode issues I experienced with html5lib or lxml’s logic. BeautifulSoup is straightforward and “gives you unicode, dammit!” (quoting the author).
  • Use numpy for easier data manipulation. Since my html, css, DOM, etc. knowledge is basic, I thought it might be better to use numpy to manipulate the table data rather than rely solely on the parser. This meant vectorizing the html data into a 1D array, cleaning it up, and generally preparing it for future reshaping. Numpy, how did I ever live without you?

This would’ve been much easier if all the tables were exactly the same format. Unfortunately, that’s never the case. An extra cell here or there, or weird characters, can throw things off. This isn’t an issue if you are parsing individual pieces of data or a single table. But what if you need to parse ten, 20, 100, etc. tables? It can get ugly fast. The DTCC data is broken into 23 pages, some of which have multiple tables. Luckily, most of my pain was self-inflicted (hey, I’m a parsing virgin). I only had to account for a few different table formats in the end.

One downside to my approach is I do not dynamically produce headers for the data I’m pulling. I plan to manually set the headers for each table (the ultimate destination for the data right now are csv files). If there’s a better way, please let me know.

You can find the code here via pastebin (feedback is welcome).
You can find the DTCC tables here (if you want to view the html source).

Part 2 will cover the process of reformatting the data with numpy and perhaps feature some charts. I’m very curious to see what the numbers show!

Here are a few screenshots of a terminal session using the code so far:


See and download the full gallery on posterous

Advertisements

Written by DK

September 15, 2009 at 7:15 am

Posted in Finance, Python

Tagged with , , , , ,

Finance Primer Round-Up

leave a comment »

Here’s a round-up of some “primer” posts I’ve either written or linked, for convenient reference.

“Yet Another CDO Primer” Videos:

Ep 1: Basic Intuition

Ep 2: Economic motivations and PPIP

Posts:
Delta and Mark-to-Market. This has been NoteToSelf’s most popular post, by far. It explains the basic intuition behind expected loss and delta for synthetic tranches.

Fixed Coupon is the same as CDX. The “Big Bang” made for standardization of CDS coupons. Not a big deal if you understand how the CDX index works (explained in the post).

My Liability Is Your Asset. An initial reaction to Simon Johnson’s piece in the Atlantic. A bit of a ramble.

Mark To Market vs. Mark To Model. A link to Rortybomb’s explanation of this concept.

Financial Crisis for Beginners. A link to Baseline Scenario’s mega-link page of helpful articles on the current crisis.

Written by DK

June 11, 2009 at 9:10 pm

Posted in Finance

Tagged with , , , , ,

DTCC CDS Data

leave a comment »

I called DTCC many months ago asking whether they were planning on creating a feed of their CDS/Tranche data (they currently only offer weekly snapshots). The answer was something like, “We’ve been getting lots of requests, and we are planning to roll out something in the next few weeks that will allow users to download historical data.” Well, that was back in 2008. And as I understand it, the previous week’s data goes up in smoke when the new data comes arrives. I should know better. Anyway, Zero Hedge captures the weekly information caveman-style (he is promising more coverage of DTCC too, thank you very much), but c’mon DTCC! Can’t we get this data onto the website or get the FreeRisk guys to spider this stuff into a database someplace?

**End pout.**

Written by DK

June 10, 2009 at 9:24 pm

Posted in Finance

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 , , , , , ,