I am very new to this field and I want to learn forecasting of stock price using R. Please let me know which are the step should I follow?
If someone know tutorial links for forecasting in R then it will be good.
Thanks in advance.
Best Answer
To get started you'll want to load the forecast package and convert your dependent variable to a time series.
For monthly prices you could do the following:
library(forecast) ts_price <- ts(price, start = c(year, month), frequency = 12)
For defining more complex frequencies (daily, hourly, multiple) see the following post by Prof. Hyndman. You'll probably want to define something more complex for stock prices depending on your forecast horizon.
Next you can easily fit and forecast an ARIMA Model using the auto.arima
and forecast
functions from the forecast
package.
fit <- auto.arima(ts_price, stepwise = F, approximation = F) fc <- forecast(fit, h = 12, level = c(75, 85, 95)) plot(fc)
To run a working example of the above on your computer just replace ts_price
with AirPassengers
to use one of the included time series
data sets. Eliminating stepwise = F
and approximation = F
will significantly improve run time.