# Quantile Regression & DEA [Part I]

* In this post *the theory of Data Envelopment Analysis (DEA) will be applied to security selection and simple portfolio construction.DEA is used for evaluating and comparing performances of organizational units in a multi-attribute and multidimensional environment by determining the relative efficiency of a decision-making-unit (DMU). More precisely, if one can define stocks as individual decision-making-units (DMU), each associated with single/multiple dimensional inputs and outputs, it should be possible to compute an efficiency score, that encompasses all associated costs and benefits, for each asset. A security is considered efficient if its composite measure of output offsets its corresponding composite measure of input. I suppose in this context, a security can be regarded as efficient if no other combination of costs( inputs) can yield a greater benefit (output). While inputs and outputs associated with each DMU (i.e.asset) can be defined in a number of ways, here we shall use a stock’s Fama & French coefficients as inputs and annualised returns as outputs. More precisely,we shall regress each stock’s monthly excess returns, calculated from log closing prices, on Fama & French’s factor returns using OLS as well as a quantile regression framework. The first link below summarises the methodology used.

Click here for the complete post :: Click here for the Fama/French dataset

i

* After downloading* stock data for the 30 components of the Dow Jones Industrial Average index from 2005 to 2009, let’s first visualise the quarterly returns for each asset and rank the stocks according to their returns.

l

#Visualise Quarterly returns quarterly.matrix<-assets$quarterly.returns[[1]] for(i in 2:n.assets){ quarterly.matrix<-cbind(quarterly.matrix,assets$quarterly.returns[[i]]) } tq<-t(quarterly.matrix) colnames(tq)<-rownames(quarterly.matrix) rm<-rowMeans(tq) windows() par(mfrow=c(6,5),mai=c(0.1,0.15,0.15,0.1),xaxt='n') cb<-rainbow(30) for(i in 1:30){ stackpoly(axis2=F,axis4=F,lwd=2,border="darkblue",xlab='',cex.axis=0.75,quarterly.matrix[,i],cex.main=0.85,col=cb[i]) abline(h=0,lwd=1,col="black") mtext(text=index.comp[i],side=3,col='black',cex=0.6) } windows() par(mfrow=c(2,2),mai=c(0.5,0.5,0.5,0.2)) for(i in 1:4){ barplot(cex.names=0.67,horiz=T,cex.axis=0.75,beside=FALSE,border='white',tq[order(tq[,i]),][,i],las=2,main=paste("Best/Worst Performances for Quarter", i),cex.main=0.85,col=ifelse(tq[order(tq[,i]),][,i]<=0,"red","green")) abline(v=0,lwd=2,col="blue") minm<-min(tq[order(tq[,i]),][,i]) maxm<-max(tq[order(tq[,i]),][,i]) t<-as.matrix(tq[order(tq[,i]),][,i]) rmin<-rownames(t)[1] rmax<-rownames(t)[30] text(x=minm/2,y=30,paste("min :",rmin,round(t[1],2)),cex=0.75,col="red") text(x=minm/2,y=32,paste("max :",rmax,round(t[30],2)),cex=0.75,col="green") }

s

* Next *let’s regress the monthly excess asset returns on Fama-French factor returns using standard OLS as well as the quantile regression framwork for each year in the dataset. Using the

*rpanel*package, we can once again make use of the slider control which allows us to plot the OLS derived coefficients for each designated year.

d

windows() par(mfrow=c(3,1),mai=c(0.5,0.5,0.5,0.5)) if (interactive()) { draw <- function(panel) { barplot(space=0.5,cex.names=0.9,horiz=F,cex.axis=0.9,beside=T,tot.mkt[[panel$Year]],las=2,main=paste("Fama-French Betas for MKT\n",Years[[panel$Year]]),cex.main=0.95,col="orange") barplot(space=0.5,cex.names=0.9,horiz=F,cex.axis=0.9,beside=T,tot.smb[[panel$Year]],las=2,main=paste("Fama-French Betas for SMB\n",Years[[panel$Year]]),cex.main=0.95,col="green") barplot(space=0.5,cex.names=0.9,horiz=F,cex.axis=0.9,beside=T,tot.hml[[panel$Year]],las=2,main=paste("Fama-French Betas for HML\n",Years[[panel$Year]]),cex.main=0.95,col="blue") panel } panel<- rp.control(Year = 1) rp.slider(panel,Year, 1,5, action=draw,resolution=1,showvalue=TRUE

k

** Unfortunately**, 3d-surface plots cannot be that easily updated using the slider function, limiting the surface plots to one asset at a time. The first is a surface plot of factor returns across quantiles which probably does not make much sense but looks pretty non the less. The next 3 plots show how the MKT,SMB,HML coefficients (as per Fama and French) vary across quantiles and time. From these plots it is evident that high/med/low return stocks respond very differently to risk factors across time.

l

md<-expand.grid(MKT=MKT.tot$asset[[1]],SMB=SMB.tot$asset[[1]]) mm<-expand.grid(Quantiles=Quantiles,Years=Years) dataf<-data.frame(MKT=md$MKT,SMB=md$SMB,HML=HML.tot$asset[[1]]) dr<-seq(-2,2,0.1) l<-length(dr) windows() wireframe(useRaster=T,region=T,alpha.regions=0.5,at=dr,col.regions=rainbow(l),main=paste("Beta Plots for",index.comp[1]),data=dataf,HML~MKT*SMB,screen = list(z =-15, x =-70),colorkey=TRUE,drape=T) windows() dataf2<-data.frame(Quantiles=mm$Quantiles,Years=mm$Years,MKT=MKT.tot$asset[[1]]) wireframe(main=paste("MKT across quantiles and time for",index.comp[1]),useRaster=T,region=T,alpha.regions=1,at=c(-2,-1.5,-1,0,1,1.5,2),col.regions=brewer.pal(7,"Blues"),data=dataf2,MKT~Years*Quantiles,screen = list(z =-15, x =-70),colorkey=TRUE,drape=T) windows() dataf3<-data.frame(Quantiles=mm$Quantiles,Years=mm$Years,SMB=SMB.tot$asset[[1]]) wireframe(main=paste("SMB across quantiles and time for",index.comp[1]),useRaster=T,region=T,alpha.regions=1,at=c(-2,-1.5,-1,0,1,1.5,2),col.regions=brewer.pal(7,"Greens"),data=dataf3,SMB~Years*Quantiles,screen = list(z =-15, x =-70),colorkey=TRUE,drape=T) windows() dataf4<-data.frame(Quantiles=mm$Quantiles,Years=mm$Years,HML=HML.tot$asset[[1]]) wireframe(main=paste("HML across quantiles and time for",index.comp[1]),useRaster=T,region=T,alpha.regions=1,at=c(-2,-1.5,-1,0,1,1.5,2),col.regions=brewer.pal(7,"Reds"),data=dataf4,HML~Years*Quantiles,screen = list(z =-15, x =-70),colorkey=TRUE,drape=T)

d