The time series that FinancialData
creates has the option TemporalRegularity -> Automatic
. With this option, this series does not interpolate values.
data =
FinancialData["SBUX", "Close", {{2013, 1, 1}, {2013, 8, 1}, "Week"}, "Value"];
Time series that aren't regularly sampled can interpolate values with the option TemporalRegularity -> True
. To demonstrate, let's use TimeSeries
to make a list of dates between two of the data
samples. Change the data
time series to assume regular time samples with TemporalRegularity -> True
.
{dt1, dt2} = data["Dates"][[9;;10]];
dates = DateRange[dt1, dt2];
ts = TimeSeries[data, TemporalRegularity -> True];
The data
series does not interpolate values.
data[dates]
{$27.43, $27.43, $27.43, $27.43, $27.43, $27.43, $27.43, $29.33}
With TemporalRegularity -> True
, the ts
series linearly interpolates values for dates between samples.
ts[dates]
{$27.43, $27.71, $27.98, $28.25, $28.52, $28.79, $29.06, $29.33}
To get evenly-spaced interpolated values for the entire time series, use the first and last dates of the series for the list of dates. With these new dates, ts[dates]
gives regular, evenly-spaced values. Here's a plot of the interpolated values.
ts = TimeSeries[data, TemporalRegularity -> True];
{dt1, dt2} = ts /@ {"FirstDate", "LastDate"};
dates = DateRange[dt1, dt2];
DateListPlot[Transpose[{dates, ts[dates]}]]