I have the same procedure to install my R and the packages that I need. But I'm having this weird behaviour where when I ran my R
script below in my centOS 7
the result is correct. But when I ran the same script in my Ubuntu 14
I have this error, where the CAPM.jensenAlpha
functions return NaN
. These are the outputs from Rserve
on each machine (Ubuntu and centOS). I pasted a short version of the output below too. But my key point is: how can the same script provide different outputs ?
R script
library(xts)
library(PerformanceAnalytics)
cleanSeries <- function (benchmarkSeries, timeSeries) {
commonDates = merge(timeSeries, benchmarkSeries, all = FALSE)
allSeriesDates = merge(timeSeries, commonDates[,2])
allSeriesDates[is.na(allSeriesDates)] <- 0
return( xts(allSeriesDates[,2], index(allSeriesDates)) )
}
# input
timeSeries = xts(inputClass1@values, inputClass1@dates)
print('timeSeries')
print(timeSeries)
benchmarkSeries = xts(inputClass2@values, inputClass2@dates)
print('benchmarkSeries')
print(benchmarkSeries)
riskFreeSeries = xts(inputClass3@values, inputClass3@dates)
print('riskFreeSeries')
print(riskFreeSeries)
# amend dates of series (only dates from timeSeries are used)
cleanedBenchmarkSeries = cleanSeries(benchmarkSeries, timeSeries)
print('cleanedBenchmarkSeries')
print(cleanedBenchmarkSeries)
cleanedRiskFreeSeries = cleanSeries(riskFreeSeries, timeSeries)
print('cleanedRiskFreeSeries')
print(cleanedRiskFreeSeries)
jensensAlpha = CAPM.jensenAlpha(timeSeries, cleanedBenchmarkSeries, cleanedRiskFreeSeries, method = "alternative")
print('jensensAlpha')
print(jensensAlpha)
# output
setClass("ResultClass", representation(value = "numeric"))
traceback()
resultClass <- new("ResultClass", value = as.numeric(jensensAlpha))
CentOS (logger)
valter@eniac:centos$ R
R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Rserve)
> Rserve(args = "--vanilla --RS-enable-control --RS-enable-remote");
Starting Rserve:
/usr/lib/R/bin/R CMD /usr/local/lib/R/site-library/Rserve/libs//Rserve --vanilla --RS-enable-control --RS-enable-remote
R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
Rserv started in daemon mode.
> Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
Package PerformanceAnalytics (1.4.3541) loaded.
Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson, GPL-2 | GPL-3
http://r-forge.r-project.org/projects/returnanalytics/
Attaching package: ‘PerformanceAnalytics’
The following object is masked from ‘package:graphics’:
legend
[1] "timeSeries"
[,1]
2006-03-29 4.099731e-03
2006-03-30 1.173501e-02
2006-03-31 -2.357880e-03
2006-04-03 9.040080e-03
...
[1] "benchmarkSeries"
[,1]
2006-03-29 2.514452e-03
2006-03-30 6.105668e-03
2006-03-31 9.068408e-03
2006-04-03 5.285038e-03
...
[1] "riskFreeSeries"
[,1]
2006-03-29 7.594521e-05
2006-03-30 7.663014e-05
2006-03-31 7.709589e-05
2006-04-03 2.314521e-04
...
[1] "cleanedBenchmarkSeries"
benchmarkSeries
2006-03-29 2.514452e-03
2006-03-30 6.105668e-03
2006-03-31 9.068408e-03
2006-04-03 5.285038e-03
2006-04-04 4.359010e-03
...
[1] "cleanedRiskFreeSeries"
benchmarkSeries
2006-03-29 7.594521e-05
2006-03-30 7.663014e-05
2006-03-31 7.709589e-05
2006-04-03 2.314521e-04
2006-04-04 7.720548e-05
...
[1] "jensensAlpha"
benchmarkSeries
2006-03-29 0.03980130
2006-03-30 0.03980089
2006-03-31 0.03980062
2006-04-03 0.03970984
2006-04-04 0.03980056
...
No traceback available
Ubuntu (logger)
vagrant@vagrant-ubuntu-trusty-64:~$ R
R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Rserve)
> Rserve(args = "--vanilla --RS-enable-control --RS-enable-remote");
Starting Rserve:
/usr/lib/R/bin/R CMD /usr/local/lib/R/site-library/Rserve/libs//Rserve --vanilla --RS-enable-control --RS-enable-remote
R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
Rserv started in daemon mode.
> Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
Package PerformanceAnalytics (1.4.3541) loaded.
Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson, GPL-2 | GPL-3
http://r-forge.r-project.org/projects/returnanalytics/
Attaching package: ‘PerformanceAnalytics’
The following object is masked from ‘package:graphics’:
legend
[1] "timeSeries"
[,1]
2006-03-29 4.099731e-03
2006-03-30 1.173501e-02
2006-03-31 -2.357880e-03
2006-04-03 9.040080e-03
2006-04-04 -1.693213e-03
...
[1] "benchmarkSeries"
[,1]
2006-03-29 2.514452e-03
2006-03-30 6.105668e-03
2006-03-31 9.068408e-03
2006-04-03 5.285038e-03
2006-04-04 4.359010e-03
...
[1] "riskFreeSeries"
[,1]
2006-03-29 7.594521e-05
2006-03-30 7.663014e-05
2006-03-31 7.709589e-05
2006-04-03 2.314521e-04
2006-04-04 7.720548e-05
...
[1] "cleanedBenchmarkSeries"
benchmarkSeries
2006-03-29 2.514452e-03
2006-03-30 6.105668e-03
2006-03-31 9.068408e-03
2006-04-03 5.285038e-03
2006-04-04 4.359010e-03
2006-04-05 3.705145e-03
...
[1] "cleanedRiskFreeSeries"
benchmarkSeries
2006-03-29 7.594521e-05
2006-03-30 7.663014e-05
2006-03-31 7.709589e-05
2006-04-03 2.314521e-04
2006-04-04 7.720548e-05
...
[1] "jensensAlpha"
benchmarkSeries
2006-03-29 NA
2006-03-30 NA
2006-03-31 NA
2006-04-03 NA
2006-04-04 NA
No traceback available
Just to let you know what happened with my issue.
The problem was the TIMEZONE. I don't know exactly why, but R
or some of the packages that we use for our calculations requires the timezone to be the same.
I'm located in Germany (timezone CET which is +1 UTC) and I was setting my virtual machine to use UTC and thus the problem. Oh man, I'm really glad to solve this issue (3 days straight working on this!) but now everything is fine! A huge thank you to my colleague @Ralf
for the tip!