differencing a time series
4 views (last 30 days)
Show older comments
I want to difference a time series till it becomes stationary.how to code it using matlab.i am writing my code below.please help me to continue it acf=autocorr of time series
l(k)=lower limit
u(k)=upper limit
if ((acf(k+1)<l(k)) || (acf(k+1)>u(k))),a time series is non-stationary.now i have to difference a time series till it becomes stationary.how to write using a single expression.
2 Comments
dpb
on 10 Aug 2013
Edited: dpb
on 10 Aug 2013
What's k supposed to represent--the k-th lag of the acf series or the acf after the k-th difference of x?
Maybe my utility function can help some w/ the complexity -- it's just syntactic sugar but by putting the logic expressions at a lower level it can often lead to seeing how to reduce expressions...
while ~all(iswithin(acf,l,u))
... do another difference here
end
where acf is presumed to be the acf at the kth iteration
iswithin is
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
Answers (1)
dpb
on 11 Aug 2013
OK, presuming you have a vector of given length and the limits of the same, then
(acf(k+1)<l(k)) || (acf(k+1)>u(k)))
is
acf(2:end)<l || acf(2:end)>u
if do want the short-circuiting operator here.
0 Comments
See Also
Categories
Find more on Mathematics and Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!