##                               ME       RMSE        MAE
## Forecast Horizon  1  0.006453426 0.07736933 0.06253613
## Forecast Horizon  2  0.024247690 0.13884393 0.11476053
## Forecast Horizon  3  0.043628031 0.18730782 0.15481758
## Forecast Horizon  4  0.061126734 0.21789025 0.18681617
## Forecast Horizon  5  0.076456327 0.23858599 0.20007859
## Forecast Horizon  6  0.088712893 0.24523884 0.20778445
## Forecast Horizon  7  0.092167042 0.24692791 0.20762653
## Forecast Horizon  8  0.093048364 0.24793008 0.20976361
## Forecast Horizon  9  0.096178884 0.25461775 0.21510258
## Forecast Horizon  10 0.097809306 0.25274765 0.21601997
## Forecast Horizon  11 0.099709946 0.26814498 0.22554474
## Forecast Horizon  12 0.102970236 0.28673568 0.24552146
## Forecast Horizon  13 0.105442894 0.29559532 0.24578107
## Forecast Horizon  14 0.104981550 0.30538870 0.25267381
## Forecast Horizon  15 0.100833482 0.30865952 0.25138375
## Forecast Horizon  16 0.091999941 0.30823409 0.25651071
## Forecast Horizon  17 0.080886375 0.32026699 0.27269085
## Forecast Horizon  18 0.074368040 0.32994752 0.28536848
## Forecast Horizon  19 0.071729587 0.32561587 0.28167605
## Forecast Horizon  20 0.069435626 0.31389323 0.26507898
## Forecast Horizon  21 0.063524184 0.31952572 0.26600392
## Forecast Horizon  22 0.054079798 0.32772913 0.26962889
## Forecast Horizon  23 0.042528268 0.32015629 0.26319882
## Forecast Horizon  24 0.033856218 0.31325536 0.26125586
library(nnfor)
library(forecast)

fei_elm<-elm.thief(fei_propane,h=120)
fei_mlp<-mlp.thief(fei_propane,h=120)

plot(fei_elm)

plot(fei_mlp)

fei_propane
##            Jan       Feb       Mar       Apr       May       Jun       Jul
## 2010 1.4940499 1.3984325 1.4224735 1.4085550 1.3716891 1.2684523 1.1324812
## 2011 1.6687620 1.6106846 1.7372945 1.8579655 1.7383877 1.6553830 1.6436797
## 2012 1.8595313 2.1518600 2.1573460 1.7741363 1.4514483 1.2545471 1.4863462
## 2013 1.7857267 1.8072084 1.5943858 1.4892689 1.5257746 1.6431382 1.6699491
## 2014 1.8395485 1.7139635 1.6528654 1.7182159 1.7185221 1.7493374 1.7162363
## 2015 0.8864363 1.1007144 1.0348543 1.0204734 0.9726488 0.9453889 0.8769412
## 2016 0.6330614 0.6116274 0.6538126 0.6590805 0.6613198 0.6293404 0.5860845
## 2017 0.9679463 0.9525912 0.8565885 0.7991716 0.7771684 0.7279042 0.7576090
## 2018 1.0786730 0.9597939 0.9233388 0.9417329 1.0850928 1.0781670 1.1422527
## 2019 0.8326863 0.8892088 0.9672790 1.0372452 0.9120053 0.7873523 0.7854460
## 2020 0.9844621 0.7398752 0.5489880 0.5846586 0.5942365 0.6254144 0.6511059
##            Aug       Sep       Oct       Nov       Dec
## 2010 1.2349877 1.3178411 1.4850105 1.6819098 1.8292581
## 2011 1.5983457 1.5345926 1.4907390 1.5767297 1.6224294
## 2012 1.8605703 2.1021113 2.0923050 2.0340462 1.8642994
## 2013 1.7108445 1.7005301 1.7135317 1.9977150 2.0258660
## 2014 1.5842245 1.5943989 1.4233617 1.2414587 0.9209562
## 2015 0.7537630 0.8039347 0.8489356 0.9393474 0.7821061
## 2016 0.5601989 0.6343570 0.7374554 0.7295847 0.8178411
## 2017 0.8920782 1.0445777 1.1018188 1.1347060 1.1422985
## 2018 1.1484325 1.2614203 1.1961320 0.9531121 0.8951002
## 2019 0.6790307 0.7390321 0.8398403 0.8866420 1.0445572
## 2020 0.6929942 0.6875327 0.8308760
bootseries <- bld.mbb.bootstrap(fei_propane, 10) %>%
  as.data.frame() %>% ts(start=c(2010,1), frequency=12)
bootseries <- bootseries %>% ts(start=c(2010,1), frequency=12)

fei_hybrid_bagged<-baggedModel(fei_propane,bootseries,fn=hybrid.fun)
## Fitting the auto.arima model
## Fitting the nnetar model
## Fitting the auto.arima model
## Fitting the nnetar model
## Fitting the auto.arima model
## Fitting the nnetar model
## Fitting the auto.arima model
## Fitting the nnetar model
## Fitting the auto.arima model
## Fitting the nnetar model
## Fitting the auto.arima model
## Fitting the nnetar model
## Fitting the auto.arima model
## Fitting the nnetar model
## Fitting the auto.arima model
## Fitting the nnetar model
## Fitting the auto.arima model
## Fitting the nnetar model
## Fitting the auto.arima model
## Fitting the nnetar model
fei_hybrid_bagged_forecasts<-fei_hybrid_bagged %>% forecast(h=120)

autoplotly(fei_hybrid_bagged_forecasts)
fit<-hybrid.fun(fei_propane)
## Fitting the auto.arima model
## Fitting the nnetar model
fcast <- forecast(fit, PI=TRUE, h=120)
autoplotly(fcast)
set.seed(1)
elm_thief_FEI<-elm.thief(fei_propane,h=120)
mlp_thief_FEI<-mlp.thief(fei_propane,h=120)
mlp_thief_FEI$mean<-mlp_thief_FEI$mean %>% ts(frequency = 12,start = c(2020,11))

plot(mlp_thief_FEI)

autoplotly(mlp_thief_FEI$mean)
mlp_thief_forecast<-mlp_thief_FEI$mean
fei_propane_fcast<-hybrid.fun(fei_propane)%>% forecast(h=120)
## Fitting the auto.arima model
## Fitting the nnetar model
FEI_Propane_Forecast<-fei_propane_fcast$mean %>% ts(start = c(2020,11),frequency = 12)

forecasts<-autoplot(ts.union(fei_propane,FEI_Propane_Forecast,mlp_thief_forecast,fei_hybrid_bagged_forecasts$mean),facets=FALSE,size=1)+guides(color=guide_legend(title = "Forecast Models"))+labs(y="Price",x="Date")+ggtitle("FEI Propane Future 10 Year Forecast")+scale_color_manual(values = c(1,2,3,4))

autoplotly(forecasts)
FEI_MtBelvieu_Propane_Differential<-ngl$`Propane-FEI`-ngl$`Propane-MontBelvieu` %>% ts(start = c(2010,1),frequency = 12)

differential_fit<-hybrid.fun(FEI_MtBelvieu_Propane_Differential)
## Fitting the auto.arima model
## Fitting the nnetar model
differential_fcast <- forecast(differential_fit, PI=TRUE, h=120)

diff_plot<-autoplot(differential_fcast)+labs(y="Price",x="Date")+ggtitle("FEI-MontBelvieu Propane Differential Forecast")+guides(color=guide_legend(title = "Forecast Model"))+scale_color_manual(values = 1)

autoplotly(diff_plot)
set.seed(1)
cv.hybrid.differential<-cvts(FEI_MtBelvieu_Propane_Differential,
                FUN = hybrid.fun,
                rolling = TRUE,
                maxHorizon = 24,
                saveForecasts = FALSE,
                saveModels = FALSE,
                windowSize = 72,
                verbose = FALSE)


accuracy.hybrid.differential<-accuracy(cv.hybrid.differential)
accuracy.hybrid.differential
##                               ME       RMSE        MAE
## Forecast Horizon  1  -0.01102230 0.05237064 0.04014832
## Forecast Horizon  2  -0.02672479 0.07190826 0.05079138
## Forecast Horizon  3  -0.04411992 0.10051484 0.07245818
## Forecast Horizon  4  -0.05558533 0.12783217 0.08733821
## Forecast Horizon  5  -0.06431739 0.14716109 0.10228665
## Forecast Horizon  6  -0.07067528 0.17012370 0.12460319
## Forecast Horizon  7  -0.08261342 0.20104264 0.14106161
## Forecast Horizon  8  -0.09514373 0.23179191 0.16616831
## Forecast Horizon  9  -0.10281402 0.24586336 0.18134595
## Forecast Horizon  10 -0.11205080 0.26828066 0.19811809
## Forecast Horizon  11 -0.11467857 0.27429311 0.20841510
## Forecast Horizon  12 -0.11599027 0.28035909 0.22126749
## Forecast Horizon  13 -0.11914289 0.29082761 0.23491715
## Forecast Horizon  14 -0.11779049 0.30637684 0.25434507
## Forecast Horizon  15 -0.10780247 0.31734752 0.26562650
## Forecast Horizon  16 -0.09523102 0.30606695 0.26417952
## Forecast Horizon  17 -0.08184307 0.29185121 0.25187370
## Forecast Horizon  18 -0.06732661 0.27778659 0.23889900
## Forecast Horizon  19 -0.05751779 0.26506215 0.22894971
## Forecast Horizon  20 -0.04918251 0.25269565 0.21899930
## Forecast Horizon  21 -0.03727985 0.23620279 0.20751119
## Forecast Horizon  22 -0.02693344 0.21978013 0.19394238
## Forecast Horizon  23 -0.02205031 0.20758688 0.18156953
## Forecast Horizon  24 -0.02047670 0.20477642 0.17429240
Propane_MontBelvieu<-ngl$`Propane-MontBelvieu` %>% ts(start = c(2010,1), frequency = 12)

autoplotly(ts.union(Propane_MontBelvieu,fei_propane))