Free Essay

Ahutuatusi21 @Yahoo.Com

In:

Submitted By ahutuatusi
Words 399
Pages 2
#importing data into R x<-read.csv("C:/Users/chrisson/Desktop/data.csv",header=T) prices=x$COFFEE_ARABICA

#Calculating the log returns log.prices<-log(prices) log.ret<-diff(log.prices)
#Converting the log prices into time series series<- ts(log.prices, start=c(1960,1), freq=12) par(mfrow=c(2,1)); plot(series,main="Arabica coffee price movement") plot(log.ret,type="l",main="Price returns")
# normality test library(tseries) jarque.bera.test(log.ret)
# stationarity test adf.test(log.ret) # Testing for the presence of ARCH effects
Box.test(log.ret,lag=10,type="Ljung")
# testing for ARCH effects up to lag 4
ArchTest(log.ret, lags=4)
#plotting the ACF and PACF plots par(mfrow=c(2,1)) acf(log.ret);pacf(log.ret)

#determination of the models library(rugarch) ret.model<-log.ret[1:635] spec1= ugarchspec(variance.model = list(model = 'eGARCH',garchOrder = c(1,1)), distribution = 'ged') egarch.fit <- ugarchfit(data=c(log.ret), spec = spec1) #fitting EGARCH model egarch.fit coef(egarch.fit) spec <- ugarchspec( variance.model = list(model = "fGARCH", submodel =
"GARCH", garchOrder = c(1,2))) garch.fit <- ugarchfit(data=log.ret, spec = spec) #fitting GARCH model garch.fit coef(garch.fit)
#forecasting with GARCH and EGARCH
e.fit = ugarchfit(data = ret.model, spec = spec1, out.sample = 10)
#10 step ahead forecast for EGARCH
e.forc= ugarchforecast(e.fit, n.ahead=10,n.roll=10)
e.forc
g.fit = ugarchfit(data = ret.model, spec = spec, out.sample = 10)
#10 step ahead forecast for garch
g.forc = ugarchforecast(g.fit, n.ahead=10,n.roll=10)
g.forc
#evaluation of the forecasts d<-log.ret[636:645] v<-var(d) s<-read.csv("C:/Users/chrisson/Desktop/forecasts.csv",header=T) g.f<-s$ GARCH.1.2.
e.f<-s$ X.....EGARCH.1.1. n<-length(g.f) mfe.g<-1/n*sum(g.f^2-v) mfe.e<-1/n*sum(e.f^2-v) mae.g<-1/n*sum(abs(g.f^2-v)) mae.e<-1/n*sum(abs(e.f^2-v)) rmse.g<-(1/n*sum(g.f^2-v)^2)^0.5 rmse.e<-(1/n*sum(e.f^2-v)^2)^0.5 mfe.g mfe.e mae.g mae.e rmse.g
rmse.e

Similar Documents