Stochastic processes III

The ASTA team

Models with exogenous variables

Exogenous variables

Data example

elspot<-read.csv("https://asta.math.aau.dk/eng/static/datasets?file=elspot.csv", header = TRUE)
forecast<-elspot[,2]
price<-elspot[,3]
ts.plot(ts(forecast),ts(-price),col=1:2)
legend("topright",legend=c("forecast","- price"),col=1:2,lty=1)

plot(forecast,price)

Regression models with exogenous variables

Example

Simulation of the example

alpha = 0.9; gamma = 1; n = 100
x = as.ts(5*sin(1:n/5))
eps = arima.sim(model=list(ar=alpha),n=n)
y = gamma*x+eps
ts.plot(x,y,col=1:2)

plot(as.numeric(x),as.numeric(y))

Estimation and model checking

mod=arima(y,order=c(1,0,0),xreg=x); mod
## 
## Call:
## arima(x = y, order = c(1, 0, 0), xreg = x)
## 
## Coefficients:
##          ar1  intercept       x
##       0.8069     0.0679  1.0551
## s.e.  0.0569     0.4795  0.1018
## 
## sigma^2 estimated as 0.923:  log likelihood = -138.41,  aic = 284.82
plot(resid(mod))

acf(resid(mod))

Fitting AR(1) model to data example

forecast<- ts(forecast)
price<-ts(price)
model=arima(price,order=c(1,0,0),xreg=forecast); model
## 
## Call:
## arima(x = price, order = c(1, 0, 0), xreg = forecast)
## 
## Coefficients:
##          ar1  intercept  forecast
##       0.3886  1715.8412   -0.3053
## s.e.  0.0680    73.2894    0.0271
## 
## sigma^2 estimated as 117486:  log likelihood = -1364.2,  aic = 2736.41
plot(resid(model))

acf(resid(model))

Prediction

nnew = 20
xnew = lag(as.ts(5*sin(((n+1):(n+nnew))/5)),-n)
ts.plot(x,y,xnew,col=c(1,2,1),lty=c(1,1,2))

p = predict(mod,n.ahead=nnew,newxreg=xnew)
ts.plot(x,y,xnew,p$pred,p$pred+2*p$se,p$pred-2*p$se,col=c(1,2,1,2,2,2),lty=c(1,1,2,2,3,3))

An example with delay

alpha = 0.5; gamma = 1; n = 100; delay = 5
x = as.ts(5*sin(1:(n+delay)/5))
eps = arima.sim(model=list(ar=alpha),n=n+delay)
y = gamma*lag(x,-delay)+eps
dat_lag = ts.intersect(x,y)
ts.plot(dat_lag[,1],dat_lag[,2],col=1:2)

The cross-correlation function

cc = ccf(dat_lag[,1],dat_lag[,2],lag.max=10)

ccf(forecast,price)

Fitting models with lag

estlag = cc$lag[which(cc$acf==max(abs(cc$acf)))]
estlag
## [1] -5
dat_shifted = ts.intersect(lag(as.ts(dat_lag[,1]),estlag),dat_lag[,2] )
ts.plot(dat_shifted[,1],dat_shifted[,2],col=1:2)

mod=arima(dat_shifted[,2],order=c(1,0,0),xreg=dat_shifted[,1]); mod
## 
## Call:
## arima(x = dat_shifted[, 2], order = c(1, 0, 0), xreg = dat_shifted[, 1])
## 
## Coefficients:
##          ar1  intercept  dat_shifted[, 1]
##       0.5938    -0.2047            1.0526
## s.e.  0.0820     0.2347            0.0615
## 
## sigma^2 estimated as 0.8884:  log likelihood = -129.39,  aic = 266.79

ARMAX models

Continuous time processes

Discrete vs. continuous time

There are two fundamentally different model classes for time series data.

So far we have only looked at the discrete time case. We will finish todays lecture by looking a bit at the continuous time case, just to give you an idea of this topic.

Continuous time stochastic processes

The Wiener process

## Package 'Sim.DiffProc', version 4.8
## browseVignettes('Sim.DiffProc') for more informations.

Stochastic differential equations

Stochastic differential equations