#1. Step: Importing the Data—-
#first look
raw_data<- file.choose() #please choose data.file return.RDS
raw_data_unpacked <- readRDS(raw_data)
assets_log_returns_row <- data.frame(raw_data_unpacked)
#first look
str(assets_log_returns_row)
## 'data.frame': 2347 obs. of 5 variables:
## $ STOXX_EU_600 : num 0 0.021227 -0.001757 -0.000513 -0.003961 ...
## $ DOWJONES_INDUSTRIALS : num 0 0.014988 -0.001128 0.000798 0.003267 ...
## $ MSCI_EM : num 0 0.01531 0.01071 0.0064 -0.00717 ...
## $ S.P_U.S._TREASURY_BOND: num 0 0.001415 0.002608 -0.002013 -0.000337 ...
## $ S.P_GSCI_Commodity : num 0 0.025407 0.000994 0.017457 -0.009653 ...
head(assets_log_returns_row)
###convert to time series###
library(quantmod)
## Loading required package: xts
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.0.4
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Version 0.4-0 included new data defaults. See ?getSymbols.
library(PerformanceAnalytics)
## Warning: package 'PerformanceAnalytics' was built under R version 4.0.4
##
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
##
## legend
time_span_row <- dimnames(assets_log_returns_row)[[1]]
time_span_conv=as.Date(time_span_row,tryFormats = c("%d.%m.%Y"))
head(time_span_conv)
## [1] "2010-01-01" "2010-01-04" "2010-01-05" "2010-01-06" "2010-01-07"
## [6] "2010-01-08"
tail(time_span_conv)
## [1] "2018-12-24" "2018-12-25" "2018-12-26" "2018-12-27" "2018-12-28"
## [6] "2018-12-31"
assets_log_returns <-xts(raw_data_unpacked,time_span_conv) #as timeseries
#check if data matches/conversion was successful
str(assets_log_returns)
## An 'xts' object on 2010-01-01/2018-12-31 containing:
## Data: num [1:2347, 1:5] 0 0.021227 -0.001757 -0.000513 -0.003961 ...
## - attr(*, "dimnames")=List of 2
## ..$ : NULL
## ..$ : chr [1:5] "STOXX_EU_600" "DOWJONES_INDUSTRIALS" "MSCI_EM" "S&P_U.S._TREASURY_BOND" ...
## Indexed by objects of class: [Date] TZ: UTC
## xts Attributes:
## NULL
head(assets_log_returns_row)
tail(assets_log_returns_row)
#2. Step: Sighting the data—-
library(moments)
##
## Attaching package: 'moments'
## The following objects are masked from 'package:PerformanceAnalytics':
##
## kurtosis, skewness
library(tseries)
library(car)
## Warning: package 'car' was built under R version 4.0.4
## Loading required package: carData
STOXX_EU_600 <- assets_log_returns[,1]
DOWJONES_INDUSTRIALS <- assets_log_returns[,2]
MSCI_EM <- assets_log_returns[,3]
SP_U.S._TREASURY_BOND <- assets_log_returns[,4]
SP_GSCI_Commodity<- assets_log_returns[,5]
##2.1 STOXX_EU_600—-
#STOXX_EU_600
plot(density(STOXX_EU_600))
lines(density(rnorm(10000000,mean=mean(STOXX_EU_600),sd=sd(STOXX_EU_600))),col="blue")
mean(STOXX_EU_600)
## [1] 0.0002270614
summary(STOXX_EU_600)
## Index STOXX_EU_600
## Min. :2010-01-01 Min. :-0.0895678
## 1st Qu.:2012-04-02 1st Qu.:-0.0053755
## Median :2014-07-02 Median : 0.0003142
## Mean :2014-07-02 Mean : 0.0002271
## 3rd Qu.:2016-09-29 3rd Qu.: 0.0063351
## Max. :2018-12-31 Max. : 0.0876473
sd(STOXX_EU_600)
## [1] 0.01189288
skewness(STOXX_EU_600)
## STOXX_EU_600
## -0.2257724
kurtosis(STOXX_EU_600)
## STOXX_EU_600
## 8.07337
acf(STOXX_EU_600,20)
acf(STOXX_EU_600^2,20)
jarque.bera.test(STOXX_EU_600)
##
## Jarque Bera Test
##
## data: STOXX_EU_600
## X-squared = 2537, df = 2, p-value < 2.2e-16
Box.test(STOXX_EU_600, lag=20, type=c("Ljung-Box")) #portmanteau test
##
## Box-Ljung test
##
## data: STOXX_EU_600
## X-squared = 33.413, df = 20, p-value = 0.03038
Box.test(STOXX_EU_600^2, lag=20, type=c("Ljung-Box"))
##
## Box-Ljung test
##
## data: STOXX_EU_600^2
## X-squared = 861.05, df = 20, p-value < 2.2e-16
qqPlot(coredata(STOXX_EU_600),envelope=F) #graphical test for fat tail analysis (normal)
## [1] 1691 92
qqPlot(coredata(STOXX_EU_600),distribution="t",df=4,envelope=F) #graphical test for fat tail analysis (t)
## [1] 1691 92
##2.2 DOWJONES_INDUSTRIALS —-
#DOWJONES_INDUSTRIALS
plot(density(DOWJONES_INDUSTRIALS))
lines(density(rnorm(10000000,mean=mean(DOWJONES_INDUSTRIALS),sd=sd(DOWJONES_INDUSTRIALS))),col="blue")
summary(DOWJONES_INDUSTRIALS)
## Index DOWJONES_INDUSTRIALS
## Min. :2010-01-01 Min. :-0.0549947
## 1st Qu.:2012-04-02 1st Qu.:-0.0029829
## Median :2014-07-02 Median : 0.0004184
## Mean :2014-07-02 Mean : 0.0004786
## 3rd Qu.:2016-09-29 3rd Qu.: 0.0047275
## Max. :2018-12-31 Max. : 0.0498454
sd(DOWJONES_INDUSTRIALS)
## [1] 0.00880256
skewness(DOWJONES_INDUSTRIALS)
## DOWJONES_INDUSTRIALS
## -0.3785422
kurtosis(DOWJONES_INDUSTRIALS)
## DOWJONES_INDUSTRIALS
## 7.154601
acf(DOWJONES_INDUSTRIALS,20)
acf(DOWJONES_INDUSTRIALS^2,20)
jarque.bera.test(DOWJONES_INDUSTRIALS)
##
## Jarque Bera Test
##
## data: DOWJONES_INDUSTRIALS
## X-squared = 1744, df = 2, p-value < 2.2e-16
Box.test(DOWJONES_INDUSTRIALS, lag=20, type=c("Ljung-Box")) #portmanteau test
##
## Box-Ljung test
##
## data: DOWJONES_INDUSTRIALS
## X-squared = 28.229, df = 20, p-value = 0.1041
Box.test(DOWJONES_INDUSTRIALS^2, lag=20, type=c("Ljung-Box"))
##
## Box-Ljung test
##
## data: DOWJONES_INDUSTRIALS^2
## X-squared = 1177.7, df = 20, p-value < 2.2e-16
qqPlot(coredata(DOWJONES_INDUSTRIALS),envelope=F) #graphical test for fat tail analysis (normal)
## [1] 417 2344
qqPlot(coredata(DOWJONES_INDUSTRIALS),distribution="t",df=3,envelope=F) #graphical test for fat tail analysis (t)
## [1] 417 2344
##2.3 MSCI_EM—-
#MSCI_EM
plot(density(MSCI_EM))
lines(density(rnorm(10000000,mean=mean(MSCI_EM),sd=sd(MSCI_EM))),col="blue")
summary(MSCI_EM)
## Index MSCI_EM
## Min. :2010-01-01 Min. :-0.0630901
## 1st Qu.:2012-04-02 1st Qu.:-0.0051575
## Median :2014-07-02 Median : 0.0006174
## Mean :2014-07-02 Mean : 0.0001429
## 3rd Qu.:2016-09-29 3rd Qu.: 0.0058716
## Max. :2018-12-31 Max. : 0.0493297
sd(MSCI_EM)
## [1] 0.009760328
skewness(MSCI_EM)
## MSCI_EM
## -0.3157781
kurtosis(MSCI_EM)
## MSCI_EM
## 5.521222
acf(MSCI_EM,20)
acf(MSCI_EM^2,20)
jarque.bera.test(MSCI_EM)
##
## Jarque Bera Test
##
## data: MSCI_EM
## X-squared = 660.62, df = 2, p-value < 2.2e-16
Box.test(MSCI_EM, lag=20, type=c("Ljung-Box"))
##
## Box-Ljung test
##
## data: MSCI_EM
## X-squared = 143.01, df = 20, p-value < 2.2e-16
Box.test(MSCI_EM^2, lag=20, type=c("Ljung-Box"))
##
## Box-Ljung test
##
## data: MSCI_EM^2
## X-squared = 878.26, df = 20, p-value < 2.2e-16
plot(density(MSCI_EM))
summary(MSCI_EM)
## Index MSCI_EM
## Min. :2010-01-01 Min. :-0.0630901
## 1st Qu.:2012-04-02 1st Qu.:-0.0051575
## Median :2014-07-02 Median : 0.0006174
## Mean :2014-07-02 Mean : 0.0001429
## 3rd Qu.:2016-09-29 3rd Qu.: 0.0058716
## Max. :2018-12-31 Max. : 0.0493297
qqPlot(coredata(MSCI_EM),envelope=F) #graphical test for fat tail analysis (normal)
## [1] 450 1472
qqPlot(coredata(MSCI_EM),distribution="t",df=5,envelope=F) #graphical test for fat tail analysis (t)
## [1] 450 1472
##2.4 SP_U.S._TREASURY_BOND—-
#SP_U.S._TREASURY_BOND
plot(density(SP_U.S._TREASURY_BOND))
lines(density(rnorm(10000000,mean=mean(SP_U.S._TREASURY_BOND),sd=sd(SP_U.S._TREASURY_BOND))),col="blue")
summary(SP_U.S._TREASURY_BOND)
## Index S&P_U.S._TREASURY_BOND
## Min. :2010-01-01 Min. :-9.572e-03
## 1st Qu.:2012-04-02 1st Qu.:-1.063e-03
## Median :2014-07-02 Median : 8.743e-05
## Mean :2014-07-02 Mean : 8.809e-05
## 3rd Qu.:2016-09-29 3rd Qu.: 1.213e-03
## Max. :2018-12-31 Max. : 9.174e-03
sd(SP_U.S._TREASURY_BOND)
## [1] 0.001852771
skewness(SP_U.S._TREASURY_BOND)
## S&P_U.S._TREASURY_BOND
## -0.03517757
kurtosis(SP_U.S._TREASURY_BOND)
## S&P_U.S._TREASURY_BOND
## 4.385586
acf(SP_U.S._TREASURY_BOND,20)
acf(SP_U.S._TREASURY_BOND^2,20)
jarque.bera.test(SP_U.S._TREASURY_BOND)
##
## Jarque Bera Test
##
## data: SP_U.S._TREASURY_BOND
## X-squared = 188.23, df = 2, p-value < 2.2e-16
Box.test(SP_U.S._TREASURY_BOND, lag=20, type=c("Ljung-Box")) #portmanteau test
##
## Box-Ljung test
##
## data: SP_U.S._TREASURY_BOND
## X-squared = 26.344, df = 20, p-value = 0.1547
Box.test(SP_U.S._TREASURY_BOND^2, lag=20, type=c("Ljung-Box"))
##
## Box-Ljung test
##
## data: SP_U.S._TREASURY_BOND^2
## X-squared = 409.75, df = 20, p-value < 2.2e-16
qqPlot(coredata(SP_U.S._TREASURY_BOND),envelope=F) #graphical test for fat tail analysis (normal)
## [1] 1789 90
qqPlot(coredata(SP_U.S._TREASURY_BOND),distribution="t",df=7,envelope=F) #graphical test for fat tail analysis (t)
## [1] 1789 90
##2.5 SP_GSCI_Commodity
#SP_GSCI_Commodity
plot(density(SP_GSCI_Commodity))
lines(density(rnorm(10000000,mean=mean(SP_GSCI_Commodity),sd=sd(SP_GSCI_Commodity))),col="blue")
summary(SP_GSCI_Commodity)
## Index S&P_GSCI_Commodity
## Min. :2010-01-01 Min. :-0.0652110
## 1st Qu.:2012-04-02 1st Qu.:-0.0065111
## Median :2014-07-02 Median : 0.0000000
## Mean :2014-07-02 Mean :-0.0002373
## 3rd Qu.:2016-09-29 3rd Qu.: 0.0061778
## Max. :2018-12-31 Max. : 0.0563424
sd(SP_GSCI_Commodity)
## [1] 0.01183495
skewness(SP_GSCI_Commodity)
## S&P_GSCI_Commodity
## -0.1800893
kurtosis(SP_GSCI_Commodity)
## S&P_GSCI_Commodity
## 5.27084
acf(SP_GSCI_Commodity,20)
acf(SP_GSCI_Commodity^2,20)
jarque.bera.test(SP_GSCI_Commodity)
##
## Jarque Bera Test
##
## data: SP_GSCI_Commodity
## X-squared = 516.97, df = 2, p-value < 2.2e-16
Box.test(SP_GSCI_Commodity, lag=20, type=c("Ljung-Box")) #portmanteau test
##
## Box-Ljung test
##
## data: SP_GSCI_Commodity
## X-squared = 16.347, df = 20, p-value = 0.6949
Box.test(SP_GSCI_Commodity^2, lag=20, type=c("Ljung-Box"))
##
## Box-Ljung test
##
## data: SP_GSCI_Commodity^2
## X-squared = 304.64, df = 20, p-value < 2.2e-16
qqPlot(coredata(SP_GSCI_Commodity),envelope=F) #graphical test for fat tail analysis (normal)
## [1] 350 1281
qqPlot(coredata(SP_GSCI_Commodity),distribution="t",df=5,envelope=F) #graphical test for fat tail analysis (t) df=5
## [1] 350 1281
#3. Step: modeling single indexes—-
#install.packages("rmgarch")
library(rugarch)
## Warning: package 'rugarch' was built under R version 4.0.4
## Loading required package: parallel
##
## Attaching package: 'rugarch'
## The following object is masked from 'package:stats':
##
## sigma
library(rmgarch)
## Warning: package 'rmgarch' was built under R version 4.0.4
##
## Attaching package: 'rmgarch'
## The following objects are masked from 'package:xts':
##
## first, last
library(zoo)
library(quantmod)
library(PerformanceAnalytics)
#spec for specifications
#gar for Garch Mode
#using demeaned return data
assets_log_returns_mean <- c(mean(STOXX_EU_600),mean(DOWJONES_INDUSTRIALS),mean(MSCI_EM),mean(SP_U.S._TREASURY_BOND),mean(SP_GSCI_Commodity))
assets_log_returns_mean
## [1] 2.270614e-04 4.786251e-04 1.428530e-04 8.809264e-05 -2.372699e-04
assets_log_returns_dmean <- assets_log_returns - assets_log_returns_mean #demeaning data
str(assets_log_returns_dmean)
## An 'xts' object on 2010-01-01/2018-12-31 containing:
## Data: num [1:2347, 1:5] -0.000227 0.020749 -0.001899 -0.000601 -0.003724 ...
## - attr(*, "dimnames")=List of 2
## ..$ : NULL
## ..$ : chr [1:5] "STOXX_EU_600" "DOWJONES_INDUSTRIALS" "MSCI_EM" "S&P_U.S._TREASURY_BOND" ...
## Indexed by objects of class: [Date] TZ: UTC
## xts Attributes:
## NULL
Fit u_garch_models
#3.1 STOXX_EU_600 —-
plot(assets_log_returns_dmean[,1])
qqPlot(coredata(assets_log_returns_dmean[,1]),distribution="t",df=4,envelope=F)
## [1] 1691 92
acf(assets_log_returns_dmean[,1],20)
acf(assets_log_returns_dmean[,1]^2,20)
Box.test(assets_log_returns_dmean[,1], type=c("Ljung-Box"))
##
## Box-Ljung test
##
## data: assets_log_returns_dmean[, 1]
## X-squared = 0.73852, df = 1, p-value = 0.3901
### GARCH(1,1)
u_STO_spec_1 = ugarchspec(variance.model = list( garchOrder = c(1, 1)),
mean.model = list( armaOrder = c(0,0),include.mean = FALSE)) #because portfolio is de-meaned mean is 0 theirefore include mean= 0
u_gar_STO_1 = ugarchfit(spec = u_STO_spec_1, data = assets_log_returns_dmean[,1])
#plot(u_gar_STO_1)
##!!! Plots are turned of because they require a choice, if you like to see tham switch plot on again
### GARCH(1,1) t_dist
u_STO_spec_2 = ugarchspec(variance.model = list( garchOrder = c(1, 1)),
mean.model = list( armaOrder = c(0,0),include.mean = FALSE), #because portfolio is de-meaned mean is 0 theirefore include mean= 0
distribution.model = "std")
u_gar_STO_2 = ugarchfit(spec = u_STO_spec_2 , data = assets_log_returns_dmean[,1])
#plot(u_gar_STO_2)
### GARCH(1,1) st_dist
u_STO_spec_3 = ugarchspec(variance.model = list( garchOrder = c(1, 1)),
mean.model = list( armaOrder = c(0,0),include.mean = FALSE),
distribution.model = "sstd") #because portfolio is de-meaned mean is 0 theirefore include mean= 0
u_gar_STO_3 = ugarchfit(spec = u_STO_spec_3, data = assets_log_returns_dmean[,1])
#plot(u_gar_STO_3)
### GARCH(1,0) st_dist
u_STO_spec_4 = ugarchspec(variance.model = list( garchOrder = c(1, 0)),
mean.model = list( armaOrder = c(0,0),include.mean = FALSE),
distribution.model = "sstd") #because portfolio is de-meaned mean is 0 theirefore include mean= 0
u_gar_STO_4 = ugarchfit(spec = u_STO_spec_4, data = assets_log_returns_dmean[,1])
#plot(u_gar_STO_4)
### GARCH(2,1) sstd_dist
u_STO_spec_5 = ugarchspec(variance.model = list( garchOrder = c(2, 1)),
mean.model = list( armaOrder = c(0,0),include.mean = FALSE),
distribution.model = "sstd") #because portfolio is de-meaned mean is 0 theirefore include mean= 0
u_gar_STO_5 = ugarchfit(spec = u_STO_spec_5, data = assets_log_returns_dmean[,1])
#plot(u_gar_STO_5)
#3.2 DOWJONES_INDUSTRIALS—-
plot(assets_log_returns_dmean[,2])
plot(density(assets_log_returns_dmean[,2]))
qqPlot(coredata(assets_log_returns_dmean[,2]))
## [1] 417 2344
qqPlot(coredata(assets_log_returns_dmean[,2]),distribution="t",df=4,envelope=F)
## [1] 417 2344
acf(assets_log_returns_dmean[,2],20)
acf(assets_log_returns_dmean[,2]^2,20)
### GARCH(1,1) sstd_dist
u_DOW_spec_1 = ugarchspec(variance.model = list( garchOrder = c(1, 1)),
mean.model = list( armaOrder = c(0,0),include.mean = FALSE), #because portfolio is de-meaned mean is 0 theirefore include mean= 0
distribution.model = "sstd")
u_gar_DOW_1 = ugarchfit(spec = u_DOW_spec_1 , data = assets_log_returns_dmean[,2])
#plot(u_gar_DOW_1)
### GARCH(1,1) "ghyp” for the Generalized Hyperbolic
u_DOW_spec_2 = ugarchspec(variance.model = list( garchOrder = c(1, 1)),
mean.model = list( armaOrder = c(0,0),include.mean = FALSE), #because portfolio is de-meaned mean is 0 theirefore include mean= 0
distribution.model = "ghyp")
u_gar_DOW_2 = ugarchfit(spec = u_DOW_spec_2 , data = assets_log_returns_dmean[,2])
#plot(u_gar_DOW_2)
#3.3 MSCI_EM—-
plot(assets_log_returns_dmean[,3])
plot(density(assets_log_returns_dmean[,3]))
qqPlot(coredata(assets_log_returns_dmean[,3]))
## [1] 450 1472
qqPlot(coredata(assets_log_returns_dmean[,3]),distribution="t",df=4,envelope=F)
## [1] 450 1472
acf(assets_log_returns_dmean[,3],20)
acf(assets_log_returns_dmean[,3]^2,20)
### GARCH(1,1) "ghyp” for the Generalized Hyperbolic
u_MSCI_spec_1 = ugarchspec(variance.model = list( garchOrder = c(1, 1)),
mean.model = list( armaOrder = c(0,0),include.mean = FALSE) #because portfolio is de-meaned mean is 0 theirefore include mean= 0
,distribution.model = "ghyp")
u_gar_MSCI_1 = ugarchfit(spec = u_MSCI_spec_1 , data = assets_log_returns_dmean[,2])
#plot(u_gar_MSCI_1)
#3.4 SP_U.S._TREASURY_BOND —-
plot(assets_log_returns_dmean[,4])
plot(density(assets_log_returns_dmean[,4]))
qqPlot(coredata(assets_log_returns_dmean[,4]))
## [1] 1789 90
qqPlot(coredata(assets_log_returns_dmean[,4]),distribution="t",df=4,envelope=F)
## [1] 1789 90
acf(assets_log_returns_dmean[,4],20)
acf(assets_log_returns_dmean[,4]^2,20)
### GARCH(1,1) "sstd”
u_TREASURY_spec_1 = ugarchspec(variance.model = list( garchOrder = c(1, 1)),
mean.model = list( armaOrder = c(0,0),include.mean = FALSE) #because portfolio is de-meaned mean is 0 theirefore include mean= 0
,distribution.model = "sstd")
u_gar_TREASURY_1 = ugarchfit(spec = u_TREASURY_spec_1 , data = assets_log_returns_dmean[,2])
#plot(u_gar_TREASURY_1)
#3.5 SP_GSCI_Commodity—-
plot(assets_log_returns_dmean[,5])
plot(density(assets_log_returns_dmean[,5]))
qqPlot(coredata(assets_log_returns_dmean[,5]))
## [1] 350 1281
qqPlot(coredata(assets_log_returns_dmean[,5]),distribution="t",df=4,envelope=F)
## [1] 350 1281
acf(assets_log_returns_dmean[,5],20)
acf(assets_log_returns_dmean[,5]^2,20)
### GARCH(1,1) "sstd”
u_GSCI_spec_1 = ugarchspec(variance.model = list( garchOrder = c(1, 1)),
mean.model = list( armaOrder = c(0,0),include.mean = FALSE) #because portfolio is de-meaned mean is 0 theirefore include mean= 0
,distribution.model = "sstd")
u_gar_GSCI_1 = ugarchfit(spec = u_GSCI_spec_1 , data = assets_log_returns_dmean[,2])
#plot(u_gar_GSCI_1)
#4. Step: Modeling portfolio —-
# creating list of the specifications of the single GARCH models for the singe indexes
u_garch_list <-list(u_STO_spec_5,u_DOW_spec_2,u_MSCI_spec_1,u_TREASURY_spec_1,u_GSCI_spec_1)
uspec_assets<-multispec(u_garch_list)
# deriving a Copular Garch model with a students t copular
cGarch_spec_mt<-cgarchspec(uspec=uspec_assets,distribution.model = list(copula = c("mvt")))
cGarch_res_mt <-cgarchfit(cGarch_spec_mt, assets_log_returns_dmean)
show(cGarch_spec_mt)
##
## *--------------------------------*
## * Copula GARCH Spec *
## *--------------------------------*
##
## Distribution : mvt
## Transformation : parametric
## Correlation Estimate: KENDALL
## No. of Parameters : 39
## [VAR GARCH COV] : [0+28+10]
## No. of Series : 5
show(cGarch_res_mt)
##
## *-------------------------------------------------*
## * Copula GARCH Fit *
## *-------------------------------------------------*
##
## Distribution : mvt
## No. of Parameters : 29
## [VAR GARCH CC] : [0+28+1]
## No. of Series : 5
## No. of Observations : 2347
## Log-Likelihood : 43933.07
## Av.Log-Likelihood : 18.719
##
## Optimal Parameters
## ---------------------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## [STOXX_EU_600].omega 0.000001 0.000001 1.082060 0.279226
## [STOXX_EU_600].alpha1 0.076026 0.027642 2.750349 0.005953
## [STOXX_EU_600].alpha2 0.014898 0.032883 0.453067 0.650500
## [STOXX_EU_600].beta1 0.903297 0.016691 54.120339 0.000000
## [STOXX_EU_600].skew 0.923993 0.023686 39.009301 0.000000
## [STOXX_EU_600].shape 6.078524 0.783998 7.753236 0.000000
## [DOWJONES_INDUSTRIALS].omega 0.000002 0.000058 0.041188 0.967146
## [DOWJONES_INDUSTRIALS].alpha1 0.158424 0.732629 0.216241 0.828800
## [DOWJONES_INDUSTRIALS].beta1 0.822877 0.883492 0.931392 0.351651
## [DOWJONES_INDUSTRIALS].skew -0.064869 1.817055 -0.035700 0.971521
## [DOWJONES_INDUSTRIALS].shape 0.250008 26.083695 0.009585 0.992353
## [DOWJONES_INDUSTRIALS].ghlambda 1.211671 7.900499 0.153366 0.878109
## [MSCI_EM].omega 0.000001 0.000001 0.992062 0.321167
## [MSCI_EM].alpha1 0.068317 0.014861 4.597167 0.000004
## [MSCI_EM].beta1 0.918070 0.017365 52.870072 0.000000
## [MSCI_EM].skew -0.176434 0.045134 -3.909154 0.000093
## [MSCI_EM].shape 1.676705 2.553916 0.656523 0.511488
## [MSCI_EM].ghlambda 3.515704 1.833222 1.917773 0.055140
## [S&P_U.S._TREASURY_BOND].omega 0.000000 0.000000 0.126540 0.899305
## [S&P_U.S._TREASURY_BOND].alpha1 0.030820 0.002506 12.300608 0.000000
## [S&P_U.S._TREASURY_BOND].beta1 0.963058 0.001803 534.158633 0.000000
## [S&P_U.S._TREASURY_BOND].skew 0.974207 0.026640 36.569128 0.000000
## [S&P_U.S._TREASURY_BOND].shape 8.857453 1.306080 6.781709 0.000000
## [S&P_GSCI_Commodity].omega 0.000000 0.000030 0.015861 0.987346
## [S&P_GSCI_Commodity].alpha1 0.041464 0.198336 0.209060 0.834402
## [S&P_GSCI_Commodity].beta1 0.956468 0.174727 5.474065 0.000000
## [S&P_GSCI_Commodity].skew 0.926303 0.153848 6.020884 0.000000
## [S&P_GSCI_Commodity].shape 6.288314 23.405536 0.268668 0.788185
## [Joint]mshape 11.269901 0.826604 13.633973 0.000000
##
## Information Criteria
## ---------------------
##
## Akaike -37.413
## Bayes -37.342
## Shibata -37.413
## Hannan-Quinn -37.387
##
##
## Elapsed time : 1.911846
rshape(cGarch_res_mt)
## mshape
## 11.2699
summary(cGarch_res_mt)
## Length Class Mode
## 1 cGARCHfit S4
sigma_portfolio= sigma(cGarch_res_mt)
head(sigma_portfolio)
## STOXX_EU_600 DOWJONES_INDUSTRIALS MSCI_EM S&P_U.S._TREASURY_BOND
## 2010-01-01 0.01189857 0.008810799 0.009760353 0.001854964
## 2010-01-04 0.01189857 0.008140303 0.009422146 0.001827176
## 2010-01-05 0.01273030 0.009595862 0.009917785 0.001811870
## 2010-01-06 0.01243068 0.008847486 0.009937976 0.001837110
## 2010-01-07 0.01187877 0.008175939 0.009729194 0.001834462
## 2010-01-08 0.01140020 0.007656277 0.009582011 0.001807888
## S&P_GSCI_Commodity
## 2010-01-01 0.01183236
## 2010-01-04 0.01159260
## 2010-01-05 0.01250136
## 2010-01-06 0.01224676
## 2010-01-07 0.01248540
## 2010-01-08 0.01239179
head(assets_log_returns_dmean)
## STOXX_EU_600 DOWJONES_INDUSTRIALS MSCI_EM
## 2010-01-01 -0.0002270614 -0.0001428530 0.0002372699
## 2010-01-04 0.0207486715 0.0148999931 0.0150848268
## 2010-01-05 -0.0018994218 -0.0008911532 0.0102276169
## 2010-01-06 -0.0006013267 0.0005707206 0.0062539673
## 2010-01-07 -0.0037239977 0.0027878996 -0.0072586438
## 2010-01-08 0.0039709059 0.0009260131 0.0021997212
## S&P_U.S._TREASURY_BOND S&P_GSCI_Commodity
## 2010-01-01 -0.0004786251 -8.809264e-05
## 2010-01-04 0.0012723591 2.564414e-02
## 2010-01-05 0.0025194764 7.668374e-04
## 2010-01-06 -0.0017760671 1.697866e-02
## 2010-01-07 -0.0005636298 -9.796230e-03
## 2010-01-08 0.0007959353 -1.571828e-04
#5. Step: calculating VaR—-
library(MASS)
weight=matrix(c(1/5,1/5,1/5,1/5,1/5))
weight
## [,1]
## [1,] 0.2
## [2,] 0.2
## [3,] 0.2
## [4,] 0.2
## [5,] 0.2
portfolio_returns=xts(assets_log_returns_dmean%*%c(weight),time_span_conv)
VaR_portfolio = -sigma_portfolio%*%c(weight)*qnorm(0.01)
VaR_portfolio_xts=xts(VaR_portfolio,time_span_conv)
plot(portfolio_returns, main="99% - Value at Risk ", ylim=c(-0.06,0.06),type="l",lwd=0.1)
legend ("bottomright", legend=c("Log returns", "99% - VaR"), col=c("black", "red"), lty=1:2, cex=0.8)
lines(VaR_portfolio_xts,col="red", lwd = 0.2)
lines(-VaR_portfolio_xts,col="green", lwd = 0.2)
```