简体   繁体   中英

Create data for portfolio in R

I have data in Excel. Suppose I read it like this (only one series is shown below):

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

Then, I construct a vector with all the data:

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)

Then, I try to insert the data into format of fportfolio, by using:

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

However, I get this error:

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

This was solved by making the matrix a "timeSeries" object. Thanks for reading the question...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM