Periodic table of investment returns

Here we will  try to replicate the pretty periodic table of investment returns found on the ishares websiteFor those countries where MSCI index data was not available, a general market index was used instead. Returns are computed from log differences in adjusted prices across 18 developed countries.

h

setwd("C:/University of Warwick/R experiments/Spatial")

library(quantmod)
library(timeSeries)
library(RColorBrewer)

dev.names<-c('Austria','Australia','Italy','Switzerland','Japan','Singapore','Canada','UK','Spain','Belgium','Hong Kong','France','Germany','USA','Netherlands','Sweden','Ireland','New Zealand')
dev.abr<-c('AUS','AUST','ITAL','CHF','JPY','SGP','CAN','UK','SPA','BEL','HK','FRA','GER','USA','NET','SWD','IRL','NZL')
dev.ticker<-c('EWO','EWA','EWI','EWL','EWJ','EWS','EWC','EWU','EWP','EWK','EWH','EWQ','EWG','VTI','EWN','EWS','^ISEQ','^NZGI')
dev.col<-as.matrix(topo.colors(length(dev.names),alpha=0.8))
rownames(dev.col)<-dev.abr
time.frame<-as.character(2002:2011)
num<-length(dev.names)
f<-as.Date('2002-01-01')
e<-as.Date('2011-12-31')
assets<-NULL
dev.ret.matrix<-NULL

for(i in 1:num){
  print(paste("Downloading data for :", dev.names[i]))
  assets$name[[i]]<-dev.names[[i]]
  assets$ticker[[i]]<-dev.ticker[[i]]
  getSymbols(dev.ticker[i],from=f,to=e)
  ifelse(strsplit(dev.ticker[i],'')[[1]][1]=='^',assets$prices[[i]]<-get(substr(dev.ticker[i],start=2,stop=5))[,4],assets$prices[[i]]<-get(dev.ticker[i])[,4])
  assets$annRet[[i]]<-as.timeSeries(annualReturn(assets$prices[[i]],type='log')*100)
  dev.ret.matrix<-cbind(dev.ret.matrix,assets$annRet[[i]])
}

dev.ret.matrix<-t(dev.ret.matrix)
rownames(dev.ret.matrix)<-dev.abr
colnames(dev.ret.matrix)<-time.frame

windows(width=14,height=14)
par(mai=c(0,0.2,0,0))
layout(matrix(c(1,1,1,1,1,1,1,1,1,2),nrow=10,ncol=1))
plot.new()
plot.window(xlim=c(-1,109),ylim=c(0,194))

for(i in 1:10){
  for(j in 1:19){
    if(j==19)
      {
       rect((i-1)*11,(j-1)*10,11*i,(j*10)-2,density=NA,col='darkblue',lty=1,border='white')
       text((11*i)-5.5,(19*10)-6,time.frame[i],cex=0.95,col="white",font=2)
    }

    else if(j<19)
    {
       temp<-as.matrix(dev.ret.matrix[order(dev.ret.matrix[,i]),i][j],1)
       col.code<-dev.col[rownames(temp),]
       rect((i-1)*11,(j-1)*10+1,11*i,(j*10)+4,density=NA,col=col.code,lwd=1.0,border='white')
       text((i-1)*11+5,(j-1)*10+8,rownames(temp),col='black',cex=0.8,font=2)
       text((i-1)*11+6,(j-1)*10+4,paste(round(temp,2),'%'),col='black',cex=0.8,font=2)
    }
}
}

mtext(side=2,'Ranked in order of performance',cex=0.70,col='black',font=2)
text(x=50,y=195,'Periodic Table Of Investment Returns',col='black',font=2)

arrows(-3,100,-3,170,length=0.07,col='black',lwd=2)
arrows(-3,100,-3,11,length=0.07,col='black',lwd=2)
text(x=-2.8,y=175,'Max',col='black',font=2,cex=1)
text(x=-3.0,y=6,'Min',col='black',font=2,cex=1)

plot.new()
par(mai=c(0,0.2,0,0.2))
legend("top",fill=dev.col,legend=dev.names,ncol=6,bty='n',x.intersp=0.3,title.adj=0.95,title='Colour Codes',border='white')
abline(h=0.75)

l

For a better quality click on the pdf version here : HighQuality

Leave a comment