({{, (RefLink[TimeSeriesMapThread, paclet:ref/TimeSeriesMapThread])[f,tseries] 
gives {{(Subscript[t, 1]),f[(Subscript[t, 1]),(Subscript[x, 1])]},{(Subscript[t, 2]),f[(Subscript[t, 2]),(Subscript[x, 2])]},…} for the time series tseries.}, {, (RefLink[TimeSeriesMapThread, paclet:ref/TimeSeriesMapThread])[f,tseries,{{(Subscript[a, 1]),(Subscript[a, 2]),…},{(Subscript[b, 1]),(Subscript[b, 2]),…},…}]
gives {{(Subscript[t, 1]),f[(Subscript[t, 1]),(Subscript[x, 1]),(Subscript[a, 1]),(Subscript[b, 1]),…]},{(Subscript[t, 2]),f[(Subscript[t, 2]),(Subscript[x, 2]),(Subscript[a, 2]),(Subscript[b, 2]),…]},…} for the time series tseries.}})

OpenersNotesSection(Spacer1)Details

(RefLink[TimeSeriesMapThread, paclet:ref/TimeSeriesMapThread]) can be used for regularly and irregularly spaced time series.

The input 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]).

(RefLink[TimeSeriesMapThread, paclet:ref/TimeSeriesMapThread]) threads over the paths in tseries.

OpenersPrimaryExamplesSection(Spacer1)Examples  (14)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Apply a function f to the times and values in a time series:

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

TimeSeriesMapThread[f,ts]["Path"]

Create a series with increasing variance as a function of time:

ts=TimeSeries[RandomReal[{-1,1},10^3],{1}];

ListPlot[ts]

mvar=TimeSeriesMapThread[RandomReal[NormalDistribution[#2,#1]]&,ts];

ListPlot[mvar]

Add quadratic trend to the values:

TimeSeriesMapThread[#2+#3&,mvar,{((Range[0,50,(50/999)])^2)}];

ListPlot[%]

OpenersExampleSection1(Spacer1)Scope  (7)

OpenersExampleSubsection0(Spacer1)Basic Uses  (2)

Set a value at time 3 to 0:

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

f[3,_]:=0;
f[_,v_]:=v;

TimeSeriesMapThread[f,ts]["Path"]

Add time-dependent noise to a vector-valued signal:

data=TimeSeries[Table[{t,{Sin[t],Cos[t]}},{t,0,30,0.1}]];

ListLinePlot[data]

ListLinePlot[TimeSeriesMapThread[RandomReal[{-#1/50,#1/50}]+#2&,data]]

OpenersExampleSubsection1(Spacer1)Data Types  (5)

Apply a function f to a list of time-value pairs:

ts={{1,a},{2,b},{3,c},{7,d}};

TimeSeriesMapThread[f,ts]

Set the values for times greater than 3 in (RefLink[TimeSeries, paclet:ref/TimeSeries]) to 1:

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

f[a_,b_]:=If[a>3,1,b]

TimeSeriesMapThread[f,ts]["Path"]

Visualize (RefLink[TemporalData, paclet:ref/TemporalData]) for integer times:

data=RandomFunction[WienerProcess[0,7],{0,20,.1},40]

ListLinePlot[data,PlotStyle->Thin]

TimeSeriesMapThread[If[Mod[#1,1]==0.,#2,0]&,data]

ListLinePlot[%]

Set the middle 50 values of (RefLink[EventSeries, paclet:ref/EventSeries]) to 0:

es=EventSeries[];

ListPlot[es,Filling->Axis]

TimeSeriesMapThread[If[25<#1<74,0,#2]&,es]

ListPlot[%,Filling->Axis]

Modify the values of a time series involving quantities:

s=Quantity[{0,16,9,3,20,23},"Meters"];

ts=TimeSeries[s]

Modify the values for times greater than 2:

f[a_,b_]:=If[a>2,(Quantity[1, "m", meters, "Meters"]),b]

new=TimeSeriesMapThread[f,ts]

new["Path"]

OpenersExampleSection2(Spacer1)Applications  (5)

OpenersExampleSubsection2(Spacer1)Inflation  (1)

The following are spot oil prices from 1970 to 2010. This data is not corrected for inflation:

oilPrices=TimeSeries[];

DateListPlot[oilPrices,Joined->True]

The consumer price index (CPI) is often used to correct historical prices for inflation:

pi=TimeSeries[];

DateListPlot[pi,Joined->True]

cpiCor[base_,t_,v_]:=((v*base)/(pi[t]))

Adjusted prices for inflation using the most recent value of the CPI:

baseCPI=pi["December 31st, 2009"]

cp=TimeSeriesMapThread[cpiCor[baseCPI,#1,#2]&,oilPrices];

DateListPlot[{cp,oilPrices},Joined->True,PlotLegends->{"Adjusted","Original"},PlotStyle->Thick]

Find the adjusted oil price on March 5, 2001:

cp["March 5th, 2001"]

OpenersExampleSubsection3(Spacer1)Weather  (1)

The following are monthly average temperatures for a Missouri city over a three-year period. Separate the seasonal and nonseasonal components of this data:

temp=TimeSeries[];

DateListPlot[temp,Joined->True]

Fit a model for the seasonal component:

mod=NonlinearModelFit[temp,a Sin[((x-b)/5000000)],{a,b},x];

DateListPlot[scomp=TimeSeriesMapThread[mod[#1]&,temp],Joined->True]

Use the model to obtain the nonseasonal component:

sCor[t_,v_]:=v-scomp[t]

ncomp=TimeSeriesMapThread[sCor,temp];

DateListPlot[ncomp,Joined->True]

Combining the components yields the original data:

Normal[TimeSeriesThread[Total,{ncomp,scomp}]]==Normal[temp]

OpenersExampleSubsection4(Spacer1)Simulation  (1)

Use (RefLink[TimeSeriesMapThread, paclet:ref/TimeSeriesMapThread]) to simulate a transformed random process:

μ=0;σ=1/3;t0=0;t1=2;x0=0;x1=0;

Simulate (RefLink[WienerProcess, paclet:ref/WienerProcess]):

proc=WienerProcess[μ,σ];
SeedRandom[3];
data=RandomFunction[proc,{t0,t1,.1}];

Apply transformation to the random sample to obtain Brownian bridge:

sample=TimeSeriesMapThread[x0(x1-x0)(#1-t0)/(t1-t0)+#2-(#1-t0) Last[data["Values"]]/(t1-t0)-(t1-#1)First[data["Values"]]/(t1-t0)&,data];

Compare to the corresponding (RefLink[BrownianBridgeProcess, paclet:ref/BrownianBridgeProcess]):

SeedRandom[3];
data=RandomFunction[BrownianBridgeProcess[σ,{t0,x0},{t1,x1}],{t0,t1,.1}];

ListLinePlot[{sample,data},PlotStyle->{Thick,Dotted}]

OpenersExampleSubsection5(Spacer1)GDP  (1)

Study the discrepancy in the estimate of GDP for Switzerland, in dollars:

GDPDiscrepancy=EntityValue[Entity["Country","Switzerland"],EntityProperty["Country","DiscrepancyInExpenditureEstimateOfGDP",{"CurrencyUnit"->"CurrentLCU","Date"->All}]]

The currency in which data is given:

GDPDiscrepancy["FirstValue"]//QuantityUnit

Transfer to US dollars and adjust for inflation:

GDPDiscrepancyInUSDollars=TimeSeriesMapThread[InflationAdjust[Quantity[QuantityMagnitude[#2],DatedUnit["SwissFrancs",First@DateList[#1]]],DatedUnit["USDollars",First@DateList[#1]]]&,GDPDiscrepancy]

DateListPlot[GDPDiscrepancyInUSDollars]

OpenersExampleSubsection6(Spacer1)Moon Phases  (1)

Create a lunar calendar in which the background color depends on the fraction of the moon illumination:

dates=DateRange[DateObject[{2014,1,1,12}],DateObject[{2014,1,31,12}],1];

mp=MoonPhase[dates,"Icon"];
sf=MoonPhase[dates,"Fraction"];

Create a new series of labeled images with gradient background:

phases=TimeSeriesMapThread[Framed[Labeled[ImageResize[#2,45],Style[DateString[#1,{"DayNameShort"," ","DayShort"}]]],Background->Lighter[ColorData["StarryNightColors",#3],.3]]&,mp,{sf["Values"]}];

Visualize the lunar calendar:

Labeled[Grid[Partition[phases["Values"], 7, 7, 4, ""], Dividers -> All,Spacings->{0,0}],  "January 2014", Top]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[MovingMap, paclet:ref/MovingMap])  ▪  (RefLink[TimeSeriesAggregate, paclet:ref/TimeSeriesAggregate])  ▪  (RefLink[TimeSeriesResample, paclet:ref/TimeSeriesResample])  ▪  (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[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])}})}})

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