在R中创建投资组合的数据

时间:2016-03-26 16:26:17

标签: r

我在Excel中有数据。假设我是这样读的(下面只显示了一个系列):

 ccl<-ts(mysheets$CCL$`Adj Close`,start=c(2000, 1), end=c(2012, 12), frequency=12)
    ccl.r<-diff(log(ccl), lag=1)

然后,我构建了一个包含所有数据的向量:

data<-cbind(aal.r, adm.r, aht.r, anto.r, arm.r, av.r, azn.r, ba.r, bab.r, barc.r, bats.r,bdev.r, bkg.r, blnd.r, blt.r, bnzl.r, bta.r, bznl.r, ccl.r)

然后,我尝试使用以下方法将数据插入到fportfolio的格式中:

ewSpec<-portfolioSpec()
nAssets<-ncol(data)
setWeights(ewSpec)<-rep(1/nAssets, time=nAssets)
mydata<-portfolioData(data=data, spec=portfolioSpec())

然而,我收到此错误:

Error in portfolioData(data = data, spec = portfolioSpec()) : 
  object 'assetsNames' not found
In addition: Warning messages:
1: In if (class(data) == "timeSeries") { :
  the condition has length > 1 and only the first element will be used
2: In if (class(data) == "list") { :
  the condition has length > 1 and only the first element will be used

1 个答案:

答案 0 :(得分:0)

这是通过使矩阵成为&#34; timeSeries&#34;宾语。感谢您阅读问题...