Why do I receive NaN values with the tsmovavg function from Financial Toolbox 5.6?
1 view (last 30 days)
Show older comments
I am currently running into the issue where the first set of values within the length of the moving average window is assigned as NaN. I believe this issue is of similar nature to a different post http://www.mathworks.com/matlabcentral/answers/92471-why-do-i-receive-nan-values-when-i-use-the-tsmovavg-function-in-the-financial-time-series-toolbox-2 but with Financial Toolbox 5.6 rather than Financial Time Series Toolbox 2.1. I am running R2015b with the trial version of the Financial Toolbox 5.6.
0 Comments
Accepted Answer
Nitin Khola
on 4 Nov 2015
Hi Matthew,
This is expected behavior. In the Answers post you mentioned in your question, the reason for such a behavior has been explained. I quote from the same post,
"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."
This is also illustrated by the first example in the documentation. Refer to the following link to access it: http://www.mathworks.com/help/finance/tsmovavg.html#examples
The first 13 elements of the resultant vector have been displayed below. Note that for the first 11 elements, the value is NaN.
>> simple
simple =
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
20.6320
20.6077
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!