I computed AR's models to predict the value of BTC. In order to make the data stationary i have transformed it :
My code is the following :
Construct data
df_byday <- read_excel("C:/Users/33610/Downloads/dfday.xlsx")
df_byday$log <- log(df_byday$Price)
df_byday$LOGdiff1 <- c(0, diff(df_byday$log, lag = 1))
tsBTC2 <- ts(df_byday$LOGdiff1, start=c(2017,01,01), frequency=365)
Estimate :
summary(mod_ar1)
mod_ma1 <- Arima(tsBTC2, order = c(0, 0, 1))
summary(mod_ma1)
mod_ar8 <- Arima(tsBTC2, order = c(8, 0, 0))
summary(mod_ar8)
mod_arma11 <- Arima(tsBTC2, order = c(1, 0, 1))
summary(mod_arma11)
Correct for non-significant coefficients :
mod_ar8fix <- Arima(tsBTC2, order = c(8, 0, 0), fixed=c(NA,0,0,0,0,0,0,NA,NA))
summary(mod_ar8fix)
Forecast (for the transformed data) :
forecast_ar8 <- forecast(mod_ar8fix, h = 5)
forecast_ar1 <- forecast(mod_ar1, h = 5)
forecast_ma1 <- forecast(mod_ma1, h = 5)
I want to use this forcast to predict the future value of the BTC and avoid the problem of the log and the difference
Thanks you for your helping!
Build the log and difference into the fitted model, and the forecast()
function will take care of it for you.
e.g.,
library(forecast)
price <- ts(df_byday$Price, start = 2027, frequency = 365)
mod_arima011 <- Arima(price, order = c(0, 1, 1), lambda = 0)
forecast_arima011 <- forecast(mod_arima011, h = 5)
The lambda=0
argument specifies a logarithm. See https://otexts.com/fpp2/arima.html for a textbook introduction.
But since you're modelling daily data, you would be better off not using a ts
object or the forecast
package. Instead, consider tsibble
objects with the fable
package. See https://otexts.com/fpp3/arima.html.