# Tag Archives: Efficiency scores

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.

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&lt;-assets\$quarterly.returns[]
for(i in 2:n.assets){
quarterly.matrix&lt;-cbind(quarterly.matrix,assets\$quarterly.returns[[i]])
}

tq&lt;-t(quarterly.matrix)
colnames(tq)&lt;-rownames(quarterly.matrix)
rm&lt;-rowMeans(tq)

windows()
par(mfrow=c(6,5),mai=c(0.1,0.15,0.15,0.1),xaxt='n')
cb&lt;-rainbow(30)
for(i in 1:30){

stackpoly(axis2=F,axis4=F,lwd=2,border=&quot;darkblue&quot;,xlab='',cex.axis=0.75,quarterly.matrix[,i],cex.main=0.85,col=cb[i])
abline(h=0,lwd=1,col=&quot;black&quot;)
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(&quot;Best/Worst Performances for Quarter&quot;, i),cex.main=0.85,col=ifelse(tq[order(tq[,i]),][,i]&lt;=0,&quot;red&quot;,&quot;green&quot;))
abline(v=0,lwd=2,col=&quot;blue&quot;)
minm&lt;-min(tq[order(tq[,i]),][,i])
maxm&lt;-max(tq[order(tq[,i]),][,i])
t&lt;-as.matrix(tq[order(tq[,i]),][,i])
rmin&lt;-rownames(t)
rmax&lt;-rownames(t)
text(x=minm/2,y=30,paste(&quot;min :&quot;,rmin,round(t,2)),cex=0.75,col=&quot;red&quot;)
text(x=minm/2,y=32,paste(&quot;max :&quot;,rmax,round(t,2)),cex=0.75,col=&quot;green&quot;)
}
```

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 &lt;- 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(&quot;Fama-French Betas for MKT\n&quot;,Years[[panel\$Year]]),cex.main=0.95,col=&quot;orange&quot;)
barplot(space=0.5,cex.names=0.9,horiz=F,cex.axis=0.9,beside=T,tot.smb[[panel\$Year]],las=2,main=paste(&quot;Fama-French Betas for SMB\n&quot;,Years[[panel\$Year]]),cex.main=0.95,col=&quot;green&quot;)
barplot(space=0.5,cex.names=0.9,horiz=F,cex.axis=0.9,beside=T,tot.hml[[panel\$Year]],las=2,main=paste(&quot;Fama-French Betas for HML\n&quot;,Years[[panel\$Year]]),cex.main=0.95,col=&quot;blue&quot;)
panel
}
panel&lt;- 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&lt;-expand.grid(MKT=MKT.tot\$asset[],SMB=SMB.tot\$asset[])
mm&lt;-expand.grid(Quantiles=Quantiles,Years=Years)
dataf&lt;-data.frame(MKT=md\$MKT,SMB=md\$SMB,HML=HML.tot\$asset[])
dr&lt;-seq(-2,2,0.1)
l&lt;-length(dr)

windows()
wireframe(useRaster=T,region=T,alpha.regions=0.5,at=dr,col.regions=rainbow(l),main=paste(&quot;Beta Plots for&quot;,index.comp),data=dataf,HML~MKT*SMB,screen = list(z =-15, x =-70),colorkey=TRUE,drape=T)

windows()
dataf2&lt;-data.frame(Quantiles=mm\$Quantiles,Years=mm\$Years,MKT=MKT.tot\$asset[])
wireframe(main=paste(&quot;MKT across quantiles and time for&quot;,index.comp),useRaster=T,region=T,alpha.regions=1,at=c(-2,-1.5,-1,0,1,1.5,2),col.regions=brewer.pal(7,&quot;Blues&quot;),data=dataf2,MKT~Years*Quantiles,screen = list(z =-15, x =-70),colorkey=TRUE,drape=T)

windows()
dataf3&lt;-data.frame(Quantiles=mm\$Quantiles,Years=mm\$Years,SMB=SMB.tot\$asset[])
wireframe(main=paste(&quot;SMB across quantiles and time for&quot;,index.comp),useRaster=T,region=T,alpha.regions=1,at=c(-2,-1.5,-1,0,1,1.5,2),col.regions=brewer.pal(7,&quot;Greens&quot;),data=dataf3,SMB~Years*Quantiles,screen = list(z =-15, x =-70),colorkey=TRUE,drape=T)

windows()
dataf4&lt;-data.frame(Quantiles=mm\$Quantiles,Years=mm\$Years,HML=HML.tot\$asset[])
wireframe(main=paste(&quot;HML across quantiles and time for&quot;,index.comp),useRaster=T,region=T,alpha.regions=1,at=c(-2,-1.5,-1,0,1,1.5,2),col.regions=brewer.pal(7,&quot;Reds&quot;),data=dataf4,HML~Years*Quantiles,screen = list(z =-15, x =-70),colorkey=TRUE,drape=T)
```

d    