【问题标题】:R stockPortfolio Package not connecting to YahooR stockPortfolio 包未连接到雅虎
【发布时间】:2014-08-28 05:48:43
【问题描述】:

我正在尝试复制此示例,因为我是通过 R 进行投资组合优化的新手:

http://economistatlarge.com/portfolio-theory/r-optimized-portfolio

但是,我不断收到以下错误:

    R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (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(stockPortfolio)
Warning message:
package ‘stockPortfolio’ was built under R version 3.1.1 
> library(quadprog)
Warning message:
package ‘quadprog’ was built under R version 3.1.1 
> stocks <- c(
+ "SPY" = .30,
+ "EFA" = .20,
+ "IWM" = .15,
+ "VWO" = .10,
+ "LQD" = .15,
+ "HYG" = .10)
> returns <- getReturns(names(stocks), freq="week")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  unable to connect to 'ichart.finance.yahoo.com' on port 80.

我不知道如何解决这个问题,有什么建议吗?

【问题讨论】:

  • 我知道这是一篇旧帖子,您现在可能已经想通了,但以防万一您没有...为了他人的利益...股票
  • 因此,代码应如下所示: library(stockPortfolio) library(quadprog) stock
  • 我无法弄清楚为什么所有内容都连接在一起。当一切都被包装起来并挤在一起时,很难阅读这个......无论如何,看看这个:economistatlarge.com/portfolio-theory/r-optimized-portfolio

标签: r optimization


【解决方案1】:

这可能不是导致错误的确切答案。但它旨在作为一个起点。此外,这对于维护已安装软件包的正确预期功能非常重要。


从代码的顶部开始,您的 R 版本是

R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"

如果您在使用library(或require)附加包裹时收到警告消息,那应该会激发您的兴趣。您的代码显示以下警告消息。

> library(stockPortfolio)
# Warning message:
# package ‘stockPortfolio’ was built under R version 3.1.1 
> library(quadprog)
# Warning message:
# package ‘quadprog’ was built under R version 3.1.1 

您的软件包是用比您使用的新版本的 R 构建的。这可能是由于代码或其他方面的更改而导致的问题。

我建议您更新到最新版本的 R,然后重试。

【讨论】:

  • 我的公司终于允许我安装 3.1.1 并且我得到了同样的错误。但是,我找到了这个站点:sites.google.com/site/swlazlowski/Home/hardware/… 并输入了 setInternet2() 并且它起作用了(尽管我在输入该命令后遇到了一个奇怪的错误)。不确定它是否有效,因为我升级到了 3.1.1,但感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2020-07-20
  • 1970-01-01
  • 2014-04-12
  • 1970-01-01
  • 2023-02-21
  • 2017-01-27
  • 2015-01-23
  • 2021-09-30
相关资源
最近更新 更多