Getting the date on which an event in a time-series (e.g., the minimum value) occurs

6

1

I want to get the time in a time series that a particular event (e.g., the minimum value) occurs. The approach I take below seems clumsy. Is there a better way?

ts = TimeSeries[FinancialData["GE", "Jan. 1, 2007"]];
DateListPlot[ts]

enter image description here

6.66 = Min[ts]
p = Position[ts["Values"], Min[ts]][[1, 1]];
ts["DatePath"][[p]]

{DateObject[{2009, 3, 5, 0, 0, 0.}], 6.66}

George Wolfe

Posted 2017-11-12T02:05:31.883

Reputation: 5 088

Answers

6

A few other versions, the first one being the cleanest in a sense that it combines operation of finding the minimum and extracting the date.

MinimalBy[Normal[ts], Last]

Cases[Normal[ts], {_, Min[ts]}]

Cases[ts["DatePath"], {_, Min[ts]}]

Extract[Normal[ts], Position[ts["Values"], Min[ts]]]

Vitaliy Kaurov

Posted 2017-11-12T02:05:31.883

Reputation: 66 672

Thanks, Vitaliy. I appreciate the different examples. I didn't know about Extract. – George Wolfe – 2017-11-12T14:53:21.823