options(digits = 4, width = 70)
library(boot)
library(tseries)
library(zoo)
library(PerformanceAnalytics)
library(multicore)
returns.df = read.csv(file = "~/Documents/annual/returnsCME.csv", sep = ";",
header = TRUE, stringsAsFactors = FALSE)
returns.df[is.na(returns.df)] = 0
returns.z = zooreg(data = returns.df[, -1], start = c(1992, 41), end = c(2011,
12), frequency = 52)
energy.z = returns.z[, c("crude", "gasoline", "heating", "natural", "electricity")]
wget.and.source <- function(url) {
fname <- tempfile()
download.file(url, fname, method = "wget")
source(fname)
unlink(fname)
}
wget.and.source("https://gist.github.com/bautheac/b2e8269868a881b66a69/raw/")
rollMomentsenergy.ls = rollingMoments.fun(energy.z, startYear = 1992, startWeek = 41,
width = 52)
mu95CI(energy.z, "crude")
## muhat standard error lower bound upper bound
## [1,] 0.001722 0.001495 -0.001268 0.004712
sd95CI(energy.z, "crude")
## sdhat standard error lower bound upper bound
## [1,] 0.04642 0.001528 0.04336 0.04947
skew95CI(returns.df, "crude")
## skewhat standard error lower bound upper bound
## [1,] -0.5614 0.2088 -0.9791 -0.1438
kurt95CI(returns.df, "crude")
## kurthat standard error lower bound upper bound
## [1,] 2.285 0.7825 0.7201 3.85
head(rollMomentsenergy.ls[["crude"]][["mu"]])
## muhat.lower muhat muhat.upper
## 1993(41) -0.2959 -0.24 -0.1841
## 1993(42) -0.3155 -0.26 -0.2045
## 1993(43) -0.3357 -0.28 -0.2243
## 1993(44) -0.3044 -0.25 -0.1956
## 1993(45) -0.3469 -0.29 -0.2331
## 1993(46) -0.3271 -0.27 -0.2129
plotRollingMoments(data = rollMomentsenergy.ls, commo = "crude", statistic = "mu")
head(rollMomentsenergy.ls[["crude"]][["sd"]])
## sdhat.lower sdhat sdhat.upper
## 1993(41) 0.1962 0.2017 0.2072
## 1993(42) 0.1947 0.2002 0.2057
## 1993(43) 0.1949 0.2007 0.2065
## 1993(44) 0.1904 0.1961 0.2017
## 1993(45) 0.1992 0.2052 0.2111
## 1993(46) 0.1997 0.2057 0.2117
plotRollingMoments(data = rollMomentsenergy.ls, commo = "crude", statistic = "sd")
head(rollMomentsenergy.ls[["crude"]][["skew"]])
## skewhat.lower skewhat skewhat.upper
## 1993(41) -0.3063 0.2330 0.7723
## 1993(42) -0.2952 0.2666 0.8284
## 1993(43) -0.2258 0.3033 0.8324
## 1993(44) -0.2420 0.3453 0.9326
## 1993(45) -0.4542 0.1588 0.7718
## 1993(46) -0.4666 0.1200 0.7066
plotRollingMoments(data = rollMomentsenergy.ls, commo = "crude", statistic = "skew")
head(rollMomentsenergy.ls[["crude"]][["kurt"]])
## kurthat.lower kurthat kurthat.upper
## 1993(41) -1.0570 -1.086e-05 1.057
## 1993(42) -1.0025 9.250e-02 1.187
## 1993(43) -0.9689 7.988e-02 1.129
## 1993(44) -0.8974 2.044e-01 1.306
## 1993(45) -0.7573 2.238e-01 1.205
## 1993(46) -0.8462 1.845e-01 1.215
plotRollingMoments(data = rollMomentsenergy.ls, commo = "crude", statistic = "kurt")
mu95CI(energy.z, "gasoline")
## muhat standard error lower bound upper bound
## [1,] 0.0003008 0.000935 -0.001569 0.002171
sd95CI(energy.z, "gasoline")
## sdhat standard error lower bound upper bound
## [1,] 0.02903 0.00215 0.02473 0.03333
skew95CI(returns.df, "gasoline")
## skewhat standard error lower bound upper bound
## [1,] -1.174 0.9267 -3.027 0.6795
kurt95CI(returns.df, "gasoline")
## kurthat standard error lower bound upper bound
## [1,] 19.63 4.447 10.74 28.53
head(rollMomentsenergy.ls[["gasoline"]][["mu"]])
## muhat.lower muhat muhat.upper
## 1993(41) 0 0 0
## 1993(42) 0 0 0
## 1993(43) 0 0 0
## 1993(44) 0 0 0
## 1993(45) 0 0 0
## 1993(46) 0 0 0
plotRollingMoments(data = rollMomentsenergy.ls, commo = "gasoline", statistic = "mu")
head(rollMomentsenergy.ls[["gasoline"]][["sd"]])
## sdhat.lower sdhat sdhat.upper
## 1993(41) 0 0 0
## 1993(42) 0 0 0
## 1993(43) 0 0 0
## 1993(44) 0 0 0
## 1993(45) 0 0 0
## 1993(46) 0 0 0
plotRollingMoments(data = rollMomentsenergy.ls, commo = "gasoline", statistic = "sd")
tail(rollMomentsenergy.ls[["gasoline"]][["skew"]])
## skewhat.lower skewhat skewhat.upper
## 2011(12) -1.733 -0.9065 -0.079810
## 2011(13) -1.588 -0.8008 -0.013348
## 2011(14) -1.611 -0.8008 0.009806
## 2011(15) -1.574 -0.7839 0.006485
## 2011(16) -1.583 -0.7673 0.048287
## 2011(17) -1.618 -0.8318 -0.045333
plotRollingMoments(data = rollMomentsenergy.ls, commo = "gasoline", statistic = "skew")
tail(rollMomentsenergy.ls[["gasoline"]][["kurt"]])
## kurthat.lower kurthat kurthat.upper
## 2011(12) -0.3900 1.837 4.063
## 2011(13) -0.4243 1.601 3.627
## 2011(14) -0.2780 1.601 3.481
## 2011(15) -0.3358 1.542 3.419
## 2011(16) -0.3483 1.504 3.356
## 2011(17) -0.3976 1.588 3.573
plotRollingMoments(data = rollMomentsenergy.ls, commo = "gasoline", statistic = "kurt")
mu95CI(energy.z, "heating")
## muhat standard error lower bound upper bound
## [1,] 0.001566 0.001433 -0.0013 0.004433
sd95CI(energy.z, "heating")
## sdhat standard error lower bound upper bound
## [1,] 0.0445 0.001297 0.04191 0.04709
skew95CI(returns.df, "heating")
## skewhat standard error lower bound upper bound
## [1,] -0.3483 0.169 -0.6863 -0.0104
kurt95CI(returns.df, "heating")
## kurthat standard error lower bound upper bound
## [1,] 1.559 0.5963 0.3664 2.752
head(rollMomentsenergy.ls[["heating"]][["mu"]])
## muhat.lower muhat muhat.upper
## 1993(41) -0.2590 -0.20 -0.1410
## 1993(42) -0.2983 -0.24 -0.1817
## 1993(43) -0.3187 -0.26 -0.2013
## 1993(44) -0.2875 -0.23 -0.1725
## 1993(45) -0.2980 -0.24 -0.1820
## 1993(46) -0.2571 -0.20 -0.1429
plotRollingMoments(data = rollMomentsenergy.ls, commo = "heating", statistic = "mu")
head(rollMomentsenergy.ls[["heating"]][["sd"]])
## sdhat.lower sdhat sdhat.upper
## 1993(41) 0.2058 0.2128 0.2198
## 1993(42) 0.2032 0.2101 0.2170
## 1993(43) 0.2047 0.2116 0.2184
## 1993(44) 0.2004 0.2071 0.2139
## 1993(45) 0.2020 0.2091 0.2163
## 1993(46) 0.1991 0.2060 0.2129
plotRollingMoments(data = rollMomentsenergy.ls, commo = "heating", statistic = "sd")
head(rollMomentsenergy.ls[["heating"]][["skew"]])
## skewhat.lower skewhat skewhat.upper
## 1993(41) -0.11553 0.5525 1.221
## 1993(42) -0.14099 0.6233 1.388
## 1993(43) -0.04607 0.6374 1.321
## 1993(44) -0.06649 0.6916 1.450
## 1993(45) -0.09261 0.6519 1.396
## 1993(46) -0.07471 0.6378 1.350
plotRollingMoments(data = rollMomentsenergy.ls, commo = "heating", statistic = "skew")
head(rollMomentsenergy.ls[["heating"]][["kurt"]])
## kurthat.lower kurthat kurthat.upper
## 1993(41) -0.6487 0.7416 2.132
## 1993(42) -0.5331 0.9669 2.467
## 1993(43) -0.6207 0.9017 2.424
## 1993(44) -0.5510 1.0684 2.688
## 1993(45) -0.6173 1.0102 2.638
## 1993(46) -0.4145 1.1361 2.687
plotRollingMoments(data = rollMomentsenergy.ls, commo = "heating", statistic = "kurt")
mu95CI(energy.z, "natural")
## muhat standard error lower bound upper bound
## [1,] -0.003102 0.002094 -0.007289 0.001085
sd95CI(energy.z, "natural")
## sdhat standard error lower bound upper bound
## [1,] 0.065 0.001774 0.06145 0.06855
skew95CI(returns.df, "natural")
## skewhat standard error lower bound upper bound
## [1,] -0.07297 0.1311 -0.3352 0.1893
kurt95CI(returns.df, "natural")
## kurthat standard error lower bound upper bound
## [1,] 0.9401 0.2883 0.3634 1.517
head(rollMomentsenergy.ls[["natural"]][["mu"]])
## muhat.lower muhat muhat.upper
## 1993(41) 0.1219 0.21 0.2981
## 1993(42) 0.1219 0.21 0.2981
## 1993(43) 0.1020 0.19 0.2780
## 1993(44) 0.1222 0.21 0.2978
## 1993(45) 0.1624 0.25 0.3376
## 1993(46) 0.1723 0.26 0.3477
plotRollingMoments(data = rollMomentsenergy.ls, commo = "natural", statistic = "mu")
head(rollMomentsenergy.ls[["natural"]][["sd"]])
## sdhat.lower sdhat sdhat.upper
## 1993(41) 0.3105 0.3178 0.3251
## 1993(42) 0.3105 0.3178 0.3251
## 1993(43) 0.3097 0.3174 0.3251
## 1993(44) 0.3092 0.3165 0.3238
## 1993(45) 0.3085 0.3159 0.3233
## 1993(46) 0.3087 0.3163 0.3239
plotRollingMoments(data = rollMomentsenergy.ls, commo = "natural", statistic = "sd")
head(rollMomentsenergy.ls[["natural"]][["skew"]])
## skewhat.lower skewhat skewhat.upper
## 1993(41) -0.5181 -0.03897 0.4402
## 1993(42) -0.5037 -0.03897 0.4258
## 1993(43) -0.4789 -0.01361 0.4517
## 1993(44) -0.5208 -0.03718 0.4465
## 1993(45) -0.5537 -0.08634 0.3810
## 1993(46) -0.5686 -0.09857 0.3715
plotRollingMoments(data = rollMomentsenergy.ls, commo = "natural", statistic = "skew")
head(rollMomentsenergy.ls[["natural"]][["kurt"]])
## kurthat.lower kurthat kurthat.upper
## 1993(41) -1.271 -0.5628 0.1452
## 1993(42) -1.304 -0.5628 0.1788
## 1993(43) -1.254 -0.5519 0.1506
## 1993(44) -1.301 -0.5251 0.2505
## 1993(45) -1.249 -0.5044 0.2400
## 1993(46) -1.266 -0.5128 0.2410
plotRollingMoments(data = rollMomentsenergy.ls, commo = "natural", statistic = "kurt")
mu95CI(energy.z, "electricity")
## muhat standard error lower bound upper bound
## [1,] -0.001929 0.001232 -0.004393 0.000534
sd95CI(energy.z, "electricity")
## sdhat standard error lower bound upper bound
## [1,] 0.03824 0.001817 0.03461 0.04188
skew95CI(returns.df, "electricity")
## skewhat standard error lower bound upper bound
## [1,] -0.2474 0.3272 -0.9018 0.4069
kurt95CI(returns.df, "electricity")
## kurthat standard error lower bound upper bound
## [1,] 6.691 0.85 4.991 8.391
head(rollMomentsenergy.ls[["electricity"]][["mu"]])
## muhat.lower muhat muhat.upper
## 1993(41) 0 0 0
## 1993(42) 0 0 0
## 1993(43) 0 0 0
## 1993(44) 0 0 0
## 1993(45) 0 0 0
## 1993(46) 0 0 0
plotRollingMoments(data = rollMomentsenergy.ls, commo = "electricity",
statistic = "mu")
head(rollMomentsenergy.ls[["electricity"]][["sd"]])
## sdhat.lower sdhat sdhat.upper
## 1993(41) 0 0 0
## 1993(42) 0 0 0
## 1993(43) 0 0 0
## 1993(44) 0 0 0
## 1993(45) 0 0 0
## 1993(46) 0 0 0
plotRollingMoments(data = rollMomentsenergy.ls, commo = "electricity",
statistic = "sd")
head(rollMomentsenergy.ls[["electricity"]][["skew"]])
## skewhat.lower skewhat skewhat.upper
## 1993(41) NaN NaN NaN
## 1993(42) NaN NaN NaN
## 1993(43) NaN NaN NaN
## 1993(44) NaN NaN NaN
## 1993(45) NaN NaN NaN
## 1993(46) NaN NaN NaN
plotRollingMoments(data = rollMomentsenergy.ls, commo = "electricity",
statistic = "skew")
head(rollMomentsenergy.ls[["electricity"]][["kurt"]])
## kurthat.lower kurthat kurthat.upper
## 1993(41) NaN NaN NaN
## 1993(42) NaN NaN NaN
## 1993(43) NaN NaN NaN
## 1993(44) NaN NaN NaN
## 1993(45) NaN NaN NaN
## 1993(46) NaN NaN NaN
plotRollingMoments(data = rollMomentsenergy.ls, commo = "electricity",
statistic = "kurt")