time series - reading monthly returns in R -


i have following monthly equity data in file "equity.dat":

2010-03,1e+06 2010-03,1.00611e+06 2010-04,998465 2010-05,1.00727e+06 2010-06,1.00965e+06 

i trying compute monthly returns using following code:

library(performanceanalytics) y = return.read(filename="equity.dat", frequency = "m", sep=",", header=false) y  z = return.calculate(y) z z[1]=0 #added remove na in first return 

but following error:

error in read.zoo(filename, sep = sep, format = format, fun = fun, header = header,  :    index has bad entries @ data rows: 1 2 3 4 5 

i checked out formatting return.read when using as.mon , why using yyyy-mm. should using different format.

according ?return.read default format.in= here "%f" not format of data have specified. index must unique (in case not) or else must aggregated per ?zoo , ?read.zoo latter of uses internally:

return.read(filename = "equity.dat", frequency = "m", sep = ",", header = false,    aggregate = function(x) tail(x, 1), format = "%y-%m") 

we have used tail define aggregating function -- may or may not wish use else.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -