Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer

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]
share|improve this answer
That is really faster. Thank you – molekyla777 Jul 18 '14 at 11:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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