return.calculate - Error in checkData(prices, method = "xts")

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

return.calculate - Error in checkData(prices, method = "xts")

cthesky
This post has NOT been accepted by the mailing list yet.
I have a CSV file with 5 stocks daily closing price. Would like to calculate the daily return with return.calculate function from Portfolio Analytics package. The following error message showed. I have attached some info of my data as well. Error message at the very bottom. Thanks!

##load the csv file
> data1 <- read.csv(choose.files(),header = T)
> head(data1)
        Date XMI.TO XMU.TO XMW.TO XMV.TO XMM.TO
1 2012-08-20  20.48  19.93  20.14  20.91  20.36
2 2012-08-27  20.44  19.87  20.02  20.81  20.05
3 2012-09-03  20.51  20.00  20.04  21.00  20.07
4 2012-09-10  20.43  19.80  19.95  21.00  20.07
5 2012-09-17  20.63  19.95  19.97  21.33  20.48
6 2012-09-24  20.92  19.99  20.10  21.25  20.63

##Change the date from "factor" into "date" class
> data1$Date <-as.Date(data1$Date)
> class(data1$Date)
[1] "Date"

> str(data1)
'data.frame': 261 obs. of  6 variables:
 $ Date  : Date, format: "2012-08-20" "2012-08-27" ...
 $ XMI.TO: num  20.5 20.4 20.5 20.4 20.6 ...
 $ XMU.TO: num  19.9 19.9 20 19.8 20 ...
 $ XMW.TO: num  20.1 20 20 20 20 ...
 $ XMV.TO: num  20.9 20.8 21 21 21.3 ...
 $ XMM.TO: num  20.4 20 20.1 20.1 20.5 ...

##Calculate daily return
> Return.calculate(data1)
Error in checkData(prices, method = "xts") :
  The data cannot be converted into a time series.  If you are trying to pass in names from a data object with one column, you should use the form 'data[rows, columns, drop = FALSE]'.  Rownames should have standard date formats, such as '1985-03-15'.
>