[Gogarch-commits] r4 - in pkg: . R data man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 22 22:10:12 CET 2009


Author: bpfaff
Date: 2009-01-22 22:10:12 +0100 (Thu, 22 Jan 2009)
New Revision: 4

Added:
   pkg/DESCRIPTION
   pkg/NAMESPACE
   pkg/R/Rd2.R
   pkg/R/UprodR.R
   pkg/R/gollh.R
   pkg/R/orthom-class.R
   pkg/R/orthom-show.R
   pkg/R/unvech.R
   pkg/data/
   pkg/data/BVDW.rda
   pkg/data/VDW.rda
   pkg/man/BVDW.Rd
   pkg/man/Rd2.Rd
   pkg/man/UprodR.Rd
   pkg/man/VDW.Rd
   pkg/man/gollh.Rd
   pkg/man/orthom-class.Rd
   pkg/man/unvech.Rd
   pkg/man/validOrthomObject.Rd
Log:
Initial import of package


Added: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	                        (rev 0)
+++ pkg/DESCRIPTION	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,12 @@
+Package: gogarch
+Version: 0.0-4
+Type: Package
+Title: Generalized Orthogonal GARCH (GO-GARCH) models
+Date: 2009-01-22
+Author: Bernhard Pfaff
+Maintainer: Bernhard Pfaff <bernhard at pfaffikus.de>
+Depends: R (>= 2.7.0), methods, fGarch
+Description: Implementation of the GO-GARCH model class. 
+License: GPL (>= 2)
+LazyLoad: yes
+Packaged: Thu Jan 22 17:27:27 2009; pfaffb

Added: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE	                        (rev 0)
+++ pkg/NAMESPACE	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,11 @@
+##
+import(methods)
+
+## Functions
+export(gollh, Rd2, UprodR, unvech, validOrthomObject)
+
+## Classes       
+exportClasses("Orthom")
+
+## Methods
+exportMethods("show")

Added: pkg/R/Rd2.R
===================================================================
--- pkg/R/Rd2.R	                        (rev 0)
+++ pkg/R/Rd2.R	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,13 @@
+Rd2 <-
+function(theta){
+  theta <- as.vector(theta)
+  if(length(theta) > 1){
+    stop("\nLength of argument 'theta' should be one.\n")
+    }
+  if((theta <= 0) | (theta > pi/2)){
+    stop("\nTheta should be in the interval [0, pi/2).\n")
+  }
+  R <- matrix(c(cos(theta), sin(theta), -sin(theta), cos(theta)), ncol = 2, nrow = 2)
+  return(R)              
+}
+

Added: pkg/R/UprodR.R
===================================================================
--- pkg/R/UprodR.R	                        (rev 0)
+++ pkg/R/UprodR.R	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,22 @@
+UprodR <-
+function(theta){
+  theta <- as.vector(theta)
+  l <- length(theta)
+  d <- as.integer(0.5 + sqrt(0.5^2 + 2*l))  
+  if(l != d * (d - 1) / 2){
+    stop("\nLength of theta does not match implied dimension of U.\n")
+  }
+  Id <- diag(d)
+  U <- Id
+  rc <- combn(x = d, m = 2)
+  idx <- seq(along.with = theta)
+  Rs <- lapply(idx, function(x){
+    tmp <- Id
+    tmp[rc[, x], rc[, x]] <- Rd2(theta = theta[x])
+    return(tmp)
+  })
+  for(i in 1:l) U <- U %*% Rs[[i]]
+  result <- new("Orthom", M = U)
+  return(result)
+}
+

Added: pkg/R/gollh.R
===================================================================
--- pkg/R/gollh.R	                        (rev 0)
+++ pkg/R/gollh.R	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,22 @@
+gollh <-
+function(params, X, P, Dsqr, m, n, formula = ~ garch(1,1), garchlist = list(
+         init.rec = "mci", delta = 2, skew = 1, shape = 4, cond.dist = "norm",
+         include.mean = FALSE, include.delta = NULL, include.skew = NULL,
+         include.shape = NULL, leverage = NULL, trace = FALSE,
+         algorithm = "nlminb", hessian = "ropt", control = list(),
+         title = NULL, description = NULL)){
+  U <- UprodR(params)
+  Z <- P %*% Dsqr %*% t(U)
+  Zinv <- solve(Z)
+  Y <- X %*% Zinv
+  fitted <- apply(Y, 2, function(x) garchFit(formula = formula, data = x, include.mean = FALSE, trace = FALSE))
+  H <- matrix(unlist(lapply(fitted, function(x) x at h.t)), ncol = m, nrow = n)
+  Hinv <- 1.0 / H
+  arg1 <- n * m * log(2 * pi)
+  arg2 <- log(det(Z %*% t(Z))) * n
+  arg3 <- sum(log(apply(H, 1, prod)))
+  arg4 <- sum(rowSums(Y * Hinv * Y))
+  ll <- -0.5 * (arg1 + arg2 + arg3 + arg4)
+  negll <- -1.0 * ll
+  return(negll)
+}

Added: pkg/R/orthom-class.R
===================================================================
--- pkg/R/orthom-class.R	                        (rev 0)
+++ pkg/R/orthom-class.R	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,29 @@
+##
+## Class definition of orthogonal matrices
+##
+setClass("Orthom", representation(M = "matrix"))
+##
+## Validity function for objects of class Orthom
+##
+validOrthomObject <- function(object){
+  m <- nrow(object at M)
+  if(all.equal(diff(dim(object at M)), 0, check.attributes = FALSE)){
+    TRUE
+  } else {
+    stop("\nObject is not a square matrix.\n")
+  }
+  if(all.equal(det(object at M), 1, check.attributes = FALSE)){
+    TRUE
+  } else {
+    stop("\nDeterminant of object is not equal to 1.\n")
+  }
+  if(all.equal(crossprod(object at M), diag(m), check.attributes = FALSE)){
+    TRUE
+  } else {
+    stop("\nThe cross product of the object is not the Identity matrix.\n")
+  }
+}
+##
+## Setting validOrthomObject() as validity function
+##
+setValidity("Orthom", validOrthomObject)

Added: pkg/R/orthom-show.R
===================================================================
--- pkg/R/orthom-show.R	                        (rev 0)
+++ pkg/R/orthom-show.R	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,4 @@
+##
+## show-method for objects of class orthom
+##
+setMethod("show", "Orthom", function(object) print(object at M))

Added: pkg/R/unvech.R
===================================================================
--- pkg/R/unvech.R	                        (rev 0)
+++ pkg/R/unvech.R	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,14 @@
+unvech <-
+function(v){
+  v <- as.vector(v)
+  l <- length(v)
+  n <- -(1 - sqrt(1 + 8 * l)) / 2
+  if(n %% 1 != 0.0){
+    stop("\nCannot produce symmetric matrix, check length of v.\n")
+  }
+  X <- matrix(NA, ncol = n, nrow = n)
+  X[lower.tri(X, diag = TRUE)] <- v
+  X[upper.tri(X)] <- X[lower.tri(X)]
+  return(X)
+}
+

Added: pkg/data/BVDW.rda
===================================================================
(Binary files differ)


Property changes on: pkg/data/BVDW.rda
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: pkg/data/VDW.rda
===================================================================
(Binary files differ)


Property changes on: pkg/data/VDW.rda
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: pkg/man/BVDW.Rd
===================================================================
--- pkg/man/BVDW.Rd	                        (rev 0)
+++ pkg/man/BVDW.Rd	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,52 @@
+\name{BVDW}
+
+\alias{BVDW}
+
+\encoding{latin1}
+
+\docType{data}
+
+\title{
+Dow Jones Industrial Average and Nasdaq stock indices
+}
+
+\description{
+  Levels of the Dow Jones Industrial Average and NASDAQ stock indices
+  for the period 03/23/1990 until 03/23/2000.
+}
+
+\usage{data(BVDW)}
+\format{
+  A data frame with 2610 observations on the following 3 variables.
+  \describe{
+    \item{\code{Date}}{Date in the format YYYYMMDD.}
+    \item{\code{DJIA}}{Level of the DIJA.}
+    \item{\code{NASDAQ}}{Level of the NASDAQ.}
+  }
+}
+
+\details{
+  This data set has been utilized in the source below and was kindly
+  provided by Roy van der Weide. 
+}
+
+\source{
+  Boswijk, H. Peter and van der Weide, Roy (2006), Wake me up before you
+  GO-GARCH, \emph{Tinbergen Institute Discussion Paper}, \bold{TI
+    2006-079/4}, University of Amsterdam and Tinbergen Institute.
+}
+
+\references{
+  \url{http://www.nasdaq.com}, \url{http://www.djindexes.com}
+}
+
+\seealso{
+  \code{\link{VDW}}
+}
+
+\examples{
+data(BVDW)
+str(BVDW)
+}
+
+\keyword{datasets}

Added: pkg/man/Rd2.Rd
===================================================================
--- pkg/man/Rd2.Rd	                        (rev 0)
+++ pkg/man/Rd2.Rd	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,43 @@
+\name{Rd2}
+
+\alias{Rd2}
+
+\encoding{latin1}
+
+\title{
+  Rotation matrix, 2-dimensional
+}
+
+\description{
+  Given an angle \eqn{\theta} whereby \eqn{\theta \in [0, \pi/2)} the
+  function \code{Rd2} returns a 2-dimensional rotation matrix of Euler angles.  
+}
+
+\usage{
+Rd2(theta)
+}
+
+\arguments{
+  \item{theta}{Numeric, angle in the interval \eqn{[0, \pi/2)}.}
+}
+
+\value{
+  \item{R}{A 2-dimensional rotation matrix.}
+}
+
+\author{
+  Bernhard Pfaff
+}
+
+\seealso{
+  \code{\link{UprodR}}
+}
+
+\examples{
+Rd2(pi/3)
+}
+
+\keyword{algebra}
+\concept{Rotation Matrix}
+\concept{Euler angle}
+\concept{Euler angles}

Added: pkg/man/UprodR.Rd
===================================================================
--- pkg/man/UprodR.Rd	                        (rev 0)
+++ pkg/man/UprodR.Rd	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,50 @@
+\name{UprodR}
+
+\encoding{latin1}
+
+\alias{UprodR}
+
+\title{
+Creation of an orthogonal matrix
+}
+
+\description{
+This function returns an orthogonal matrix which results of the
+matrix products of rotation matrices. 
+}
+
+\usage{
+UprodR(theta)
+}
+
+\arguments{
+  \item{theta}{Vector, of angles of the rotation matrices.}
+}
+
+\details{
+  The length of \code{theta} must be equal to \eqn{m * (m - 1) / 2},
+  where \eqn{m} is the dimension of the orthogonal matrix. The elements
+  of \code{theta} must lie in the interval \eqn{[0, \pi/2)}. 
+}
+\value{
+  \item{result}{Object of class \code{Orthom}.}
+}
+\references{
+  Vilenkin, N. Ja. (1968), Special Functions and the Theory of Group
+  Representations, Translations of Mathematical Monographs, \bold{22},
+  American Math. Soc., Providence, Rhode Island, USA. 
+}
+
+\author{
+  Bernhard Pfaff
+}
+\seealso{
+  \code{\link{Rd2}}, \code{\linkS4class{Orthom}}
+}
+\examples{
+theta <- c(pi/3, pi/5, pi/7)
+U <- UprodR(theta)
+U
+}
+\keyword{algebra}
+\concept{Orthogonal Matrix}
\ No newline at end of file

Added: pkg/man/VDW.Rd
===================================================================
--- pkg/man/VDW.Rd	                        (rev 0)
+++ pkg/man/VDW.Rd	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,55 @@
+\name{VDW}
+
+\alias{VDW}
+
+\encoding{latin1}
+
+\docType{data}
+
+\title{
+  Dow Jones Industrial Average and Nasdaq stock indices
+}
+
+\description{
+  The daily (log) returns of the Dow Jones Industrial Average and the
+  NASDAQ composite, respectively. The daily observations start at the
+  first of January, 1990, and end in October 2001.
+}
+
+\usage{data(VDW)}
+
+\format{
+  A data frame with 3082 observations on the following 2 variables.
+  \describe{
+    \item{\code{DJIA}}{Log-return of Dow Jones Industrial Average.}
+    \item{\code{NASDAQ}}{Log-return of NASDAQ.}
+  }
+}
+
+\details{
+  This data set has been utilized in the source below and can be
+  downloaded from the web-site of the \emph{Journal of Applied
+    Econometrics} (see link below). 
+}
+
+\source{
+  Van der Weide, Roy (2002), GO-GARCH: A Multivariate Generalized
+  Orthogonal GARCH Model, \emph{Journal of Applied Econometrics},
+  \bold{17(5)}, 549 -- 564.
+}
+
+\references{
+  \url{http://www.nasdaq.com}, \url{http://www.djindexes.com} \\
+  \url{http://qed.econ.queensu.ca/jae/2002-v17.5/van_der_weide}
+}
+
+\seealso{
+  \code{\link{BVDW}}
+}
+
+\examples{
+data(VDW)
+str(VDW)
+}
+
+\keyword{datasets}

Added: pkg/man/gollh.Rd
===================================================================
--- pkg/man/gollh.Rd	                        (rev 0)
+++ pkg/man/gollh.Rd	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,70 @@
+\name{gollh}
+
+\alias{gollh}
+
+\encoding{latin1}
+
+\title{
+  Log-Likelihood function of GO-GARCH models
+}
+
+\description{
+  This function returns the negative of the log-Likelihood function for
+  GO-GARCH models. 
+}
+
+\usage{
+gollh(params, X, P, Dsqr, m, n, formula = ~garch(1, 1),
+      garchlist = list(init.rec = "mci", delta = 2, skew = 1,
+      shape = 4, cond.dist = "norm", include.mean = FALSE, 
+      include.delta = NULL, include.skew = NULL, include.shape = NULL,
+      leverage = NULL, trace = FALSE, algorithm = "nlminb",
+      hessian = "ropt", control = list(), title = NULL,
+      description = NULL))
+}
+
+\arguments{
+  \item{params}{Vector of initial values for \code{theta}.}
+  \item{X}{Matrix, the original data matrix with dimension \eqn{n \times m}.}
+  \item{P}{Matrix, rotation matrix returned by \code{svd} or
+  \code{prcomp}, dimension \eqn{m \times m}.}
+  \item{Dsqr}{Matrix, square roots of the eigenvalue decomposition on
+  its diagonal, dimension \eqn{m \times m}.}
+  \item{m}{Integer, number of columns of \code{X}.}
+  \item{n}{Integer, number of rows of \code{X}.}
+  \item{formula}{Formula, type of GARCH model, default is \code{~ garch(1,1)}.}
+  \item{garchlist}{List, elements are passed to \code{garchFit}.}
+}
+
+\details{
+  The log-Likelihood function of GO-GARCH models is given as:
+
+  \deqn{
+    L_{\theta, \alpha, \beta} = - \frac{1}{2} \sum_{t=1}^T m \log(2\pi)
+    + \log|Z_\theta Z_\theta '| + \log|H_t| + y' H_t^{-1}y_t
+  }
+  whereby \eqn{Z = P \Delta^{\frac{1}{2}} U_0}, \eqn{y_t = Z^{-1}x_t} and
+    \eqn{H_t} is the conditional variance matrix of the independent
+    components. 
+}
+
+\value{
+  \item{negll}{Scalar, the negative value of the log-Likelihood function.}
+}
+
+\references{
+  Van der Weide, Roy (2002), GO-GARCH: A Multivariate Generalized
+  Orthogonal GARCH Model, \emph{Journal of Applied Econometrics},
+  \bold{17(5)}, 549 -- 564.
+}
+
+\author{
+  Bernhard Pfaff
+}
+
+\seealso{
+  \code{\link[fGarch]{garchFit}}
+}
+\keyword{models}
+\concept{GO-GARCH}
+\concept{Likelihood}
\ No newline at end of file

Added: pkg/man/orthom-class.Rd
===================================================================
--- pkg/man/orthom-class.Rd	                        (rev 0)
+++ pkg/man/orthom-class.Rd	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,52 @@
+\name{Orthom-class}
+
+\docType{class}
+
+\alias{Orthom-class}
+\alias{show,Orthom-method}
+
+\encoding{latin1}
+
+\title{Class "Orthom": Orthogonal matrices}
+
+\description{
+  This class defines an orthogonal matrix, which is characterized by
+  \eqn{det(M) = 1} and \eqn{M M' = I}.
+}
+
+\section{Objects from the Class}{
+  Objects can be created by calls of the form \code{new("Orthom",
+  ...)}. In addition the function \code{UprodR} returns an object of
+  formal class \code{Orthom}.
+}
+
+\section{Slots}{
+  \describe{
+    \item{\code{M}:}{Object of class \code{"matrix"}.}
+  }
+}
+
+\section{Methods}{
+  \describe{
+    \S4method{show}{print-method applied to \code{object at M}.}
+  }
+}
+
+\author{
+  Bernhard Pfaff
+}
+
+\note{Objects are validated by \code{validOrthomObject()}. This function
+  is utilised by \code{validObject()}.}
+
+\seealso{
+   \code{\link{UprodR}}, \code{\link{validOrthomObject}} 
+}
+
+\examples{
+showClass("Orthom")
+}
+
+\keyword{classes}
+\keyword{algebra}
+\concept{Orthogonal Matrix}

Added: pkg/man/unvech.Rd
===================================================================
--- pkg/man/unvech.Rd	                        (rev 0)
+++ pkg/man/unvech.Rd	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,49 @@
+\name{unvech}
+
+\encoding{latin1}
+
+\alias{unvech}
+
+\title{
+  Returns a symmetric matrix from a vector 
+}
+
+\description{
+  This function returns the symmetric matrix \eqn{X} from a vector that
+  resulted from \eqn{v = vech(X)}.
+}
+
+\usage{
+unvech(v)
+}
+
+\arguments{
+  \item{v}{Vector, numeric.}
+}
+
+\details{
+  The vector \code{v} must have length equal to \eqn{m * (m + 1) / 2},
+  whereby \eqn{m} is a dimension of the symmetric matrix \eqn{X_{m
+  \times m}}. 
+}
+
+\value{
+  \item{X}{Matrix, symmetric of order \eqn{m \times m}.}
+}
+
+\author{
+  Bernhard Pfaff
+}
+
+\seealso{
+  \code{\link[fBasics]{vec}}
+}
+
+\examples{
+v <- c(1, 2, 3, 4, 5, 6)
+unvech(v)
+}
+
+\keyword{algebra}
+\concept{vech}
+\concept{vech invert}

Added: pkg/man/validOrthomObject.Rd
===================================================================
--- pkg/man/validOrthomObject.Rd	                        (rev 0)
+++ pkg/man/validOrthomObject.Rd	2009-01-22 21:10:12 UTC (rev 4)
@@ -0,0 +1,45 @@
+\name{validOrthomObject}
+
+\alias{validOrthomObject}
+
+\encoding{latin1}
+
+\title{
+Validation function for objects of class Orthom
+}
+\description{
+  This function validates objects of class \code{Orthom}.
+}
+\usage{
+validOrthomObject(object)
+}
+\arguments{
+  \item{object}{Object of class \code{Orthom}.}
+}
+
+\details{
+  This function is utilized by \code{validObject()}. It is tested
+  whether \code{object at M} is a square matrix, has \eqn{det(M) = 1} and
+  \eqn{MM' = I}. 
+}
+
+\value{
+  \item{TRUE}{Logical, \code{TRUE} if the object passes the validation,
+  otherwise an informative error message is returned.}
+}
+
+\author{
+  Bernhard Pfaff
+}
+
+\seealso{
+  \code{\linkS4class{Orthom}}
+}
+
+\examples{
+theta <- c(pi/3, pi/5, pi/7)
+U <- UprodR(theta)
+validObject(U)
+}
+
+\keyword{utilities}



More information about the Gogarch-commits mailing list