In an example found at Use Time Series Processing for Financial Analysis the time series

prices = sp500["PathComponent", "Adj Close"]   

is followed by

simpleReturns = TimeSeries[Ratios[prices] - 1, prices["Options"]]

to create a time series of x1/x2-1 price returns. That is the normal way to calculate price returns. But, what is the prices["Options"] part supposed to do? TimeSeries[Ratios[prices] - 1] returns exactly the same thing. I don't understand the prices["Options"] construction.


"Options" here is an undocumented property that returns the options that were used to originally to create the time series:


(* { MetaInformation -> {"ComponentNames" -> {"Adj Close"}}
   , ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}
   , TemporalRegularity -> True
   , ValueDimensions -> 1

In the example those options are subsequently passed explicitly to TimeSeries when creating simpleReturns, presumably to ensure that the new series will be created using the same options as prices. But in this case it is redundant because by default calculations involving a single series automatically propagate that series' options to the results.

We can see this propagation by observing that all of the following expressions return the same set of options as listed above:




TimeSeries[Ratios[prices]-1, prices["Options"]]["Options"]

My guess is that the code in the example was adapted from a different example where it was important to preserve the options from one series involved in a multi-series calculation. Or perhaps the example dates back to a time when series options were not automatically propagated by arithmetic operations.

When Would We Use This?

This idiom could be useful in circumstances where arithmetic is being performed upon time series that have been constructed with differing options. In such cases, we might want to explicitly control the resultant options instead of letting them default. An illustrative, if contrived, example follows...

First, we create a series that uses the default linear interpolation between data points (note the triangular sparkline in the output form):

$ts1 = TimeSeries[{1, 2, 1}, {"2000", Automatic, "Month"}]

time series with linear interpolation

Then we create a series with quadratic interpolation (note the curved sparkline):

$ts2 = TimeSeries[{10, 20, 10}, {"2000", Automatic, "Month"},
         ResamplingMethod -> {"Interpolation", InterpolationOrder -> 2}]

time series with quadratic interpolation

If we add these two series together then the linear interpolation from the first series takes precedence:

$ts1 + $ts2

sum with default options, showing linear interpolation

But we can explicitly force the result to use the options from the second series (including its quadratic interpolation):

TimeSeries[$ts1 + $ts2, $ts2["Options"]]

sum with explicit options, showing quadratic interpolation

Are There Other Undocumented TimeSeries/TemporalData Properties?

Yes, there are lots of undocumented properties. In version 12.2 the complete(?) list can be found by:

TimeSeries; (* you MUST evaluate this first or risk hanging the front-end! *)

property list

Many of these are not documented (in version 12.2).


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.