CAPM.jensenAlpha 无法使用 Ubuntu

CAPM.jensenAlpha not working with Ubuntu

我使用相同的程序来安装我的 R 和我需要的包。但是我有这种奇怪的行为,当我 运行 我的 R 下面的脚本在我的 centOS 7 中时,结果是正确的。但是当我 运行 在我的 Ubuntu 14 中使用相同的脚本时,我有这个错误,其中 CAPM.jensenAlpha 函数 return NaN。这些是每台机器 (Ubuntu and centOS) 上 Rserve 的输出。我也在下面粘贴了 short 版本的输出。但我的重点是:同一个脚本如何提供不同的输出?

R 脚本

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(记录器)

    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(记录器)

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 

只是想让你知道我的问题是怎么回事。 问题是 TIMEZONE。我不知道为什么,但是 R 或我们用于计算的某些软件包要求时区相同。

我位于德国(CET 时区 +1 UTC),我将我的虚拟机设置为使用 UTC,因此出现了问题。哦,伙计,我真的很高兴解决这个问题(连续 3 天处理这个问题!)但现在一切都很好!非常感谢我的同事 @Ralf 的提示!

其他相关问题:, , 。 我希望这可以帮助别人! :)