[Yuima-commits] r350 - in pkg/yuima: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Nov 6 16:15:13 CET 2014
Author: lorenzo
Date: 2014-11-06 16:15:13 +0100 (Thu, 06 Nov 2014)
New Revision: 350
Added:
pkg/yuima/R/ClassCogarch.R
pkg/yuima/R/setCogarch.R
pkg/yuima/man/cogarch.info-class.Rd
pkg/yuima/man/setCogarch.Rd
pkg/yuima/man/yuima.cogarch-class.Rd
Modified:
pkg/yuima/DESCRIPTION
pkg/yuima/NAMESPACE
Log:
Add Classes and Methods for Mathematical Description of cogarch(p,q) model
Modified: pkg/yuima/DESCRIPTION
===================================================================
--- pkg/yuima/DESCRIPTION 2014-10-31 12:52:51 UTC (rev 349)
+++ pkg/yuima/DESCRIPTION 2014-11-06 15:15:13 UTC (rev 350)
@@ -1,8 +1,8 @@
Package: yuima
Type: Package
Title: The YUIMA Project package for SDEs
-Version: 1.0.46
-Date: 2014-10-29
+Version: 1.0.47
+Date: 2014-11-06
Depends: methods, zoo, stats4, utils, expm, cubature, mvtnorm
Author: YUIMA Project Team
Maintainer: Stefano M. Iacus <stefano.iacus at unimi.it>
Modified: pkg/yuima/NAMESPACE
===================================================================
--- pkg/yuima/NAMESPACE 2014-10-31 12:52:51 UTC (rev 349)
+++ pkg/yuima/NAMESPACE 2014-11-06 15:15:13 UTC (rev 350)
@@ -5,8 +5,8 @@
import("zoo")
importFrom(stats, confint)
import("stats4")
-import("expm")
-import("mvtnorm")
+import("expm")
+import("mvtnorm")
import("cubature")
importFrom(utils, toLatex)
@@ -24,10 +24,12 @@
"model.parameter",
"yuima.carma",
"carma.info",
- "yuima.carma.qmle",
- "yuima.poisson",
- "yuima.qmle",
- "yuima.CP.qmle"
+ "yuima.carma.qmle",
+ "yuima.poisson",
+ "yuima.qmle",
+ "yuima.CP.qmle",
+ "cogarch.info",
+ "yuima.cogarch"
)
exportMethods(
@@ -68,10 +70,12 @@
export(setSampling)
export(setCharacteristic)
export(setCarma)
-export(setPoisson)
-export(dconst)
-export(rconst)
+export(setPoisson)
+export(dconst)
+export(rconst)
+export(setCogarch)
+
export(dim)
export(length)
#export(start)
@@ -135,7 +139,7 @@
S3method(toLatex, yuima)
S3method(toLatex, yuima.model)
S3method(toLatex, yuima.carma)
-
+
useDynLib(yuima)
Added: pkg/yuima/R/ClassCogarch.R
===================================================================
--- pkg/yuima/R/ClassCogarch.R (rev 0)
+++ pkg/yuima/R/ClassCogarch.R 2014-11-06 15:15:13 UTC (rev 350)
@@ -0,0 +1,30 @@
+# In order to deal the cogarch model in the \texttt{yuima} package
+# We define a new class called \texttt{yuima.cogarch} and its structure
+# is similar to those used for the carma model.
+# The class \texttt{yuima.cogarch} extends the \texttt{yuima.model} and has
+# an additional slot that contains informations about the model stored in an object of
+# class \texttt{cogarch.info}.
+# The class \texttt{cogarch.info} is build internally by the function \texttt{setCogarch} and it is a
+# the first slot of an object of class \texttt{yuima.cogarch}.
+
+# Class 'cogarch.info'
+setClass("cogarch.info",
+ representation(p="numeric",
+ q="numeric",
+ ar.par="character",
+ ma.par="character",
+ loc.par="character",
+ Cogarch.var="character",
+ V.var="character",
+ Latent.var="character",
+ XinExpr="logical",
+ measure="list",
+ measure.type="character")
+)
+
+# Class 'yuima.cogarch'
+
+setClass("yuima.cogarch",
+ representation(info="cogarch.info"),
+ contains="yuima.model")
+
Added: pkg/yuima/R/setCogarch.R
===================================================================
--- pkg/yuima/R/setCogarch.R (rev 0)
+++ pkg/yuima/R/setCogarch.R 2014-11-06 15:15:13 UTC (rev 350)
@@ -0,0 +1,204 @@
+setMethod("initialize", "cogarch.info",
+ function(.Object,
+ p=numeric(),
+ q=numeric(),
+ ar.par=character(),
+ ma.par=character(),
+ loc.par=character(),
+ Cogarch.var=character(),
+ V.var=character(),
+ Latent.var=character(),
+ XinExpr=logical(),
+ measure=list(),
+ measure.type=character()){
+ .Object at p <- p
+ .Object at q <- q
+ .Object at ar.par <- ar.par
+ .Object at ma.par <- ma.par
+ .Object at loc.par <- loc.par
+ .Object at Cogarch.var <- Cogarch.var
+ .Object at V.var <- V.var
+ .Object at Latent.var <- Latent.var
+ .Object at XinExpr <- XinExpr
+ .Object at measure<-measure
+ .Object at measure.type<-measure.type
+ return(.Object)
+ })
+
+setMethod("initialize", "yuima.cogarch",
+ function(.Object,
+ info = new("cogarch.info"),
+ drift = expression() ,
+ diffusion = list() ,
+ hurst = 0.5,
+ jump.coeff = list(),
+ measure=list(),
+ measure.type=character(),
+ parameter = new("model.parameter"),
+ state.variable = "x",
+ jump.variable = "z",
+ time.variable = "t",
+ noise.number = numeric(),
+ equation.number = numeric(),
+ dimension = numeric(),
+ solve.variable = character(),
+ xinit = expression(),
+ J.flag = logical()
+ # quadr.var=new("quadratic.variation")
+ ){
+ .Object at info <- info
+ .Object at drift <- drift
+ .Object at diffusion <- diffusion
+ .Object at hurst <- hurst
+ .Object at jump.coeff <- jump.coeff
+ .Object at measure <- measure
+ .Object at measure.type <- measure.type
+ .Object at parameter <- parameter
+ .Object at state.variable <- state.variable
+ .Object at jump.variable <- jump.variable
+ .Object at time.variable <- time.variable
+ .Object at noise.number <- noise.number
+ .Object at equation.number <- equation.number
+ .Object at dimension <- dimension
+ .Object at solve.variable <- solve.variable
+ .Object at xinit <- xinit
+ .Object at J.flag <- J.flag
+ #.Object at quadr.var <- quadr.var
+ return(.Object)
+ })
+
+
+setCogarch<-function(p,
+ q,
+ ar.par="a",
+ ma.par="b",
+ loc.par="mu",
+ Cogarch.var="g",
+ V.var="v",
+ Latent.var="y",
+ jump.variable="z",
+ time.variable="t",
+ measure=NULL,
+ measure.type=NULL,
+ XinExpr=FALSE,
+ startCogarch=0,
+ work=TRUE,...){
+# We use the same parametrization as in Brockwell (2000)
+ call <- match.call()
+ mydots <- as.list(call)[-(1:2)]
+
+
+ if (work==TRUE){
+ Model_Cogarch=NULL
+ return(Model_Cogarch)
+ }
+ if(is.null(measure)){
+ yuima.warn("The Levy measure must be specified. The Brownian
+ is not allowed as underlying process for Cogarch model.")
+ return(NULL)
+ }
+ if(is.null(measure.type)){
+ yuima.warn("The measure.type must be specified. See yuima documentation.")
+ return(NULL)
+ }
+ # We need to build the auxiliar carma model that is the variance process
+ # If we consider a Cogarch(p,q) the variance process is a Carma(q,p-1) model
+ if(is.null(mydots$xinit)){
+ aux.Carma<-setCarma(p=q,
+ q=p-1,
+ ar.par=ar.par,
+ ma.par=ma.par,
+ loc.par=loc.par,
+ lin.par=ma.par)
+ }else{
+ if(!is.null(mydots$xinit)){
+ aux.Carma<-setCarma(p=q,
+ q=p-1,
+ loc.par=loc.par,
+ ar.par=ar.par,
+ ma.par=ma.par,
+ lin.par=ma.par,
+ xinit=mydots$xinit)
+ }
+ }
+
+ newdrift<-c(0,as.character(aux.Carma at drift))
+ newdiffusion<-c(0,as.character(eval(aux.Carma at diffusion)))
+ line1<-c(paste0("sqrt(",V.var,")"),as.character(matrix(0,nrow=(q+1),ncol=1)))
+
+ dumm<-as.character(eval(aux.Carma at diffusion))
+ len.dumm<-length(dumm)
+ line2<-character(length = (len.dumm+1))
+ line2[1]<-"0"
+ for(i in 1:length(dumm)){
+ dumm.tmp<-nchar(x=dumm[i])
+ line2[i+1]<-substring(dumm[i],13,dumm.tmp-2)
+ }
+
+ state<-c(Cogarch.var,aux.Carma at state.variable)
+ # We need now to modify the setModel in order to introduce a new component that represents
+ # the discrete parts of the quadratic variation.
+ # A possible solution is to write a new class that extends the yuima.model class and gives the possibility
+ # to add the additional components.
+ # The way to introduce the differentiation of the discrete part of the quadratic variation have to follow the same
+ # structure used for the jump component.
+ Lev.coeff<-matrix(c(line1,line2),ncol=2)
+ resdummy1<-setModel(drift=newdrift,
+ jump.coeff=Lev.coeff,
+ #quadr.coeff=line2,
+ measure=measure,
+ measure.type=measure.type,
+ #quadr.measure=measure,
+ #quadr.measure.type=measure.type,
+ state.variable=state,
+ jump.variable=jump.variable,
+ #quadr.variable=quadr.variable,
+ time.variable=time.variable,
+ xinit=c(startCogarch,as.character(aux.Carma at xinit)))
+
+ resdummy2 <- new("cogarch.info",
+ p=p,
+ q=q,
+ ar.par=ar.par,
+ ma.par=ma.par,
+ loc.par=loc.par,
+ Cogarch.var=Cogarch.var,
+ V.var=V.var,
+ Latent.var=Latent.var,
+ XinExpr=XinExpr,
+ measure=measure,
+ measure.type=measure.type
+ )
+
+# res.quadr.var<-new("quadratic.variation",
+# quadr.coeff=resdummy1 at quadr.var@quadr.coeff,
+# measure=resdummy1 at quadr.var@measure,
+# measure.type=resdummy1 at quadr.var@measure.type,
+# parms.quadr=resdummy1 at quadr.var@parms.quadr,
+# parms.quadr.meas = resdummy1 at quadr.var@parms.quadr.meas,
+# quadr.variable = resdummy1 at quadr.var@quadr.variable,
+# Q.flag = resdummy1 at quadr.var@Q.flag)
+
+ res<-new("yuima.cogarch",
+ info=resdummy2,
+ drift= resdummy1 at drift,
+ diffusion= resdummy1 at diffusion,
+ hurst=resdummy1 at hurst,
+ jump.coeff=resdummy1 at jump.coeff,
+ measure= resdummy1 at measure,
+ measure.type= resdummy1 at measure.type,
+ parameter= resdummy1 at parameter,
+ state.variable= resdummy1 at state.variable,
+ jump.variable= resdummy1 at jump.variable,
+ time.variable= resdummy1 at time.variable,
+ noise.number= resdummy1 at noise.number,
+ equation.number= resdummy1 at equation.number,
+ dimension= resdummy1 at dimension,
+ solve.variable= resdummy1 at solve.variable,
+ xinit= resdummy1 at xinit,
+ J.flag = resdummy1 at J.flag
+ # quadr.var=res.quadr.var
+ )
+
+ return(res)
+}
Added: pkg/yuima/man/cogarch.info-class.Rd
===================================================================
--- pkg/yuima/man/cogarch.info-class.Rd (rev 0)
+++ pkg/yuima/man/cogarch.info-class.Rd 2014-11-06 15:15:13 UTC (rev 350)
@@ -0,0 +1,32 @@
+\name{cogarch.info-class}
+\docType{class}
+\alias{cogarch.info-class}
+
+\title{Class for information about CoGarch(p,q)}
+\description{
+ The \code{cogarch.info-class} is a class of the \pkg{yuima} package
+}
+\section{Slots}{
+ \describe{
+ \item{\code{p}:}{Number of autoregressive coefficients in the variance process. }
+ \item{\code{q}:}{Number of moving average coefficients in the variance process. }
+ \item{\code{ar.par}:}{Label of autoregressive coefficients. }
+ \item{\code{ma.par}:}{Label of moving average coefficients. }
+ \item{\code{loc.par}:}{Label of location coefficient in the variance process. }
+ \item{\code{Cogarch.var}:}{Label of the observed process. }
+ \item{\code{V.var}:}{Label of the variance process. }
+ \item{\code{Latent.var}:}{Label of the latent process in the state representation of the variance.}
+ \item{\code{XinExpr}:}{Logical variable. If \code{XinExpr=FALSE}, the starting condition of \code{Latent.var} is zero otherwise each component of Latent.var has a parameter as a starting point. }
+ \item{\code{measure}:}{Levy measure for jump and quadratic part. }
+ \item{\code{measure.type}:}{Type specification for Levy measure. }
+ }
+}
+
+\note{
+The \code{cogarch.info-class} object cannot be directly specified by the user
+but it is built when the \code{\link{yuima.cogarch-class}} object is
+constructed via \code{\link{setCogarch}}.
+}
+
+\author{The YUIMA Project Team}
+\keyword{classes}
Added: pkg/yuima/man/setCogarch.Rd
===================================================================
--- pkg/yuima/man/setCogarch.Rd (rev 0)
+++ pkg/yuima/man/setCogarch.Rd 2014-11-06 15:15:13 UTC (rev 350)
@@ -0,0 +1,88 @@
+\name{setCogarch}
+\alias{setCogarch}
+\alias{Cogarch}
+\alias{cogarch}
+\alias{COGARCH}
+\alias{CoGarch}
+
+
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{ Continuous-time GARCH (p,q) process
+}
+\description{
+\code{setCogarch} describes the following model:
+
+\code{dGt = sqrt(Vt)dZt}
+
+\code{Vt = mu0 + (b0 Yt(0) + ... + b(q) Yt(q))}
+
+\code{dYt(0) = Yt(1) dt}
+
+ \code{...}
+
+ \code{dYt(p-2) = Yt(p-1) dt}
+
+ \code{dYt(p-1) = (-a(p) Yt(0) - ... - a(1) Yt(p-1))dt + (mu0 + (b0 Yt(0) + ... + b(q) Yt(q))d[ZtZt]_{q}}
+
+
+}
+\usage{
+setCogarch(p, q, ar.par = "a", ma.par = "b", loc.par = "mu", Cogarch.var = "g", V.var = "v", Latent.var = "y", jump.variable = "z", time.variable = "t", measure = NULL, measure.type = NULL, XinExpr = FALSE, startCogarch = 0, work = TRUE, ...)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{p}{a non negative integer that is the number of the autoregressive coefficients.}
+ \item{q}{a non-negative integer that indicates the number of the moving average coefficients.}
+ \item{ar.par}{a character-string that is the label of the autoregressive coefficients.}
+ \item{ma.par}{a character-string that is the label of the autoregressive coefficients.}
+ \item{loc.par}{the location coefficient.}
+ \item{Cogarch.var}{a character-string that is the label of the observed cogarch process.}
+ \item{V.var}{a character-string that is the label of the latent variance process.}
+ \item{Latent.var}{a character-string that is the label of the latent process in the state space representation for the variance process.}
+ \item{jump.variable}{the jump variable.}
+ \item{time.variable}{the time variable.}
+ \item{measure}{Levy measure of jump variables.}
+ \item{measure.type}{type specification for Levy measure.}
+ \item{XinExpr}{a vector of \code{expressions} identyfying the starting conditions for CaGarch model.}
+ \item{startCogarch}{Start condition for the CoGarch process }
+ \item{work}{ Internal Variable. In the final release this input will be removed.}
+ \item{\dots}{Arguments to be passed to \code{setCogarch} such as the slots of the \code{\link{yuima.model-class}}}
+}
+\details{
+Please refer to the vignettes and the examples or to the \pkg{yuimadocs} package.
+
+An object of \code{\link{yuima.cogarch-class}} contains:
+
+\describe{
+\item{\code{info}:}{It is an object
+ of \code{\link{cogarch.info-class}} which is a list of arguments that identifies the Cogarch(p,q) model}
+}
+and the same slots in an object of \code{\link{yuima.model-class}} .
+}
+\value{
+ \item{model}{an object of \code{\link{yuima.cogarch-class}}.}
+}
+\author{The YUIMA Project Team}
+\note{There may be missing information in the model description.
+Please contribute with suggestions and fixings.
+}
+
+ \references{
+ Brockwell, P., Chadraa, E. and Lindner, A. (2006)
+Continuous-time GARCH processes, \emph{The Annals of Applied Probability}, \bold{16}, 790-826.
+}
+
+\examples{
+# Ex 1. (Continuous time GARCH process driven by a compound poisson process)
+prova<-setCogarch(p=1,q=3,work=FALSE,
+ measure=list(intensity="1", df=list("dnorm(z, 0, 1)")),
+ measure.type="CP",
+ Cogarch.var="y",
+ V.var="v",
+ Latent.var="x")
+
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{ ~kwd1 }
+\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
Added: pkg/yuima/man/yuima.cogarch-class.Rd
===================================================================
--- pkg/yuima/man/yuima.cogarch-class.Rd (rev 0)
+++ pkg/yuima/man/yuima.cogarch-class.Rd 2014-11-06 15:15:13 UTC (rev 350)
@@ -0,0 +1,52 @@
+\name{yuima.cogarch-class}
+\docType{class}
+\alias{yuima.cogarch-class}
+\alias{initialize,yuima.cogarch-method}
+\alias{initialize,cogarch.info-method}
+\alias{limiting.gamma,yuima.cogarch-method}
+\alias{simulate,yuima.cogarch-method}
+
+\title{Class for the mathematical description of CoGarch(p,q) model}
+\description{
+The \code{yuima.cogarch} class is a class of the \pkg{yuima} package that extends the \code{\link{yuima.model-class}}.
+}
+\section{Objects from the Class}{
+Objects can be created by calls of the function \code{\link{setCogarch}}.
+%% ~~ describe objects here ~~
+}
+\section{Slots}{
+ \describe{
+ \item{\code{info}:}{is an \code{\link{cogarch.info-class}} object that describes the structure of the Cogarch(p,q) model.}
+ \item{\code{drift}:}{is an \R{} expression which specifies the drift
+ coefficient (a vector).}
+ \item{\code{diffusion}:}{is an \R{} expression which specifies the diffusion
+ coefficient (a matrix).}
+ \item{\code{hurst}:}{the Hurst parameter of the gaussian noise. }
+ \item{\code{jump.coeff}:}{a vector of \code{"expressions"} for the jump component. }
+ \item{\code{measure}:}{Levy measure for the jump component. }
+ \item{\code{measure.type}:}{Type of specification for Levy measure }
+ \item{\code{parameter}:}{is an object of class \code{\link{model.parameter-class}}. }
+ \item{\code{state.variable}:}{the state variable. }
+ \item{\code{jump.variable}:}{the jump variable. }
+ \item{\code{time.variable}:}{the time variable. }
+ \item{\code{noise.number}:}{Object of class \code{"numeric"} }
+ \item{\code{equation.number}:}{dimension of the stochastic differential equation.}
+ \item{\code{dimension}:}{number of parameters. }
+ \item{\code{solve.variable}:}{the solve variable}
+ \item{\code{xinit}:}{Object of class \code{"expression"} that contains the starting function for the SDE. }
+ \item{\code{J.flag}:}{wheather jump.coeff include jump.variable.}
+ }
+}
+\section{Extends}{
+Class \code{"\linkS4class{yuima.model}"}, directly.
+}
+\section{Methods}{
+ \describe{
+ \item{simulate}{simulation method. For more information see \code{\link{simulate}} }
+ \item{toLatex}{This method converts an object of \code{yuima.cogarch-class} to character vectors with LaTeX markup.
+ }
+ \item{qmle}{Quasi maximum likelihood estimation procedure. For more information see \code{\link{qmle}}. }
+}
+}
+\author{The YUIMA Project Team}
+\keyword{classes}
More information about the Yuima-commits
mailing list