library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
Q <- read.csv("C:/Users/yiq00/OneDrive/Desktop/BC/QQQ.csv")
Q =ts(Q[,2],start=c(2018,10,29),end=c(2020,10,27),frequency=250)
plot.ts(Q)
then Take difference to remove the trend and create a timeplot
DQ = diff(Q)
plot.ts(DQ)
fit_ets = ets(DQ)
## Warning in ets(DQ): I can't handle data with frequency greater than 24.
## Seasonality will be ignored. Try stlf() if you need seasonal forecasts.
print(summary(fit_ets))
## ETS(A,N,N)
##
## Call:
## ets(y = DQ)
##
## Smoothing parameters:
## alpha = 1e-04
##
## Initial states:
## l = 0.2305
##
## sigma: 3.5702
##
## AIC AICc BIC
## 4383.915 4383.964 4396.559
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 0.002649886 3.56303 2.437873 -Inf Inf 0.6132582 -0.1141793
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 0.002649886 3.56303 2.437873 -Inf Inf 0.6132582 -0.1141793
Using this model to estimate
checkresiduals(fit_ets)
##
## Ljung-Box test
##
## data: Residuals from ETS(A,N,N)
## Q* = 83.171, df = 98, p-value = 0.8576
##
## Model df: 2. Total lags used: 100
FQ = forecast(fit_ets, h=1)
autoplot(FQ, include=24)
accuracy(FQ)
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 0.002649886 3.56303 2.437873 -Inf Inf 0.6132582 -0.1141793
print(summary(FQ))
##
## Forecast method: ETS(A,N,N)
##
## Model Information:
## ETS(A,N,N)
##
## Call:
## ets(y = DQ)
##
## Smoothing parameters:
## alpha = 1e-04
##
## Initial states:
## l = 0.2305
##
## sigma: 3.5702
##
## AIC AICc BIC
## 4383.915 4383.964 4396.559
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 0.002649886 3.56303 2.437873 -Inf Inf 0.6132582 -0.1141793
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2020.040 0.2306205 -4.344746 4.805987 -6.766798 7.228039
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2020.040 0.2306205 -4.344746 4.805987 -6.766798 7.228039