This is a remarkably simple question for which I was not able to find an answer in the documentation.
For concreteness, suppose that we have some time series data, such as this (example taken straight from the Mathematica documentation):
ts = TimeSeries[FinancialData["MSFT", "Jan. 1, 2008"]];
...which we can plot with
DateListPlot[ts]
...to get this
Now, I can generate a linear fit to this data (which will be pretty lame, of course) with
fit = FindFit[ts, a + b t, {a, b}, t]
{a -> -526.325, b -> 1.58402*10^-7}
My question is: how do I superimpose the line corresponding to this linear approximation on top of the DateListPlot
shown above?
Is there a simple way to do this?
NB: In case it matters, I'm interested in solutions that can be extrapolated beyond the data's original range. For example, I'd like to superimpose the line fit above over the curve shown below, so that the domain of the fit extends over all of the horizontal PlotRange
(through the end of 2020):
DateListPlot[ts, PlotRange -> {{Automatic, {2020, 12, 31}}, {0, 150}}]