I have financial data (list of time-values pairs). There are more than 13000 elements.

data = FinancialData["KO", "OHLCV", {1000, 12, 31}];

I need extract from there some part of data which fall into the time interval. These parts are much. I use function TimeSeriesWindow, but it`s too slow. For example on this data


Is the any faster function with the similar functionality? Or how do that operations fater?


2 Answers 2


It is not TimeSeriesWindow that is making your code slow. What is slowing down your function is the conversion of the data received from FinancialData from a List to a TimeSeries object.
If this conversion is done before TimeSeriesWindow is applied, e.g. by




is even faster than the version presented by eldo.


I don't have MMA 10, so I can't reproduce TimeSeriesWindow. This is relatively fast:

Cases[data, {{y_, m_, d_}, __} /; 
    y >= 2013 && y <= 2013 && m >= 8 && m <= 8 && d >= 22 && d <= 26]; // Timing

{0.031200, Null}

DateInterval[data_, {y1_, m1_, d1_}, {y2_, m2_, d2_}] :=
 Cases[data, {{y_, m_, d_}, __} /; 
   y >= y1 && y <= y2 && m >= m1 && m <= m2 && d >= d1 && d <= d2]
  • $\begingroup$ That is really faster. Thank you $\endgroup$ Jul 18, 2014 at 11:17

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.