7
$\begingroup$

"EndOfMonth" is date unit that can be used with date functions. When specifying a TimeSeries object with date increments you can specify the date unit increment so that you obtain a regularly sampled time series. I need date units of "EndOfMonth" in the TimeSeries.

If I supply the month end dates the result is an irregularly sampled time series.

 TimeSeries[
  Transpose@{DateRange[{2006, 12, 31}, {2007, 9, 30}, "EndOfMonth"], 
    Range[10]}] // RegularlySampledQ
(* False *)

If I request a time increment of "EndOfMonth" then TimeSeries errors.

TimeSeries[Range[10], {Automatic, {2007, 9, 30}, {1, "EndOfMonth"}}]

TemporalData::tpspc: The time specification {Automatic,{2007,9,30},{1,EndOfMonth}} should be one of Automatic, a time range, a list containing a list of explicit times, or a list containing one such specification for each path in the data.

If I request a time increment of "Month" I get a regularly sampled time series but the dates are not month ends.

(m = TimeSeries[
    Range[10], {Automatic, {2007, 9, 30}, {1, "Month"}}]) // RegularlySampledQ

(* True *)

(m["Dates"] /. DateObject[d_, ___] :> DateObject[d]) === 
 DateRange[DateObject@{2006, 12, 31}, DateObject@{2007, 9, 30}, "EndOfMonth"]

(* False *)

How can a regularly sampled TimeSeries of date unit "EndOfMonth" be created?

$\endgroup$
9
+50
$\begingroup$

This is the purpose of the TemporalRegularity option.

TemporalRegularity is an option for TemporalData, TimeSeries, and EventSeries that controls whether the paths are assumed to be uniformly spaced in time.

When setting this option, the dates themselves are ignored and a standard index {0,1,...,n} is used in its place, allowing for non-uniform dates/times to be used for labeling and plotting purposes while leveraging algorithms that require uniform spacing.

TimeSeries[
  Transpose@{DateRange[{2006, 12, 31}, {2007, 9, 30}, "EndOfMonth"], 
    Range[10]}, TemporalRegularity -> True] // RegularlySampledQ

(* True *)

Edit

It is interesting to look at the InputForm of the TimeSeries object that is produced by setting TemporalRegularity to True. Note the use of a uniform time specification.

TemporalData[TimeSeries, {{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, 
  {TemporalData`UniformTimeSpecification[{3376512000, 3379190400, 3381609600, 
    3384288000, 3386880000, 3389558400, 3392150400, 3394828800, 3397507200, 
    3400099200}]}, 1, {"Continuous", 1}, {"Discrete", 1}, 1, 
  {ValueDimensions -> 1, DateFunction -> Automatic, 
   ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}, 
   TemporalRegularity -> True}}, True, 10.1]

Obviously this is exposing internal functionality that is subject to change.

$\endgroup$
  • $\begingroup$ The solution was staring at me the whole time. LOL! (+1) I don't think there will be a better answer but we'll let it sit nonetheless. $\endgroup$ – Edmund Jun 14 '16 at 9:21
  • $\begingroup$ @Edmund happens to me all the time :) $\endgroup$ – Andy Ross Jun 14 '16 at 12:20
  • $\begingroup$ @AndyRoss, given an aribtrary DateObject with month and possibly date specified, how to return EndOfMonth $\endgroup$ – alancalvitti Jul 23 '18 at 3:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.