8

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
  • 5,462
  • 21
  • 43

2 Answers2

9

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
  • 73,078
  • 9
  • 204
  • 355
0

Will find nearest value to zero and the corresponding date:

Nearest[ts["DatePath"], {0, 0}, DistanceFunction -> (#2[[2]] - #1[[2]]] &)]

{{Fri 15 May 2020 00:00:00GMT+2,$ 43.92}}

Hans W
  • 73
  • 7