Effective Number of Bets

Yesterday, I had a post on Risk Parity, however one of the drawbacks is if the assets are highly correlated the performance may not be the best. ( https://kylebalkissoon.wordpress.com/2014/04/14/risk-parity-using-various-risk-measures-volatility-expected-shortfall-semi-deviation-maximum-draw-down/ ).   Today I will be analyzing the previous group from yesterday to see what was the effective number of bets. This is built off Attilio Meucci et al’s work on the topic. As we can see with the 12 assets from yesterday we are only making 8 effective bets which implies that while risk parity might be a wise idea, there can be benefits in effectively choosing ourbets. I will be providing a future blog post on how this can be used in portfolio construction( I used equal weight as the initial weights).

 

Recall that this methodology is dependent on the weights of the portfolios and that long-only can restrict the effective number of bets possible.

 

 

 

Rplot

Effective_Number_of_bets = function(R,w){
  num_assets = ncol(R)
  ##Calculate covariance matrix
  sigma = cov(R)
  ###Calculate eign vectors E and eigenvalues 
  eigen_vectors = eigen(sigma)$vectors
  eigen_values = eigen(sigma)$values
 
  principal_variances = NULL
  for( i in 1:ncol(R)){
    principal_variances[i] = var(as.numeric(as.vector(eigen_vectors[,i])%*%t(R)))
 
  }
  principal_portfolio_return = 1/(eigen_vectors)%*%t(R)
  principal_weights = eigen_vectors^-1%*%w
 
 
  ##Calculated Weighted Ret, Rw in Meucci's slides
  weighted_ret = t(principal_weights)%*%principal_portfolio_return
 
  ##Variance Concentration
  var_concentration = data.frame(matrix(ncol=2,nrow=num_assets))
  colnames(var_concentration) = c('assets','variance')
  for( i in 1:num_assets){
    var_concentration[i,]$assets = i
 
    var_concentration[i,]$variance = (weighted_ret[i]^2)*principal_variances[i]
 
  }
 
  var_concentration$variance =  var_concentration$variance/sum( var_concentration$variance)
 
  ##volatility concentration
  volatility_concentration = data.frame(matrix(ncol=2,nrow=num_assets))
  colnames(volatility_concentration) = c('assets','volatility')
    for( i in 1:num_assets){
    volatility_concentration[i,]$assets = i
    volatility_concentration[i,]$volatility = var_concentration$variance[i]/sd(weighted_ret) 
 
 
  }
 
  volatility_concentration$volatility = volatility_concentration$volatility/sum(volatility_concentration$volatility)
 
  ##Diversification distribtuion "probability mass"
  diversification_distribution = data.frame(matrix(ncol=2,nrow=num_assets))
  colnames(diversification_distribution) = c('assets','mass')
  for( i in 1:num_assets){
    diversification_distribution[i,]$assets = i
 
    diversification_distribution[i,]$mass = var_concentration$variance[i]/var(as.numeric(weighted_ret))
 
 
 
 
  }
  diversification_distribution$mass = diversification_distribution$mass/sum(diversification_distribution$mass)
  ###Effective number of bets
  effective_number_of_bets = data.frame(matrix(ncol=2,nrow=num_assets))
  colnames(effective_number_of_bets) = c('assets','enb')
  for( i in 1:num_assets){
    effective_number_of_bets$assets[i] = i
 
    effective_number_of_bets$enb[i] = exp((-1)*sum(diversification_distribution[1:i,2]*log(diversification_distribution[1:i,2])))
 
 
    }
 
 
 
  ans = list(var_concentration,volatility_concentration,diversification_distribution,effective_number_of_bets)
  names(ans) = c('var_con','vol_con','div_dist','enb')
  return(ans)}
 
 
library(PerformanceAnalytics)
library(quantmod)
 
###Symlist
symbol_list = c('SPY','XLF','XLE','XLU','XLK','XLB','XLP','XLY','XLI','XLV','TLT','GLD')
 
getSymbols(symbol_list, from = '1990-01-01')
 
 
securities_matrix = NULL
for( sym in symbol_list){
  securities_matrix = merge.xts(securities_matrix,ROC(Ad(get(paste(sym))),type='discrete'))
 
 
}
 
##Start in 2005, as GLD has inception of 2004-11
securities_matrix = securities_matrix['2005/2015-01-01']
 
analysis = Effective_Number_of_bets(securities_matrix,rep(1/ncol(securities_matrix),ncol(securities_matrix)))

Created by Pretty R at inside-R.org

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: