Take the 2-minute tour ×

I have the following monthly equity data in file "equity.dat":


I am trying to compute the monthly returns using the following code:

y = Return.read(filename="equity.dat", frequency = "m", sep=",", header=FALSE)

z = Return.calculate(y)
z[1]=0 #added this to remove the NA in first return

but I get the following error:

Error in read.zoo(filename, sep = sep, format = format, FUN = FUN, header = header,  : 
  index has bad entries at data rows: 1 2 3 4 5

I checked out the formatting for Return.read when using as.mon and that is why am using yyyy-mm. should I be using a different format.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

According to ?Return.read the default format.in= here is "%F" which is not the format of your data so it will have to be specified. Also the index must be unique (in this case its not) or else it must be aggregated as per ?zoo and ?read.zoo the latter of which it uses internally:

  aggregate = function(x) tail(x, 1), format = "%Y-%m")

We have used tail to define the aggregating function -- you may or may not wish to use something else.

share|improve this answer
thank you for the corrected code. I will also look up tail() as I have not used it before. By using the above aggregation, it is not generating the March returns and that is something I was trying to achieve by including the initial equity –  user1155299 Mar 9 '12 at 20:01
Label the initial equity as February so you don't have two March entries. In that case you won't need aggregate= . –  G. Grothendieck Mar 9 '12 at 20:10
thanks, that was easy :-) –  user1155299 Mar 9 '12 at 20:24

Your Answer


