setwd("I:/")
ls()
source("http://www.klein.uk/R/myfunctions.R")
set.seed <- 154
wn = rnorm(500,0,1)
rw = cumsum(wn)
ar1 = arima.sim(list(order=c(1,0,0), ar=.9), n=500)
ma = arima.sim(list(order=c(0,0,1), ma=.8), n=500)
wd = wn +.2
rwd = cumsum(wd)
par(mfrow=c(4,1))
plot.ts(wn, main="white noise")
plot.ts(rw, main="random walk")
plot.ts(ar1, main=(expression(AR(1)~~~phi==+.9)))
plot.ts(ma, main=(expression(MA(1)~~~theta==.8)))
par(mfrow=c(3,1))
plot.ts(wn, main="white noise")
acf(wn); pacf(wn)
library(ccgarch)
ljung.box.test.1(x = wn, lags = seq(from=1, to=15, by=1) )
ar1 = arima.sim(list(order=c(1,0,0), ar=.9), n=500)
par(mfrow=c(3,1))
plot.ts(ar1, main=(expression(AR(1)~~~phi==+.9)))
acf(ar1); pacf(ar1)
ar2 = arima.sim(list(order=c(2,0,0), ar=c(.6,.2)), n=500)
par(mfrow=c(3,1))
plot.ts(ar2, main=(expression(AR(2)~~~phi[1]==.9~~~phi[2]==.8)))
acf(ar2); pacf(ar2)
ma1 = arima.sim(list(order=c(0,0,1), ma=.8), n=500)
par(mfrow=c(3,1))
plot.ts(ma1, main=(expression(MA(1)~~~theta==.8)))
acf(ma1); pacf(ma1)
ma2 = arima.sim(list(order=c(0,0,2), ma=c(.9,.8)), n=500)
par(mfrow=c(3,1))
plot.ts(ma2, main=(expression(MA(1)~~~theta[1]==.9~~~theta[2]==.8)))
acf(ma2); pacf(ma2)
plot.ts(rw, main="random walk")
par(mfrow=c(3,1))
plot.ts(rw, main=(expression(RW)))
acf(rw); pacf(rw)
rw.d1 <- diff(rw, lag=1, differences=1)
plot.ts(rw.d1, main=(expression(RW)))
acf(rw.d1); pacf(rw.d1)
arma11 = arima.sim(list(order=c(1,0,1), ar=.9, ma=-.5), n=500)
par(mfcol=c(3,1))
plot.ts(arma11, main=(expression(ARIMA(1,1,1)~~~phi==.9~~~theta==-.5)))
acf(arma11); pacf(arma11)
source("http://klein.uk/R/myfunctions.R")
library(tseries)
w = rnorm(500,0,1)
rw = cumsum(w)
adf.test.1(x=rw, int=T, trend=T, k=0)
ar1 = arima.sim(list(order=c(1,0,0), ar=.9), n=500)
adf.test.1(x=ar1, int=T, trend=T, k=0)
ar1 = arima.sim(list(order=c(1,0,0), ar=.9), n=500)
ar1mod<-arima(ar1, order = c(1, 0, 0))
library(lmtest)
coeftest(ar1mod)
ljung.box.test.1(x = c(ar1mod$res), lags = seq(from=1, to=15, by=1) )
acf(ar1mod$res); pacf(ar1mod$res)
ar2 = arima.sim(list(order=c(2,0,0), ar=c(.9,-.8)), n=500)
arima(ar2, order = c(2, 0, 0))
ma1 = arima.sim(list(order=c(0,0,1), ma=.8), n=500)
arima(ma1, order = c(0, 0, 1))
ma2 = arima.sim(list(order=c(0,0,2), ma=c(.9,.8)), n=500)
arima(ma2, order = c(0, 0, 2))
arma11 = arima.sim(list(order=c(1,0,1), ar=.9, ma=-.5), n=500)
arima(arma11, order = c(1, 0, 1))