3
$\begingroup$

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?

$\endgroup$
4
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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]
$\endgroup$
  • $\begingroup$ That is really faster. Thank you $\endgroup$ – molekyla777 Jul 18 '14 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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