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)
live.z = returns.z[, c("feeder", "live", "pork", "hogs")]
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/")
rollMomentslive.ls = rollingMoments.fun(live.z, startYear = 1992, startWeek = 41,
width = 52)
mu95CI(live.z, "feeder")
## muhat standard error lower bound upper bound
## [1,] 0.0005394 0.0006583 -0.0007772 0.001856
sd95CI(live.z, "feeder")
## sdhat standard error lower bound upper bound
## [1,] 0.02044 0.0005952 0.01925 0.02163
skew95CI(returns.df, "feeder")
## skewhat standard error lower bound upper bound
## [1,] -0.2466 0.1411 -0.5289 0.03557
kurt95CI(returns.df, "feeder")
## kurthat standard error lower bound upper bound
## [1,] 1.204 0.4156 0.3727 2.035
head(rollMomentslive.ls[["feeder"]][["mu"]])
## muhat.lower muhat muhat.upper
## 1993(41) 0.11827 0.14 0.1617
## 1993(42) 0.10764 0.13 0.1524
## 1993(43) 0.11721 0.14 0.1628
## 1993(44) 0.11721 0.14 0.1628
## 1993(45) 0.11721 0.14 0.1628
## 1993(46) 0.09636 0.12 0.1436
plotRollingMoments(data = rollMomentslive.ls, commo = "feeder", statistic = "mu")
head(rollMomentslive.ls[["feeder"]][["sd"]])
## sdhat.lower sdhat sdhat.upper
## 1993(41) 0.07651 0.07837 0.08022
## 1993(42) 0.07866 0.08062 0.08258
## 1993(43) 0.08022 0.08218 0.08413
## 1993(44) 0.08029 0.08218 0.08406
## 1993(45) 0.08026 0.08218 0.08410
## 1993(46) 0.08340 0.08522 0.08704
plotRollingMoments(data = rollMomentslive.ls, commo = "feeder", statistic = "sd")
head(rollMomentslive.ls[["feeder"]][["skew"]])
## skewhat.lower skewhat skewhat.upper
## 1993(41) -0.5905 -0.1799 0.2307
## 1993(42) -0.6394 -0.2497 0.1400
## 1993(43) -0.6069 -0.2209 0.1651
## 1993(44) -0.5974 -0.2209 0.1557
## 1993(45) -0.6101 -0.2209 0.1683
## 1993(46) -0.6041 -0.2393 0.1255
plotRollingMoments(data = rollMomentslive.ls, commo = "feeder", statistic = "skew")
head(rollMomentslive.ls[["feeder"]][["kurt"]])
## kurthat.lower kurthat kurthat.upper
## 1993(41) -1.183 -0.5619 0.059219
## 1993(42) -1.161 -0.5367 0.087236
## 1993(43) -1.204 -0.5971 0.009402
## 1993(44) -1.208 -0.5971 0.014103
## 1993(45) -1.211 -0.5971 0.017309
## 1993(46) -1.295 -0.6888 -0.082323
plotRollingMoments(data = rollMomentslive.ls, commo = "feeder", statistic = "kurt")
mu95CI(live.z, "live")
## muhat standard error lower bound upper bound
## [1,] 7.261e-05 0.0006881 -0.001304 0.001449
sd95CI(live.z, "live")
## sdhat standard error lower bound upper bound
## [1,] 0.02136 0.00081 0.01974 0.02298
skew95CI(returns.df, "live")
## skewhat standard error lower bound upper bound
## [1,] -0.4091 0.3627 -1.135 0.3164
kurt95CI(returns.df, "live")
## kurthat standard error lower bound upper bound
## [1,] 3.596 2.438 -1.279 8.472
head(rollMomentslive.ls[["live"]][["mu"]])
## muhat.lower muhat muhat.upper
## 1993(41) 0.09961 0.13 0.1604
## 1993(42) 0.08916 0.12 0.1508
## 1993(43) 0.10829 0.14 0.1717
## 1993(44) 0.11848 0.15 0.1815
## 1993(45) 0.10829 0.14 0.1717
## 1993(46) 0.09810 0.13 0.1619
plotRollingMoments(data = rollMomentslive.ls, commo = "live", statistic = "mu")
head(rollMomentslive.ls[["live"]][["sd"]])
## sdhat.lower sdhat sdhat.upper
## 1993(41) 0.1068 0.1096 0.1124
## 1993(42) 0.1086 0.1112 0.1138
## 1993(43) 0.1117 0.1143 0.1170
## 1993(44) 0.1111 0.1136 0.1162
## 1993(45) 0.1118 0.1143 0.1169
## 1993(46) 0.1124 0.1150 0.1176
plotRollingMoments(data = rollMomentslive.ls, commo = "live", statistic = "sd")
head(rollMomentslive.ls[["live"]][["skew"]])
## skewhat.lower skewhat skewhat.upper
## 1993(41) -0.7188 -0.2603 0.1982
## 1993(42) -0.6830 -0.2624 0.1582
## 1993(43) -0.6091 -0.2115 0.1861
## 1993(44) -0.6578 -0.2421 0.1735
## 1993(45) -0.6417 -0.2115 0.2187
## 1993(46) -0.6118 -0.1811 0.2496
plotRollingMoments(data = rollMomentslive.ls, commo = "live", statistic = "skew")
head(rollMomentslive.ls[["live"]][["kurt"]])
## kurthat.lower kurthat kurthat.upper
## 1993(41) -1.103 -0.4243 0.253971
## 1993(42) -1.159 -0.5022 0.154021
## 1993(43) -1.122 -0.5655 -0.008972
## 1993(44) -1.152 -0.5026 0.146580
## 1993(45) -1.161 -0.5655 0.029911
## 1993(46) -1.184 -0.6239 -0.063518
plotRollingMoments(data = rollMomentslive.ls, commo = "live", statistic = "kurt")
mu95CI(live.z, "pork")
## muhat standard error lower bound upper bound
## [1,] 0.0004979 0.001541 -0.002583 0.003579
sd95CI(live.z, "pork")
## sdhat standard error lower bound upper bound
## [1,] 0.04783 0.001411 0.04501 0.05065
skew95CI(returns.df, "pork")
## skewhat standard error lower bound upper bound
## [1,] 0.1826 0.1355 -0.08837 0.4536
kurt95CI(returns.df, "pork")
## kurthat standard error lower bound upper bound
## [1,] 1.25 0.3439 0.5622 1.938
head(rollMomentslive.ls[["pork"]][["mu"]])
## muhat.lower muhat muhat.upper
## 1993(41) 0.05782 0.16 0.2622
## 1993(42) 0.13623 0.24 0.3438
## 1993(43) 0.02888 0.13 0.2311
## 1993(44) 0.04877 0.15 0.2512
## 1993(45) 0.14906 0.25 0.3509
## 1993(46) 0.02507 0.13 0.2349
plotRollingMoments(data = rollMomentslive.ls, commo = "pork", statistic = "mu")
head(rollMomentslive.ls[["pork"]][["sd"]])
## sdhat.lower sdhat sdhat.upper
## 1993(41) 0.3567 0.3684 0.3801
## 1993(42) 0.3626 0.3741 0.3856
## 1993(43) 0.3526 0.3646 0.3766
## 1993(44) 0.3528 0.3650 0.3772
## 1993(45) 0.3521 0.3639 0.3757
## 1993(46) 0.3664 0.3783 0.3903
plotRollingMoments(data = rollMomentslive.ls, commo = "pork", statistic = "sd")
head(rollMomentslive.ls[["pork"]][["skew"]])
## skewhat.lower skewhat skewhat.upper
## 1993(41) -0.3386 0.4033 1.145
## 1993(42) -0.3718 0.3379 1.048
## 1993(43) -0.3720 0.3944 1.161
## 1993(44) -0.4415 0.3708 1.183
## 1993(45) -0.4984 0.2975 1.094
## 1993(46) -0.5083 0.2399 0.988
plotRollingMoments(data = rollMomentslive.ls, commo = "pork", statistic = "skew")
head(rollMomentslive.ls[["pork"]][["kurt"]])
## kurthat.lower kurthat kurthat.upper
## 1993(41) -0.5314 0.8377 2.207
## 1993(42) -0.5772 0.6168 1.811
## 1993(43) -0.4728 0.9052 2.283
## 1993(44) -0.4070 0.8763 2.160
## 1993(45) -0.4144 0.8587 2.132
## 1993(46) -0.5176 0.6533 1.824
plotRollingMoments(data = rollMomentslive.ls, commo = "pork", statistic = "kurt")
mu95CI(live.z, "hogs")
## muhat standard error lower bound upper bound
## [1,] -0.001193 0.001169 -0.00353 0.001144
sd95CI(live.z, "hogs")
## sdhat standard error lower bound upper bound
## [1,] 0.03628 0.001417 0.03345 0.03912
skew95CI(returns.df, "hogs")
## skewhat standard error lower bound upper bound
## [1,] -0.6328 0.3559 -1.345 0.07902
kurt95CI(returns.df, "hogs")
## kurthat standard error lower bound upper bound
## [1,] 3.955 2.266 -0.577 8.487
head(rollMomentslive.ls[["hogs"]][["mu"]])
## muhat.lower muhat muhat.upper
## 1993(41) 0.1526 0.20 0.2474
## 1993(42) 0.2017 0.25 0.2983
## 1993(43) 0.1713 0.22 0.2687
## 1993(44) 0.1404 0.19 0.2396
## 1993(45) 0.2017 0.25 0.2983
## 1993(46) 0.1502 0.20 0.2498
plotRollingMoments(data = rollMomentslive.ls, commo = "hogs", statistic = "mu")
head(rollMomentslive.ls[["hogs"]][["sd"]])
## sdhat.lower sdhat sdhat.upper
## 1993(41) 0.1656 0.1709 0.1761
## 1993(42) 0.1688 0.1740 0.1792
## 1993(43) 0.1705 0.1757 0.1808
## 1993(44) 0.1738 0.1789 0.1841
## 1993(45) 0.1691 0.1740 0.1789
## 1993(46) 0.1746 0.1796 0.1846
plotRollingMoments(data = rollMomentslive.ls, commo = "hogs", statistic = "sd")
head(rollMomentslive.ls[["hogs"]][["skew"]])
## skewhat.lower skewhat skewhat.upper
## 1993(41) -0.2464 0.5428 1.332
## 1993(42) -0.2501 0.4634 1.177
## 1993(43) -0.2224 0.5010 1.224
## 1993(44) -0.1693 0.4926 1.154
## 1993(45) -0.1939 0.5141 1.222
## 1993(46) -0.2174 0.4692 1.156
plotRollingMoments(data = rollMomentslive.ls, commo = "hogs", statistic = "skew")
head(rollMomentslive.ls[["hogs"]][["kurt"]])
## kurthat.lower kurthat kurthat.upper
## 1993(41) -1.273 0.5890 2.451
## 1993(42) -1.335 0.3500 2.035
## 1993(43) -1.418 0.2907 1.999
## 1993(44) -1.407 0.1721 1.752
## 1993(45) -1.439 0.2242 1.888
## 1993(46) -1.452 0.1158 1.684
plotRollingMoments(data = rollMomentslive.ls, commo = "hogs", statistic = "kurt")