Why do I receive NaN values when I use the TSMOVAVG function in the Financial Time Series Toolbox 2.1 (R14)?

1 view (last 30 days)
I use the following code to construct a financial time series object and evaluate its moving average:
data = [1:6]';
dates = [today:today+5]';
tsobjkt = fints(dates, data);
tsobjktavg = tsmovavg(tsobjkt, 'e', 3)
The moving average contains NaN values:
tsobjktavg =
desc: (none)
freq: Unknown (0)
'dates: (6)' 'series1: (6)'
'17-Mar-2005' [ NaN]
'18-Mar-2005' [ NaN]
'19-Mar-2005' [2.50000000000000]
'20-Mar-2005' [3.25000000000000]
'21-Mar-2005' [4.12500000000000]
'22-Mar-2005' [5.06250000000000]
Note that NaN values are not generated when the same code is executed in the Financial Time Series Toolbox 2.0 (R13SP1).

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This change has been incorporated into the documentation in Release 14 Service Pack 3 (R14SP3). For previous releases, read below for any additional information:
The TSMOVAVG function computes the moving average using a moving window. If the length of the moving average is "n", then, when computing the first n-1 moving average values, the moving averages depend on data before the first available data sample. Therefore, TSMOVAVG treats these moving averages as undefined and assigns NaN values.
There is a bug in the Financial Time Series Toolbox 2.0 (R13SP1) or earlier versions when using the TSMOVAVG function that it does not return NaN values for the first n-1 moving average values.
There are no workarounds.

More Answers (0)

Products


Release

R14SP2

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!