Update on Scary Derivatives

November 16, 2011

(This article was first published on Timely Portfolio, and kindly contributed to R-bloggers)

After reading Bloomberg’s article,

JPMorgan Chase & Co. and Goldman Sachs Group Inc., among the world’s biggest traders of credit derivatives, disclosed to shareholders that they have sold protection on more than $5 trillion of debt globally.


I thought we should update my post Scary Derivatives and Scary XML in R in which I said

The massive damage caused in 2008-2009 by the sliver of derivatives called credit default swaps seems like a faint warning siren when we see that they only represent < 7% of total derivatives exposure. Interest rate and currency derivatives, also where I think the next disaster occurs, are more than 10 times larger than these credit contracts at $226 Trillion.

From TimelyPortfolio

This amount of money, bilaterally netted or not, is truly unbelievable and staggering.  Total debt outstanding of the sovereign nations is not the real problem.  Like housing, the exponential exacerbation caused by the leverage and derivatives traded on the underlying is where the real potential catastrophe occurs.  No government and no central bank has the ability to counter any major damage in currencies or interest rates.


R code (click to download from Google Docs):

#read xml derivatives data from the
#US Treasury OCC Quarterly Derivatives Report
#2 methods
#still way too manual since it appears the format changes
#each reporting period

#as far as I can tell
#the first published example of how to read
#Microsoft Excel xml workbooks


#get 2nd Quarter of 2011 report (dq211)
url = “http://www.occ.treas.gov/topics/capital-markets/financial-markets/trading/derivatives/dq211-xml.xml”

doc = xmlInternalTreeParse(url)
#define namespaces
#figuring this out took hours
#but using getNodeSet was much cleaner than the
#next method
namespaces = c(o=”urn:schemas-microsoft-com:office:office”,
#this gets row 41 from the Table 3 worksheet for the total $ of derivatives
ns <- getNodeSet(doc,”/ss:Workbook/ss:Worksheet[@ss:Name=’Table 3′]/ss:Table/ss:Row”,namespaces)[[41]]
amt <- df <- as.data.frame(as.numeric(xmlSApply(ns, xmlValue))[4:11])
#believe it or not this is $trillions of dollars
#remove some zeros so we can label better on the graph
amt <- amt/1000000
df <- df/1000000
#this gets row 10 for labels
ns <- getNodeSet(doc,”/ss:Workbook/ss:Worksheet[@ss:Name=’Table 3′]/ss:Table/ss:Row”,namespaces)[[10]]
lab <- as.character(xmlSApply(ns, xmlValue)[4:11])
#combine the labels with
df <- cbind(lab,df)
#jpeg(filename=”derivatives by type.jpg”,quality=100,
#    width=6.25, height = 8,  units=”in”,res=96)
barplot(df[5:8,2],names.arg = factor(df[5:8,1]),main=”US Bank Derivatives by Type
    Q2 2011″,ylab=”$ (in trillions)”,ylim=c(0,max(df[5:8,2]+50)),space=0,
mtext(“Source: US Dept of Treasury OCC Quarterly Derivatives Report”,

To leave a comment for the author, please follow the link and comment on their blog: Timely Portfolio.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: ,

Comments are closed.


Mango solutions

RStudio homepage

Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training



CRC R books series

Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)