Evolution of Natural-logged Financial Assets Return

I have some engagement over the break, and while most of the analysis have been churned out by R after some programming, it will be some time before I  could write about them.

For now, enjoy the clip. 

Financial Assets Return Correlation Heatmap

Diversification is a timeless advice in wealth management. Even Antonio (from Shakespeare’s Merchant of Venice) quipped:
“My ventures are not in one bottom trusted,

Nor to one place; nor is my whole estate
Upon the fortune of this present year;
Therefore, my merchandise makes me not sad.” 
In contrast, David Wilson(from Mark Twain’s Pudd’nhead Wilson) declared, “Put all your eggs in the one basket, and – WATCH THAT BASKET.”
The quantitative revolution had shaped much of today’s financial landscape, yet such contrasting financial proverbs have not been swept away. While Harry Markowitz reshaped the way people think about and manage risks, the counterpoint of Antonio’s and Wilson’s remark still dazzles us in a different guise.
Is tactical asset allocation a good way to manage risk? What is the most efficient portfolio? Should it consist of the entire stock market within a nation’s border? A global portfolio of stock markets? A portfolio across all assets classes imaginable? 
The Global Financial Crisis of 2007-2008 had made me reflect on such questions deeply. In this series of posts I attempt to answer the questions above. This exploration will be done in a model-free and dynamic framework by:
1) Decomposing the eigenvalues/vectors of the correlation matrix of daily natural-logged returns of financial assets. The variation that can be explained by projecting the data in the direction of the first eigenvector is in a sense, the analog of the Beta that investors should think hardly about.
2) Building Asset Price Stress Indices to compare the observed change in asset prices relative to its history.
3) Tracking the evolution of the correlation matrix with heatmaps. 
As a sneak peek, here is the correlation heatmap of daily natural-logged returns across 82 financial assets for the period 6/1/2006-14/12/2012.
The heatmap is graphed with the ggplot2 package in R. 
The packages required are, ggplot,reshape2,scales,and R color Brewer.
Here’s a sample script, inspired by this question in Stackoverflow.
library(ggplot2)
library(reshape2) 
library (scales) 
library(RColorBrewer)
Mat<-as.data.frame(Mat)
Matm<-as.data.frame(Mat)
Matm<-data.frame(row=rownames(Matm),Matm) 
Matm.m<-melt(Matm)
Matm.m$value<-cut(Matm.m$value,breaks=c(1,0.75,0.5,0.25,0,-0.25,-0.5,-0.75,-1),include.lowest=TRUE,label=c(“(-0.75,-1)”,”(-0.5,-0.75)”,”(-0.25,-0.5)”,”(0,-0.25)”,”(0,0.25)”,”(0.25,0.5)”,”(0.5,0.75)”,”(0.75,1)”)) 
Matm.m$row<-factor(Matm.m$row,levels=rev(unique(as.character(Matm.m$variable))))
po.nopanel<-list(opts(panel.background=theme_blank(),panel.grid.minor=theme_blank(),panel.grid.major=theme_blank()))
jpeg(“histheatmap.jpeg”,height=1000,width=1000)
ggplot(Matm.m,aes(row,variable))+geom_tile(aes(fill=value),colour=”black”)+scale_fill_brewer(palette=”YlOrRd”,name=”Correlation”)+opts(axis.text.x=theme_text(angle=-90))+po.nopanel
dev.off()
As an aside, to download the packages above, type the following command in your R prompt.
>install.packages(‘ggplot’,dep=TRUE) 
Likewise for the other packages. 

A Tutorial in Graphing in R

Found an excellent tutorial from Isomorphisems for plotting graphs in R. This really showcases R’s graphing ability, and is definitely of publishing quality.

Here’s the URL.

R’s learning curve can be steep, but it is immensely rewarding.