Forecasting EUR–BNR currency exchange
Part 1: Starting with R – installation : http://msprogrammer.serviciipeweb.ro/2016/10/03/starting-with-r-as-in-sqlserver-r-server-and-vs-package/
Part 2: Starting with R – language and data http://msprogrammer.serviciipeweb.ro/2016/10/10/starting-with-r-language-and-data/
Part 3: Starting with R – basic and statistics http://msprogrammer.serviciipeweb.ro/2016/10/17/starting-with-r-basic-and-statistics/
Part 4: Making diagrams with R ( and transformation of data) : http://msprogrammer.serviciipeweb.ro/2016/10/31/making-diagrams-with-r/
Part 5: Forecasting currency exchange with R http://msprogrammer.serviciipeweb.ro/2016/11/06/forecasting-eurbnr-currency-exchange/
Let’s suppose that we have data from previous post
The form of the data was:
head(EUR,10)
EUR Data RealDate Year
1 4.4629 2016-03-09 00:00:00 2016-03-09 2016
2 4.4624 2016-03-11 00:00:00 2016-03-11 2016
3 4.4705 2016-03-15 00:00:00 2016-03-15 2016
4 4.4775 2016-03-16 00:00:00 2016-03-16 2016
5 4.4765 2016-03-17 00:00:00 2016-03-17 2016
6 4.4694 2016-03-22 00:00:00 2016-03-22 2016
7 4.4641 2016-03-23 00:00:00 2016-03-23 2016
8 4.4655 2016-03-24 00:00:00 2016-03-24 2016
9 4.4639 2016-03-25 00:00:00 2016-03-25 2016
10 4.4619 2016-03-28 00:00:00 2016-03-28 2016
After reading materials
http://www.statoek.wiso.uni-goettingen.de/veranstaltungen/zeitreihen/sommer03/ts_r_intro.pdf
http://a-little-book-of-r-for-time-series.readthedocs.io/en/latest/src/timeseries.html
https://www.otexts.org/fpp/8/7
https://www.r-bloggers.com/time-series-analysis-using-r-forecast-package/
http://www.statmethods.net/advstats/timeseries.html
and understanding that time series is not for beginners, I decide to find R packages that can do the job for me “automatically” . I mean, I give the pervious data –give me the forecast
So this link proved to be useful: http://blog.revolutionanalytics.com/2013/06/learning-time-series-with-r.html
So this is the code to importing forecast package( to forecast) and xts – extended time series – to can specify dates .
install.packages("forecast")
install.packages("xts")
library("forecast")
library("xts")
Then the real code:
myts <- xts(eur$EUR, eur$RealDate)
To see the data
head(myts,3)
and the result:
[,1]
1999-01-04 1.3062
1999-01-05 1.3169
1999-01-06 1.3155
Data from backwards
tail(myts,3)
and the result
[,1]
2016-09-23 4.4470
2016-09-26 4.4504
2016-09-27 4.4495
Now to the forecasting: tried to generate a model with auto.arima
fit<- auto.arima(myts)
auto.arima result was a warning also
Warning message:
In auto.arima(myts) :
Unable to fit final model using maximum likelihood. AIC value approximated
So I tried
fit <- ets(myts)
that worked without warnings.
So let’s try a forecast for 5 days:
forecast(fit,5)
and the result
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
3835 4.449745 4.428025 4.471464 4.416527 4.482962
3836 4.449989 4.419210 4.480769 4.402916 4.497062
3837 4.450234 4.412485 4.487983 4.392502 4.507966
3838 4.450478 4.406836 4.494120 4.383734 4.517223
3839 4.450723 4.401874 4.499572 4.376014 4.525431
( below the arima result
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
3835 4.449287 4.427748 4.470825 4.416347 4.482226
3836 4.448930 4.416600 4.481259 4.399485 4.498374
3837 4.448847 4.409238 4.488455 4.388270 4.509423
3838 4.448763 4.403960 4.493565 4.380244 4.517282
3839 4.448666 4.399278 4.498054 4.373133 4.524198
)
And this is the situation
RealValues (RV) |
ETS |
Dif ETS (ETS-RV)/RV*100 |
arima |
Dif Arima (A-RV)/RV*100 |
4.4493 |
4.449745 |
0.0100% |
4.449287 |
0.0003% |
4.4514 |
4.449989 |
0.0317% |
4.448930 |
0.0555% |
4.4523 |
4.450234 |
0.0464% |
4.448847 |
0.0776% |
4.4484 |
4.450478 |
0.0467% |
4.448763 |
0.0082% |
4.4576 |
4.450723 |
0.1543% |
4.448666 |
0.2004% |
Apparently , ETS is pretty ok ( with the exception of first result)
Leave a Reply