metals

get started

load libraries

options(digits = 4, width = 70)
library(boot)
library(tseries)
library(zoo)
library(PerformanceAnalytics)
library(multicore)

load data

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)
metals.z = returns.z[, c("copper", "gold", "palladium", "platinum", "silver")]

load functions

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/")

metals distributions:

rolling estimates

rollMomentsmetals.ls = rollingMoments.fun(metals.z, startYear = 1992, startWeek = 41, 
    width = 52)

copper

summary

plot of chunk copper distribution summary

moments

mean (\( \widehat{\mu} \)) and 95% confidence interval:

mu95CI(metals.z, "copper")
##         muhat standard error lower bound upper bound
## [1,] 0.001712        0.00121   -0.000709    0.004132

standard deviation (\( \widehat{\sigma} \)) and 95% confidence interval:

sd95CI(metals.z, "copper")
##        sdhat standard error lower bound upper bound
## [1,] 0.03758       0.001489      0.0346     0.04056

coeffciient of skweness (\( \widehat{\gamma}_{1} \)) and 95% confidence interval:

skew95CI(returns.df, "copper")
##      skewhat standard error lower bound upper bound
## [1,] -0.8038           0.31      -1.424     -0.1838

coefficient of kurtosis (\( \widehat{\beta}_{2} \)) and 95% confidence interval:

kurt95CI(returns.df, "copper")
##      kurthat standard error lower bound upper bound
## [1,]    4.11          1.836      0.4383       7.781

rolling moments

rolling \( \widehat{\mu} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["copper"]][["mu"]])
##          muhat.lower muhat muhat.upper
## 1993(41)     -0.4411 -0.38     -0.3189
## 1993(42)     -0.4411 -0.38     -0.3189
## 1993(43)     -0.4210 -0.36     -0.2990
## 1993(44)     -0.4414 -0.38     -0.3186
## 1993(45)     -0.4609 -0.40     -0.3391
## 1993(46)     -0.3902 -0.33     -0.2698
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "copper", statistic = "mu")

plot of chunk copper rolling mu plot

rolling \( \widehat{\sigma} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["copper"]][["sd"]])
##          sdhat.lower  sdhat sdhat.upper
## 1993(41)      0.2138 0.2204      0.2269
## 1993(42)      0.2138 0.2204      0.2269
## 1993(43)      0.2136 0.2201      0.2266
## 1993(44)      0.2147 0.2213      0.2278
## 1993(45)      0.2132 0.2197      0.2261
## 1993(46)      0.2104 0.2171      0.2237
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "copper", statistic = "sd")

plot of chunk copper rolling sd plot

rolling \( \widehat{\gamma}_{1} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["copper"]][["skew"]])
##          skewhat.lower skewhat skewhat.upper
## 1993(41)        -1.338 -0.8241       -0.3104
## 1993(42)        -1.360 -0.8241       -0.2885
## 1993(43)        -1.410 -0.8636       -0.3171
## 1993(44)        -1.355 -0.8201       -0.2848
## 1993(45)        -1.360 -0.8141       -0.2680
## 1993(46)        -1.480 -0.9090       -0.3376
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "copper", statistic = "skew")

plot of chunk copper rolling skew plot

rolling \( \widehat{\beta}_{2} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["copper"]][["kurt"]])
##          kurthat.lower kurthat kurthat.upper
## 1993(41)       -1.0287  0.3768         1.782
## 1993(42)       -1.0936  0.3768         1.847
## 1993(43)       -1.0557  0.4356         1.927
## 1993(44)       -1.1519  0.3262         1.804
## 1993(45)       -1.0529  0.3700         1.793
## 1993(46)       -0.9015  0.6232         2.148
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "copper", statistic = "kurt")

plot of chunk copper rolling kurt plot

gold

summary

plot of chunk gold distribution summary

moments

mean (\( \widehat{\mu} \)) and 95% confidence interval:

mu95CI(metals.z, "gold")
##          muhat standard error lower bound upper bound
## [1,] 0.0005705      0.0007311  -0.0008916    0.002033

standard deviation (\( \widehat{\sigma} \)) and 95% confidence interval:

sd95CI(metals.z, "gold")
##       sdhat standard error lower bound upper bound
## [1,] 0.0227      0.0008101     0.02108     0.02432

coeffciient of skweness (\( \widehat{\gamma}_{1} \)) and 95% confidence interval:

skew95CI(returns.df, "gold")
##       skewhat standard error lower bound upper bound
## [1,] -0.06684         0.2566     -0.5801      0.4464

coefficient of kurtosis (\( \widehat{\beta}_{2} \)) and 95% confidence interval:

kurt95CI(returns.df, "gold")
##      kurthat standard error lower bound upper bound
## [1,]   3.064         0.7164       1.632       4.497

rolling moments

rolling \( \widehat{\mu} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["gold"]][["mu"]])
##          muhat.lower      muhat muhat.upper
## 1993(41)   -0.077121 -4.000e-02   -0.002879
## 1993(42)   -0.077121 -4.000e-02   -0.002879
## 1993(43)   -0.046834 -1.000e-02    0.026834
## 1993(44)   -0.036942 -3.454e-18    0.036942
## 1993(45)   -0.026834  1.000e-02    0.046834
## 1993(46)    0.002879  4.000e-02    0.077121
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "gold", statistic = "mu")

plot of chunk gold rolling mu plot

rolling \( \widehat{\sigma} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["gold"]][["sd"]])
##          sdhat.lower  sdhat sdhat.upper
## 1993(41)      0.1273 0.1338      0.1404
## 1993(42)      0.1267 0.1338      0.1410
## 1993(43)      0.1259 0.1328      0.1397
## 1993(44)      0.1262 0.1332      0.1402
## 1993(45)      0.1257 0.1328      0.1399
## 1993(46)      0.1265 0.1338      0.1412
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "gold", statistic = "sd")

plot of chunk gold rolling sd plot

rolling \( \widehat{\gamma}_{1} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["gold"]][["skew"]])
##          skewhat.lower skewhat skewhat.upper
## 1993(41)        -3.128  -1.262        0.6052
## 1993(42)        -3.105  -1.262        0.5819
## 1993(43)        -3.273  -1.360        0.5534
## 1993(44)        -3.273  -1.376        0.5211
## 1993(45)        -3.323  -1.417        0.4890
## 1993(46)        -3.336  -1.451        0.4340
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "gold", statistic = "skew")

plot of chunk gold rolling skew plot

rolling \( \widehat{\beta}_{2} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["gold"]][["kurt"]])
##          kurthat.lower kurthat kurthat.upper
## 1993(41)       -0.2323   5.282         10.80
## 1993(42)       -0.1506   5.282         10.71
## 1993(43)       -0.1489   5.688         11.53
## 1993(44)       -0.2217   5.646         11.51
## 1993(45)       -0.2368   5.806         11.85
## 1993(46)       -0.1324   5.736         11.60
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "gold", statistic = "kurt")

plot of chunk gold rolling kurt plot

palladium

summary

plot of chunk palladium distribution summary

moments

mean (\( \widehat{\mu} \)) and 95% confidence interval:

mu95CI(metals.z, "palladium")
##         muhat standard error lower bound upper bound
## [1,] 0.002002       0.001557   -0.001113    0.005117

standard deviation (\( \widehat{\sigma} \)) and 95% confidence interval:

sd95CI(metals.z, "palladium")
##        sdhat standard error lower bound upper bound
## [1,] 0.04835       0.001776      0.0448      0.0519

coeffciient of skweness (\( \widehat{\gamma}_{1} \)) and 95% confidence interval:

skew95CI(returns.df, "palladium")
##      skewhat standard error lower bound upper bound
## [1,] -0.1449         0.2564     -0.6577      0.3679

coefficient of kurtosis (\( \widehat{\beta}_{2} \)) and 95% confidence interval

kurt95CI(returns.df, "palladium")
##      kurthat standard error lower bound upper bound
## [1,]   3.145         0.9019       1.341       4.948

rolling moments

rolling \( \widehat{\mu} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["palladium"]][["mu"]])
##          muhat.lower muhat muhat.upper
## 1993(41)      0.2643  0.34      0.4157
## 1993(42)      0.2843  0.36      0.4357
## 1993(43)      0.3242  0.40      0.4758
## 1993(44)      0.3141  0.39      0.4659
## 1993(45)      0.3040  0.38      0.4560
## 1993(46)      0.2841  0.36      0.4359
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "palladium", statistic = "mu")

plot of chunk palladium rolling mu plot

rolling \( \widehat{\sigma} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["palladium"]][["sd"]])
##          sdhat.lower  sdhat sdhat.upper
## 1993(41)      0.2629 0.2728      0.2827
## 1993(42)      0.2628 0.2730      0.2832
## 1993(43)      0.2634 0.2734      0.2834
## 1993(44)      0.2638 0.2735      0.2832
## 1993(45)      0.2647 0.2740      0.2832
## 1993(46)      0.2642 0.2738      0.2833
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "palladium", statistic = "sd")

plot of chunk palladium rolling sd plot

rolling \( \widehat{\gamma}_{1} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["palladium"]][["skew"]])
##          skewhat.lower skewhat skewhat.upper
## 1993(41)        -1.334 -0.3255        0.6830
## 1993(42)        -1.370 -0.3545        0.6615
## 1993(43)        -1.371 -0.4081        0.5548
## 1993(44)        -1.378 -0.3925        0.5933
## 1993(45)        -1.398 -0.3770        0.6443
## 1993(46)        -1.330 -0.3481        0.6342
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "palladium", statistic = "skew")

plot of chunk palladium rolling skew plot

rolling \( \widehat{\beta}_{2} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["palladium"]][["kurt"]])
##          kurthat.lower kurthat kurthat.upper
## 1993(41)       -0.4518   1.477         3.406
## 1993(42)       -0.3505   1.475         3.301
## 1993(43)       -0.4114   1.482         3.375
## 1993(44)       -0.4433   1.467         3.378
## 1993(45)       -0.3245   1.430         3.185
## 1993(46)       -0.3126   1.429         3.171
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "palladium", statistic = "kurt")

plot of chunk palladium rolling kurt plot

platinum

summary

plot of chunk platinum distribution summary

moments

mean (\( \widehat{\mu} \)) and 95% confidence interval:

mu95CI(metals.z, "platinum")
##         muhat standard error lower bound upper bound
## [1,] 0.001774      0.0009631  -0.0001523      0.0037

standard deviation (\( \widehat{\sigma} \)) and 95% confidence interval:

sd95CI(metals.z, "platinum")
##       sdhat standard error lower bound upper bound
## [1,] 0.0299       0.001116     0.02767     0.03214

coeffciient of skweness (\( \widehat{\gamma}_{1} \)) and 95% confidence interval:

skew95CI(returns.df, "platinum")
##      skewhat standard error lower bound upper bound
## [1,] -0.5344          0.205     -0.9443     -0.1245

coefficient of kurtosis (\( \widehat{\beta}_{2} \)) and 95% confidence interval:

kurt95CI(returns.df, "platinum")
##      kurthat standard error lower bound upper bound
## [1,]   3.083         0.5223       2.038       4.127

rolling moments

rolling \( \widehat{\mu} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["platinum"]][["mu"]])
##          muhat.lower muhat muhat.upper
## 1993(41)   -0.035416  0.01     0.05542
## 1993(42)   -0.005131  0.04     0.08513
## 1993(43)    0.004797  0.05     0.09520
## 1993(44)    0.024491  0.07     0.11551
## 1993(45)    0.024491  0.07     0.11551
## 1993(46)    0.014902  0.06     0.10510
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "platinum", statistic = "mu")

plot of chunk platinum rolling mu plot

rolling \( \widehat{\sigma} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["platinum"]][["sd"]])
##          sdhat.lower  sdhat sdhat.upper
## 1993(41)      0.1579 0.1637      0.1696
## 1993(42)      0.1568 0.1627      0.1686
## 1993(43)      0.1571 0.1630      0.1689
## 1993(44)      0.1580 0.1641      0.1702
## 1993(45)      0.1579 0.1641      0.1703
## 1993(46)      0.1565 0.1626      0.1688
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "platinum", statistic = "sd")

plot of chunk platinum rolling sd plot

rolling \( \widehat{\gamma}_{1} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["platinum"]][["skew"]])
##          skewhat.lower skewhat skewhat.upper
## 1993(41)        -1.790 -0.8863       0.01744
## 1993(42)        -1.875 -0.9649      -0.05472
## 1993(43)        -1.894 -0.9847      -0.07494
## 1993(44)        -1.859 -1.0046      -0.14992
## 1993(45)        -1.895 -1.0046      -0.11423
## 1993(46)        -1.953 -1.0359      -0.11869
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "platinum", statistic = "skew")

plot of chunk platinum rolling skew plot

rolling \( \widehat{\beta}_{2} \) and 95% confidence interval:

time series overview
head(rollMomentsmetals.ls[["platinum"]][["kurt"]])
##          kurthat.lower kurthat kurthat.upper
## 1993(41)        -1.208   1.477         4.163
## 1993(42)        -1.128   1.675         4.478
## 1993(43)        -1.223   1.679         4.582
## 1993(44)        -1.184   1.631         4.447
## 1993(45)        -1.228   1.631         4.491
## 1993(46)        -1.126   1.724         4.574
plot
plotRollingMoments(data = rollMomentsmetals.ls, commo = "platinum", statistic = "kurt")

plot of chunk platinum rolling kurt plot

silver

summary

plot of chunk silver distribution summary

moments

mean (\( \widehat{\mu} \)) and 95% confidence interval:

mu95CI(metals.z, "silver")
##         muhat standard error lower bound upper bound
## [1,] 0.001577       0.001295   -0.001013    0.004167

standard deviation (\( \widehat{\sigma} \)) and 95% confidence interval:

sd95CI(metals.z, "silver")
##        sdhat standard error lower bound upper bound
## [1,] 0.04021       0.001386     0.03743     0.04298

coeffciient of skweness (\( \widehat{\gamma}_{1} \)) and 95% confidence interval:

skew95CI(returns.df, "silver")
##      skewhat standard error lower bound upper bound
## [1,] -0.6952         0.1804      -1.056     -0.3343

coefficient of kurtosis (\( \widehat{\beta}_{2} \)) and 95% confidence interval:

kurt95CI(returns.df, "silver")
##      kurthat standard error lower bound upper bound
## [1,]   2.829         0.5792        1.67       3.987