## Is there a convenient way to sum TimeSeries objects in Mathematica?

4

3

Imagine I have two TimeSeries objects,

test1 =
TimeSeries[{{{2010, 1, 1}, 1}, {{2010, 3, 1}, 1.1}, {{2010, 4, 1},
1.4}, {{2010, 5, 1}, 1.6}, {{2010, 6, 1}, 1.9}, {{2010, 7, 1},
2}, {{2010, 8, 1}, 2.1}, {{2010, 9, 1}, 2.4}, {{2010, 10, 1},
2.7}, {{2010, 11, 1}, 2.9}, {{2010, 12, 1}, 3.1}, {{2011, 1, 1},
3.71}}];
test2 =
TimeSeries[{{{2010, 1, 1}, 2}, {{2010, 3, 1}, 2.1}, {{2010, 4, 1},
2.4}, {{2010, 5, 1}, 2.6}, {{2010, 6, 1}, 2.9}, {{2010, 7, 1},
3}, {{2010, 8, 1}, 3.1}, {{2010, 9, 1}, 3.4}, {{2010, 10, 1},
3.7}, {{2010, 11, 1}, 3.9}, {{2010, 12, 1}, 4.1}, {{2011, 1, 2},
4.71}}];

Note that the dates on these two series do not line up exactly. Is there a convenient way to sum these two, to create a new series that either (a) reflects only the dates they have in common or (b) extrapolates/interpolates for a missing series on the missing dates? Output would then be something like

TimeSeries[{{{2010, 1, 1}, 3}, {{2010, 3, 1}, 3.2}, {{2010, 4, 1},
3.8}, {{2010, 5, 1}, 4.2}, {{2010, 6, 1}, 4.8}, {{2010, 7, 1},
5}, {{2010, 8, 1}, 5.2}, {{2010, 9, 1}, 5.8}, {{2010, 10, 1},
6.4}, {{2010, 11, 1}, 6.8}, {{2010, 12, 1}, 7.2}}]

for dates in common, or

TimeSeries[{{{2010, 1, 1}, 3}, {{2010, 3, 1}, 3.2}, {{2010, 4, 1},
3.8}, {{2010, 5, 1}, 4.2}, {{2010, 6, 1}, 4.8}, {{2010, 7, 1},
5}, {{2010, 8, 1}, 5.2}, {{2010, 9, 1}, 5.8}, {{2010, 10, 1},
6.4}, {{2010, 11, 1}, 6.8}, {{2010, 12, 1}, 7.2}, {{2011, 1, 1},
8.41}, {{2011, 1, 2}, 8.43}}]

for all dates with interpolation/extrapolation.

For that matter, is there even a convenient way to sum TimeSeries when you know in advance the dates are identical?

3TimeSeriesThread is what you want I think – Andy Ross – 2015-02-04T23:07:07.643

@AndyRoss Yes, TimesSeriesThread is very helpful. There's no automatic way to have it work only on data with common timestamps (by design it always interpolates or extrapolates for missing points), but I can edit the data I pass it to simulate this feature as needed. Thanks. – Michael Stern – 2015-02-05T03:39:31.230

You can also set the missing data method on the TimeSeries objects to None. Not sure if that will work, I don't have M in front of me to try it. – Andy Ross – 2015-02-05T03:48:25.380

Perhaps turning them into Associations and then using Merge? – Sjoerd C. de Vries – 2015-02-05T23:02:48.227