# Author Irina Max, Lead Principal Data Scientist
# This code based on the Time series Vector Autoregression model VAR for daily Claims prediction effected by Payment and Elibility.
# This model was already deployed to production and proved on the life high accuracy.
# This script is my individul contribution and research for the XXX company.
# Script also included testing case study to achive the best accuracy
# All comments are my private and please ask me if you have a questions.
getwd()
## [1] "/Users/irinamax/Documents/R/CHC"
#setwd("/home/irina/Payment")
setwd("~/Documents/R/CHC")
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(reshape2)
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(data.table)
##
## Attaching package: 'data.table'
## The following objects are masked from 'package:reshape2':
##
## dcast, melt
## The following objects are masked from 'package:dplyr':
##
## between, first, last
library(tidyr)
##
## Attaching package: 'tidyr'
## The following object is masked from 'package:reshape2':
##
## smiths
library(ggplot2)
library(anytime)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ tibble 3.1.2 ✓ stringr 1.4.0
## ✓ readr 1.4.0 ✓ forcats 0.5.1
## ✓ purrr 0.3.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x data.table::between() masks dplyr::between()
## x dplyr::filter() masks stats::filter()
## x data.table::first() masks dplyr::first()
## x dplyr::lag() masks stats::lag()
## x data.table::last() masks dplyr::last()
## x purrr::transpose() masks data.table::transpose()
library(magrittr)
##
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
##
## set_names
## The following object is masked from 'package:tidyr':
##
## extract
library(gridExtra)
##
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
##
## combine
library(zoo)
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(mltools)
##
## Attaching package: 'mltools'
## The following object is masked from 'package:tidyr':
##
## replace_na
library(fpp2)
## ── Attaching packages ────────────────────────────────────────────── fpp2 2.4 ──
## ✓ fma 2.4 ✓ expsmooth 2.3
## ── Conflicts ───────────────────────────────────────────────── fpp2_conflicts ──
## x magrittr::extract() masks tidyr::extract()
## x magrittr::set_names() masks purrr::set_names()
## x purrr::transpose() masks data.table::transpose()
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:data.table':
##
## hour, isoweek, mday, minute, month, quarter, second, wday, week,
## yday, year
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(caret)
## Loading required package: lattice
##
## Attaching package: 'caret'
## The following object is masked from 'package:purrr':
##
## lift
library(pryr)
##
## Attaching package: 'pryr'
## The following objects are masked from 'package:purrr':
##
## compose, partial
## The following object is masked from 'package:data.table':
##
## address
library(ggfortify)
## Registered S3 methods overwritten by 'ggfortify':
## method from
## autoplot.Arima forecast
## autoplot.acf forecast
## autoplot.ar forecast
## autoplot.bats forecast
## autoplot.decomposed.ts forecast
## autoplot.ets forecast
## autoplot.forecast forecast
## autoplot.stl forecast
## autoplot.ts forecast
## fitted.ar forecast
## fortify.ts forecast
## residuals.ar forecast
## always checking out the memory, may be its already extended... but if not you can make it bigger.
mem_used()
## 180 MB
##changing memory.size to 8 GB
#mem_change(x <- 1:2000000e6)
el <- read.csv("el_data.csv")
el %>% summary
## X report_date sum
## Min. : 1.0 Length:498 Min. : 2419451
## 1st Qu.:125.2 Class :character 1st Qu.: 5007648
## Median :249.5 Mode :character Median : 9156521
## Mean :249.5 Mean : 8133043
## 3rd Qu.:373.8 3rd Qu.:10349786
## Max. :498.0 Max. :14564261
el<- el %>% group_by(report_date) %>% summarise(sum = sum(sum))
el$report_date <- as.Date(el$report_date)
el %>% head
## # A tibble: 6 x 2
## report_date sum
## <date> <int>
## 1 2018-12-16 3251862
## 2 2018-12-17 11008365
## 3 2018-12-18 8740427
## 4 2018-12-19 8727231
## 5 2018-12-20 7440811
## 6 2018-12-21 6810167
el %>% tail
## # A tibble: 6 x 2
## report_date sum
## <date> <int>
## 1 2020-04-21 7927385
## 2 2020-04-22 6318721
## 3 2020-04-23 6695002
## 4 2020-04-24 6175414
## 5 2020-04-25 3019733
## 6 2020-04-26 2516450
el %>% dim #486 2
## [1] 498 2
# I will reshape el to match Payment data till 2020-04-23
el <- el[-c(1:16,496:498),]
names(el) <- c("date", "EVol") # renaming set
#el$date<-as.POSIXct(el$date,format="%m/%d/%y ") # changing date format for merging
el %>% head
## # A tibble: 6 x 2
## date EVol
## <date> <int>
## 1 2019-01-01 8793580
## 2 2019-01-02 11907700
## 3 2019-01-03 10445140
## 4 2019-01-04 9577019
## 5 2019-01-05 5647818
## 6 2019-01-06 3532067
el %>% dim # 479
## [1] 479 2
#feature engineering with claims
cl <- read.csv("cl_data.csv")
cl %>% summary
## X the_given_date sum
## Min. : 1.0 Length:498 Min. : 521261
## 1st Qu.:125.2 Class :character 1st Qu.:1663746
## Median :249.5 Mode :character Median :7356952
## Mean :249.5 Mean :5588034
## 3rd Qu.:373.8 3rd Qu.:7841872
## Max. :498.0 Max. :9438760
cl <- cl%>% group_by(the_given_date) %>% summarise(sum = sum(sum))
cl %>% head
## # A tibble: 6 x 2
## the_given_date sum
## <chr> <int>
## 1 2018-12-16 684635
## 2 2018-12-17 8394740
## 3 2018-12-18 8378415
## 4 2018-12-19 7836314
## 5 2018-12-20 7639615
## 6 2018-12-21 7575768
cl %>% tail
## # A tibble: 6 x 2
## the_given_date sum
## <chr> <int>
## 1 2020-04-21 5255620
## 2 2020-04-22 5076559
## 3 2020-04-23 4906584
## 4 2020-04-24 4981335
## 5 2020-04-25 940347
## 6 2020-04-26 570651
cl %>% dim #486 2
## [1] 498 2
cl <- cl[-c(1:16,496:498),] # 470
names(cl) <- c("date", "CVol")
#cl$date<-as.POSIXct(cl$date,format="%m/%d/%y ")
cl %>% head
## # A tibble: 6 x 2
## date CVol
## <chr> <int>
## 1 2019-01-01 2752206
## 2 2019-01-02 6014189
## 3 2019-01-03 7399520
## 4 2019-01-04 7136874
## 5 2019-01-05 1434915
## 6 2019-01-06 743909
cl$date <- as.Date(cl$date)
cl %>% dim #480
## [1] 479 2
# work with payment
pay <- read.csv('pay.csv', stringsAsFactors = F)
pay %>% str
## 'data.frame': 1431 obs. of 3 variables:
## $ X : int 1 2 3 4 5 6 7 8 9 10 ...
## $ day: chr "2019-11-26" "2020-04-02" "2019-09-18" "2019-07-16" ...
## $ vol: int 169501 170854 29280 1599 735 240014 49130 400 2638 127516 ...
pay %>% summary
## X day vol
## Min. : 1.0 Length:1431 Min. : 0.0
## 1st Qu.: 358.5 Class :character 1st Qu.: 557.5
## Median : 716.0 Mode :character Median : 4078.0
## Mean : 716.0 Mean : 50839.2
## 3rd Qu.:1073.5 3rd Qu.: 93996.0
## Max. :1431.0 Max. :448572.0
pay %>% head
## X day vol
## 1 1 2019-11-26 169501
## 2 2 2020-04-02 170854
## 3 3 2019-09-18 29280
## 4 4 2019-07-16 1599
## 5 5 2020-01-12 735
## 6 6 2019-07-08 240014
#pay <- pay[,c(1,3)]
pay <- pay[,-1]
pay %>% dim
## [1] 1431 2
pay <- pay %>% group_by(day) %>% summarise(PVol = sum(vol))
pay %>% dim # 477
## [1] 477 2
pay %>% head
## # A tibble: 6 x 2
## day PVol
## <chr> <int>
## 1 2019-01-01 175686
## 2 2019-01-02 176132
## 3 2019-01-03 292971
## 4 2019-01-04 170149
## 5 2019-01-05 1887
## 6 2019-01-06 717
pay %>% tail
## # A tibble: 6 x 2
## day PVol
## <chr> <int>
## 1 2020-04-18 664
## 2 2020-04-19 216
## 3 2020-04-20 272907
## 4 2020-04-21 145157
## 5 2020-04-22 180023
## 6 2020-04-23 81081
# find and replace missing dates in payment
d <- as.Date(pay$day)
date_range <- seq(min(d), max(d), by = 1)
date_range[!date_range %in% d]
## [1] "2019-06-30" "2020-03-29"
library(padr)
pay$day <- as.Date(pay$day)
pay <- pad(pay)
## Warning: The `.dots` argument of `group_by()` is deprecated as of dplyr 1.0.0.
## pad applied on the interval: day
pay %>% dim
## [1] 479 2
pay[is.na(pay)] <- 0
names(pay) <- c("date", "PVol")
#day$date<-as.POSIXct(pay$date,format="%m/%d/%y ")
pay %>% dim #479
## [1] 479 2
df <- cbind(pay,el,cl)
df <- df[,c(1,2,4,6)]
df %>% summary
## date PVol EVol CVol
## Min. :2019-01-01 Min. : 0 Min. : 2419451 Min. : 521261
## 1st Qu.:2019-04-30 1st Qu.: 1495 1st Qu.: 5104532 1st Qu.:1681928
## Median :2019-08-28 Median :172936 Median : 9296370 Median :7375217
## Mean :2019-08-28 Mean :151881 Mean : 8224677 Mean :5630942
## 3rd Qu.:2019-12-25 3rd Qu.:202810 3rd Qu.:10408603 3rd Qu.:7851947
## Max. :2020-04-23 Max. :549000 Max. :14564261 Max. :9438760
ts <- ts(df,frequency= 30.5)
ts %>% summary
## date PVol EVol CVol
## Min. :17897 Min. : 0 Min. : 2419451 Min. : 521261
## 1st Qu.:18016 1st Qu.: 1495 1st Qu.: 5104532 1st Qu.:1681928
## Median :18136 Median :172936 Median : 9296370 Median :7375217
## Mean :18136 Mean :151881 Mean : 8224677 Mean :5630942
## 3rd Qu.:18256 3rd Qu.:202810 3rd Qu.:10408603 3rd Qu.:7851947
## Max. :18375 Max. :549000 Max. :14564261 Max. :9438760
plot(ts)

autoplot(ts[,-1], facets = TRUE) +
geom_smooth() +
labs("2018-2019 volume of submitters distribution for all groups",
y = "volume of claims",
x = "month")
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

autoplot(ts[,-1]) +
ggtitle("2019-2020 Payment, Elibility and Claims volume distribution") +
xlab("month") +
ylab("vol")

df %>% str
## 'data.frame': 479 obs. of 4 variables:
## $ date: Date, format: "2019-01-01" "2019-01-02" ...
## $ PVol: int 175686 176132 292971 170149 1887 717 327278 197010 185195 206457 ...
## $ EVol: int 8793580 11907700 10445140 9577019 5647818 3532067 12721612 10177252 9610374 10284790 ...
## $ CVol: int 2752206 6014189 7399520 7136874 1434915 743909 8040762 7738785 7162139 7639109 ...
ts %>% head
## Time Series:
## Start = 1
## End = 1.16393442622951
## Frequency = 30.5
## date PVol EVol CVol
## 1.000000 17897 175686 8793580 2752206
## 1.032787 17898 176132 11907700 6014189
## 1.065574 17899 292971 10445140 7399520
## 1.098361 17900 170149 9577019 7136874
## 1.131148 17901 1887 5647818 1434915
## 1.163934 17902 717 3532067 743909
df %>% dim
## [1] 479 4
par(mfrow=c(2,2))
hist(df$PVol,
col = "red",
xlab = "",
main = "Histogram of Payment Volume ",
freq = T)
hist(df$EVol,
col = "green",
xlab = "",
main = "Histogram of Elegebility Volume ",
freq = T)
hist(df$CVol,
col = "blue",
xlab = "",
main = "Histogram of Claims Volume ",
freq = T)
library(lmtest)
#Granger causality by pare of the columns shows significant correlation bitween colums
grangertest(df[,2]~df[,3], order = 3, data = df)
## Granger causality test
##
## Model 1: df[, 2] ~ Lags(df[, 2], 1:3) + Lags(df[, 3], 1:3)
## Model 2: df[, 2] ~ Lags(df[, 2], 1:3)
## Res.Df Df F Pr(>F)
## 1 469
## 2 472 -3 16.742 2.389e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
grangertest(df[,2]~df[,4], order = 49, data = df)
## Granger causality test
##
## Model 1: df[, 2] ~ Lags(df[, 2], 1:49) + Lags(df[, 4], 1:49)
## Model 2: df[, 2] ~ Lags(df[, 2], 1:49)
## Res.Df Df F Pr(>F)
## 1 331
## 2 380 -49 1.8917 0.0006219 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
grangertest(df[,3]~df[,4], order = 3, data = df)
## Granger causality test
##
## Model 1: df[, 3] ~ Lags(df[, 3], 1:3) + Lags(df[, 4], 1:3)
## Model 2: df[, 3] ~ Lags(df[, 3], 1:3)
## Res.Df Df F Pr(>F)
## 1 469
## 2 472 -3 66.907 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#___________________________ VAR experiment1________________________________________________
library(vars)
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following objects are masked from 'package:fma':
##
## cement, housing, petrol
## The following object is masked from 'package:dplyr':
##
## select
## Loading required package: strucchange
## Loading required package: sandwich
##
## Attaching package: 'strucchange'
## The following object is masked from 'package:stringr':
##
## boundary
## Loading required package: urca
# install.packages("tis"); library('tis')
# install.packages("seasonal"); library('seasonal')
ts %>% head
## Time Series:
## Start = 1
## End = 1.16393442622951
## Frequency = 30.5
## date PVol EVol CVol
## 1.000000 17897 175686 8793580 2752206
## 1.032787 17898 176132 11907700 6014189
## 1.065574 17899 292971 10445140 7399520
## 1.098361 17900 170149 9577019 7136874
## 1.131148 17901 1887 5647818 1434915
## 1.163934 17902 717 3532067 743909
ts_log <- log(df[,-1])
ts.plot(ts_log)

ts.plot((ts[,-1]))
#Decomposing time series
library(TTR)
p_ts <- ts(ts[,2], start = 2019,end = 2020,frequency = 30)
plot.ts(p_ts)
p_sma3 <- SMA(p_ts,3)
plot.ts(p_sma3)
p_sma5 <- SMA(p_ts,5)
plot.ts(p_sma5)

p_sma7 <- SMA(p_ts,7)
plot.ts(p_sma7)
#decomposition for seasonal period returned multiple seasonal components, as well as a trend and remainder component.
pts_decomp <- decompose(ts[,2])
plot(pts_decomp, col = "dark red")


# the same with ggplot
ts[,2] %>% mstl() %>% autoplot() + xlab("Month")

ts[,4] %>% stlf() %>% autoplot() + xlab("Month")

ets_decomp <- decompose(ts[,3])
plot(ets_decomp, col = "dark green")

cts_decomp <- decompose(ts[,4])
plot(cts_decomp, col= " dark blue")

d_ts<- ts(df[,-1], start = 2019, end = 2020, frequency =30)
#ts_wo_random <- d_ts[,1] - pts_decomp$figure
acf(ts[,-1])

# ggplot decomposition with ACF function for all variables
ggAcf(d_ts, lag=45)

# every graph shows Yt plotted against Yt-k for different values of k.
lags_d_ts<- window(d_ts, start=2019)
gglagplot(lags_d_ts) %>% ggtitle("Lags Decomposition for CVol,EVol,PVol")
## $title

##
## $subtitle
## [1] "Lags Decomposition for CVol,EVol,PVol"
##
## attr(,"class")
## [1] "labels"
# the plot indicated 7 and
VARselect(ts[,-1], lag.max=15, type='const')$selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 14 7 7 14
# AIC(n) HQ(n) SC(n) FPE(n)
# 14 7 7 14
yd2.vselect<-vars::VARselect(ts[,-1], lag.max=14, type='const')$selection[1]
#yd2.vselect2<-vars::VARselect(ts[,-1], lag.max=10, type='const')$selection[1]
yd2.vselect
## AIC(n)
## 14
# vselect is 8
var4 <- vars::VAR(ts[,-1], p=yd2.vselect, type="const")
var4$y %>% head
## Time Series:
## Start = 1
## End = 1.16393442622951
## Frequency = 30.5
## PVol EVol CVol
## 1.000000 175686 8793580 2752206
## 1.032787 176132 11907700 6014189
## 1.065574 292971 10445140 7399520
## 1.098361 170149 9577019 7136874
## 1.131148 1887 5647818 1434915
## 1.163934 717 3532067 743909
roots(var4) # stable model has all roots <1
## [1] 0.9980454 0.9980454 0.9979488 0.9979488 0.9942826 0.9942826 0.9667127
## [8] 0.8961604 0.8961604 0.8933433 0.8933433 0.8914938 0.8886256 0.8886256
## [15] 0.8751215 0.8751215 0.8706399 0.8706399 0.8666486 0.8666486 0.8649314
## [22] 0.8649314 0.8642403 0.8642403 0.8513935 0.8513935 0.8475975 0.8475975
## [29] 0.8453417 0.8453417 0.8213217 0.8213217 0.8072327 0.8072327 0.8002886
## [36] 0.8002886 0.7924991 0.7924991 0.7729920 0.7729920 0.7432590 0.7432590
summary(var4)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: PVol, EVol, CVol
## Deterministic variables: const
## Sample size: 465
## Log Likelihood: -19438.245
## Roots of the characteristic polynomial:
## 0.998 0.998 0.9979 0.9979 0.9943 0.9943 0.9667 0.8962 0.8962 0.8933 0.8933 0.8915 0.8886 0.8886 0.8751 0.8751 0.8706 0.8706 0.8666 0.8666 0.8649 0.8649 0.8642 0.8642 0.8514 0.8514 0.8476 0.8476 0.8453 0.8453 0.8213 0.8213 0.8072 0.8072 0.8003 0.8003 0.7925 0.7925 0.773 0.773 0.7433 0.7433
## Call:
## vars::VAR(y = ts[, -1], p = yd2.vselect, type = "const")
##
##
## Estimation results for equation PVol:
## =====================================
## PVol = PVol.l1 + EVol.l1 + CVol.l1 + PVol.l2 + EVol.l2 + CVol.l2 + PVol.l3 + EVol.l3 + CVol.l3 + PVol.l4 + EVol.l4 + CVol.l4 + PVol.l5 + EVol.l5 + CVol.l5 + PVol.l6 + EVol.l6 + CVol.l6 + PVol.l7 + EVol.l7 + CVol.l7 + PVol.l8 + EVol.l8 + CVol.l8 + PVol.l9 + EVol.l9 + CVol.l9 + PVol.l10 + EVol.l10 + CVol.l10 + PVol.l11 + EVol.l11 + CVol.l11 + PVol.l12 + EVol.l12 + CVol.l12 + PVol.l13 + EVol.l13 + CVol.l13 + PVol.l14 + EVol.l14 + CVol.l14 + const
##
## Estimate Std. Error t value Pr(>|t|)
## PVol.l1 3.633e-02 5.096e-02 0.713 0.476276
## EVol.l1 8.905e-04 2.043e-03 0.436 0.663172
## CVol.l1 -3.818e-03 2.913e-03 -1.311 0.190732
## PVol.l2 -1.365e-02 5.362e-02 -0.254 0.799240
## EVol.l2 5.836e-03 2.160e-03 2.702 0.007178 **
## CVol.l2 -9.612e-03 2.952e-03 -3.256 0.001220 **
## PVol.l3 -2.169e-02 5.402e-02 -0.401 0.688255
## EVol.l3 -2.350e-03 2.175e-03 -1.081 0.280504
## CVol.l3 1.248e-03 3.015e-03 0.414 0.679192
## PVol.l4 1.811e-02 5.320e-02 0.340 0.733789
## EVol.l4 2.284e-03 2.183e-03 1.046 0.296077
## CVol.l4 -5.967e-04 3.016e-03 -0.198 0.843276
## PVol.l5 -5.323e-02 5.315e-02 -1.002 0.317107
## EVol.l5 1.598e-03 2.162e-03 0.739 0.460305
## CVol.l5 1.021e-04 3.008e-03 0.034 0.972952
## PVol.l6 -3.274e-02 5.362e-02 -0.611 0.541776
## EVol.l6 2.720e-03 2.151e-03 1.264 0.206799
## CVol.l6 -2.164e-03 2.990e-03 -0.724 0.469687
## PVol.l7 2.036e-01 5.294e-02 3.846 0.000138 ***
## EVol.l7 5.202e-03 2.146e-03 2.424 0.015774 *
## CVol.l7 5.954e-03 2.967e-03 2.007 0.045388 *
## PVol.l8 -1.007e-01 5.254e-02 -1.916 0.056023 .
## EVol.l8 -2.122e-03 2.161e-03 -0.982 0.326530
## CVol.l8 -1.503e-03 2.897e-03 -0.519 0.604148
## PVol.l9 -3.192e-02 5.282e-02 -0.604 0.545898
## EVol.l9 1.346e-03 2.161e-03 0.623 0.533836
## CVol.l9 -8.680e-04 2.897e-03 -0.300 0.764589
## PVol.l10 1.971e-02 5.284e-02 0.373 0.709291
## EVol.l10 -1.943e-03 2.154e-03 -0.902 0.367449
## CVol.l10 5.351e-03 2.908e-03 1.840 0.066461 .
## PVol.l11 7.963e-02 5.316e-02 1.498 0.134891
## EVol.l11 -2.694e-03 2.154e-03 -1.251 0.211693
## CVol.l11 -7.212e-03 2.933e-03 -2.459 0.014322 *
## PVol.l12 1.110e-03 5.314e-02 0.021 0.983350
## EVol.l12 -1.231e-03 2.141e-03 -0.575 0.565765
## CVol.l12 2.671e-03 2.941e-03 0.908 0.364367
## PVol.l13 -1.154e-01 5.250e-02 -2.199 0.028425 *
## EVol.l13 2.725e-03 2.095e-03 1.300 0.194184
## CVol.l13 -1.290e-03 2.944e-03 -0.438 0.661531
## PVol.l14 2.170e-01 5.147e-02 4.216 3.05e-05 ***
## EVol.l14 3.257e-03 2.026e-03 1.608 0.108631
## CVol.l14 2.699e-03 2.755e-03 0.980 0.327753
## const 4.318e+04 3.570e+04 1.209 0.227161
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 37400 on 422 degrees of freedom
## Multiple R-Squared: 0.9061, Adjusted R-squared: 0.8968
## F-statistic: 96.99 on 42 and 422 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation EVol:
## =====================================
## EVol = PVol.l1 + EVol.l1 + CVol.l1 + PVol.l2 + EVol.l2 + CVol.l2 + PVol.l3 + EVol.l3 + CVol.l3 + PVol.l4 + EVol.l4 + CVol.l4 + PVol.l5 + EVol.l5 + CVol.l5 + PVol.l6 + EVol.l6 + CVol.l6 + PVol.l7 + EVol.l7 + CVol.l7 + PVol.l8 + EVol.l8 + CVol.l8 + PVol.l9 + EVol.l9 + CVol.l9 + PVol.l10 + EVol.l10 + CVol.l10 + PVol.l11 + EVol.l11 + CVol.l11 + PVol.l12 + EVol.l12 + CVol.l12 + PVol.l13 + EVol.l13 + CVol.l13 + PVol.l14 + EVol.l14 + CVol.l14 + const
##
## Estimate Std. Error t value Pr(>|t|)
## PVol.l1 -9.269e+00 1.464e+00 -6.330 6.28e-10 ***
## EVol.l1 3.964e-01 5.871e-02 6.752 4.83e-11 ***
## CVol.l1 2.191e-01 8.371e-02 2.618 0.00918 **
## PVol.l2 -3.483e+00 1.541e+00 -2.260 0.02430 *
## EVol.l2 9.432e-02 6.207e-02 1.520 0.12936
## CVol.l2 -2.409e-01 8.482e-02 -2.840 0.00473 **
## PVol.l3 -1.496e+00 1.552e+00 -0.964 0.33556
## EVol.l3 6.740e-02 6.250e-02 1.078 0.28146
## CVol.l3 -8.366e-02 8.664e-02 -0.966 0.33477
## PVol.l4 -1.337e+00 1.529e+00 -0.875 0.38219
## EVol.l4 6.176e-02 6.273e-02 0.985 0.32541
## CVol.l4 -5.680e-02 8.667e-02 -0.655 0.51262
## PVol.l5 -4.285e+00 1.527e+00 -2.806 0.00525 **
## EVol.l5 2.701e-02 6.214e-02 0.435 0.66395
## CVol.l5 6.259e-02 8.644e-02 0.724 0.46940
## PVol.l6 -1.140e+00 1.541e+00 -0.740 0.45967
## EVol.l6 9.014e-02 6.181e-02 1.458 0.14550
## CVol.l6 5.254e-02 8.591e-02 0.612 0.54119
## PVol.l7 1.553e+00 1.521e+00 1.021 0.30803
## EVol.l7 1.117e-01 6.167e-02 1.811 0.07085 .
## CVol.l7 1.414e-01 8.524e-02 1.658 0.09799 .
## PVol.l8 1.651e+00 1.510e+00 1.094 0.27462
## EVol.l8 -1.073e-01 6.208e-02 -1.728 0.08465 .
## CVol.l8 -8.813e-02 8.325e-02 -1.059 0.29036
## PVol.l9 -5.587e-01 1.518e+00 -0.368 0.71295
## EVol.l9 8.713e-02 6.211e-02 1.403 0.16139
## CVol.l9 -8.380e-02 8.323e-02 -1.007 0.31458
## PVol.l10 -3.228e+00 1.518e+00 -2.126 0.03406 *
## EVol.l10 -2.462e-02 6.189e-02 -0.398 0.69098
## CVol.l10 1.225e-01 8.356e-02 1.466 0.14328
## PVol.l11 7.997e-01 1.528e+00 0.524 0.60088
## EVol.l11 1.939e-02 6.188e-02 0.313 0.75413
## CVol.l11 -8.657e-02 8.426e-02 -1.027 0.30481
## PVol.l12 2.109e+00 1.527e+00 1.381 0.16805
## EVol.l12 -5.286e-02 6.153e-02 -0.859 0.39076
## CVol.l12 4.241e-03 8.451e-02 0.050 0.96001
## PVol.l13 -2.169e+00 1.509e+00 -1.438 0.15116
## EVol.l13 -3.189e-04 6.020e-02 -0.005 0.99578
## CVol.l13 7.938e-03 8.459e-02 0.094 0.92528
## PVol.l14 1.785e+00 1.479e+00 1.207 0.22818
## EVol.l14 1.086e-02 5.822e-02 0.187 0.85206
## CVol.l14 2.605e-01 7.916e-02 3.291 0.00108 **
## const 3.367e+06 1.026e+06 3.282 0.00112 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 1075000 on 422 degrees of freedom
## Multiple R-Squared: 0.8781, Adjusted R-squared: 0.8659
## F-statistic: 72.35 on 42 and 422 DF, p-value: < 2.2e-16
##
##
## Estimation results for equation CVol:
## =====================================
## CVol = PVol.l1 + EVol.l1 + CVol.l1 + PVol.l2 + EVol.l2 + CVol.l2 + PVol.l3 + EVol.l3 + CVol.l3 + PVol.l4 + EVol.l4 + CVol.l4 + PVol.l5 + EVol.l5 + CVol.l5 + PVol.l6 + EVol.l6 + CVol.l6 + PVol.l7 + EVol.l7 + CVol.l7 + PVol.l8 + EVol.l8 + CVol.l8 + PVol.l9 + EVol.l9 + CVol.l9 + PVol.l10 + EVol.l10 + CVol.l10 + PVol.l11 + EVol.l11 + CVol.l11 + PVol.l12 + EVol.l12 + CVol.l12 + PVol.l13 + EVol.l13 + CVol.l13 + PVol.l14 + EVol.l14 + CVol.l14 + const
##
## Estimate Std. Error t value Pr(>|t|)
## PVol.l1 -3.726e+00 1.028e+00 -3.626 0.000324 ***
## EVol.l1 2.158e-01 4.120e-02 5.238 2.57e-07 ***
## CVol.l1 1.971e-01 5.875e-02 3.355 0.000864 ***
## PVol.l2 7.782e-01 1.081e+00 0.720 0.472156
## EVol.l2 4.581e-02 4.357e-02 1.051 0.293650
## CVol.l2 -2.291e-01 5.953e-02 -3.848 0.000137 ***
## PVol.l3 -6.078e-01 1.089e+00 -0.558 0.577247
## EVol.l3 -4.211e-03 4.387e-02 -0.096 0.923579
## CVol.l3 1.713e-02 6.081e-02 0.282 0.778271
## PVol.l4 2.228e-02 1.073e+00 0.021 0.983443
## EVol.l4 5.358e-02 4.403e-02 1.217 0.224339
## CVol.l4 -2.561e-02 6.083e-02 -0.421 0.673946
## PVol.l5 -2.621e+00 1.072e+00 -2.446 0.014870 *
## EVol.l5 4.913e-02 4.361e-02 1.126 0.260633
## CVol.l5 -1.790e-02 6.067e-02 -0.295 0.768184
## PVol.l6 -4.563e-01 1.081e+00 -0.422 0.673260
## EVol.l6 3.062e-02 4.338e-02 0.706 0.480727
## CVol.l6 3.596e-02 6.030e-02 0.596 0.551231
## PVol.l7 2.551e+00 1.068e+00 2.389 0.017333 *
## EVol.l7 1.373e-01 4.328e-02 3.172 0.001627 **
## CVol.l7 2.963e-01 5.983e-02 4.952 1.07e-06 ***
## PVol.l8 1.264e+00 1.060e+00 1.193 0.233607
## EVol.l8 -7.720e-02 4.357e-02 -1.772 0.077175 .
## CVol.l8 -8.146e-02 5.843e-02 -1.394 0.163998
## PVol.l9 4.692e-01 1.065e+00 0.440 0.659841
## EVol.l9 2.119e-02 4.359e-02 0.486 0.627187
## CVol.l9 6.322e-02 5.842e-02 1.082 0.279772
## PVol.l10 -2.188e-01 1.066e+00 -0.205 0.837416
## EVol.l10 -4.790e-02 4.344e-02 -1.103 0.270804
## CVol.l10 1.029e-02 5.865e-02 0.175 0.860826
## PVol.l11 1.455e+00 1.072e+00 1.357 0.175370
## EVol.l11 3.766e-02 4.343e-02 0.867 0.386376
## CVol.l11 -7.350e-02 5.914e-02 -1.243 0.214657
## PVol.l12 1.351e+00 1.072e+00 1.261 0.208012
## EVol.l12 -4.987e-03 4.319e-02 -0.115 0.908116
## CVol.l12 -9.373e-02 5.932e-02 -1.580 0.114844
## PVol.l13 -1.679e+00 1.059e+00 -1.586 0.113475
## EVol.l13 4.643e-02 4.226e-02 1.099 0.272474
## CVol.l13 4.523e-02 5.937e-02 0.762 0.446534
## PVol.l14 3.224e+00 1.038e+00 3.106 0.002027 **
## EVol.l14 -4.244e-03 4.086e-02 -0.104 0.917327
## CVol.l14 1.726e-01 5.556e-02 3.107 0.002015 **
## const -5.356e+05 7.199e+05 -0.744 0.457334
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 754200 on 422 degrees of freedom
## Multiple R-Squared: 0.9414, Adjusted R-squared: 0.9356
## F-statistic: 161.4 on 42 and 422 DF, p-value: < 2.2e-16
##
##
##
## Covariance matrix of residuals:
## PVol EVol CVol
## PVol 1.399e+09 1.186e+10 9.333e+09
## EVol 1.186e+10 1.155e+12 4.568e+11
## CVol 9.333e+09 4.568e+11 5.689e+11
##
## Correlation matrix of residuals:
## PVol EVol CVol
## PVol 1.0000 0.2951 0.3309
## EVol 0.2951 1.0000 0.5636
## CVol 0.3309 0.5636 1.0000
accuracy(var4$varresult$PVol)
## ME RMSE MAE MPE MAPE MASE
## Training set 3.137008e-13 35627.11 22907.16 Inf Inf 0.2509142
accuracy(var4$varresult$EVol)
## ME RMSE MAE MPE MAPE MASE
## Training set 4.224358e-11 1023712 736650.7 -1.872186 10.22821 0.2912055
accuracy(var4$varresult$CVol)
## ME RMSE MAE MPE MAPE MASE
## Training set 2.300138e-11 718527.8 441497.5 -3.133515 14.02615 0.1653564
# Serial.test. Could be used for autocorrelation in errors using a portmanteau test. The null hypothesis of no autocorrelation is
#rejected when the pp-value < 0.05. Since autocorrelation is an undesirable feature of the model, we want to look for another model
#that does not have autocorrelation. I want a p value such that the null of no autocorrelation cannot be rejected because the pp-value > 0.05
vars::serial.test(var4, lags.pt=2, type="PT.asymptotic")
## Warning in pchisq(STATISTIC, df = PARAMETER): NaNs produced
## Warning in pchisq(STATISTIC, df = PARAMETER): NaNs produced
##
## Portmanteau Test (asymptotic)
##
## data: Residuals of VAR object var4
## Chi-squared = 1.5148, df = -108, p-value = NA
p.value <- vars::serial.test(var4, lags.pt=5, type="PT.asymptotic")
## Warning in pchisq(STATISTIC, df = PARAMETER): NaNs produced
## Warning in pchisq(STATISTIC, df = PARAMETER): NaNs produced
p.value
##
## Portmanteau Test (asymptotic)
##
## data: Residuals of VAR object var4
## Chi-squared = 5.7942, df = -81, p-value = NA
yd2.vselect<-VARselect(ts, lag.max=45, type='const')$selection[1]
yd2.vselect
## AIC(n)
## 7
var4 <- VAR(ts[,-1], p=yd2.vselect, type="const")
# I will try to predict on 5 month ahead
f_var4 <- predict(var4, n.ahead = 30 )
f_var4$fcst
## $PVol
## fcst lower upper CI
## [1,] 155279.09 75919.48 234638.70 79359.61
## [2,] 15802.85 -64696.94 96302.64 80499.79
## [3,] 26934.33 -55424.80 109293.47 82359.13
## [4,] 257635.36 174978.22 340292.50 82657.14
## [5,] 150204.09 67234.61 233173.57 82969.48
## [6,] 165225.60 82118.98 248332.21 83106.62
## [7,] 122632.02 38487.34 206776.70 84144.68
## [8,] 176347.62 76142.95 276552.30 100204.67
## [9,] 35735.14 -66216.36 137686.65 101951.50
## [10,] 44534.98 -59015.28 148085.25 103550.26
## [11,] 259670.03 155904.66 363435.40 103765.37
## [12,] 167663.12 63708.62 271617.62 103954.50
## [13,] 168599.28 64429.79 272768.77 104169.49
## [14,] 137545.53 32720.96 242370.09 104824.57
## [15,] 181315.95 65770.99 296860.91 115544.96
## [16,] 46799.14 -69959.61 163557.90 116758.76
## [17,] 53990.99 -64171.83 172153.82 118162.83
## [18,] 256278.77 137964.47 374593.08 118314.30
## [19,] 176658.34 58199.47 295117.21 118458.87
## [20,] 166802.33 48168.00 285436.66 118634.33
## [21,] 143586.99 24600.12 262573.87 118986.88
## [22,] 180454.64 53180.24 307729.05 127274.41
## [23,] 53021.65 -75010.20 181053.50 128031.85
## [24,] 59707.90 -69652.06 189067.87 129359.96
## [25,] 250862.86 121396.56 380329.17 129466.31
## [26,] 182540.80 52951.73 312129.88 129589.08
## [27,] 164018.55 34259.59 293777.51 129758.96
## [28,] 147233.99 17256.55 277211.43 129977.44
## [29,] 178641.76 41985.25 315298.27 136656.51
## [30,] 57952.25 -79200.63 195105.13 137152.88
##
## $EVol
## fcst lower upper CI
## [1,] 7740905 5574839 9906971 2166066
## [2,] 4701750 2319348 7084153 2382403
## [3,] 4194628 1715670 6673585 2478958
## [4,] 8745671 6219987 11271355 2525684
## [5,] 8992051 6444198 11539903 2547853
## [6,] 8923441 6337988 11508893 2585453
## [7,] 7773176 5126631 10419721 2646545
## [8,] 8273993 5395793 11152193 2878200
## [9,] 5397306 2482084 8312528 2915222
## [10,] 4876746 1930127 7823364 2946618
## [11,] 9121630 6157061 12086199 2964569
## [12,] 9437818 6467539 12408097 2970279
## [13,] 9125938 6145670 12106206 2980268
## [14,] 8050616 5054763 11046469 2995853
## [15,] 8397848 5228235 11567460 3169613
## [16,] 5650948 2468955 8832940 3181993
## [17,] 5137141 1932937 8341344 3204204
## [18,] 9170279 5953911 12386648 3216368
## [19,] 9606985 6385495 12828475 3221490
## [20,] 9169668 5942425 12396911 3227243
## [21,] 8199385 4965008 11433762 3234377
## [22,] 8451977 5075732 11828222 3376245
## [23,] 5841076 2456703 9225449 3384373
## [24,] 5341223 1935106 8747339 3406116
## [25,] 9180962 5763390 12598534 3417572
## [26,] 9729595 6306726 13152463 3422868
## [27,] 9192793 5764580 12621006 3428213
## [28,] 8309124 4876239 11742009 3432885
## [29,] 8483163 4931986 12034341 3551177
## [30,] 5996788 2438863 9554712 3557925
##
## $CVol
## fcst lower upper CI
## [1,] 5641206 4060648.893 7221763 1580557
## [2,] 1479056 -205680.880 3163793 1684737
## [3,] 1200429 -511629.423 2912488 1712059
## [4,] 5524846 3789977.308 7259716 1734869
## [5,] 5997530 4256267.362 7738793 1741263
## [6,] 6075161 4300530.011 7849791 1774631
## [7,] 5271473 3467261.487 7075684 1804211
## [8,] 6079396 3877910.306 8280881 2201486
## [9,] 2181831 -67613.963 4431276 2249445
## [10,] 1864648 -408692.411 4137988 2273340
## [11,] 5977310 3681526.318 8273094 2295784
## [12,] 6531540 4231473.258 8831608 2300067
## [13,] 6474379 4143326.739 8805431 2331052
## [14,] 5690440 3341970.552 8038910 2348470
## [15,] 6323246 3713394.596 8933096 2609851
## [16,] 2632638 -359.505 5265635 2632997
## [17,] 2250796 -398932.379 4900524 2649728
## [18,] 6172852 3506623.178 8839081 2666229
## [19,] 6817639 4146082.368 9489195 2671556
## [20,] 6619908 3923003.711 9316813 2696904
## [21,] 5923452 3218081.983 8628823 2705370
## [22,] 6411349 3507001.469 9315696 2904347
## [23,] 2915982 -2616.151 5834581 2918599
## [24,] 2487365 -446125.124 5420854 2933490
## [25,] 6244659 3297366.220 9191953 2947293
## [26,] 6975644 4021878.324 9929410 2953766
## [27,] 6667548 3691789.283 9643307 2975759
## [28,] 6056668 3076127.844 9037207 2980540
## [29,] 6429481 3288220.549 9570741 3141260
## [30,] 3117610 -34736.566 6269957 3152347
#yd2.vselect <- VARselect(yd2, lag.max =10, type = 'const')$selection[1]
#yd2.var <- VAR(yd2, p = d.vselect, type ="const")
#autoplot(predict(var4, n.ahead = 2, ci =0.95), ts.colour = 'dodgerblue4',
# predict.colour = 'blue', predict.linetype = 'dashed') + geom_line(y =var4[[6]] )
autoplot(predict(var4, n.ahead = 30), ts.colour = 'dodgerblue4',
predict.colour = 'blue', predict.linetype = 'dashed') + geom_line(y =var4[[6]] )# Impulse response coefficients, I can define set of endogenous variables manually or not defineirf.var4 <- irf(var4, impulse = c( "EVol", "CVol"), response = c("PVol"), boot = T, n.ahead = 30)

irf1.var4 <- irf(var4, boot = T, n.ahead = 2 )
irf1.var4
##
## Impulse response coefficients
## $PVol
## PVol EVol CVol
## [1,] 40490.340 387219.6 330403.63
## [2,] -5003.382 -191132.7 -56401.61
## [3,] -2196.173 -241356.5 -49134.56
##
## $EVol
## PVol EVol CVol
## [1,] 0.000 1035099.3 379320.0
## [2,] -2877.840 452315.3 270737.5
## [3,] 1642.732 231270.1 120700.0
##
## $CVol
## PVol EVol CVol
## [1,] 0.000 0.0 630290.03
## [2,] -3759.248 122606.4 109882.24
## [3,] -8444.249 -102230.7 -84714.25
##
##
## Lower Band, CI= 0.95
## $PVol
## PVol EVol CVol
## [1,] 34506.078 276918.7 215421.6
## [2,] -7809.627 -273439.0 -120999.1
## [3,] -4473.350 -321905.0 -113735.0
##
## $EVol
## PVol EVol CVol
## [1,] 0.000 933494.3 245186.69
## [2,] -6216.190 331947.0 190410.62
## [3,] -2153.826 110138.6 46887.26
##
## $CVol
## PVol EVol CVol
## [1,] 0.000 0.00 520967.164
## [2,] -7349.928 27199.54 7648.226
## [3,] -11062.184 -206026.52 -150409.438
##
##
## Upper Band, CI= 0.95
## $PVol
## PVol EVol CVol
## [1,] 43928.0582 505497.5 452252.22
## [2,] -2077.5487 -87656.8 19391.33
## [3,] 709.7299 -137480.4 17649.63
##
## $EVol
## PVol EVol CVol
## [1,] 0.0000 1102593.7 498316.7
## [2,] 100.0114 561139.4 361686.3
## [3,] 5533.1659 320078.3 184277.3
##
## $CVol
## PVol EVol CVol
## [1,] 0.0000 0.00 692609.22
## [2,] -198.4485 214008.99 162815.53
## [3,] -5292.0990 -18555.72 -24495.69
plot(irf1.var4)



predict(var4, mn.ahead = 30) # shows 10 prediction
## $PVol
## fcst lower upper CI
## [1,] 155279.09 75919.48 234638.70 79359.61
## [2,] 15802.85 -64696.94 96302.64 80499.79
## [3,] 26934.33 -55424.80 109293.47 82359.13
## [4,] 257635.36 174978.22 340292.50 82657.14
## [5,] 150204.09 67234.61 233173.57 82969.48
## [6,] 165225.60 82118.98 248332.21 83106.62
## [7,] 122632.02 38487.34 206776.70 84144.68
## [8,] 176347.62 76142.95 276552.30 100204.67
## [9,] 35735.14 -66216.36 137686.65 101951.50
## [10,] 44534.98 -59015.28 148085.25 103550.26
##
## $EVol
## fcst lower upper CI
## [1,] 7740905 5574839 9906971 2166066
## [2,] 4701750 2319348 7084153 2382403
## [3,] 4194628 1715670 6673585 2478958
## [4,] 8745671 6219987 11271355 2525684
## [5,] 8992051 6444198 11539903 2547853
## [6,] 8923441 6337988 11508893 2585453
## [7,] 7773176 5126631 10419721 2646545
## [8,] 8273993 5395793 11152193 2878200
## [9,] 5397306 2482084 8312528 2915222
## [10,] 4876746 1930127 7823364 2946618
##
## $CVol
## fcst lower upper CI
## [1,] 5641206 4060648.89 7221763 1580557
## [2,] 1479056 -205680.88 3163793 1684737
## [3,] 1200429 -511629.42 2912488 1712059
## [4,] 5524846 3789977.31 7259716 1734869
## [5,] 5997530 4256267.36 7738793 1741263
## [6,] 6075161 4300530.01 7849791 1774631
## [7,] 5271473 3467261.49 7075684 1804211
## [8,] 6079396 3877910.31 8280881 2201486
## [9,] 2181831 -67613.96 4431276 2249445
## [10,] 1864648 -408692.41 4137988 2273340
# prepare and save result
prd <- predict(var4, n.ahead = 30, ci = 0.95, dumvar = NULL)
#plots Residual aganst Fitted for every columns
plot(var4, facet =T, names = "PVol")
## Warning in plot.window(xlim, ylim, log, ...): "facet" is not a graphical
## parameter
## Warning in title(main = main, xlab = xlab, ylab = ylab, ...): "facet" is not a
## graphical parameter
## Warning in axis(2, pretty(c(y, fitted))[-1], ...): "facet" is not a graphical
## parameter
## Warning in mtext(main.fit, side = 3, line = 3, adj = adj.mtext, padj =
## padj.mtext, : "facet" is not a graphical parameter
## Warning in plot.window(xlim, ylim, log, ...): "facet" is not a graphical
## parameter
## Warning in title(main = main, xlab = xlab, ylab = ylab, ...): "facet" is not a
## graphical parameter
## Warning in axis(1, ...): "facet" is not a graphical parameter
## Warning in axis(2, ...): "facet" is not a graphical parameter
## Warning in box(...): "facet" is not a graphical parameter
## Warning in plot.window(...): "facet" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "facet" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "facet" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "facet" is not a
## graphical parameter
## Warning in box(...): "facet" is not a graphical parameter
## Warning in title(...): "facet" is not a graphical parameter
## Warning in plot.window(...): "facet" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "facet" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "facet" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "facet" is not a
## graphical parameter
## Warning in box(...): "facet" is not a graphical parameter
## Warning in title(...): "facet" is not a graphical parameter

plot(var4, facet =T, names = "EVol")
## Warning in plot.window(xlim, ylim, log, ...): "facet" is not a graphical
## parameter
## Warning in title(main = main, xlab = xlab, ylab = ylab, ...): "facet" is not a
## graphical parameter
## Warning in axis(2, pretty(c(y, fitted))[-1], ...): "facet" is not a graphical
## parameter
## Warning in mtext(main.fit, side = 3, line = 3, adj = adj.mtext, padj =
## padj.mtext, : "facet" is not a graphical parameter
## Warning in plot.window(xlim, ylim, log, ...): "facet" is not a graphical
## parameter
## Warning in title(main = main, xlab = xlab, ylab = ylab, ...): "facet" is not a
## graphical parameter
## Warning in axis(1, ...): "facet" is not a graphical parameter
## Warning in axis(2, ...): "facet" is not a graphical parameter
## Warning in box(...): "facet" is not a graphical parameter
## Warning in plot.window(...): "facet" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "facet" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "facet" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "facet" is not a
## graphical parameter
## Warning in box(...): "facet" is not a graphical parameter
## Warning in title(...): "facet" is not a graphical parameter
## Warning in plot.window(...): "facet" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "facet" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "facet" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "facet" is not a
## graphical parameter
## Warning in box(...): "facet" is not a graphical parameter
## Warning in title(...): "facet" is not a graphical parameter

plot(var4, facet =T, names = "CVol")
## Warning in plot.window(xlim, ylim, log, ...): "facet" is not a graphical
## parameter
## Warning in title(main = main, xlab = xlab, ylab = ylab, ...): "facet" is not a
## graphical parameter
## Warning in axis(2, pretty(c(y, fitted))[-1], ...): "facet" is not a graphical
## parameter
## Warning in mtext(main.fit, side = 3, line = 3, adj = adj.mtext, padj =
## padj.mtext, : "facet" is not a graphical parameter
## Warning in plot.window(xlim, ylim, log, ...): "facet" is not a graphical
## parameter
## Warning in title(main = main, xlab = xlab, ylab = ylab, ...): "facet" is not a
## graphical parameter
## Warning in axis(1, ...): "facet" is not a graphical parameter
## Warning in axis(2, ...): "facet" is not a graphical parameter
## Warning in box(...): "facet" is not a graphical parameter
## Warning in plot.window(...): "facet" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "facet" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "facet" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "facet" is not a
## graphical parameter
## Warning in box(...): "facet" is not a graphical parameter
## Warning in title(...): "facet" is not a graphical parameter
## Warning in plot.window(...): "facet" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "facet" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "facet" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "facet" is not a
## graphical parameter
## Warning in box(...): "facet" is not a graphical parameter
## Warning in title(...): "facet" is not a graphical parameter

# fitted value
prd %>% summary
## Length Class Mode
## fcst 3 -none- list
## endog 1437 mts numeric
## model 10 varest list
## exo.fcst 0 -none- NULL
prd$endog
## Time Series:
## Start = 1
## End = 16.672131147541
## Frequency = 30.5
## PVol EVol CVol
## 1.000000 175686 8793580 2752206
## 1.032787 176132 11907700 6014189
## 1.065574 292971 10445140 7399520
## 1.098361 170149 9577019 7136874
## 1.131148 1887 5647818 1434915
## 1.163934 717 3532067 743909
## 1.196721 327278 12721612 8040762
## 1.229508 197010 10177252 7738785
## 1.262295 185195 9610374 7162139
## 1.295082 206457 10284790 7639109
## 1.327869 204224 8775848 7149493
## 1.360656 1761 4720416 1603111
## 1.393443 537 3493661 711440
## 1.426230 319353 10937008 5281774
## 1.459016 199706 10515096 7644625
## 1.491803 170545 9826259 7328824
## 1.524590 200070 8829121 7453101
## 1.557377 216379 8180128 7344972
## 1.590164 1346 4308321 1626990
## 1.622951 717 3035678 632681
## 1.655738 235536 9369877 6737645
## 1.688525 212442 9330145 8184652
## 1.721311 170038 10030408 7468505
## 1.754098 185125 8720549 7284296
## 1.786885 206272 7980629 7130361
## 1.819672 1093 4549551 1594940
## 1.852459 567 3270396 763567
## 1.885246 344902 10800412 7951295
## 1.918033 153427 9758139 7792892
## 1.950820 117572 9687054 7719227
## 1.983607 75647 9187450 7380073
## 2.016393 180727 11047448 7791602
## 2.049180 1427 5380939 1379677
## 2.081967 486 3472095 696399
## 2.114754 321457 12227279 8015351
## 2.147541 190046 12714236 8538382
## 2.180328 149193 10846191 7972386
## 2.213115 214211 9619150 7405662
## 2.245902 201117 8457375 7534281
## 2.278689 1712 4859889 1415748
## 2.311475 71 3281392 793666
## 2.344262 386301 10613980 8191872
## 2.377049 183958 10452563 7636307
## 2.409836 174671 9445679 7517029
## 2.442623 164452 8179087 7247092
## 2.475410 223152 8553566 7435169
## 2.508197 1314 4502031 1357965
## 2.540984 329 3380426 724535
## 2.573770 263235 9923259 7338871
## 2.606557 214817 11086644 7725310
## 2.639344 195063 10128248 7449507
## 2.672131 223719 8710969 7388725
## 2.704918 209233 7828017 8038475
## 2.737705 1552 4916393 1525688
## 2.770492 499 3193430 720703
## 2.803279 394973 10390469 8174263
## 2.836066 202523 9887266 8270007
## 2.868852 145911 9278571 7846960
## 2.901639 58386 9879080 7856880
## 2.934426 234878 11122416 8003820
## 2.967213 1473 4691472 1371728
## 3.000000 517 3724569 767887
## 3.032787 406868 10649989 8540254
## 3.065574 174815 11554511 8213776
## 3.098361 162541 9803367 8263407
## 3.131148 176248 9354503 7860019
## 3.163934 193479 8081636 7531976
## 3.196721 1115 4442983 1463806
## 3.229508 153 3110901 722147
## 3.262295 408680 10500732 7956802
## 3.295082 187218 9969645 8115756
## 3.327869 164596 9569332 7877766
## 3.360656 207178 10288358 7694280
## 3.393443 170373 9910807 7908558
## 3.426230 1425 4528341 1761857
## 3.459016 724 3662692 539742
## 3.491803 422958 10810887 8113264
## 3.524590 219875 11012913 7982914
## 3.557377 168728 9797461 7806724
## 3.590164 203015 8963488 7512600
## 3.622951 164588 8154412 7411701
## 3.655738 1311 4691542 1475036
## 3.688525 8496 3198796 734650
## 3.721311 403494 11908389 8021646
## 3.754098 210553 11396213 8083034
## 3.786885 179333 10072745 7888086
## 3.819672 173811 9526508 7499734
## 3.852459 175403 8385194 7545091
## 3.885246 841 3296858 1590776
## 3.918033 3931 4209367 869487
## 3.950820 368276 13770127 8624436
## 3.983607 223725 12109804 8219841
## 4.016393 166662 9968445 8200426
## 4.049180 217554 9466555 7687187
## 4.081967 174801 10053497 7816776
## 4.114754 1478 4626039 1559902
## 4.147541 965 3383089 770443
## 4.180328 361673 10253373 8394616
## 4.213115 171181 10443129 7936724
## 4.245902 164406 9451306 7857668
## 4.278689 197068 10009101 7249779
## 4.311475 183213 8701618 7308636
## 4.344262 1617 4418610 1442036
## 4.377049 1511 3356864 684746
## 4.409836 379194 10503450 8022580
## 4.442623 202605 10490088 8146072
## 4.475410 185935 9250735 7606958
## 4.508197 206477 8831424 7368932
## 4.540984 155227 7966082 6773979
## 4.573770 1177 5409996 1394649
## 4.606557 446 3694846 686435
## 4.639344 348014 10289223 7579589
## 4.672131 196803 9813165 7723911
## 4.704918 193229 9895801 7587230
## 4.737705 200493 9505188 7446647
## 4.770492 175403 8634106 7198715
## 4.803279 937 4686225 1463944
## 4.836066 506 3329051 756420
## 4.868852 232870 10365739 7686501
## 4.901639 91694 9984469 8066849
## 4.934426 153054 11968372 8266347
## 4.967213 199688 9968507 7519203
## 5.000000 178950 9953592 7482509
## 5.032787 1884 5788669 1469516
## 5.065574 492 3827928 735424
## 5.098361 402237 11034735 8645638
## 5.131148 164915 12297241 7957693
## 5.163934 189363 10109281 7732121
## 5.196721 198209 10481005 7547130
## 5.229508 172936 8576824 7643225
## 5.262295 1098 4717445 1510726
## 5.295082 609 3284183 691619
## 5.327869 371778 10052008 7801411
## 5.360656 189267 10308866 7750081
## 5.393443 169420 9175566 7964291
## 5.426230 207878 9332019 7505175
## 5.459016 198889 9416553 7156089
## 5.491803 1181 4549151 1591307
## 5.524590 369 3644011 626576
## 5.557377 362029 10620637 7607250
## 5.590164 186752 11297952 7940737
## 5.622951 174039 9664565 7694667
## 5.655738 248539 8974841 7142698
## 5.688525 183283 7357635 7184228
## 5.721311 1239 4016900 1651127
## 5.754098 403 2979320 521261
## 5.786885 269814 5239583 3028778
## 5.819672 198951 9322788 6753871
## 5.852459 148011 9843399 7877063
## 5.885246 171619 9616975 7865361
## 5.918033 42440 8439364 7681754
## 5.950820 971 6668580 1655453
## 5.983607 661 4168755 717415
## 6.016393 385206 12523069 8119657
## 6.049180 157978 12813980 8221075
## 6.081967 160138 12317538 7883927
## 6.114754 161468 9482259 7965594
## 6.147541 203571 8397847 7391842
## 6.180328 1085 4474089 1422811
## 6.213115 620 3524404 700128
## 6.245902 452054 10990588 7973500
## 6.278689 195313 10890299 7886253
## 6.311475 175509 9564828 7371997
## 6.344262 187796 9938409 7555319
## 6.377049 198888 10740892 7122015
## 6.409836 1079 4916024 1398399
## 6.442623 589 3280860 707925
## 6.475410 386347 10353105 7842825
## 6.508197 170646 10008911 7852827
## 6.540984 187439 9079421 7435809
## 6.573770 187663 9413680 7231934
## 6.606557 197670 8134842 7369339
## 6.639344 906 3781727 1469906
## 6.672131 646 3443907 667218
## 6.704918 265122 9693037 7899539
## 6.737705 189129 10641645 7662039
## 6.770492 175609 8923507 7477586
## 6.803279 192588 8473921 7278972
## 6.836066 187432 7788819 7081510
## 6.868852 1040 4091222 1504469
## 6.901639 0 3027811 907573
## 6.934426 379462 13159024 8415187
## 6.967213 182730 12697131 8170780
## 7.000000 228476 9505370 7618779
## 7.032787 118360 4229579 3212179
## 7.065574 150350 7647524 5467942
## 7.098361 1046 4309985 1094839
## 7.131148 756 3356321 601964
## 7.163934 361899 11340991 7417965
## 7.196721 176453 10909686 7376968
## 7.229508 170268 9709750 7280036
## 7.262295 193962 10079319 7141022
## 7.295082 169749 9402764 6975065
## 7.327869 1265 4682462 1388133
## 7.360656 662 3211680 728068
## 7.393443 549000 11197953 7681029
## 7.426230 192935 10405894 7564093
## 7.459016 150496 9634006 7461272
## 7.491803 203099 8953788 7401571
## 7.524590 156406 7903280 7051273
## 7.557377 1333 4357904 1429104
## 7.590164 681 3608702 574313
## 7.622951 379611 9946273 7783108
## 7.655738 169530 9816974 7436681
## 7.688525 185133 9667554 7262212
## 7.721311 206988 8509372 5388385
## 7.754098 179465 7884124 5211802
## 7.786885 1040 4389930 4491713
## 7.819672 678 3151070 704096
## 7.852459 388254 10056855 6905701
## 7.885246 114696 9751811 7662286
## 7.918033 26000 8548286 8605568
## 7.950820 202527 12638455 6945381
## 7.983607 170474 10271081 9438760
## 8.016393 1143 4894565 1986243
## 8.049180 673 3702790 683197
## 8.081967 363917 11766450 8122690
## 8.114754 193608 11710440 7747008
## 8.147541 130867 9253498 7681001
## 8.180328 211812 8666860 7241898
## 8.213115 176265 7947747 7064440
## 8.245902 708 5561793 1471857
## 8.278689 53 3772837 655912
## 8.311475 385510 10971693 7638217
## 8.344262 180644 10742075 7507340
## 8.377049 171770 10332475 7336153
## 8.409836 198487 9510670 7094059
## 8.442623 199297 8030787 6202271
## 8.475410 1414 4900682 2162252
## 8.508197 711 3395887 669567
## 8.540984 379103 10576778 7656342
## 8.573770 229775 10009253 6947773
## 8.606557 177622 9446399 7374400
## 8.639344 186662 8322339 8138957
## 8.672131 199014 8401271 7185776
## 8.704918 1000 4391232 1692989
## 8.737705 898 3606118 667888
## 8.770492 372548 10607413 7821982
## 8.803279 192233 10744025 7700438
## 8.836066 173205 9630500 7593132
## 8.868852 177305 7967362 7467994
## 8.901639 179984 7462425 7300627
## 8.934426 1231 3983471 1813742
## 8.967213 1168 4643954 629887
## 9.000000 270124 7614097 2888628
## 9.032787 215624 11769306 7154767
## 9.065574 177026 9873867 7805867
## 9.098361 210106 9718871 7698212
## 9.131148 167517 9452711 7331514
## 9.163934 1021 5040654 1540261
## 9.196721 907 4341039 753843
## 9.229508 418178 11633456 7912132
## 9.262295 198583 11039432 7765705
## 9.295082 171667 10810697 7721031
## 9.327869 171028 9441565 7300033
## 9.360656 185447 8241420 7272821
## 9.393443 1348 3760071 1539791
## 9.426230 350 3612967 561117
## 9.459016 387261 10808060 7885239
## 9.491803 230806 10017300 7915351
## 9.524590 165949 11960694 7433537
## 9.557377 192662 9871239 7551673
## 9.590164 167371 9653180 7269011
## 9.622951 1062 6203235 1660572
## 9.655738 970 3923738 740200
## 9.688525 356839 11073622 8148791
## 9.721311 205436 10339829 7858484
## 9.754098 169206 9626578 7804000
## 9.786885 195902 8263525 7598293
## 9.819672 193001 9167469 7289763
## 9.852459 528 4749994 1678179
## 9.885246 788 3511572 893228
## 9.918033 122365 10565672 8610937
## 9.950820 177508 14564261 8834447
## 9.983607 163268 11635323 7859126
## 10.016393 220175 9959671 7741778
## 10.049180 183845 9788222 7380070
## 10.081967 1140 5259127 2027355
## 10.114754 456 3302513 914883
## 10.147541 326028 11872892 8553851
## 10.180328 222634 10854154 8129767
## 10.213115 208033 9215930 7752133
## 10.245902 187008 11363475 7695395
## 10.278689 199467 8593465 7313321
## 10.311475 854 4273811 1796068
## 10.344262 60 3163870 918456
## 10.377049 264890 10630918 7862781
## 10.409836 220619 11071790 7921591
## 10.442623 182443 10259871 7687639
## 10.475410 188477 10291881 7614494
## 10.508197 169135 9480258 7219684
## 10.540984 1450 4999762 2014403
## 10.573770 316 3172072 735659
## 10.606557 369967 11579834 8175638
## 10.639344 205217 10324577 7945473
## 10.672131 156953 10021162 8168621
## 10.704918 201105 9801363 6563895
## 10.737705 152929 8408206 8534717
## 10.770492 1059 5155857 1923588
## 10.803279 762 3245219 771872
## 10.836066 343441 10677939 8262705
## 10.868852 102250 9846420 7935358
## 10.901639 9865 8529829 7851067
## 10.934426 58976 9898047 7766853
## 10.967213 187219 10411312 7971897
## 11.000000 1386 4935027 1844298
## 11.032787 356 3558049 765502
## 11.065574 379765 12462136 8765998
## 11.098361 151556 13545550 8329155
## 11.131148 131122 11319965 7728859
## 11.163934 311710 10141975 7287083
## 11.196721 210556 9415965 7073795
## 11.229508 2076 5786270 1868338
## 11.262295 52 4597849 648896
## 11.295082 220075 11412589 7800273
## 11.327869 214744 11473202 8212863
## 11.360656 160868 11209344 7949307
## 11.393443 237825 9545820 7610870
## 11.426230 178652 8687544 7509571
## 11.459016 931 4541561 1744605
## 11.491803 333 3528286 799043
## 11.524590 344856 11528916 8294662
## 11.557377 213538 11442497 8170892
## 11.590164 172705 13552456 8164671
## 11.622951 193592 9296370 7738438
## 11.655738 204141 9220393 7537079
## 11.688525 947 4819480 1751006
## 11.721311 623 3499624 843217
## 11.754098 422629 10973685 8741008
## 11.786885 226130 11508766 8545993
## 11.819672 211678 7829265 8091394
## 11.852459 124739 4525122 3263427
## 11.885246 106515 5610161 3154052
## 11.918033 772 3366050 1219760
## 11.950820 1073 5879312 612300
## 11.983607 301830 12440896 7880960
## 12.016393 183848 12277771 7921563
## 12.049180 159784 10869290 8103643
## 12.081967 189927 10226010 7852979
## 12.114754 176968 9796273 7656458
## 12.147541 1407 5190651 1511409
## 12.180328 812 4643408 716627
## 12.213115 385407 11767489 8434101
## 12.245902 207721 10893981 8181734
## 12.278689 185258 10172440 7720971
## 12.311475 198278 10925177 7861454
## 12.344262 167507 9874099 7375217
## 12.377049 1166 4142938 1539448
## 12.409836 1672 4464299 927278
## 12.442623 350156 11705992 8214936
## 12.475410 189507 9954743 8042338
## 12.508197 178378 9661777 7942871
## 12.540984 194411 9393292 7606018
## 12.573770 177787 8525656 7423526
## 12.606557 1092 4329526 1572640
## 12.639344 1348 3499539 808950
## 12.672131 362774 9577628 8381013
## 12.704918 155813 7287152 6151792
## 12.737705 85658 3793929 2256099
## 12.770492 172286 6916464 5446691
## 12.803279 186227 7268217 6130759
## 12.836066 788 3995514 879748
## 12.868852 1342 2419451 648967
## 12.901639 321734 9786750 7422220
## 12.934426 124819 7548165 7532537
## 12.967213 93077 9839238 2951921
## 13.000000 147136 11165061 5978794
## 13.032787 159496 11155699 7152685
## 13.065574 399 5225287 1547121
## 13.098361 1493 4322601 694637
## 13.131148 343305 11849860 7944378
## 13.163934 155316 12134699 7859759
## 13.196721 129418 11507630 7660720
## 13.229508 186890 11806955 7408390
## 13.262295 217995 11063941 7226339
## 13.295082 1129 6159862 1506463
## 13.327869 1425 5031308 748621
## 13.360656 345258 11161540 8127322
## 13.393443 180857 10453877 7964313
## 13.426230 151245 10304999 7517240
## 13.459016 178099 8355480 7383561
## 13.491803 119277 10462421 7234676
## 13.524590 1913 4811880 1798803
## 13.557377 1392 4060010 676142
## 13.590164 285742 10183067 6806107
## 13.622951 181262 10699399 8176280
## 13.655738 190495 10533034 7811501
## 13.688525 175257 9055958 7546270
## 13.721311 181409 8596946 7377294
## 13.754098 1041 4855850 1505213
## 13.786885 939 3439018 816384
## 13.819672 369967 10950022 7206340
## 13.852459 171104 7940971 8758026
## 13.885246 214958 10261622 7772677
## 13.918033 165286 9064557 7830027
## 13.950820 187387 8187747 7631425
## 13.983607 1422 6757327 1685678
## 14.016393 1162 3888938 817715
## 14.049180 327100 11155389 8659050
## 14.081967 167831 13609652 8411685
## 14.114754 155784 12054573 8101745
## 14.147541 178517 9991051 8212134
## 14.180328 149414 10111170 7681066
## 14.213115 1543 5520461 1480023
## 14.245902 1497 5284140 859439
## 14.278689 375333 11791542 8432634
## 14.311475 212433 11731273 8217726
## 14.344262 171595 9750054 7968627
## 14.377049 192201 10478128 7830143
## 14.409836 150534 9573175 7406250
## 14.442623 1229 5647202 1462857
## 14.475410 1332 4019406 933863
## 14.508197 240251 10233702 7334247
## 14.540984 231498 12395081 8045953
## 14.573770 176150 10678606 7690020
## 14.606557 162573 9126755 7739648
## 14.639344 154694 8129932 7761546
## 14.672131 1159 5053208 1402067
## 14.704918 1183 4406737 978419
## 14.737705 403263 11601207 8276989
## 14.770492 140492 10969070 7901483
## 14.803279 167792 9145573 8190505
## 14.836066 246397 9438509 7485826
## 14.868852 170663 10116845 7880377
## 14.901639 1526 4343704 1673267
## 14.934426 957 6033366 1091464
## 14.967213 315713 13115153 8819939
## 15.000000 165300 12195229 8502770
## 15.032787 167175 12424293 8160041
## 15.065574 162982 11364290 8143986
## 15.098361 166032 10497438 7931692
## 15.131148 1498 4404727 1614693
## 15.163934 1226 3594078 867133
## 15.196721 325459 11329928 8337709
## 15.229508 177759 13040255 7907888
## 15.262295 167923 9658537 7839013
## 15.295082 191381 10450397 7538204
## 15.327869 183844 8722382 7084335
## 15.360656 1462 4323701 1486836
## 15.393443 858 3656087 903053
## 15.426230 368046 9646341 7741846
## 15.459016 210613 10020361 7719005
## 15.491803 184745 8285512 7332316
## 15.524590 190966 7600565 6908191
## 15.557377 180871 6998584 6443488
## 15.590164 522 3984421 1460150
## 15.622951 237 2983664 829321
## 15.655738 338257 8061477 6637684
## 15.688525 174903 8918128 6318537
## 15.721311 162679 7239242 6051126
## 15.754098 178494 6449318 5636767
## 15.786885 179432 5800178 5362920
## 15.819672 788 3327178 1218893
## 15.852459 0 3019349 706591
## 15.885246 326050 7354237 5653267
## 15.918033 164818 7524797 5739591
## 15.950820 156064 10525827 5828832
## 15.983607 210843 7344329 5568127
## 16.016393 174910 7408961 5075778
## 16.049180 93 4277563 1089580
## 16.081967 531 2438116 729157
## 16.114754 306351 7303348 6777056
## 16.147541 139378 10243933 5752347
## 16.180328 133600 7793662 5311874
## 16.213115 206696 5926351 5130375
## 16.245902 142782 6351033 4426924
## 16.278689 1 3166063 889452
## 16.311475 221 3647863 610825
## 16.344262 299246 8464470 4853710
## 16.377049 171019 7334884 5025365
## 16.409836 190955 7118664 5062696
## 16.442623 170176 5544694 5004678
## 16.475410 166222 5638350 4763098
## 16.508197 664 3031578 1000927
## 16.540984 216 2690801 633985
## 16.573770 272907 7854009 4990367
## 16.606557 145157 7927385 5255620
## 16.639344 180023 6318721 5076559
## 16.672131 81081 6695002 4906584
prd$fcst
## $PVol
## fcst lower upper CI
## [1,] 155279.09 75919.48 234638.70 79359.61
## [2,] 15802.85 -64696.94 96302.64 80499.79
## [3,] 26934.33 -55424.80 109293.47 82359.13
## [4,] 257635.36 174978.22 340292.50 82657.14
## [5,] 150204.09 67234.61 233173.57 82969.48
## [6,] 165225.60 82118.98 248332.21 83106.62
## [7,] 122632.02 38487.34 206776.70 84144.68
## [8,] 176347.62 76142.95 276552.30 100204.67
## [9,] 35735.14 -66216.36 137686.65 101951.50
## [10,] 44534.98 -59015.28 148085.25 103550.26
## [11,] 259670.03 155904.66 363435.40 103765.37
## [12,] 167663.12 63708.62 271617.62 103954.50
## [13,] 168599.28 64429.79 272768.77 104169.49
## [14,] 137545.53 32720.96 242370.09 104824.57
## [15,] 181315.95 65770.99 296860.91 115544.96
## [16,] 46799.14 -69959.61 163557.90 116758.76
## [17,] 53990.99 -64171.83 172153.82 118162.83
## [18,] 256278.77 137964.47 374593.08 118314.30
## [19,] 176658.34 58199.47 295117.21 118458.87
## [20,] 166802.33 48168.00 285436.66 118634.33
## [21,] 143586.99 24600.12 262573.87 118986.88
## [22,] 180454.64 53180.24 307729.05 127274.41
## [23,] 53021.65 -75010.20 181053.50 128031.85
## [24,] 59707.90 -69652.06 189067.87 129359.96
## [25,] 250862.86 121396.56 380329.17 129466.31
## [26,] 182540.80 52951.73 312129.88 129589.08
## [27,] 164018.55 34259.59 293777.51 129758.96
## [28,] 147233.99 17256.55 277211.43 129977.44
## [29,] 178641.76 41985.25 315298.27 136656.51
## [30,] 57952.25 -79200.63 195105.13 137152.88
##
## $EVol
## fcst lower upper CI
## [1,] 7740905 5574839 9906971 2166066
## [2,] 4701750 2319348 7084153 2382403
## [3,] 4194628 1715670 6673585 2478958
## [4,] 8745671 6219987 11271355 2525684
## [5,] 8992051 6444198 11539903 2547853
## [6,] 8923441 6337988 11508893 2585453
## [7,] 7773176 5126631 10419721 2646545
## [8,] 8273993 5395793 11152193 2878200
## [9,] 5397306 2482084 8312528 2915222
## [10,] 4876746 1930127 7823364 2946618
## [11,] 9121630 6157061 12086199 2964569
## [12,] 9437818 6467539 12408097 2970279
## [13,] 9125938 6145670 12106206 2980268
## [14,] 8050616 5054763 11046469 2995853
## [15,] 8397848 5228235 11567460 3169613
## [16,] 5650948 2468955 8832940 3181993
## [17,] 5137141 1932937 8341344 3204204
## [18,] 9170279 5953911 12386648 3216368
## [19,] 9606985 6385495 12828475 3221490
## [20,] 9169668 5942425 12396911 3227243
## [21,] 8199385 4965008 11433762 3234377
## [22,] 8451977 5075732 11828222 3376245
## [23,] 5841076 2456703 9225449 3384373
## [24,] 5341223 1935106 8747339 3406116
## [25,] 9180962 5763390 12598534 3417572
## [26,] 9729595 6306726 13152463 3422868
## [27,] 9192793 5764580 12621006 3428213
## [28,] 8309124 4876239 11742009 3432885
## [29,] 8483163 4931986 12034341 3551177
## [30,] 5996788 2438863 9554712 3557925
##
## $CVol
## fcst lower upper CI
## [1,] 5641206 4060648.893 7221763 1580557
## [2,] 1479056 -205680.880 3163793 1684737
## [3,] 1200429 -511629.423 2912488 1712059
## [4,] 5524846 3789977.308 7259716 1734869
## [5,] 5997530 4256267.362 7738793 1741263
## [6,] 6075161 4300530.011 7849791 1774631
## [7,] 5271473 3467261.487 7075684 1804211
## [8,] 6079396 3877910.306 8280881 2201486
## [9,] 2181831 -67613.963 4431276 2249445
## [10,] 1864648 -408692.411 4137988 2273340
## [11,] 5977310 3681526.318 8273094 2295784
## [12,] 6531540 4231473.258 8831608 2300067
## [13,] 6474379 4143326.739 8805431 2331052
## [14,] 5690440 3341970.552 8038910 2348470
## [15,] 6323246 3713394.596 8933096 2609851
## [16,] 2632638 -359.505 5265635 2632997
## [17,] 2250796 -398932.379 4900524 2649728
## [18,] 6172852 3506623.178 8839081 2666229
## [19,] 6817639 4146082.368 9489195 2671556
## [20,] 6619908 3923003.711 9316813 2696904
## [21,] 5923452 3218081.983 8628823 2705370
## [22,] 6411349 3507001.469 9315696 2904347
## [23,] 2915982 -2616.151 5834581 2918599
## [24,] 2487365 -446125.124 5420854 2933490
## [25,] 6244659 3297366.220 9191953 2947293
## [26,] 6975644 4021878.324 9929410 2953766
## [27,] 6667548 3691789.283 9643307 2975759
## [28,] 6056668 3076127.844 9037207 2980540
## [29,] 6429481 3288220.549 9570741 3141260
## [30,] 3117610 -34736.566 6269957 3152347
prd_df <- data.frame(prd$fcst)
t(prd_df) # transpose matrix long format
## [,1] [,2] [,3] [,4] [,5] [,6]
## PVol.fcst 155279.09 15802.85 26934.33 257635.36 150204.09 165225.60
## PVol.lower 75919.48 -64696.94 -55424.80 174978.22 67234.61 82118.98
## PVol.upper 234638.70 96302.64 109293.47 340292.50 233173.57 248332.21
## PVol.CI 79359.61 80499.79 82359.13 82657.14 82969.48 83106.62
## EVol.fcst 7740904.79 4701750.28 4194627.54 8745671.29 8992050.70 8923440.66
## EVol.lower 5574839.02 2319347.51 1715669.97 6219987.37 6444198.02 6337988.10
## EVol.upper 9906970.57 7084153.05 6673585.11 11271355.20 11539903.38 11508893.22
## EVol.CI 2166065.77 2382402.77 2478957.57 2525683.91 2547852.68 2585452.56
## CVol.fcst 5641206.15 1479055.90 1200429.17 5524846.48 5997529.99 6075160.60
## CVol.lower 4060648.89 -205680.88 -511629.42 3789977.31 4256267.36 4300530.01
## CVol.upper 7221763.41 3163792.68 2912487.76 7259715.65 7738792.62 7849791.19
## CVol.CI 1580557.26 1684736.78 1712058.59 1734869.17 1741262.63 1774630.59
## [,7] [,8] [,9] [,10] [,11] [,12]
## PVol.fcst 122632.02 176347.62 35735.14 44534.98 259670.0 167663.12
## PVol.lower 38487.34 76142.95 -66216.36 -59015.28 155904.7 63708.62
## PVol.upper 206776.70 276552.30 137686.65 148085.25 363435.4 271617.62
## PVol.CI 84144.68 100204.67 101951.50 103550.26 103765.4 103954.50
## EVol.fcst 7773175.91 8273993.01 5397306.07 4876745.80 9121630.3 9437817.96
## EVol.lower 5126630.63 5395793.38 2482083.88 1930127.36 6157061.3 6467538.97
## EVol.upper 10419721.18 11152192.64 8312528.25 7823364.24 12086199.3 12408096.94
## EVol.CI 2646545.27 2878199.63 2915222.19 2946618.44 2964569.0 2970278.98
## CVol.fcst 5271472.86 6079395.88 2181831.03 1864647.64 5977310.4 6531540.39
## CVol.lower 3467261.49 3877910.31 -67613.96 -408692.41 3681526.3 4231473.26
## CVol.upper 7075684.22 8280881.46 4431276.03 4137987.69 8273094.5 8831607.53
## CVol.CI 1804211.37 2201485.57 2249445.00 2273340.05 2295784.1 2300067.13
## [,13] [,14] [,15] [,16] [,17]
## PVol.fcst 168599.28 137545.53 181315.95 46799.144 53990.99
## PVol.lower 64429.79 32720.96 65770.99 -69959.613 -64171.83
## PVol.upper 272768.77 242370.09 296860.91 163557.902 172153.82
## PVol.CI 104169.49 104824.57 115544.96 116758.757 118162.83
## EVol.fcst 9125937.96 8050615.82 8397847.55 5650947.512 5137140.55
## EVol.lower 6145670.42 5054762.89 5228234.76 2468954.949 1932936.70
## EVol.upper 12106205.50 11046468.75 11567460.35 8832940.075 8341344.39
## EVol.CI 2980267.54 2995852.93 3169612.79 3181992.563 3204203.85
## CVol.fcst 6474378.93 5690440.41 6323245.54 2632637.551 2250795.97
## CVol.lower 4143326.74 3341970.55 3713394.60 -359.505 -398932.38
## CVol.upper 8805431.13 8038910.26 8933096.47 5265634.607 4900524.32
## CVol.CI 2331052.19 2348469.85 2609850.94 2632997.056 2649728.35
## [,18] [,19] [,20] [,21] [,22]
## PVol.fcst 256278.8 176658.34 166802.3 143586.99 180454.64
## PVol.lower 137964.5 58199.47 48168.0 24600.12 53180.24
## PVol.upper 374593.1 295117.21 285436.7 262573.87 307729.05
## PVol.CI 118314.3 118458.87 118634.3 118986.88 127274.41
## EVol.fcst 9170279.3 9606985.00 9169667.8 8199384.73 8451976.77
## EVol.lower 5953911.1 6385495.06 5942424.8 4965007.89 5075731.66
## EVol.upper 12386647.5 12828474.94 12396910.9 11433761.58 11828221.89
## EVol.CI 3216368.2 3221489.94 3227243.1 3234376.85 3376245.11
## CVol.fcst 6172851.9 6817638.74 6619908.2 5923452.31 6411348.56
## CVol.lower 3506623.2 4146082.37 3923003.7 3218081.98 3507001.47
## CVol.upper 8839080.6 9489195.12 9316812.6 8628822.64 9315695.65
## CVol.CI 2666228.7 2671556.38 2696904.5 2705370.33 2904347.09
## [,23] [,24] [,25] [,26] [,27]
## PVol.fcst 53021.649 59707.90 250862.9 182540.80 164018.55
## PVol.lower -75010.199 -69652.06 121396.6 52951.73 34259.59
## PVol.upper 181053.498 189067.87 380329.2 312129.88 293777.51
## PVol.CI 128031.849 129359.96 129466.3 129589.08 129758.96
## EVol.fcst 5841076.334 5341222.79 9180962.1 9729594.54 9192792.99
## EVol.lower 2456703.413 1935106.46 5763390.4 6306726.45 5764579.51
## EVol.upper 9225449.255 8747339.12 12598533.7 13152462.63 12621006.47
## EVol.CI 3384372.921 3406116.33 3417571.6 3422868.09 3428213.48
## CVol.fcst 2915982.467 2487364.57 6244659.4 6975644.26 6667548.30
## CVol.lower -2616.151 -446125.12 3297366.2 4021878.32 3691789.28
## CVol.upper 5834581.085 5420854.27 9191952.7 9929410.19 9643307.32
## CVol.CI 2918598.618 2933489.70 2947293.2 2953765.93 2975759.02
## [,28] [,29] [,30]
## PVol.fcst 147233.99 178641.76 57952.25
## PVol.lower 17256.55 41985.25 -79200.63
## PVol.upper 277211.43 315298.27 195105.13
## PVol.CI 129977.44 136656.51 137152.88
## EVol.fcst 8309123.99 8483163.08 5996787.59
## EVol.lower 4876239.47 4931985.60 2438863.08
## EVol.upper 11742008.52 12034340.57 9554712.11
## EVol.CI 3432884.53 3551177.49 3557924.52
## CVol.fcst 6056667.60 6429480.98 3117610.14
## CVol.lower 3076127.84 3288220.55 -34736.57
## CVol.upper 9037207.35 9570741.42 6269956.85
## CVol.CI 2980539.75 3141260.44 3152346.71
print(prd)
## $PVol
## fcst lower upper CI
## [1,] 155279.09 75919.48 234638.70 79359.61
## [2,] 15802.85 -64696.94 96302.64 80499.79
## [3,] 26934.33 -55424.80 109293.47 82359.13
## [4,] 257635.36 174978.22 340292.50 82657.14
## [5,] 150204.09 67234.61 233173.57 82969.48
## [6,] 165225.60 82118.98 248332.21 83106.62
## [7,] 122632.02 38487.34 206776.70 84144.68
## [8,] 176347.62 76142.95 276552.30 100204.67
## [9,] 35735.14 -66216.36 137686.65 101951.50
## [10,] 44534.98 -59015.28 148085.25 103550.26
## [11,] 259670.03 155904.66 363435.40 103765.37
## [12,] 167663.12 63708.62 271617.62 103954.50
## [13,] 168599.28 64429.79 272768.77 104169.49
## [14,] 137545.53 32720.96 242370.09 104824.57
## [15,] 181315.95 65770.99 296860.91 115544.96
## [16,] 46799.14 -69959.61 163557.90 116758.76
## [17,] 53990.99 -64171.83 172153.82 118162.83
## [18,] 256278.77 137964.47 374593.08 118314.30
## [19,] 176658.34 58199.47 295117.21 118458.87
## [20,] 166802.33 48168.00 285436.66 118634.33
## [21,] 143586.99 24600.12 262573.87 118986.88
## [22,] 180454.64 53180.24 307729.05 127274.41
## [23,] 53021.65 -75010.20 181053.50 128031.85
## [24,] 59707.90 -69652.06 189067.87 129359.96
## [25,] 250862.86 121396.56 380329.17 129466.31
## [26,] 182540.80 52951.73 312129.88 129589.08
## [27,] 164018.55 34259.59 293777.51 129758.96
## [28,] 147233.99 17256.55 277211.43 129977.44
## [29,] 178641.76 41985.25 315298.27 136656.51
## [30,] 57952.25 -79200.63 195105.13 137152.88
##
## $EVol
## fcst lower upper CI
## [1,] 7740905 5574839 9906971 2166066
## [2,] 4701750 2319348 7084153 2382403
## [3,] 4194628 1715670 6673585 2478958
## [4,] 8745671 6219987 11271355 2525684
## [5,] 8992051 6444198 11539903 2547853
## [6,] 8923441 6337988 11508893 2585453
## [7,] 7773176 5126631 10419721 2646545
## [8,] 8273993 5395793 11152193 2878200
## [9,] 5397306 2482084 8312528 2915222
## [10,] 4876746 1930127 7823364 2946618
## [11,] 9121630 6157061 12086199 2964569
## [12,] 9437818 6467539 12408097 2970279
## [13,] 9125938 6145670 12106206 2980268
## [14,] 8050616 5054763 11046469 2995853
## [15,] 8397848 5228235 11567460 3169613
## [16,] 5650948 2468955 8832940 3181993
## [17,] 5137141 1932937 8341344 3204204
## [18,] 9170279 5953911 12386648 3216368
## [19,] 9606985 6385495 12828475 3221490
## [20,] 9169668 5942425 12396911 3227243
## [21,] 8199385 4965008 11433762 3234377
## [22,] 8451977 5075732 11828222 3376245
## [23,] 5841076 2456703 9225449 3384373
## [24,] 5341223 1935106 8747339 3406116
## [25,] 9180962 5763390 12598534 3417572
## [26,] 9729595 6306726 13152463 3422868
## [27,] 9192793 5764580 12621006 3428213
## [28,] 8309124 4876239 11742009 3432885
## [29,] 8483163 4931986 12034341 3551177
## [30,] 5996788 2438863 9554712 3557925
##
## $CVol
## fcst lower upper CI
## [1,] 5641206 4060648.893 7221763 1580557
## [2,] 1479056 -205680.880 3163793 1684737
## [3,] 1200429 -511629.423 2912488 1712059
## [4,] 5524846 3789977.308 7259716 1734869
## [5,] 5997530 4256267.362 7738793 1741263
## [6,] 6075161 4300530.011 7849791 1774631
## [7,] 5271473 3467261.487 7075684 1804211
## [8,] 6079396 3877910.306 8280881 2201486
## [9,] 2181831 -67613.963 4431276 2249445
## [10,] 1864648 -408692.411 4137988 2273340
## [11,] 5977310 3681526.318 8273094 2295784
## [12,] 6531540 4231473.258 8831608 2300067
## [13,] 6474379 4143326.739 8805431 2331052
## [14,] 5690440 3341970.552 8038910 2348470
## [15,] 6323246 3713394.596 8933096 2609851
## [16,] 2632638 -359.505 5265635 2632997
## [17,] 2250796 -398932.379 4900524 2649728
## [18,] 6172852 3506623.178 8839081 2666229
## [19,] 6817639 4146082.368 9489195 2671556
## [20,] 6619908 3923003.711 9316813 2696904
## [21,] 5923452 3218081.983 8628823 2705370
## [22,] 6411349 3507001.469 9315696 2904347
## [23,] 2915982 -2616.151 5834581 2918599
## [24,] 2487365 -446125.124 5420854 2933490
## [25,] 6244659 3297366.220 9191953 2947293
## [26,] 6975644 4021878.324 9929410 2953766
## [27,] 6667548 3691789.283 9643307 2975759
## [28,] 6056668 3076127.844 9037207 2980540
## [29,] 6429481 3288220.549 9570741 3141260
## [30,] 3117610 -34736.566 6269957 3152347
write.csv(prd_df,"Payment prediction after 04_23.csv" )
check <-read.csv("Payment prediction after 04_23.csv")
check
## X PVol.fcst PVol.lower PVol.upper PVol.CI EVol.fcst EVol.lower EVol.upper
## 1 1 155279.09 75919.48 234638.70 79359.61 7740905 5574839 9906971
## 2 2 15802.85 -64696.94 96302.64 80499.79 4701750 2319348 7084153
## 3 3 26934.33 -55424.80 109293.47 82359.13 4194628 1715670 6673585
## 4 4 257635.36 174978.22 340292.50 82657.14 8745671 6219987 11271355
## 5 5 150204.09 67234.61 233173.57 82969.48 8992051 6444198 11539903
## 6 6 165225.60 82118.98 248332.21 83106.62 8923441 6337988 11508893
## 7 7 122632.02 38487.34 206776.70 84144.68 7773176 5126631 10419721
## 8 8 176347.62 76142.95 276552.30 100204.67 8273993 5395793 11152193
## 9 9 35735.14 -66216.36 137686.65 101951.50 5397306 2482084 8312528
## 10 10 44534.98 -59015.28 148085.25 103550.26 4876746 1930127 7823364
## 11 11 259670.03 155904.66 363435.40 103765.37 9121630 6157061 12086199
## 12 12 167663.12 63708.62 271617.62 103954.50 9437818 6467539 12408097
## 13 13 168599.28 64429.79 272768.77 104169.49 9125938 6145670 12106206
## 14 14 137545.53 32720.96 242370.09 104824.57 8050616 5054763 11046469
## 15 15 181315.95 65770.99 296860.91 115544.96 8397848 5228235 11567460
## 16 16 46799.14 -69959.61 163557.90 116758.76 5650948 2468955 8832940
## 17 17 53990.99 -64171.83 172153.82 118162.83 5137141 1932937 8341344
## 18 18 256278.77 137964.47 374593.08 118314.30 9170279 5953911 12386648
## 19 19 176658.34 58199.47 295117.21 118458.87 9606985 6385495 12828475
## 20 20 166802.33 48168.00 285436.66 118634.33 9169668 5942425 12396911
## 21 21 143586.99 24600.12 262573.87 118986.88 8199385 4965008 11433762
## 22 22 180454.64 53180.24 307729.05 127274.41 8451977 5075732 11828222
## 23 23 53021.65 -75010.20 181053.50 128031.85 5841076 2456703 9225449
## 24 24 59707.90 -69652.06 189067.87 129359.96 5341223 1935106 8747339
## 25 25 250862.86 121396.56 380329.17 129466.31 9180962 5763390 12598534
## 26 26 182540.80 52951.73 312129.88 129589.08 9729595 6306726 13152463
## 27 27 164018.55 34259.59 293777.51 129758.96 9192793 5764580 12621006
## 28 28 147233.99 17256.55 277211.43 129977.44 8309124 4876239 11742009
## 29 29 178641.76 41985.25 315298.27 136656.51 8483163 4931986 12034341
## 30 30 57952.25 -79200.63 195105.13 137152.88 5996788 2438863 9554712
## EVol.CI CVol.fcst CVol.lower CVol.upper CVol.CI
## 1 2166066 5641206 4060648.893 7221763 1580557
## 2 2382403 1479056 -205680.880 3163793 1684737
## 3 2478958 1200429 -511629.423 2912488 1712059
## 4 2525684 5524846 3789977.308 7259716 1734869
## 5 2547853 5997530 4256267.362 7738793 1741263
## 6 2585453 6075161 4300530.011 7849791 1774631
## 7 2646545 5271473 3467261.487 7075684 1804211
## 8 2878200 6079396 3877910.306 8280881 2201486
## 9 2915222 2181831 -67613.963 4431276 2249445
## 10 2946618 1864648 -408692.411 4137988 2273340
## 11 2964569 5977310 3681526.318 8273094 2295784
## 12 2970279 6531540 4231473.258 8831608 2300067
## 13 2980268 6474379 4143326.739 8805431 2331052
## 14 2995853 5690440 3341970.552 8038910 2348470
## 15 3169613 6323246 3713394.596 8933096 2609851
## 16 3181993 2632638 -359.505 5265635 2632997
## 17 3204204 2250796 -398932.379 4900524 2649728
## 18 3216368 6172852 3506623.178 8839081 2666229
## 19 3221490 6817639 4146082.368 9489195 2671556
## 20 3227243 6619908 3923003.711 9316813 2696904
## 21 3234377 5923452 3218081.983 8628823 2705370
## 22 3376245 6411349 3507001.469 9315696 2904347
## 23 3384373 2915982 -2616.151 5834581 2918599
## 24 3406116 2487365 -446125.124 5420854 2933490
## 25 3417572 6244659 3297366.220 9191953 2947293
## 26 3422868 6975644 4021878.324 9929410 2953766
## 27 3428213 6667548 3691789.283 9643307 2975759
## 28 3432885 6056668 3076127.844 9037207 2980540
## 29 3551177 6429481 3288220.549 9570741 3141260
## 30 3557925 3117610 -34736.566 6269957 3152347
# for 5 month
prd <- predict(var4, n.ahead = 30, ci = 0.95, dumvar = NULL)
#par(mfrow = c(2,3))
#image(as.matrix(leg),col=cx,axes=T)
#op <- par(oma=c(5,7,1,1))
plot(prd, "single")

#par(mfrow = c(1,1))
# beautiful plot by var
fanchart(prd)

# ggplot(data = month.all, aes(y = arimaFitHH$residuals, x = month.all$vHH)) + geom_point(col = 'red') + geom_smooth(method="lm", col = "Blue")
# ggplot(data = df, aes(y = var4$datamat$PVol, x = ts[,2])) + geom_point(col = 'red') + geom_smooth(method="lm", col = "Blue")
var4$datamat %>% as.data.frame %>% dim
## [1] 472 25
ts %>% head
## Time Series:
## Start = 1
## End = 1.16393442622951
## Frequency = 30.5
## date PVol EVol CVol
## 1.000000 17897 175686 8793580 2752206
## 1.032787 17898 176132 11907700 6014189
## 1.065574 17899 292971 10445140 7399520
## 1.098361 17900 170149 9577019 7136874
## 1.131148 17901 1887 5647818 1434915
## 1.163934 17902 717 3532067 743909
# fitted value
prd %>% summary
## Length Class Mode
## fcst 3 -none- list
## endog 1437 mts numeric
## model 10 varest list
## exo.fcst 0 -none- NULL
prd$endog %>% head
## Time Series:
## Start = 1
## End = 1.16393442622951
## Frequency = 30.5
## PVol EVol CVol
## 1.000000 175686 8793580 2752206
## 1.032787 176132 11907700 6014189
## 1.065574 292971 10445140 7399520
## 1.098361 170149 9577019 7136874
## 1.131148 1887 5647818 1434915
## 1.163934 717 3532067 743909
prd$fcst %>% head
## $PVol
## fcst lower upper CI
## [1,] 155279.09 75919.48 234638.70 79359.61
## [2,] 15802.85 -64696.94 96302.64 80499.79
## [3,] 26934.33 -55424.80 109293.47 82359.13
## [4,] 257635.36 174978.22 340292.50 82657.14
## [5,] 150204.09 67234.61 233173.57 82969.48
## [6,] 165225.60 82118.98 248332.21 83106.62
## [7,] 122632.02 38487.34 206776.70 84144.68
## [8,] 176347.62 76142.95 276552.30 100204.67
## [9,] 35735.14 -66216.36 137686.65 101951.50
## [10,] 44534.98 -59015.28 148085.25 103550.26
## [11,] 259670.03 155904.66 363435.40 103765.37
## [12,] 167663.12 63708.62 271617.62 103954.50
## [13,] 168599.28 64429.79 272768.77 104169.49
## [14,] 137545.53 32720.96 242370.09 104824.57
## [15,] 181315.95 65770.99 296860.91 115544.96
## [16,] 46799.14 -69959.61 163557.90 116758.76
## [17,] 53990.99 -64171.83 172153.82 118162.83
## [18,] 256278.77 137964.47 374593.08 118314.30
## [19,] 176658.34 58199.47 295117.21 118458.87
## [20,] 166802.33 48168.00 285436.66 118634.33
## [21,] 143586.99 24600.12 262573.87 118986.88
## [22,] 180454.64 53180.24 307729.05 127274.41
## [23,] 53021.65 -75010.20 181053.50 128031.85
## [24,] 59707.90 -69652.06 189067.87 129359.96
## [25,] 250862.86 121396.56 380329.17 129466.31
## [26,] 182540.80 52951.73 312129.88 129589.08
## [27,] 164018.55 34259.59 293777.51 129758.96
## [28,] 147233.99 17256.55 277211.43 129977.44
## [29,] 178641.76 41985.25 315298.27 136656.51
## [30,] 57952.25 -79200.63 195105.13 137152.88
##
## $EVol
## fcst lower upper CI
## [1,] 7740905 5574839 9906971 2166066
## [2,] 4701750 2319348 7084153 2382403
## [3,] 4194628 1715670 6673585 2478958
## [4,] 8745671 6219987 11271355 2525684
## [5,] 8992051 6444198 11539903 2547853
## [6,] 8923441 6337988 11508893 2585453
## [7,] 7773176 5126631 10419721 2646545
## [8,] 8273993 5395793 11152193 2878200
## [9,] 5397306 2482084 8312528 2915222
## [10,] 4876746 1930127 7823364 2946618
## [11,] 9121630 6157061 12086199 2964569
## [12,] 9437818 6467539 12408097 2970279
## [13,] 9125938 6145670 12106206 2980268
## [14,] 8050616 5054763 11046469 2995853
## [15,] 8397848 5228235 11567460 3169613
## [16,] 5650948 2468955 8832940 3181993
## [17,] 5137141 1932937 8341344 3204204
## [18,] 9170279 5953911 12386648 3216368
## [19,] 9606985 6385495 12828475 3221490
## [20,] 9169668 5942425 12396911 3227243
## [21,] 8199385 4965008 11433762 3234377
## [22,] 8451977 5075732 11828222 3376245
## [23,] 5841076 2456703 9225449 3384373
## [24,] 5341223 1935106 8747339 3406116
## [25,] 9180962 5763390 12598534 3417572
## [26,] 9729595 6306726 13152463 3422868
## [27,] 9192793 5764580 12621006 3428213
## [28,] 8309124 4876239 11742009 3432885
## [29,] 8483163 4931986 12034341 3551177
## [30,] 5996788 2438863 9554712 3557925
##
## $CVol
## fcst lower upper CI
## [1,] 5641206 4060648.893 7221763 1580557
## [2,] 1479056 -205680.880 3163793 1684737
## [3,] 1200429 -511629.423 2912488 1712059
## [4,] 5524846 3789977.308 7259716 1734869
## [5,] 5997530 4256267.362 7738793 1741263
## [6,] 6075161 4300530.011 7849791 1774631
## [7,] 5271473 3467261.487 7075684 1804211
## [8,] 6079396 3877910.306 8280881 2201486
## [9,] 2181831 -67613.963 4431276 2249445
## [10,] 1864648 -408692.411 4137988 2273340
## [11,] 5977310 3681526.318 8273094 2295784
## [12,] 6531540 4231473.258 8831608 2300067
## [13,] 6474379 4143326.739 8805431 2331052
## [14,] 5690440 3341970.552 8038910 2348470
## [15,] 6323246 3713394.596 8933096 2609851
## [16,] 2632638 -359.505 5265635 2632997
## [17,] 2250796 -398932.379 4900524 2649728
## [18,] 6172852 3506623.178 8839081 2666229
## [19,] 6817639 4146082.368 9489195 2671556
## [20,] 6619908 3923003.711 9316813 2696904
## [21,] 5923452 3218081.983 8628823 2705370
## [22,] 6411349 3507001.469 9315696 2904347
## [23,] 2915982 -2616.151 5834581 2918599
## [24,] 2487365 -446125.124 5420854 2933490
## [25,] 6244659 3297366.220 9191953 2947293
## [26,] 6975644 4021878.324 9929410 2953766
## [27,] 6667548 3691789.283 9643307 2975759
## [28,] 6056668 3076127.844 9037207 2980540
## [29,] 6429481 3288220.549 9570741 3141260
## [30,] 3117610 -34736.566 6269957 3152347
prd_paym <- data.frame(prd$fcst$PVol)
prd_paym %>% str
## 'data.frame': 30 obs. of 4 variables:
## $ fcst : num 155279 15803 26934 257635 150204 ...
## $ lower: num 75919 -64697 -55425 174978 67235 ...
## $ upper: num 234639 96303 109293 340293 233174 ...
## $ CI : num 79360 80500 82359 82657 82969 ...
# payment <- prd_df[,1:4]
# payment <- t(payment) # transpose matrix long format
# payment
startDate <- as.Date("2020-04-24")
dnew <- seq(startDate, by="1 day", length.out=30)
prd_paym <- cbind(dnew,prd_paym)
# prd_paym$date <- dnew
# payment <- cbind(payment[,5], payment[,1:4])
prd_paym %>% head(20)
## dnew fcst lower upper CI
## 1 2020-04-24 155279.09 75919.48 234638.70 79359.61
## 2 2020-04-25 15802.85 -64696.94 96302.64 80499.79
## 3 2020-04-26 26934.33 -55424.80 109293.47 82359.13
## 4 2020-04-27 257635.36 174978.22 340292.50 82657.14
## 5 2020-04-28 150204.09 67234.61 233173.57 82969.48
## 6 2020-04-29 165225.60 82118.98 248332.21 83106.62
## 7 2020-04-30 122632.02 38487.34 206776.70 84144.68
## 8 2020-05-01 176347.62 76142.95 276552.30 100204.67
## 9 2020-05-02 35735.14 -66216.36 137686.65 101951.50
## 10 2020-05-03 44534.98 -59015.28 148085.25 103550.26
## 11 2020-05-04 259670.03 155904.66 363435.40 103765.37
## 12 2020-05-05 167663.12 63708.62 271617.62 103954.50
## 13 2020-05-06 168599.28 64429.79 272768.77 104169.49
## 14 2020-05-07 137545.53 32720.96 242370.09 104824.57
## 15 2020-05-08 181315.95 65770.99 296860.91 115544.96
## 16 2020-05-09 46799.14 -69959.61 163557.90 116758.76
## 17 2020-05-10 53990.99 -64171.83 172153.82 118162.83
## 18 2020-05-11 256278.77 137964.47 374593.08 118314.30
## 19 2020-05-12 176658.34 58199.47 295117.21 118458.87
## 20 2020-05-13 166802.33 48168.00 285436.66 118634.33
#write.csv(prd_paym,"Payment_VAR_30days_predAfter04_23.csv" )
#check <-read.csv("Payment_VAR_30days_predAfter04_23.csv")
#check
# #-------- testing -------------------------------
# # devtools::install_github("yeukyul/lindia")
# # library(lindia)
# # lindia::gg_diagnose(lm4)
# #install.packages("svars")
# #Chi-square test for joint hypotheses
# library(gsl)
# library(svars)
# v1 <- vars::VAR(ts[,-1], lag.max = 45, ic = "AIC" )
# x1 <- id.dc(v1)
# # Bootstrapping of SVAR
# bb <- wild.boot(x1, nboot = 100, n.ahead = 30)
# # Testing the hypothesis of a lower triangular matrix as
# # relation between structural and reduced form errors
# R <- rbind(c(0,0,0,1,0,0,0,0,0), c(0,0,0,0,0,0,1,0,0),
# c(0,0,0,0,0,0,0,1,0))
# c.test <- js.test(bb, R)
# summary(c.test)
acc_var<- rbind(accuracy(var4$varresult$PVol),
accuracy(var4$varresult$EVol),
accuracy(var4$varresult$CVol))
acc_var
## ME RMSE MAE MPE MAPE MASE
## Training set -3.064682e-12 39535.45 25653.78 NaN Inf 0.2809902
## Training set -1.014492e-11 1079092.83 774407.85 -2.161971 10.66989 0.3063573
## Training set -7.200604e-11 787403.61 489915.01 -4.576030 15.19916 0.1837148
#write.csv(acc, "Accuracy_VAR_Model.csv", row.names = T, na = " ")
# my_acc <- list()
#
# for(i in 1:4)
#
# {
# fc <- structure(list(mean=var4$fcst[[i]][,"fcst"], x=trainingdata[,i],
# fitted=c(NA,NA,fits[,i])),class="forecast")
# my_acc[[i]] <- accuracy(fc,testdata[,i])
# }
#
#
# my_acc <- do.call(rbind,my_acc)
# Let's see ACF and PACF
acf(ts[,-1], lag.max = 45)

pacf(ts[,-1], lag.max = 45)

# we can see lot of correlation between PVol and EVol and CVol, particulaly on the 3 step
Box.test(diff(ts[,2]), lag=10, type="Ljung-Box")
##
## Box-Ljung test
##
## data: diff(ts[, 2])
## X-squared = 807.41, df = 10, p-value < 2.2e-16
Box.test(diff(ts[,3]), lag=10, type="Ljung-Box")
##
## Box-Ljung test
##
## data: diff(ts[, 3])
## X-squared = 595.58, df = 10, p-value < 2.2e-16
Box.test(diff(ts[,4]), lag=10, type="Ljung-Box")
##
## Box-Ljung test
##
## data: diff(ts[, 4])
## X-squared = 737.34, df = 10, p-value < 2.2e-16
#Perform the McLeod-Li test for conditional heteroscedascity (ARCH).
#install.packages("TSA")
library(TSA)
## Registered S3 methods overwritten by 'TSA':
## method from
## fitted.Arima forecast
## plot.Arima forecast
##
## Attaching package: 'TSA'
## The following object is masked from 'package:mltools':
##
## skewness
## The following object is masked from 'package:readr':
##
## spec
## The following objects are masked from 'package:stats':
##
## acf, arima
## The following object is masked from 'package:utils':
##
## tar
r.cref=diff(log(ts[,3]))*100
McLeod.Li.test(y=r.cref)

grangertest(df[,2]~df[,3], order = 3, data = df)
## Granger causality test
##
## Model 1: df[, 2] ~ Lags(df[, 2], 1:3) + Lags(df[, 3], 1:3)
## Model 2: df[, 2] ~ Lags(df[, 2], 1:3)
## Res.Df Df F Pr(>F)
## 1 469
## 2 472 -3 16.742 2.389e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
grangertest(df[,2]~df[,4], order = 3, data = df)
## Granger causality test
##
## Model 1: df[, 2] ~ Lags(df[, 2], 1:3) + Lags(df[, 4], 1:3)
## Model 2: df[, 2] ~ Lags(df[, 2], 1:3)
## Res.Df Df F Pr(>F)
## 1 469
## 2 472 -3 53.549 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
grangertest(df[,4]~df[,3], order = 3, data = df)
## Granger causality test
##
## Model 1: df[, 4] ~ Lags(df[, 4], 1:3) + Lags(df[, 3], 1:3)
## Model 2: df[, 4] ~ Lags(df[, 4], 1:3)
## Res.Df Df F Pr(>F)
## 1 469
## 2 472 -3 27.507 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#ARCH test (Autoregressive conditional heteroscedasdicity)
vars::arch.test(var4, lags.single = 10, lags.multi = 45, multivariate.only = T)
##
## ARCH (multivariate)
##
## data: Residuals of VAR object var4
## Chi-squared = 1822.1, df = 1620, p-value = 0.0003077
# ARCH (multivariate)
#
# data: Residuals of VAR object var4
# Chi-squared = 1786.8, df = 1620, p-value = 0.002205
vars::arch.test(var4, lags.single = 10, lags.multi = 10, multivariate.only = T)
##
## ARCH (multivariate)
##
## data: Residuals of VAR object var4
## Chi-squared = 565.84, df = 360, p-value = 2.277e-11
acc_var<- rbind(accuracy(var4$varresult$PVol),
accuracy(var4$varresult$EVol),
accuracy(var4$varresult$CVol))
acc_var
## ME RMSE MAE MPE MAPE MASE
## Training set -3.064682e-12 39535.45 25653.78 NaN Inf 0.2809902
## Training set -1.014492e-11 1079092.83 774407.85 -2.161971 10.66989 0.3063573
## Training set -7.200604e-11 787403.61 489915.01 -4.576030 15.19916 0.1837148
# All accuracy criteria indicate very high level model
# ME RMSE MAE MPE MAPE MASE
# Training set -3.064682e-12 39535.45 25653.78 NaN Inf 0.2809902
# Training set -1.014492e-11 1079092.83 774407.85 -2.161971 10.66989 0.3063573
# Training set -7.200604e-11 787403.61 489915.01 -4.576030 15.19916 0.1837148
library(FitAR)
## Loading required package: leaps
## Loading required package: ltsa
## Loading required package: bestglm
##
## Attaching package: 'FitAR'
## The following object is masked from 'package:forecast':
##
## BoxCox
#test for subset case
#notice that the test is also available as a component of the output of FitAR
z<-log(df[,3])
pvec<-SelectModel(z, ARModel="ARp", Criterion="AIC", lag.max=10, Best=1)
ans<-FitAR(z, pvec)
## Warning in matrix(c(racf, sdRacf), ncol = 2): data length [191] is not a sub-
## multiple or multiple of the number of rows [96]
## Warning in (ra^2)/(n - (1:lag.max)): longer object length is not a multiple of
## shorter object length
#a plot of the test is produced
plot(ans)
## Warning in (ra^2)/(n - (1:lag.max)): longer object length is not a multiple of
## shorter object length

#doing the test manually
res<-resid(ans)
LjungBoxTest(res, k=length(pvec), lag.max=20, StartLag=11)
## Warning in (ra^2)/(n - (1:lag.max)): longer object length is not a multiple of
## shorter object length
## m Qm pvalue
## 11 92.23 0.000000e+00
## 12 92.38 0.000000e+00
## 13 98.39 0.000000e+00
## 14 98.73 0.000000e+00
## 15 98.74 0.000000e+00
## 16 98.92 1.110223e-16
## 17 105.54 0.000000e+00
## 18 110.30 0.000000e+00
## 19 110.32 0.000000e+00
## 20 111.92 0.000000e+00
#test for ARCH effect,
LjungBoxTest(res,SquaredQ=TRUE)
## Warning in (ra^2)/(n - (1:lag.max)): longer object length is not a multiple of
## shorter object length
## m Qm pvalue
## 1 0.61 4.348433e-01
## 2 5.94 5.136932e-02
## 3 10.50 1.473527e-02
## 4 10.82 2.864725e-02
## 5 11.19 4.768825e-02
## 6 84.43 4.440892e-16
## 7 84.54 1.665335e-15
## 8 85.10 4.551914e-15
## 9 85.21 1.487699e-14
## 10 85.30 4.563017e-14
## 11 86.82 6.961098e-14
## 12 87.07 1.821876e-13
## 13 89.45 1.780798e-13
## 14 91.46 2.006173e-13
## 15 93.90 1.844080e-13
## 16 93.96 4.635181e-13
## 17 94.45 9.378054e-13
## 18 95.34 1.568523e-12
## 19 96.12 2.680411e-12
## 20 96.17 6.062262e-12
## 21 97.19 9.036438e-12
## 22 98.06 1.402756e-11
## 23 106.05 1.250111e-12
## 24 106.71 2.106981e-12
## 25 106.78 4.411582e-12
## 26 112.79 8.789636e-13
## 27 125.36 1.276756e-14
## 28 126.28 1.931788e-14
## 29 126.34 4.085621e-14
## 30 126.99 6.727952e-14