Financial Python

Studies in Finance and Python

Posts Tagged ‘cdx

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

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 ,

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