Problem with plot forecast

Hello,

I am a new user. I have a problem when I try to plot the forecast of the price of a stock for the next years.
For example Amazon.

The code that I am using is:

AMAZON1 <- getSymbols(Symbols = "AMZN", src = "yahoo", from = Sys.Date() - 1953, 
                        to = Sys.Date(), auto.assign = FALSE)

AMAZON1 <- Cl(AMAZON1)

AMAZON <- na.omit(AMAZON1)

chart_Series(AMAZON, col = "black")
add_SMA(n = 100, on = 1, col = "red")
add_SMA(n = 20, on = 1, col = "black")
add_RSI(n = 14, maType = "SMA")
add_BBands(n = 20, maType = "SMA", sd = 1, on = -1)
add_MACD(fast = 12, slow = 25, signal = 9, maType = "SMA", histogram = TRUE)

AMAZON_LOG <- log(AMAZON)
head(AMAZON_LOG, n = 10)

plot(AMAZON_LOG, main = "log AMAZON chart")

ACF_AMAZON_LOG <- acf(AMAZON_LOG, lag.max = 320)

PACF_AMAZON_LOG <- pacf(AMAZON_LOG, lag.max = 320)

### difference logged data
AMAZON_DIFF <- diff(AMAZON_LOG, lag = 1)

AMAZON_DIFF <- na.locf(AMAZON_DIFF, na.rm = TRUE,
                     fromLast = TRUE)
plot(AMAZON_DIFF)

AMAZONDIFF.acf <- acf(AMAZON_DIFF)

AMAZONDIFF.pacf <- pacf(AMAZON_DIFF)

### splitting into train and test data
library(caTools)
train_data <- AMAZON_DIFF[1:1270]
### 2015/01/06 - 2020/01/13 (1270 obs.)

library(forecast)
set.seed(123)
arima_model <- auto.arima(train_data, stationary = TRUE, ic = c("aicc", "aic", "bic"), 
                          trace = TRUE)

summary(arima_model) ###summary for choosen best arima(p,d,q) model

checkresiduals(arima_model) ###diagnostic cheking

arima <- arima(train_data, order = c(2, 0, 4))
summary(arima)

forecast1 <- forecast(arima, h = 100)
plot(forecast1)

checkresiduals(arima)

arima <- arima(indf_log[1:1270], order = c(2, 1, 4))
summary(arima)

forecast_ori <- forecast(arima, h = 100)
a <- ts(AMAZON_LOG)
forecast_ori %>% autoplot() + autolayer(a)

To sum up, I thing that the problem is the next fragment of the code

forecast_ori <- forecast(arima, h = 100)
a <- ts(AMAZON_LOG)
forecast_ori %>% autoplot() + autolayer(a)

When I use this code, the result is the next:

Rplot01

It plot de historical price but no the forecast.

Can you help me please?

Do you have another code to forecast the same stock using model GARCH?

Thanks

forecast_ori %>% autoplot()

There is a forecast, but perhaps you are plotting the residuals (or something else) and they are around zero?

Also noting that you are using `library(quantmod) for the data.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.