4
$\begingroup$

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?

$\endgroup$
  • 3
    $\begingroup$ TimeSeriesThread is what you want I think $\endgroup$ – Andy Ross Feb 4 '15 at 23:07
  • $\begingroup$ @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. $\endgroup$ – Michael Stern Feb 5 '15 at 3:39
  • $\begingroup$ 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. $\endgroup$ – Andy Ross Feb 5 '15 at 3:48
  • $\begingroup$ Perhaps turning them into Associations and then using Merge? $\endgroup$ – Sjoerd C. de Vries Feb 5 '15 at 23:02

Your Answer

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

Browse other questions tagged or ask your own question.