Saturday, 24 June 2017

Financial Analytics with R (Part 1) - Upside and Downside Capture Ratio

Introduction

I will be taking a bit of a break from Oil & Gas research. Recently, I was going through the performance of several hedge funds when I noticed an interesting metric: the Upside and Downside Capture Ratio. The Upside and Downside captures an investment's performance against a reference. This reference is usually an index. The goal of this tutorial is to quantify how a common stock, say Apple, performs against the market. The index chosen to represent the market, Wilshire 5000, is the broadest measure of the U.S economy.

Unlike a linear correlation, the ratios gives better perspective of how dependent an investment is on the market's rise or fall. For instance, Algonquin Capital, a Toronto-based hedge fund, had an downside capture of -0.51 against the S&P 500 (Algonquin Capital, 2017). This means that, since inception, the value of the investment has grown significantly even in a bear market. The downside capture for a hedge fund should be as low as possible.

Background
Figure 1, As far as mathematics go, the Upside and Downside Capture Ratio is surprisingly intuitive
The Upside and Downside Capture Ratio looks at cumulative return over during market gain and decline respectively (Figure 1). The exponential term gives greater weight to gains/losses reaped over a shorter period of time.

Figure 2, A good hedge fund should be able to deliver above-average returns in both a bull and bear economy. The Upside and Downside Capture Ratio successfully quantifies its ability to do so


Technique 

I broke the calculations into a series of functions with R. In my next post, I will upload all coding into Github. 

library("Quandl")
library("quantmod")

#generates data from ticker, calls monthlyReturn and year_sep 
cfa<-function(symbol)
{
  getSymbols(symbol)
  testa<-monthlyReturn(get(paste(symbol)))
  year_sep(testa,2016)
}
#divide index data into specified range and call the bull and bear functions respectively
year_sep_index<-function(x,year,year2)
{
  annual_x<<- (x[substr(index(x),1,4)==year | substr(index(x),1,4)==year2])
  bull_market(annual_x)
  bear_market(annual_x)
}
#divide investment data into specified range and call the bull and bear functions respectively
year_sep<-function(y,year,year2)
{
  annual_y<<-(y[substr(index(y),1,4)==year | y[substr(index(y),1,4)==year2])
  test<<-annual_y[index(annual_y)%in%index(bull)]+1
  upside(test)
  downside(test)
}
#isolate periods of monthly cumulative gain
bull_market<-function(x)
{
  bull<<-x[x[,1]>=0]+1
  annualized_bullreturn<<-((prod(bull))^(12/nrow(bull)))-1
}
#isolate periods of monthly cumulative loss
bear_market<-function(x)
{
  bear<<-x[x[,1]<=0]+1
  annualized_bearreturn<<-((prod(bear))^(12/nrow(bear)))-1
}
#calculate upside gain
upside<-function(y)
{
  upside_return<<-(annualized_bullreturn)/((prod(y)^(12/nrow(bull)))-1)
}
#calculate downside gain 
downside<-function(y)
{
  downside_return<<-(annualized_bearreturn)/((prod(y)^(12/nrow(bear)))-1)
}

The Wilshire 5000 Total Market Index was chosen because it provided the broadest measure of the U.S economy. Therefore, it gave a very reasonable approximation of the direction the market was moving overall. 

getSymbols("^W5000",from = '2014-01-01',to = '2016-12-31')
#clean data with na.omit 
W5000_monthly<-(monthlyReturn(na.omit(W5000)))
year_sep_index(W5000_monthly,2016,2015)

Extracting financial data from Apple was not difficult. I called the cfa method with "AAPL" (Figure 3). The upside return and downside return are also global variables.


Results 

Figure 3, Screenshot of my output. Simple, easy and fast. 

The results show that the upside and downside capture ratio is 334.9% and -183% respectively across 2015 and 2016. Small sample size for the index was not an issue. 9 months, out of 24, saw a fall in cumulative return for Wilshire 5000 Total Market Index. The remaining months marked a period of growth. Altogether, an investment made in January 2015 on the Wilshire 5000 would yeild 8.1% by December 2016. 

Even during a weak market, Apple Inc. (AAPL) demonstrates profitability (Figure 3). The stock price continues to grow - but at approximately half the rate as it would in a rising market. Future steps include cycling through a large database of stocks to rank securities that perform under different circumstances.  

Conclusions 

The Upward and Downward Capture Ratio quantifies a company's susceptibility to changes in the market. In creating a portfolio robust enough to withstand market fluctuations, the success of an investment can be attributed to shrewd security selection rather than from outside forces as the market. In the example performed with Apple Inc., I established that the stock will grow even when the market is experiencing a downturn. However, it can not be considered fully independent from the Wilshire 5000 Total Market Index. 

References 

Morning Side Investing Glossary. Upside and Downside Capture Ratio. Retrieved 06/23/2017, from http://www.morningstar.com/InvGlossary/upside-downside-capture-ratio.aspx

Algonquin Capital. Funds Performance. Retrived 06/21/2017
http://www.algonquincap.com/funds/performance/