【问题标题】:CAPM.jensenAlpha not working with UbuntuCAPM.jensenAlpha 不适用于 Ubuntu
【发布时间】:2015-10-29 10:05:03
【问题描述】:

我有相同的过程来安装我的 R 和我需要的包。但是我有这种奇怪的行为,当我在centOS 7 中运行下面的R 脚本时,结果是正确的。但是当我在Ubuntu 14 中运行相同的脚本时,我遇到了这个错误,CAPM.jensenAlpha 函数返回NaN。这些是每台机器上Rserve 的输出(UbuntucentOS)。我也粘贴了下面输出的 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 

【问题讨论】:

  • inputClass1inputClass2等是什么?
  • 您是否尝试过在 Ubuntu 上手动调试以查看引入 NA(不是 NaN)的位置?
  • @Pascal 他们来自这里:stackoverflow.com/questions/33393040/…
  • @RomanLuštrik 如何在 Ubuntu 上做到这一点?
  • 就像在任何其他环境中一样。单步执行代码,一旦您看到 NA 可能来自哪里,就可以调试该函数。请参阅?browser?debug?debugonce

标签: r ubuntu centos rserve


【解决方案1】:

只是为了让您知道我的问题发生了什么。 问题出在 TIMEZONE。我不知道具体原因,但R 或我们用于计算的某些包要求时区相同。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-26
    • 2019-12-05
    • 1970-01-01
    • 2017-01-25
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 2015-02-25
    相关资源
    最近更新 更多