({{, (RefLink[TimeSeriesResample, paclet:ref/TimeSeriesResample])[tseries] 
uniformly resamples tseries according to its minimum time increment.}, {, (RefLink[TimeSeriesResample, paclet:ref/TimeSeriesResample])[tseries,rspec] 
resamples tseries according to rspec.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[TimeSeriesResample, paclet:ref/TimeSeriesResample]) is often used to convert irregular time series to regular ones. It can also be used to align time series.

The time series tseries can be a list of values {(Subscript[x, 1]),(Subscript[x, 2]),…}, a list of time-value pairs {{(Subscript[t, 1]),(Subscript[x, 1])},{(Subscript[t, 2]),(Subscript[x, 2])},…}, a (RefLink[TimeSeries, paclet:ref/TimeSeries]), an (RefLink[EventSeries, paclet:ref/EventSeries]), or (RefLink[TemporalData, paclet:ref/TemporalData]).

Some basic settings for rspec include:

Possible dayspec types are: "Weekday", "Weekend", (RefLink[Monday, paclet:ref/Monday]) through (RefLink[Sunday, paclet:ref/Sunday]), "BeginningOfMonth", "EndOfMonth", "BusinessDay" and "Holiday".

If dt is set to (RefLink[Automatic, paclet:ref/Automatic]), the minimum time increment in tseries is used.

The following settings for rspec are useful if tseries contains multiple paths:

If times are not given, then tseries is assumed to be regular with unit spacing.

(RefLink[TimeSeriesResample, paclet:ref/TimeSeriesResample]) takes the following option:

OpenersPrimaryExamplesSection(Spacer1)Examples  (28)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Resample a time series:

ts=TimeSeries[RandomReal[1,5],{0}]

Resampling with spacing smaller than the minimum time increment will add time stamps:

ts["MinimumTimeIncrement"]

res1=TimeSeriesResample[ts,1/3]

ListPlot[{ts,res1},Joined->{True,False},Filling->{2->0}]

Resampling with spacing larger than the minimum time increment:

res2=TimeSeriesResample[ts,2]

ListPlot[{ts,res2},Joined->{True,False},Filling->{2->0}]

Resample time series with dates:

ts=TimeSeries[Range[20],{{2016,5,30,3,10,1.},Automatic,"Day"}]

Select business days:

res1=TimeSeriesResample[ts,"BusinessDay"]

DateListPlot[{ts,res1},Joined->{True,False},Filling->{2->0}]

Select weekends:

res2=TimeSeriesResample[ts,"Weekend"]

DayName/@res2["Dates"]

Select Wednesdays:

res3=TimeSeriesResample[ts,Wednesday]

res3//Normal

Resample an irregular data:

data=RandomFunction[PoissonProcess[.3],{1,50}];

ListPlot[data]

RegularlySampledQ[data]

Resample with step of 2:

rdata=TimeSeriesResample[data,2];

ListPlot[rdata]

The resampled time series is now regularly sampled:

RegularlySampledQ[rdata]

OpenersExampleSection1(Spacer1)Scope  (13)

OpenersExampleSubsection0(Spacer1)Basic Uses  (3)

Downsample a time series:

data=RandomFunction[PoissonProcess[30],{1,5}];

ListPlot[data]

data["PathLength"]

Resample at a granularity of 0.25:

ds=TimeSeriesResample[data,.25];

ListPlot[ds]

ds["PathLength"]

Sample multiple paths at the same time:

data=RandomFunction[PoissonProcess[10],{1,5},20];

ListPlot[data]

Resample at a granularity of 0.1:

ds=TimeSeriesResample[data,0.1];

ListPlot[ds]

Fill in missing values:

appl=FinancialData["APPLX",{"January 2013","March 2013"}];

RegularlySampledQ[appl]

Resample at a daily resolution, interpolating holidays and weekends:

applR=TimeSeriesResample[appl,"Day"];

RegularlySampledQ[applR]

DateListPlot[applR,Joined->True]

Alternatively, insert (RefLink[Missing, paclet:ref/Missing]):

applM=TimeSeriesResample[appl,"Day",ResamplingMethod->None];

DateListPlot[applM,Joined->True]

OpenersExampleSubsection1(Spacer1)Data Types  (6)

Resample a time series in the form of a vector:

data={(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[x, 3]),(Subscript[x, 4]),(Subscript[x, 5])};

Upsample by a factor of 2:

TimeSeriesResample[data,1/2]

Downsample by a factor of 2:

TimeSeriesResample[data,2]

A time series given as time-value pairs:

data={{1,(Subscript[x, 1])},{2,(Subscript[x, 2])},{3,(Subscript[x, 3])},{4,(Subscript[x, 4])},{5,(Subscript[x, 5])}};

Upsample by a factor of 2:

TimeSeriesResample[data,1/2]

Downsample by a factor of 2:

TimeSeriesResample[data,2]

Resample a (RefLink[TimeSeries, paclet:ref/TimeSeries]):

data=TimeSeries[{{1,(Subscript[x, 1])},{2,(Subscript[x, 2])},{3,(Subscript[x, 3])},{4,(Subscript[x, 4])},{5,(Subscript[x, 5])}}];

Upsample by a factor of 2:

TimeSeriesResample[data,1/2]["Path"]

Downsample by a factor of 2:

TimeSeriesResample[data,2]["Path"]

Resample an (RefLink[EventSeries, paclet:ref/EventSeries]):

data=EventSeries[{{1,(Subscript[x, 1])},{2,(Subscript[x, 2])},{3,(Subscript[x, 3])},{4,(Subscript[x, 4])},{5,(Subscript[x, 5])}}];

By default, an event series is not interpolated:

TimeSeriesResample[data,1/2]["Path"]

Setting the (RefLink[ResamplingMethod, paclet:ref/ResamplingMethod]) overrides this:

TimeSeriesResample[data,1/2,ResamplingMethod->{"Constant",c}]["Path"]

A single path given as (RefLink[TemporalData, paclet:ref/TemporalData]):

data=TemporalData[{{1,(Subscript[x, 1])},{2,(Subscript[x, 2])},{3,(Subscript[x, 3])},{4,(Subscript[x, 4])},{5,(Subscript[x, 5])}}];

Upsample by a factor of 2:

TimeSeriesResample[data,1/2]["Path"]

Downsample by a factor of 2:

TimeSeriesResample[data,2]["Path"]

Multiple paths given as (RefLink[TemporalData, paclet:ref/TemporalData]):

data=TemporalData[{{(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[x, 3]),(Subscript[x, 4]),(Subscript[x, 5])},{(Subscript[y, 1]),(Subscript[y, 2]),(Subscript[y, 3]),(Subscript[y, 4]),(Subscript[y, 5])}},{1}];

Upsample by a factor of 2:

TimeSeriesResample[data,.5]["Paths"]

Downsample by a factor of 2:

TimeSeriesResample[data,2]["Paths"]

OpenersExampleSubsection2(Spacer1)Sampling  (4)

Resample according to the smallest time increment:

data=RandomFunction[PoissonProcess[3],{1,100}];

rdata=TimeSeriesResample[data];

The original data is irregular:

RegularlySampledQ[data]

mti1=Min[Differences[data["Times"]]]

Resampling gives regular data with the same minimum time increment:

RegularlySampledQ[rdata]

mti2=Min[Differences[rdata["Times"]]]

mti1==mti2

Specify a sampling increment of 3:

data=RandomFunction[PoissonProcess[3],{1,100}];

ListPlot[TimeSeriesResample[data,3]]

Larger values give coarser sampling:

Table[ListPlot[TimeSeriesResample[data,dt],PlotLabel->dt],{dt,{1,5,10}}]

Use a sampling increment based in calendar time:

data=FinancialData["APPLX","2010"];

DateListPlot[data]

DateListPlot[TimeSeriesResample[data,{2,"Month"}]]

Resample multiple paths:

td=TemporalData[{{{1,x1},{2,x2},{2.1,x3},{3,x4},{4,x5}},{{1,y1},{1.5,y2},{2,y3},{2.5,y4},{3,y5},{3.5,y6},{4,y7}}}];

Use the union of times:

TimeSeriesResample[td,"Union"]["Times"]

The intersection:

TimeSeriesResample[td,"Intersection"]["Times"]

Use times from the first path:

TimeSeriesResample[td,{"Times",1}]["Times"]

OpenersExampleSection2(Spacer1)Options  (6)

OpenersExampleSubsection3(Spacer1)ResamplingMethod  (3)

Resample irregular data using linear interpolation:

data=TimeSeries[{1,2,3,4,5},{{1,2,3,4,7}}];

TimeSeriesResample[data,ResamplingMethod->{"Interpolation",InterpolationOrder->1}]["Path"]

By default, the method setting for the data is used:

data=TimeSeries[{1,2,3,4,5},{{1,2,3,4,7}},ResamplingMethod->{"Interpolation",InterpolationOrder->1}];

TimeSeriesResample[data]["Path"]

Setting (RefLink[ResamplingMethod, paclet:ref/ResamplingMethod]) to (RefLink[None, paclet:ref/None]) gives missing values for irregular data:

data=TimeSeries[{1,2,3,4,5},{{1,2,3,4,7}}];

TimeSeriesResample[data,ResamplingMethod->None]["Path"]

Use a constant value:

data=TimeSeries[{1,2,3,4,5},{{1,2,3,4,7}}];

TimeSeriesResample[data,ResamplingMethod->{"Constant",c}]["Path"]

OpenersExampleSubsection4(Spacer1)CalendarType  (1)

The time series of stock prices:

stocks=FinancialData["TXN","Close",{{2015,1,1},{2015,6,30}}];
data=TimeSeries[stocks]

Resample using Islamic calendar:

res=TimeSeriesResample[data,CalendarType->"Islamic"]

res["Dates"][[;;3]]

OpenersExampleSubsection5(Spacer1)HolidayCalendar  (1)

The time series of stock prices:

stocks=FinancialData["AAPL","Close",{{2015,1,1},{2015,6,30}}];
data=TimeSeries[stocks]

Resample according to business days in United States:

res1=TimeSeriesResample[data,"BusinessDay",HolidayCalendar->"UnitedStates"]

Resample according to business days at New York Stock Exchange:

res2=TimeSeriesResample[data,"BusinessDay",HolidayCalendar->{"UnitedStates","NYSE"}]

Find the one business day NYSE was closed:

{d}=Complement[res1["Dates"],res2["Dates"]]

The holiday observed by NYSE:

WolframAlpha[DateString[d,"Date"],{{"ObservanceDate (country)",1},"ComputableData"}]

OpenersExampleSubsection6(Spacer1)TimeZone  (1)

The time series of stock prices:

stocks=FinancialData["SBUX","Close",{{2015,1,1},{2015,6,30}}];
data=TimeSeries[stocks]

The time series are not regularly sampled:

RegularlySampledQ[data]

Resample according to the NYSE business day in the time zone of New York City:

res=TimeSeriesResample[data,"BusinessDay",HolidayCalendar->{"UnitedStates","NYSE"},TimeZone->"America/New_York"]

res["Dates"][[1]]

OpenersExampleSection3(Spacer1)Applications  (5)

This time series contains the number of steps taken daily by a person during a period of five months:

stepdata=TimeSeries[];

Analyze the number of steps depending on a day of the week:

weekdays={Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday};
wk=Map[TimeSeriesResample[stepdata,#]&,weekdays];

avg=Map[Floor[Mean[#]]&,wk];

PieChart[avg,ChartLabels->Placed[{avg,weekdays},{"RadialCenter","RadialOutside"}],ImagePadding->20]

Financial information is generated only for business days:

data=TimeSeries@FinancialData["SBUX","Close",{{2013,12,1},{2013,12,31}}]

The automatically created time series is not regularly sampled:

RegularlySampledQ[data]

Resample according to "BusinessDay" to create a uniformly sampled time series:

ts=TimeSeriesResample[data,"BusinessDay"]

RegularlySampledQ[ts]

The paths are the same:

data["Path"]==ts["Path"]

Consider some financial data:

data=TimeSeries@FinancialData["SBUX","Close",{{2013,12,1},{2013,12,31}}]

The data is generated only for business days. There are no changes on the remaining days; hence, we can resample by day by keeping the value from the left:

ts=TimeSeriesResample[data,ResamplingMethod->{"Interpolation",InterpolationOrder->0}]

The plot is flat over the weekends and holidays:

DateListPlot[ts]

Use (RefLink[AirPressureData, paclet:ref/AirPressureData]) to examine pressure changes due to Hurricane Sandy at Long Island MacArthur Airport:

pressure=AirPressureData["KISP",{DateObject[{2012,10,26}],DateObject[{2012,10,30}]}]

DateListPlot[pressure,FrameLabel->Automatic]

The data is not regularly sampled:

RegularlySampledQ[pressure]

To analyze the rate of change, data needs to be resampled into a regularly sampled time series:

res=TimeSeriesResample[pressure,{DateObject[{2012,10,27}],Automatic,"Hour"}]

RegularlySampledQ[res]

Plotting each observation disjointly shows the rate of change of the pressure, with larger spacing indicating faster changes:

DateListPlot[res,Joined->False]

Analyze the monthly temperatures in Champaign during 2014:

td=TimeSeries[];

The raw data comes in one-day increments:

td["MinimumTimeIncrement"]

Resample by a month:

monthlyTemps=TimeSeriesResample[td,{Automatic,Automatic,"Month"}]

monthlyTemps["MinimumTimeIncrement"]

Basic descriptive statistics:

{Min[#],Mean[#],Max[#]}&@monthlyTemps

Compare to the original data:

{Min[#],Mean[#],Max[#]}&@td

DateListPlot[{td,monthlyTemps},PlotLegends->{"daily temperatures","resampled monthly"},FrameLabel->Automatic]

OpenersExampleSection4(Spacer1)Possible Issues  (1)

The original time stamps may not be preserved after resampling:

v={1,3,9,3,2};
t={0,.3,1,1.3,2};
ts=TimeSeries[v,{t}]

Note that the time series is not regularly sampled:

RegularlySampledQ[ts]

Resample according to (RefLink[MinimumTimeIncrement, paclet:ref/MinimumTimeIncrement]):

ts1=TimeSeriesResample[ts]

New times:

ts1["Times"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[MovingMap, paclet:ref/MovingMap])  ▪  (RefLink[TimeSeriesAggregate, paclet:ref/TimeSeriesAggregate])  ▪  (RefLink[TimeSeriesThread, paclet:ref/TimeSeriesThread])  ▪  (RefLink[RegularlySampledQ, paclet:ref/RegularlySampledQ])  ▪  (RefLink[MinimumTimeIncrement, paclet:ref/MinimumTimeIncrement])  ▪  (RefLink[TimeSeriesShift, paclet:ref/TimeSeriesShift])  ▪  (RefLink[TimeSeriesRescale, paclet:ref/TimeSeriesRescale])  ▪  (RefLink[TimeSeriesMap, paclet:ref/TimeSeriesMap])  ▪  (RefLink[TimeSeriesMapThread, paclet:ref/TimeSeriesMapThread])  ▪  (RefLink[TimeSeriesInsert, paclet:ref/TimeSeriesInsert])  ▪  (RefLink[TimeSeriesModelFit, paclet:ref/TimeSeriesModelFit])  ▪  (RefLink[TimeSeriesWindow, paclet:ref/TimeSeriesWindow])  ▪  (RefLink[TemporalData, paclet:ref/TemporalData])  ▪  (RefLink[TimeSeries, paclet:ref/TimeSeries])  ▪  (RefLink[EventSeries, paclet:ref/EventSeries])  ▪  (RefLink[ResamplingMethod, paclet:ref/ResamplingMethod])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Time Series Processing, paclet:guide/TimeSeries])}, {▪(RefLinkPlain[Signal Processing, paclet:guide/SignalProcessing])}})}})