[Yuima-commits] r363 - in pkg/yuima: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Mar 1 21:23:49 CET 2015


Author: lorenzo
Date: 2015-03-01 21:23:49 +0100 (Sun, 01 Mar 2015)
New Revision: 363

Added:
   pkg/yuima/R/DiagnosticCogarch.R
   pkg/yuima/man/cogarch.gmm.incr.rd
   pkg/yuima/man/cogarch.gmm.rd
   pkg/yuima/man/cogarchNoise.Rd
Modified:
   pkg/yuima/R/ClassCogarch.R
   pkg/yuima/R/MM.COGARCH.R
   pkg/yuima/R/simulate.R
Log:
Add new routines for cogarch model

Modified: pkg/yuima/R/ClassCogarch.R
===================================================================
--- pkg/yuima/R/ClassCogarch.R	2015-02-19 22:02:05 UTC (rev 362)
+++ pkg/yuima/R/ClassCogarch.R	2015-03-01 20:23:49 UTC (rev 363)
@@ -28,3 +28,18 @@
          representation(info="cogarch.info"),
          contains="yuima.model")
 
+# Class 'gmm.cogarch'
+setClass("cogarch.gmm.incr",representation(Incr.Lev = "ANY",
+                                           model = "yuima.cogarch",
+                                           logL.Incr = "ANY"
+),
+contains="mle"
+)
+
+setClass("cogarch.gmm",representation(
+  model = "yuima.cogarch"),
+  contains="mle"
+)
+# setClass("gmm.cogarch",
+#   contains="mle"
+#   )  
\ No newline at end of file

Added: pkg/yuima/R/DiagnosticCogarch.R
===================================================================
--- pkg/yuima/R/DiagnosticCogarch.R	                        (rev 0)
+++ pkg/yuima/R/DiagnosticCogarch.R	2015-03-01 20:23:49 UTC (rev 363)
@@ -0,0 +1,68 @@
+StartValCog<-function(yuima.cogarch, param=list(), mu=1, rho=3){
+  
+  
+  if(missing(yuima.cogarch))
+    yuima.stop("yuima.cogarch or yuima object is missing.")
+  
+  if(length(param)==0)
+    yuima.stop("missing values parameters")
+    
+  if(!is.COGARCH(yuima.cogarch)){
+    yuima.warn("The model does not belong to the class yuima.cogarch")
+  }
+  
+  
+  if(is(yuima.cogarch,"yuima")){
+    model<-yuima.cogarch at model
+  }else{
+    if(is(yuima.cogarch,"yuima.cogarch")){
+      model<-yuima.cogarch
+    }
+  }
+  
+  info <- model at info
+  numb.ar <- info at q
+  ar.name <- paste(info at ar.par,c(numb.ar:1),sep="")
+  numb.ma <- info at p
+  ma.name <- paste(info at ma.par,c(1:numb.ma),sep="")
+  loc.par <- info at loc.par
+  
+  nm <- c(names(param))
+  param<-as.numeric(param)
+  names(param)<-nm
+  
+  
+  xinit.name0 <- model at parameter@xinit
+  idx <- na.omit(match(c(loc.par, ma.name), xinit.name0))
+  xinit.name <- xinit.name0[-idx]
+  fullcoeff <- c(ar.name, ma.name, loc.par,xinit.name)
+  
+  oo <- match(nm, fullcoeff)
+  
+  if(any(is.na(oo)))
+    yuima.stop("some named arguments in 'param' are not arguments to the supplied yuima.cogarch model")
+ 
+  acoeff <- param[ma.name]
+  b <- param[ar.name]
+  cost<- param[loc.par]
+  res<-StationaryMoments(cost,b,acoeff,mu,rho)
+  return(res)
+
+}
+
+StationaryMoments<-function(cost,b,acoeff,mu=1,rho=3){
+  # We obtain stationary mean of State process
+  # stationary mean of the variance 
+  # E\left(Y\right)=-a_{0}m_{2}\left(A+m_{2}ea'\right)^{-1}e
+  q<-length(b) 
+  a <- e <- matrix(0,nrow=q,ncol=1)
+  e[q,1] <- 1
+  p<-length(acoeff)
+  a[1:p,1] <- acoeff
+  B_tilde <- MatrixA(b[c(q:1)])+mu*e%*%t(a)
+  ExpStatVar <- -cost*mu*solve(B_tilde)%*%e
+  ExpVar <- cost+t(a)%*%ExpStatVar
+  res <- list(ExpVar=ExpVar, ExpStatVar=ExpStatVar)
+  return(res)
+}
+

Modified: pkg/yuima/R/MM.COGARCH.R
===================================================================
--- pkg/yuima/R/MM.COGARCH.R	2015-02-19 22:02:05 UTC (rev 362)
+++ pkg/yuima/R/MM.COGARCH.R	2015-03-01 20:23:49 UTC (rev 363)
@@ -63,19 +63,19 @@
     yuima.stop("Data must be an object of class yuima.data-class")  
   } 
   
-  if( !missing(upper)){
-    yuima.warn("The upper constraints will be implemented as soon as possible")
-    upper <- list()
+  if( !missing(upper) && (method!="L-BFGS-B"||method!="brent")){
+    yuima.warn("The upper requires L-BFGS-B or brent methods. We change method in  L-BFGS-B")
+    method <- "L-BFGS-B"
   }
 
-  if( !missing(lower)){
-    yuima.warn("The lower constraints will be implemented as soon as possible")
-    lower <- list()
+  if( !missing(lower) && (method!="L-BFGS-B"||method!="brent")){
+    yuima.warn("The lower constraints requires L-BFGS-B or brent methods. We change method in  L-BFGS-B")
+    method <- "L-BFGS-B"
   }
 
-  if( !missing(fixed)){
-    yuima.warn("The fixed constraints will be implemented as soon as possible")
-    fixed <- list()
+  if( !missing(fixed) && (method!="L-BFGS-B"||method!="brent")){
+    yuima.warn("The fixed constraints requires L-BFGS-B or brent methods. We change method in  L-BFGS-B")
+    method <- "L-BFGS-B"
   }
   
   # We identify the model parameters
@@ -199,15 +199,86 @@
    } 
   ErrTerm(yuima=yuima, param=mycoef, print=print, env)
 }
- out<- optim(start, objectiveFun, method = method, env=env)
+if(method!="L-BFGS-B"||method!="brent"){
+  out<- optim(start, objectiveFun, method = method, env=env)
+}else{
+  if(length(fixed)!=0 && !missing(upper) && !missing(lower)){
+    out<- optim(start, objectiveFun, method = method, 
+                fixed=as.numeric(fixed), 
+                lower=as.numeric(lower), 
+                upper=as.numeric(upper), env=env)
+  }else{
+    if(!missing(upper) && !missing(lower)){
+      out<- optim(start, objectiveFun, method = method, 
+                  lower=as.numeric(lower), 
+                  upper=as.numeric(upper), env=env)
+    }
+    if(length(fixed)!=0 && !missing(lower)){
+      out<- optim(start, objectiveFun, method = method, 
+                  fixed=as.numeric(fixed), 
+                  lower=as.numeric(lower), env=env)
+    }
+    if(!missing(upper) && length(fixed)!=0){
+      out<- optim(start, objectiveFun, method = method, 
+                  fixed=as.numeric(fixed), 
+                  upper=as.numeric(upper), env=env)
+    }
+  }
+  
+  if(length(fixed)!=0 && missing(upper) && missing(lower)){
+    out<- optim(start, objectiveFun, method = method, 
+                fixed=as.numeric(fixed), env=env)
+  }
+  
+  if(length(fixed)==0 && !missing(upper) && missing(lower)){
+    out<- optim(start, objectiveFun, method = method,
+                lower=as.numeric(lower), env=env)
+  }
+  
+  if(length(fixed)==0 && missing(upper) && !missing(lower)){
+    out<- optim(start, objectiveFun, method = method, 
+                upper=as.numeric(upper), env=env)
+  }
+  
+}
 
  bvect<-out$par[ar.name]
  bq<-bvect[1]
  avect<-out$par[ma.name]
  a1<-avect[1]
- out$par[loc.par]<-(bq-a1)*mu_G2/(bq*r)
+ 
+  out$par[loc.par]<-(bq-a1)*mu_G2/(bq*r)
 
- return(out)
+ # Determine the Variance-Covariance Matrix
+ dimOutp<-length(out$par)-2
+ coef <- out$par[c(1:dimOutp)] 
+ vcov<-matrix(NA, dimOutp, dimOutp)
+  names_coef<-names(coef)
+  colnames(vcov) <- names_coef
+  rownames(vcov) <- names_coef
+  mycoef <- start
+  min <- out$value 
+# # call
+
+ logL.Incr<-cogarchNoise(yuima.cogarch=model, data=observ, 
+                    param=as.list(coef), mu=1)
+
+# Build an object of class mle
+
+ 
+ 
+
+ # Build an object of class cogarch.gmm.incr
+res<-new("cogarch.gmm.incr", call = call, coef = coef, fullcoef = unlist(coef), 
+    vcov = vcov, min = min, details = list(), 
+    method = character(),
+    Incr.Lev=logL.Incr,
+    model = model, nobs=as.integer(length(logL.Incr)+1),
+    logL.Incr = numeric())
+
+
+
+ return(res)
   
 }
 

Modified: pkg/yuima/R/simulate.R
===================================================================
--- pkg/yuima/R/simulate.R	2015-02-19 22:02:05 UTC (rev 362)
+++ pkg/yuima/R/simulate.R	2015-03-01 20:23:49 UTC (rev 363)
@@ -599,7 +599,7 @@
 #        sim[t,3:ncolsim]<-expm(AMatrix*Delta)%*%sim[t-1,3:ncolsim]+expm(AMatrix)%*%evect*sim[t-1,2]*incr.L[2,t]
 #        sim[t,3:ncolsim]<-sim[t-1,3:ncolsim]+AMatrix*Delta%*%sim[t-1,3:ncolsim]+evect*sim[t-1,2]*incr.L[2,t-1]
         sim[t,2]<-value.a0+tavect%*%sim[t,3:ncolsim]
-        sim[t,1]<-sim[t-1,1]+sqrt(sim[t-1,2])*incr.L[1,t-1]
+        sim[t,1]<-sim[t-1,1]+sqrt(sim[t-1,2])*incr.L[1,t]
         
       }
       X <- ts(sim)

Added: pkg/yuima/man/cogarch.gmm.incr.rd
===================================================================
--- pkg/yuima/man/cogarch.gmm.incr.rd	                        (rev 0)
+++ pkg/yuima/man/cogarch.gmm.incr.rd	2015-03-01 20:23:49 UTC (rev 363)
@@ -0,0 +1,34 @@
+\name{cogarch.gmm.incr-class}
+\docType{class}
+\alias{cogarch.gmm.incr-class}
+\alias{plot,cogarch.gmm.incr,ANY-method}
+\alias{gmm.cogarch.class}
+\alias{cogarch.gmm.class}
+%%\alias{setSampling,yuima.carma-method}
+
+\title{Class for Generalized Method of Moments Estimation for COGARCH(p,q) model with underlying increments}
+\description{
+  The \code{cogarch.gmm.incr} class is a class of the  \pkg{yuima} package that extends the \code{\link{cogarch.gmm-class}} and is filled by the function \code{\link{gmm}}.  
+}
+\section{Slots}{
+  \describe{
+    \item{\code{Incr.Lev}:}{is an object of class \code{\link{zoo}} that contains the estimated increments of the noise obtained using \code{\link{cogarchNoise}}.}
+    \item{\code{model}:}{is an object of of \code{\link{yuima.cogarch-class}}.}
+    \item{\code{logL.Incr}:}{is an object of class \code{numeric} that contains the value of the log-likelihood for estimated Levy increments.}
+    \item{\code{call}:}{is an object of class \code{language}. }
+    \item{\code{coef}:}{is an object of class \code{numeric} that contains estimated parameters.}
+    \item{\code{fullcoef}:}{is an object of class \code{numeric} that contains estimated and fixed parameters.}
+    \item{\code{vcov}:}{is an object of class \code{matrix}.}
+    \item{\code{min}:}{is an object of class \code{numeric}.}
+    \item{\code{minuslogl}:}{is an object of class \code{function}.}
+    \item{\code{method}:}{is an object of class \code{character}.}
+  }
+}
+\section{Methods}{
+  \describe{
+    \item{plot}{Plot method for estimated increment of the noise.}
+    \item{Methods mle}{All methods for \code{mle-class} are available.}
+  }
+}
+\author{The YUIMA Project Team}
+\keyword{classes}

Added: pkg/yuima/man/cogarch.gmm.rd
===================================================================
--- pkg/yuima/man/cogarch.gmm.rd	                        (rev 0)
+++ pkg/yuima/man/cogarch.gmm.rd	2015-03-01 20:23:49 UTC (rev 363)
@@ -0,0 +1,29 @@
+\name{cogarch.gmm.-class}
+\docType{class}
+\alias{cogarch.gmm-class}
+\alias{plot,cogarch.gmm.,ANY-method}
+%%\alias{setSampling,yuima.carma-method}
+
+\title{Class for Generalized Method of Moments Estimation for COGARCH(p,q) model}
+\description{
+  The \code{cogarch.gmm} class is a class of the  \pkg{yuima} package that contains estimated parameters obtained by the function \code{\link{gmm}}.  
+}
+\section{Slots}{
+  \describe{
+    \item{\code{model}:}{is an object of of \code{\link{yuima.cogarch-class}}.}
+    \item{\code{call}:}{is an object of class \code{language}. }
+    \item{\code{coef}:}{is an object of class \code{numeric} that contains estimated parameters.}
+    \item{\code{fullcoef}:}{is an object of class \code{numeric} that contains estimated and fixed parameters.}
+    \item{\code{vcov}:}{is an object of class \code{matrix}.}
+    \item{\code{min}:}{is an object of class \code{numeric}.}
+    \item{\code{minuslogl}:}{is an object of class \code{function}.}
+    \item{\code{method}:}{is an object of class \code{character}.}
+  }
+}
+\section{Methods}{
+  \describe{
+    \item{Methods mle}{All methods for \code{mle-class} are available.}
+  }
+}
+\author{The YUIMA Project Team}
+\keyword{classes}

Added: pkg/yuima/man/cogarchNoise.Rd
===================================================================
--- pkg/yuima/man/cogarchNoise.Rd	                        (rev 0)
+++ pkg/yuima/man/cogarchNoise.Rd	2015-03-01 20:23:49 UTC (rev 363)
@@ -0,0 +1,43 @@
+\name{cogarchNoise}
+\alias{Recovering.Noise.cogarch}
+\alias{cogarch.Recovering}
+\alias{CogarchRecovNoise}
+\alias{cogarchNoise}
+\alias{Levy.cogarch}
+\title{Estimation for the underlying Levy in a COGARCH(p,q) model}
+\description{Retrieve the increment of the underlying Levy for the COGARCH(p,q) process}
+\usage{
+cogarchNoise(yuima.cogarch, data=NULL, param, mu=1)
+}
+\arguments{
+  \item{yuima.cogarch}{a yuima object or an object of \code{\link{yuima.cogarch-class}}.}
+  \item{data}{an object of class \code{\link{yuima.data-class}} contains the observations available at uniformly spaced time. If \code{data=NULL}, the default, the \code{cogarchNoise} uses the data in an object of \code{\link{yuima.data-class}}.}
+  \item{param}{\code{list} of parameters for the COGARCH(p,q).}
+  \item{mu}{a numeric object that contains the value of the second moments of the levy measure.}
+}
+\value{
+  %\item{QL}{a real value.}
+  \item{incr.Levy}{a numeric object contains the estimated increments.}
+  }
+\author{The YUIMA Project Team}
+\note{
+  %The function ml.ql uses the function optim internally.
+  The function \code{cogarchNoise} assumes the underlying Levy process is centered in zero.
+  
+  The function \code{gmm} uses the function \code{cogarchNoise} for estimation of underlying Levy in the COGARCH(p,q) model.
+  }
+
+ \references{
+               Chadraa. (2009)
+Statistical Modelling with COGARCH(P,Q) Processes, \emph{PhD Thesis}.
+}
+
+
+\examples{
+# Insert here some examples
+}
+
+
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{ts}



More information about the Yuima-commits mailing list