根据http://timelyportfolio.blogspot.com/2012/04/中给出的说明,并通过跟进列出的示例,我了解检测结构中断。在确定结构中断后,有人可以帮助我如何使用 R 进行预测。以下是上面网页中的代码。
library(bfast)
library(quantmod)
getSymbols("^GSPC",from="1950-01-01")
GSPC.monthly <- log(to.monthly(GSPC)[,4])
GSPC.ts <- ts(as.vector(GSPC.monthly["1951-01::"]),start=c(1951,1),frequency=12)
GSPC.stl <- stl(GSPC.ts,s.window="periodic")
plot(GSPC.stl,main="STL Decomposition of S&P 500")
GSPC.bfast <- bfast(GSPC.ts,h=0.2,max.iter=1,season="none")
plot(GSPC.bfast,type="components",ylim=c(3,max(GSPC.monthly)+1),main="S&P 500 with bfast Breakpoints and Components")
plot(GSPC.bfast,type="trend",ylim=c(3,max(GSPC.monthly)+1),main="S&P 500 with bfast Trend Breakpoints")
GSPC.bfast$output[[1]]$St