Function Repository Resource:

TimeSeriesPartition

Source Notebook

Partition a time series into non-overlapping segments

Contributed by: Ting Sun

ResourceFunction["TimeSeriesPartition"][ts,dt]

partitions ts into a list of non-overlapping segments of window width dt.

Details

ResourceFunction["TimeSeriesPartition"] is used to partition a whole time series into segments for further processing (e.g. ensemble, aggregation, etc.).
ResourceFunction["TimeSeriesPartition"] breaks a time series similarly to TimeSeriesAggregate; thus, dt can be given the same way as in TimeSeriesAggregate.

Examples

Basic Examples (2) 

Divide a time series of 15 elements into elements 1–5, 6–10 and 11–15:

In[1]:=
v = {2, 1, 6, 5, 7, 4};
t = {1, 2, 5, 10, 12, 15};
ts = TimeSeries[v, {t}];
ResourceFunction["TimeSeriesPartition"][ts, 5]
Out[1]=

Partition a financial time series into annual segments:

In[2]:=
data = FinancialData[
   "GOOGL", {DateObject[{2005, 1, 1}, "Day", "Gregorian", -6.`], DateObject[{2013, 12, 31}, "Day", "Gregorian", -6.`]}];
In[3]:=
parts = ResourceFunction["TimeSeriesPartition"][data, "Year"]
Out[3]=

Show the annual segments in different colors:

In[4]:=
DateListPlot[parts]
Out[4]=

Possible Issues (2) 

TimeSeriesPartition is designed for TemporalData rather than simple List-like data:

In[5]:=
ResourceFunction["TimeSeriesPartition"][{1, 2, 3, 4}, 2]
Out[5]=

Partition can be employed to deal with more generic List-like data:

In[6]:=
Partition[{1, 2, 3, 4}, 2]
Out[6]=

Publisher

Ting Sun

Version History

  • 1.0.0 – 12 July 2021

Related Resources

License Information