Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

TimeSeriesWindow[data,{{2013,8,22},{2013,8,26}}];//AbsoluteTiming
(*{0.618035,Null}*)

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

share|improve this question

2 Answers 2

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

tsData=TimeSeries[data]

Than

TimeSeriesWindow[tsData,{{2013,8,22},{2013,8,26}}]

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 at 11:17

Your Answer

 
discard

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.