R: Compute variance covariance of Inverse 'Unified' Second...
ism_vcov
R Documentation
Compute variance covariance of Inverse 'Unified' Second Moment
Description
Computes the variance covariance matrix of the inverse unified
second moment matrix.
Usage
ism_vcov(X,vcov.func=vcov,fit.intercept=TRUE)
Arguments
X
an n x p matrix of observed returns.
vcov.func
a function which takes an object of class lm,
and computes a variance-covariance matrix. If equal to the string
"normal", we assume multivariate normal returns.
fit.intercept
a boolean controlling whether we add a column
of ones to the data, or fit the raw uncentered second moment.
Details
Given p-vector x with mean mu and
covariance, Sigma, let y be x
with a one prepended. Then let
Theta = E[yy'],
the uncentered second moment matrix. The inverse of
Theta contains the (negative) Markowitz portfolio
and the precision matrix.
Given n contemporaneous observations of p-vectors,
stacked as rows in the n x p matrix X,
this function estimates the mean and the asymptotic
variance-covariance matrix of Theta^-1.
One may use the default method for computing covariance,
via the vcov function, or via a 'fancy' estimator,
like sandwich:vcovHAC, sandwich:vcovHC, etc.
Value
a list containing the following components:
mu
a q = p(p+3)/2 vector of the negative Markowitz
portfolio, then the vech'd precision matrix of the sample data
Ohat
the q x q estimated variance
covariance matrix.
n
the number of rows in X.
p
the number of assets.
Note
By flipping the sign of X, the inverse of
Theta contains the positive Markowitz
portfolio and the precision matrix on X. Performing
this transform before passing the data to this function
should be considered idiomatic.
This function will be deprecated in future releases of this package.
Users should migrate at that time to a similar function in the
MarkowitzR package.
X <- matrix(rnorm(1000*3),ncol=3)
# putting in -X is idiomatic:
ism <- ism_vcov(-X)
iSigmas.n <- ism_vcov(-X,vcov.func="normal")
iSigmas.n <- ism_vcov(-X,fit.intercept=FALSE)
# compute the marginal Wald test statistics:
ism.mu <- ism$mu[1:ism$p]
ism.Sg <- ism$Ohat[1:ism$p,1:ism$p]
wald.stats <- ism.mu / sqrt(diag(ism.Sg))
# make it fat tailed:
X <- matrix(rt(1000*3,df=5),ncol=3)
ism <- ism_vcov(X)
wald.stats <- ism$mu[1:ism$p] / sqrt(diag(ism$Ohat[1:ism$p,1:ism$p]))
## Not run:
if (require(sandwich)) {
ism <- ism_vcov(X,vcov.func=vcovHC)
wald.stats <- ism$mu[1:ism$p] / sqrt(diag(ism$Ohat[1:ism$p,1:ism$p]))
}
## End(Not run)
# add some autocorrelation to X
Xf <- filter(X,c(0.2),"recursive")
colnames(Xf) <- colnames(X)
ism <- ism_vcov(Xf)
wald.stats <- ism$mu[1:ism$p] / sqrt(diag(ism$Ohat[1:ism$p,1:ism$p]))
## Not run:
if (require(sandwich)) {
ism <- ism_vcov(Xf,vcov.func=vcovHAC)
wald.stats <- ism$mu[1:ism$p] / sqrt(diag(ism$Ohat[1:ism$p,1:ism$p]))
}
## End(Not run)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(SharpeR)
Attaching package: 'SharpeR'
The following object is masked from 'package:base':
summary
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/SharpeR/ism_vcov.Rd_%03d_medium.png", width=480, height=480)
> ### Name: ism_vcov
> ### Title: Compute variance covariance of Inverse 'Unified' Second Moment
> ### Aliases: ism_vcov
> ### Keywords: univar
>
> ### ** Examples
>
> X <- matrix(rnorm(1000*3),ncol=3)
> # putting in -X is idiomatic:
> ism <- ism_vcov(-X)
> iSigmas.n <- ism_vcov(-X,vcov.func="normal")
> iSigmas.n <- ism_vcov(-X,fit.intercept=FALSE)
> # compute the marginal Wald test statistics:
> ism.mu <- ism$mu[1:ism$p]
> ism.Sg <- ism$Ohat[1:ism$p,1:ism$p]
> wald.stats <- ism.mu / sqrt(diag(ism.Sg))
>
> # make it fat tailed:
> X <- matrix(rt(1000*3,df=5),ncol=3)
> ism <- ism_vcov(X)
> wald.stats <- ism$mu[1:ism$p] / sqrt(diag(ism$Ohat[1:ism$p,1:ism$p]))
> ## Not run:
> ##D if (require(sandwich)) {
> ##D ism <- ism_vcov(X,vcov.func=vcovHC)
> ##D wald.stats <- ism$mu[1:ism$p] / sqrt(diag(ism$Ohat[1:ism$p,1:ism$p]))
> ##D }
> ## End(Not run)
> # add some autocorrelation to X
> Xf <- filter(X,c(0.2),"recursive")
> colnames(Xf) <- colnames(X)
> ism <- ism_vcov(Xf)
> wald.stats <- ism$mu[1:ism$p] / sqrt(diag(ism$Ohat[1:ism$p,1:ism$p]))
> ## Not run:
> ##D if (require(sandwich)) {
> ##D ism <- ism_vcov(Xf,vcov.func=vcovHAC)
> ##D wald.stats <- ism$mu[1:ism$p] / sqrt(diag(ism$Ohat[1:ism$p,1:ism$p]))
> ##D }
> ## End(Not run)
>
>
>
>
>
>
> dev.off()
null device
1
>