# How to compute maximum or minimum value between two dates that are not hardcoded

2 messages
Open this post in threaded view
|
Report Content as Inappropriate

## How to compute maximum or minimum value between two dates that are not hardcoded

 This post has NOT been accepted by the mailing list yet. I've been grappling with this one put can't crack it.  Have checked the online forums, xts docs etc. but seems this is one step beyond what's there. What I'm doing 1. start with a time-series 2. filter the time-series in 1 in some way 3. filter the results in 2 in some way, returning pairs of dates What I then want to do: screen the original time-series in step 1 for the Max and Min price between the pair of dates in Step 3. I can filter an xts in a hard-coded way e.g. xts["2012-08-01::2012-08-05"] but I've tried with a variable and it doesn't work.  It just passes everything through: originalTimeSeries[paste(as.Date(combined[[1]]), "::", as.Date(combined[[2]]))] where combined is      firstDate secondDate [1,]     -2747      -1179 [2,]      1737       2981 [3,]      2981       3738 [4,]      6501       7588 [5,]      8470       8796 (for whatever reasons the dates come through as longs.) and created from firstDate <- secondDate <- combined <- cbind(firstDate,secondDate) So what I want is some kind of way to go     max(originalTimeSeries[between firstDate and secondDate]) where firstDate and secondDate are the results of some other query for each line in combined.  Effectively this is just a min-max exercise where the window-size is determined by some other criteria, dynamically, and will typically change with each run. Any ideas on how to get the results all chained together?  Clearly it can be done with hard-coded dates but that defeats the point of the exercise.