1

I am new in this forum, and new in R. So it will be hard to help me :)

Sorry for the display, I tried to make it as clear as possible but that is not easy !

I want to forecast the prices of natural gas for my internship so I naturally went to R.

Here is my code (I think it is full of mistakes but I am a very beginner so be cool with me please !)

require(urca)
require(tseries)
require(forecast)
require(rugarch)
require(rmgarch)

setwd(file.path("C:","Users","I0309781","Desktop","ARMA"))
gaz <- read.csv2("gaz.csv",header=TRUE,sep=";")
Time=as.Date(gaz$Day,"%d/%m/%Y")
Time=Time[1:length(Time)]


R<-gaz$R[1:(length(gaz$R))]
R<-na.omit(R)
P<-gaz$Prix[1:length(gaz$Prix)]

plot.default(Time, R, xlim=c(min(Time), max(Time)), 
    ylim=c(min(R),max(R)), main="Rendement log - Valeur Cal+1", 
    ylab="Rendement", type="l")

res_rac<-ur.df(R,type="none",lags=1)

arma01=arma(R,order=c(0,1))
arma10=arma(R,order=c(1,0))

AvM<-gaz$AvM[1:58]

Aarma11=arma(AvM,order=c(1,1))
res01=arma01$residuals[2:length(arma01$residuals)]
res10=arma10$residuals[2:length(arma10$residuals)]

res11=Aarma11$residuals[2:length(Aarma11$residuals)]

squared.res11=res11^2

plot(squared.res11,type="l",main="Squared residuals")

par(mfcol=c(3,1))
plot(squared.res11,main='Squared Residuals',type="l")
acf.squared11=acf(squared.res11,main='ACF Squared Residuals',lag.max=25)
pacf.squared11=pacf(squared.res11,main='PACF Squared   Residuals',lag.max=25)

arch01=garch(res11,order=c(0,1),trace=F)
arch02=garch(res11,order=c(0,2),trace=F)
arch03=garch(res11,order=c(0,3),trace=F)

plot(forecast(arch01))

i do not think you have to read all but my main problem is with the forecast(arch01) for example.

Rstudio returns me :

 plot(forecast(arch01))

Error in is.constant(y) : (list) object cannot be coerced to type 'double'

And I really don't understand why ... I tried to use as.numeric(arch01) but it did not work !

Thanks :)

emilliman5
  • 5,816
  • 3
  • 27
  • 37
  • 1
    Welcome to SO! Please have a look at the following post on how to make a reproducible example. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – emilliman5 Jul 20 '17 at 14:16
  • Hi and welcome to Stack Overflow, please take a time to go through the [welcome tour](https://stackoverflow.com/tour) to know your way around here (and also to earn your first badge), read how to create a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and also check [How to Ask Good Questions](https://stackoverflow.com/help/how-to-ask) so you increase your chances to get feedback and useful answers. – DarkCygnus Jul 20 '17 at 15:52
  • I met the same error. It's OK for `ar` and `arima` model. Only `arma` model raise this error. Can't figure out why... – Leo Jul 20 '18 at 08:59

0 Answers0