8
$\begingroup$

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}
$\endgroup$

2 Answers 2

9
$\begingroup$

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]]]
$\endgroup$
1
  • $\begingroup$ Thanks, Vitaliy. I appreciate the different examples. I didn't know about Extract. $\endgroup$ Nov 12, 2017 at 14:53
0
$\begingroup$

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}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.