0
$\begingroup$

This is the first time I use the Package ‘PerformanceAnalytics’. I have a problem when it comes to use "Rf" (risk-free rate) when using the CAPM.beta. I use EONIA as a proxy for the risk free-rate. Here is my code :

library(zoo)
library(Quandl)
library(PerformanceAnalytics)
cac <- Quandl('YAHOO/INDEX_FCHI', start_date = '2014-01-01', end_date = '2016-01-01', type = 'zoo')
saf <- Quandl('YAHOO/PA_SAF', start_date = '2014-01-01', end_date = '2016-01-01', type = 'zoo')
eonia <-Quandl("BOF/QS_D_IEUEONIA", start_date = '2014-01-01', end_date = '2016-01-01', type = 'zoo')
safreturn <- Return.calculate(saf$Close, method = ("log"))
cacreturn <- Return.calculate(cac$Close, method = ("log"))

then when I try to use the CAPM.beta() function I get :

CAPM.beta(safreturn, cacreturn, eonia)
Error in NextMethod(.Generic) : 
  dims [product 523] do not match the length of object [266730]

I think that I understand that the problem comes from the length of Rf = eonia. I have noticed that even if the length of safreturn and cacreturn are not the same, if I put a random number for Rf I can obtain a solution, but I need to use the daily rate of EONIA.

Can someone help me ? Thanks in advance :)

$\endgroup$
0
$\begingroup$

The problem is that the length of the time series are different, despite you setting similar starting dates. CAPM.Beta then try to coerce the data unsuccessfully, which can be seen in the length of object [266730], which is equal to 510 * 523, which in turn is the length of the eonia series and the cacreturn series, respectively.

I am not much of a zoologist, so I prefer to use the xts library for financial series. The following should solve the problem:

library(xts)
library(Quandl)
library(PerformanceAnalytics)
cac <- Quandl('YAHOO/INDEX_FCHI', start_date = '2014-01-01', end_date = '2016-01-01', type = 'xts')
saf <- Quandl('YAHOO/PA_SAF', start_date = '2014-01-01', end_date = '2016-01-01', type = 'xts')
eonia <-Quandl("BOF/QS_D_IEUEONIA", start_date = '2014-01-01', end_date = '2016-01-01', type = 'xts')
safreturn <- Return.calculate(saf$Close, method = ("log"))
cacreturn <- Return.calculate(cac$Close, method = ("log"))

retmerge <- na.exclude(merge.xts(cacreturn, safreturn, eonia)) #na.exclude removes all rows with NA values

CAPM.beta(retmerge[,1], retmerge[,2], retmerge[,3])
$\endgroup$
  • $\begingroup$ Thank you for your help. I have never used the xts package before, and I had a look at the documentation, but it is still not clear to me. When I past into R the following retmerge <- as.xts(na.exclude(merge.xts(cacreturn, safreturn, eonia)))I get Error in merge.xts(cacreturn, safreturn, eonia) : no xts object to merge $\endgroup$ – bixoez Dec 27 '16 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.