Hi David, Thanks for replying.
On Fri, Jul 3, 2009 at 8:08 PM, David Winsemius<dwinsem...@comcast.net> wrote: > > On Jul 3, 2009, at 7:34 PM, Ted Byers wrote: > >> Hi Mark >> >> Thanks for replying. >> >> Here is a short snippet that reproduces the problem: >> >> library(PerformanceAnalytics) >> thedata = read.csv("K:\\Work\\SignalTest\\BP.csv", sep = "\t", header >> = FALSE, na.strings="") >> thedata >> x = as.timeseries(thedata) >> x >> table.Drawdowns(thedata,top = 10) >> table.Drawdowns(thedata$V2, top = 10) >> >> The object 'thedata' has exactly what I expected. the line 'thedata' >> prints the correct contents of the file with each row prepended by a >> line number. The last few lines are: >> >> 8191 2009-06-17 48.40 >> 8192 2009-06-18 47.72 >> 8193 2009-06-19 48.83 >> 8194 2009-06-22 46.85 >> 8195 2009-06-23 47.11 >> 8196 2009-06-24 46.97 >> 8197 2009-06-25 47.43 >> >> The number of lines (8197), dates (and their format) and prices are >> correct. >> >> The last four lines produce the following output: >>> >>> x = as.timeseries(thedata) >> >> Error: could not find function "as.timeseries" > > That is not telling you that there is no such function but rather that you > have not loaded the package that contains it. To find out what package ( > which you have installed on your machine) contains a function, you type one > of these equivalents: > > ??"as.timeseries" > > help.search("as.timeseries") > I did this, which is why I tried as.timeseries in the first place. > If the needed package is not installed on your machine then you need to use > one of the R search sites. I use: > http://search.r-project.org/nmz.html > > In my installation there is a function named as.timeSeries in the package > timeSeries. Not sure if that is the function you want. (Spelling must be > exact in R.) If it is, then try: > > library(timeSeries) > timeSeries was already installed. And using library(timeSeries) succeeds but does not help. >>> x >> >> Error: object 'x' not found > > Not surprising, since the effort to create "x" failed. > Right,. I wasn't surprised by this. > >>> table.Drawdowns(thedata,top = 10) >> >> Error in 1 + na.omit(x) : non-numeric argument to binary operator > > Not sure whether this is due to earlier errors or something that is wrong > with your data. Most probably the latter, and since you have not reduced it > to a reproducible example, no one can tell from a distance. If you were > expecting the operation of giving "thedata" to as.timeseries() to have a > lasting effect on "thedata", you need to re-read the introductory material > on R that is readily available. That's not how the language works. > This only thing missing from my example is the data file itself. I have no problems providing that too, but I didn't think that was permitted (and it is too large to embed within a message. No, I did not expect "thedata" to be modified by as.timeseries. I just thought I'd try to see if table.Drawdowns would accept a data frame. And my call to " table.Drawdowns(thedata$V2, top = 10)" was to see if it would even accept a numeric vector (which is what I'd expected the price data to be represented as). Thanks Ted >>> table.Drawdowns(thedata$V2, top = 10) >> >> Error in if (thisSign == priorSign) { : >> missing value where TRUE/FALSE needed >>> >> >> Are the functions in your example in Rmetrics or PerformanceAnalytics? >> (like I said, I am just beginning this exploration, and I started with >> table.Drawdowns because it produces information that I need first) >> And given that my data is in tab delimited files, and can be read >> using read.csv, how do I feed my data into your four statements? >> >> My guess is I am missing something in coercing my data in (the data >> frame?) thedata into a timeseries array of the sort the time series >> analysis functions need: and one of the things I find a bit confusing >> is that some of the documentation for this mentions S3 classes and >> some mentions S4 classes (I don't know if that means I have to make >> multiple copies of my data to get the output I need). I could coerce >> thedata$V2 into a numeric vector, but I'd rather not separate the >> prices from their dates unless that is necessary (how would one >> produce monthly, annual or annualized rates of return if one did >> that?). >> >> Thanks >> >> Ted >> >> On Fri, Jul 3, 2009 at 6:39 PM, Mark Knecht<markkne...@gmail.com> wrote: >>> >>> On Fri, Jul 3, 2009 at 2:48 PM, Ted Byers<r.ted.by...@gmail.com> wrote: >>>> >>>> I have hundreds of megabytes of price data time series, and perl >>>> scripts that extract it to tab delimited files (I have C++ programs >>>> that must analyse this data too, so I get Perl to extract it rather >>>> than have multiple connections to the DB). >>>> >>>> I can read the data into an R object without any problems. >>>> >>>> thedata = read.csv("K:\\Work\\SignalTest\\BP.csv", sep = "\t", header >>>> = FALSE, na.strings="") >>>> thedata >>>> >>>> The above statements give me precisely what I expect. The last few >>>> lines of output are: >>>> 8190 2009-06-16 49.30 >>>> 8191 2009-06-17 48.40 >>>> 8192 2009-06-18 47.72 >>>> 8193 2009-06-19 48.83 >>>> 8194 2009-06-22 46.85 >>>> 8195 2009-06-23 47.11 >>>> 8196 2009-06-24 46.97 >>>> 8197 2009-06-25 47.43 >>>> >>>> I have loaded Rmetrics and PerformanceAnalytics, among other packages. >>>> I tried as.timeseries, but R2.9.1 tells me there is no such function. >>>> I tried as.ts(thedata), but that only replaces the date field by the >>>> row label in 'thedata'. >>>> >>>> If I apply the performance analytics drawdowns function to either >>>> thedata or thedate$V2, I get errors: >>>>> >>>>> table.Drawdowns(thedata,top = 10) >>>> >>>> Error in 1 + na.omit(x) : non-numeric argument to binary operator >>>>> >>>>> table.Drawdowns(thedata$V2, top = 10) >>>> >>>> Error in if (thisSign == priorSign) { : >>>> missing value where TRUE/FALSE needed >>>>> >>>> >>>> thedata$V2 by itself does give me the price data from the file. >>>> >>>> I am a relative novice in using R for timeseries, so I wouldn't be >>>> surprised it I missed something that would be obvious to someone more >>>> practiced in using R, but I don't see what that could be from the >>>> documentation of the functions I am looking at using. I have no >>>> shortage of data, and I don't want to write C++ code, or perl code, to >>>> do all the kinds of calculations provided in, Rmetrics and >>>> performanceanalytics, but getting my data into the functions these >>>> packages provide is killing me! >>>> >>>> What did I miss? >>>> >>>> Thanks >>>> >>>> Ted >>>> >>>> ______________________________________________ >>>> R-help@r-project.org mailing list >>>> 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. >>>> >>> >>> Could you supply some portion of the results when you run the example >>> on your data? The example goes like: >>> >>> data(edhec) >>> R=edhec[,"Funds.of.Funds"] >>> findDrawdowns(R) >>> sortDrawdowns(findDrawdowns(R)) >>> >>> How are you using the function with your data? >>> >>> - Mark >>> >> >> ______________________________________________ >> R-help@r-project.org mailing list >> 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. > > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > > ______________________________________________ R-help@r-project.org mailing list 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.