On Sun, Feb 26, 2017 at 11:37 PM, Allan Tanaka <allantanak...@yahoo.com> wrote: > Here is the screenshoot to show what's happening entirely > > > > On Monday, 27 February 2017, 12:23, Allan Tanaka <allantanak...@yahoo.com> > wrote: > > > See attached for updated R script > > > On Monday, 27 February 2017, 12:22, Allan Tanaka <allantanak...@yahoo.com> > wrote: > > > I have converted the data into as.Date but then the dates itself (containing > the data[,1]) have NA value. Even after removing NA values by this > particular code: > ag.direction.returns[1] <- 0
Your dates have NA values because you specified the format incorrectly in your call to as.Date(). Despite the column names, the format is "MM.DD.YYYY", not "DD.MM.YYYY". R> head(data) DD.MM.YYYY O H L C 1 3/26/2009 132.63 133.90 132.33 133.70 2 3/27/2009 133.69 133.86 129.35 130.09 3 3/30/2009 129.75 130.55 126.40 128.65 4 3/31/2009 128.64 131.87 128.22 130.95 5 4/1/2009 130.94 131.89 129.86 130.54 6 4/2/2009 130.55 134.23 130.29 134.16 Additionally, 'src' and 'dateFormat' are not arguments to as.Date(), so they're unnecessary. Your as.Date() call should be: dates <- as.Date(data[,1], format="%m/%d/%Y") > it's still containing NA values, that won't be allowedwhen i try to merge > xts in this particular code: > both.curves <- cbind(ag.curve, buy.hold.curve) > > >> both.curves <- cbind(ag.curve, buy.hold.curve) > nan, nan > Error in merge.xts(..., all = all, fill = fill, suffixes = suffixes) : > 'NA' not allowed in 'index' > > > > > > On Monday, 27 February 2017, 12:05, Joshua Ulrich <josh.m.ulr...@gmail.com> > wrote: > > > Please provide a minimal, reproducible example. It's really hard for > someone to help you if you give them nearly 100 lines of code and no > data. My guess is that data[,1] is character (or factor) and you need > to convert it to Date or POSIXct. > > On Sun, Feb 26, 2017 at 9:24 AM, Allan Tanaka <allantanak...@yahoo.com> > wrote: >> HiNot sure why i get error like this: Error in xts(forecasts, >> dates[(window.length):length(returns)]) : order.by requires an appropriate >> time-based object >> I have researched for the answer that i need to convert returns into time >> series. I did that but still it doesn't work?See attached for file.Thanks > >> ______________________________________________ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > > > -- > Joshua Ulrich | about.me/joshuaulrich > FOSS Trading | www.fosstrading.com > R/Finance 2017 | www.rinfinance.com > > > > > > > -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R/Finance 2017 | www.rinfinance.com ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.