R code template to predict the future with ARIMA auto regression. To try different models, change the line with fit <- arima(...)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# Rusquant is quantmod library with ability # to load Russian market with intraday data # Use vanilla quantmod for other markets library(rusquant) # Load symbol from data provider data.raw <- getSymbols("SBER", src = "Finam", period="5min", from = "2017-08-25", to = "2017-08-25", auto.assign = FALSE) # Convert price to stationary data data <- diff(log(Cl(data.raw))) # Train auto regression arima model fit <- arima(data, order=c(10,0,1)) # Predict the future pred <- predict(fit, n.ahead=100) # Xts index lost during prediction, so convert predicted data to xts pred.index <- as.POSIXct(index(pred$pred), origin = min(index(data))) pred.xts <- xts(pred$pred, order.by = pred.index) # Draw original and predicted values on the same chart plot(c(data, pred.xts), type = "n") lines(data) lines(pred.xts, col = "red") |
The output of the script:
Not very realistic prediction, but a good start point to investigation.