因为刚开始学习rats 有代码 有数据 不知道怎么使用,请各位好心人指导一下 谢谢 我将感激不尽
附代码
@BNDecomp( options ) z start end zbar
*
* RATS procedure to compute the Beveridge-Nelson (BN) decomposition of a time
* series.
*
* Parameters:
* z Input series
* start end Range to decompose. By default, the range of z.
* zbar Output series of fitted trend
*
* Options:
* ar = number of AR lags [1]
* ma = number of MA lags [0]
* logs/[nologs] If LOGS, takes natural log of Z before performing BN decomposition.
* ZBAR is the antilog of the permanent part computed from LN(Z)
* print/[noprint] If PRINT, print output from each recursive estimate of the ARMA model
* Box-Jenkins model
*
* rolling/[norolling] If ROLLING, does rolling estimates of the ARMA model, that is
* the analysis for time period t uses estimates prepared using only data through t.
* ROLLING can take quite a bit of time on a large data set.
*
* Revision Schedule:
* Originally written by Philip Meguire, North Carolina State University
* 10/2000 Removed the RELEASE commands
* 07/2005 Syntax changed to be more standard; option added to allow a single
* BOXJENK estimation. Switch to MAXL estimation; by Tom Doan, Estima
* 11/2006 Changed AR option to default to 1. The comments had indicated this was
* the default, but it actually defaulted to zero previously. By Tom Maycock, Estima
* 05/2007 Correct problem with ROLLING option - could give %BETA not defined error
*
* References: The algorithm is by Paul Newbold, as per his article "Precise and
* Efficient Computation of the Beveridge-Nelson Decomposition of Economic Time
* Series," Journal of Monetary Economics 26 (1990), 453-7.
*
*
procedure BNDecomp z start end zbar
type series z *zbar
type integer start end
*
option switch logs 0
option switch print 0
option integer ar 1
option integer ma 0
option switch rolling 0
*
local series y yhat c ztrans
local real divisor yhatx
local integer i j time tindex startl endl
local vector arpoly
local equation bneqn
*
if ar<0.or.ma<0 {
disp "BNDECOMP: AR and MA options must be positive integers."
return
}
if ar==0.and.ma==0 {
disp "BNDECOMP: Decomposition not defined if input series assumed to be a random walk."
return
}
inquire(series=z) startl<<start endl<<end
set ztrans startl endl = %if(logs,log(z),z)
diff(center,diffs=1) ztrans startl+1 endl y
*
* Initialize series and assign starting values to all estimated parameters.
*
zero c startl endl
zero yhat startl endl+ma
*
* If rolling, compute an initial BOXJENK through the first 24 periods
* Otherwise, compute it through the entire data range
*
if rolling
boxjenk(ar=ar,ma=ma,maxl,print=print,define=bneqn) y startl+1 startl+24
else
boxjenk(ar=ar,ma=ma,maxl,print=print,define=bneqn) y startl+1 endl
*
* Loop through data and compute BN decomposition.
*
do time=startl+1,endl
*
* Redo the estimation if requested and we have enough data
*
if rolling.and.time>startl+24
boxjenk(ar=ar,ma=ma,maxl,init=%beta,print=print,define=bneqn) y startl+1 time
*
* Forecast out MA steps
*
if ma>0
uforecast(equation=bneqn) yhat time+1 time+ma
*
* Extract the autoregressive polynomial
*
compute arpoly=%eqnlagpoly(bneqn,y)
compute divisor=1.0/%sum(arpoly)
*
* MA terms of the cycle
*
do i=1,ma
compute c(time)=c(time)+yhat(time+i)
end do i
*
* AR terms
*
do j=1,ar
compute tindex=time+ma-j+1
compute yhatx=%if(tindex>time,yhat(tindex),y(tindex))*divisor
do i=j,ar
compute c(time)=c(time)-arpoly(i+1)*yhatx
end do i
end do i
compute c(time)=c(time)
end do time
*
* Trend is remainder from the original data
*
set zbar startl end = %if(logs,z/exp(c),z-c)
end bndecomp