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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Nov 28 05:56:31 CET 2021


Author: kyuta
Date: 2021-11-28 05:56:30 +0100 (Sun, 28 Nov 2021)
New Revision: 764

Added:
   pkg/yuima/R/lm.jumptest.R
   pkg/yuima/R/ntv.R
   pkg/yuima/R/pz.test.R
   pkg/yuima/man/lm.jumptest.Rd
   pkg/yuima/man/ntv.Rd
   pkg/yuima/man/pz.test.Rd
Modified:
   pkg/yuima/DESCRIPTION
   pkg/yuima/NAMESPACE
   pkg/yuima/NEWS
   pkg/yuima/man/bns.test.Rd
   pkg/yuima/man/mpv.Rd
Log:
added new functions for jump testing

Modified: pkg/yuima/DESCRIPTION
===================================================================
--- pkg/yuima/DESCRIPTION	2021-11-23 10:58:23 UTC (rev 763)
+++ pkg/yuima/DESCRIPTION	2021-11-28 04:56:30 UTC (rev 764)
@@ -1,7 +1,7 @@
 Package: yuima
 Type: Package
 Title: The YUIMA Project Package for SDEs
-Version: 1.10.10
+Version: 1.10.11
 Depends: R(>= 2.10.0), methods, zoo, stats4, utils, expm, cubature,
         mvtnorm
 Imports: Rcpp (>= 0.12.1), boot (>= 1.3-2), glassoFast, wavethresh,
@@ -10,7 +10,7 @@
 Maintainer: Stefano M. Iacus <stefano.iacus at unimi.it>
 Description: Simulation and Inference for SDEs and Other Stochastic Processes.
 License: GPL-2
-URL: http://www.yuima-project.com
+URL: https://yuimaproject.com
 LinkingTo: Rcpp, RcppArmadillo
 Repository: R-Forge
 Repository/R-Forge/Project: yuima

Modified: pkg/yuima/NAMESPACE
===================================================================
--- pkg/yuima/NAMESPACE	2021-11-23 10:58:23 UTC (rev 763)
+++ pkg/yuima/NAMESPACE	2021-11-28 04:56:30 UTC (rev 764)
@@ -179,6 +179,7 @@
 export(simBmllag) # added by YK on Apr. 15, 2020
 export(simBmllag.coef) # added by YK on Apr. 15, 2020
 export(wllag) # added by YK on Apr. 15, 2020
+export(minrv, medrv, minrv.test, medrv.test, lm.jumptest, pz.test) # added by YK on Nov. 28, 2021
 
 export(get.zoo.data)
 

Modified: pkg/yuima/NEWS
===================================================================
--- pkg/yuima/NEWS	2021-11-23 10:58:23 UTC (rev 763)
+++ pkg/yuima/NEWS	2021-11-28 04:56:30 UTC (rev 764)
@@ -77,4 +77,6 @@
 2021/3/15: fixed a bug in qmle when yuima at model@parameter at measure is character(0) and yuima at model@measure.type is "CP"
 2021/8/16: fixed a bug in simulate when the jump intensity is not a parameter
 2021/9/24: fixed a bug regarding the "fixed" argument in qmle
-2021/11/23: fixed a bug regarding the "psd" argument in lmm
\ No newline at end of file
+2021/11/23: fixed a bug regarding the "psd" argument in lmm
+2021/11/28: added ntv.R, pz.test.R, lm.jumptest.R, ntv.Rd, pz.test.Rd, lm.jumptest.Rd
+            modified mpv.Rd, bns.test.Rd
\ No newline at end of file

Added: pkg/yuima/R/lm.jumptest.R
===================================================================
--- pkg/yuima/R/lm.jumptest.R	                        (rev 0)
+++ pkg/yuima/R/lm.jumptest.R	2021-11-28 04:56:30 UTC (rev 764)
@@ -0,0 +1,41 @@
+
+# Lee-Mykland's jump test
+
+lm.jumptest <- function(yuima, K){
+  
+  data <- get.zoo.data(yuima)
+  d.size <- length(data)
+  n <- length(yuima) - 1
+  
+  if(missing(K)) K <- pmin(floor(sqrt(252*n)), n)
+  
+  K <- rep(K, d.size)
+  
+  cn <- sqrt(2*log(n)) - 
+    (log(pi) + log(log(n)))/(2*sqrt(2*log(n)))
+  sn <- 1/sqrt(2*log(n))
+   
+  result <- vector(d.size,mode="list") 
+  
+  for(d in 1:d.size){
+    
+    x <- data[[d]]
+    adx <- abs(diff(as.numeric(x)))
+    
+    v.hat <- (pi/2) * rollmeanr(adx[-n[d]] * adx[-1], 
+                                k = K[d] - 2, fill = "e")
+    v.hat <- append(v.hat, v.hat[1], after = 0)
+    
+    stat <- (max(adx/sqrt(v.hat)) - cn[d])/sn[d]
+    p <- 1 - exp(-exp(-stat))
+    
+    result[[d]] <- list(statistic = c(LM = stat),
+                        p.value = p,
+                        method = "Lee and Mykland jump test",
+                        data.names = paste("x",d,sep = ""))
+    class(result[[d]]) <- "htest"
+    
+  }
+  
+  return(result)
+}

Added: pkg/yuima/R/ntv.R
===================================================================
--- pkg/yuima/R/ntv.R	                        (rev 0)
+++ pkg/yuima/R/ntv.R	2021-11-28 04:56:30 UTC (rev 764)
@@ -0,0 +1,149 @@
+
+###################################################### 
+# Volatility estimation and jump test using
+# nearest neighbor truncation
+######################################################
+
+######## Volatility estimation ########
+
+## MinRV
+minrv <- function(yuima){
+  
+  x <- get.zoo.data(yuima)
+  d <- length(x)
+  out <- double(d)
+  
+  for(j in 1:d){
+    dx2 <- diff(as.numeric(x[[j]]))^2
+    out[j] <- length(dx2) * mean(pmin(dx2[-length(dx2)], dx2[-1]))
+  }
+  
+  return((pi/(pi - 2)) * out)
+}
+
+## MedRV
+medrv <- function(yuima){
+  
+  x <- get.zoo.data(yuima)
+  d <- length(x)
+  out <- double(d)
+  
+  for(j in 1:d){
+    dx2 <- diff(as.numeric(x[[j]]))^2
+    out[j] <- length(dx2) * mean(rollmedian(dx2, k = 3))
+  }
+  
+  return((pi/(6 - 4*sqrt(3) + pi)) * out)
+}
+
+
+######## Jump test ########
+
+## function to compute log-type test statistics
+logstat <- function(rv, iv, iq, n, theta, adj){
+  
+  avar <- iq/iv^2
+  
+  if(adj) avar[avar < 1] <- 1
+  
+  return(log(rv/iv)/sqrt(theta * avar/n))
+}
+
+## function to compute ratio-type test statistics
+ratiostat <- function(rv, iv, iq, n, theta, adj){
+  
+  avar <- iq/iv^2
+  
+  if(adj) avar[avar < 1] <- 1
+  
+  return((1 - iv/rv)/sqrt(theta * avar/n))
+}
+
+## Jump test based on minRV
+minrv.test <- function(yuima, type = "ratio", adj = TRUE){
+  
+  data <- get.zoo.data(yuima)
+  d.size <- length(data)
+  
+  rv <- double(d.size)
+  iv <- double(d.size)
+  iq <- double(d.size)
+  n <- integer(d.size)
+  
+  for(d in 1:d.size){
+    
+    dx2 <- diff(as.numeric(data[[d]]))^2
+    n[d] <- length(dx2)
+    
+    rv[d] <- sum(dx2)
+    
+    obj <- pmin(dx2[-n[d]], dx2[-1])
+    iv[d] <- (pi/(pi - 2)) * n[d] * mean(obj)
+    iq[d] <- (pi/(3*pi - 8)) * n[d]^2 * mean(obj^2)
+    
+  }
+  
+  stat <- switch(type,
+                 "standard" = (rv - iv)/sqrt(1.81 * iq/n),
+                 "ratio" = ratiostat(rv, iv, iq, n, 1.81, adj),
+                 "log" = logstat(rv, iv, iq, n, 1.81, adj))
+  
+  p <- pnorm(stat, lower.tail = FALSE)
+  
+  result <- vector(d.size,mode="list") 
+  
+  for(d in 1:d.size){
+    result[[d]] <- list(statistic = c(ADS = stat[d]),
+                        p.value = p[d],
+                        method = "Andersen-Dobrev-Schaumburg jump test based on MinRV",
+                        data.names = paste("x",d,sep = ""))
+    class(result[[d]]) <- "htest"
+  }
+  
+  return(result)
+}
+
+## Jump test based on medRV
+medrv.test <- function(yuima, type = "ratio", adj = TRUE){
+  
+  data <- get.zoo.data(yuima)
+  d.size <- length(data)
+  
+  rv <- double(d.size)
+  iv <- double(d.size)
+  iq <- double(d.size)
+  n <- integer(d.size)
+  
+  for(d in 1:d.size){
+    
+    dx2 <- diff(as.numeric(data[[d]]))^2
+    n[d] <- length(dx2)
+    
+    rv[d] <- sum(dx2)
+    
+    obj <- rollmedian(dx2, k = 3)
+    iv[d] <- (pi/(6 - 4*sqrt(3) + pi)) * n[d] * mean(obj)
+    iq[d] <- (3*pi/(9*pi + 72 - 52*sqrt(3))) * n[d]^2 * mean(obj^2)
+    
+  }
+  
+  stat <- switch(type,
+                 "standard" = (rv - iv)/sqrt(0.96 * iq/n),
+                 "ratio" = ratiostat(rv, iv, iq, n, 0.96, adj),
+                 "log" = logstat(rv, iv, iq, n, 0.96, adj))
+  
+  p <- pnorm(stat, lower.tail = FALSE)
+  
+  result <- vector(d.size,mode="list") 
+  
+  for(d in 1:d.size){
+    result[[d]] <- list(statistic = c(ADS = stat[d]),
+                        p.value = p[d],
+                        method = "Andersen-Dobrev-Schaumburg jump test based on MedRV",
+                        data.names = paste("x",d,sep = ""))
+    class(result[[d]]) <- "htest"
+  }
+  
+  return(result)
+}
+

Added: pkg/yuima/R/pz.test.R
===================================================================
--- pkg/yuima/R/pz.test.R	                        (rev 0)
+++ pkg/yuima/R/pz.test.R	2021-11-28 04:56:30 UTC (rev 764)
@@ -0,0 +1,57 @@
+
+# Podolskij-Ziggel's Jump Test
+
+pz.test <- function(yuima, p = 4, threshold = "local", tau = 0.05){
+  
+  data <- get.zoo.data(yuima)
+  d.size <- length(data)
+  
+  adx <- vector(d.size,mode="list")
+  
+  for(d in 1:d.size){
+    
+    X <- as.numeric(data[[d]])
+    idt <- which(is.na(X))
+    if(length(idt>0)){
+      X <- X[-idt]
+    }
+    if(length(X)<2) {
+      stop("length of data (w/o NA) must be more than 1")
+    }
+    adx[[d]] <- abs(diff(X))
+  }
+  
+  n <- sapply(adx, "length")
+  
+  if(threshold == "local"){
+    thr <- local_univ_threshold(data)
+  }else if(threshold == "PZ"){
+    thr <- 2.3^2 * mpv(yuima, r = c(1, 1)) * n^(-0.8)
+  }else{
+    thr <- threshold
+  }
+  
+  # core part
+  result <- vector(d.size, mode = "list")
+  
+  for(d in 1:d.size){
+    # thresholding
+    tr.idx <- (adx[[d]]^2 <= thr[[d]])
+    
+    eta <- sample(c(1 - tau, 1 + tau), size = n[d], replace = TRUE)
+    
+    numer <- sum(adx[[d]]^p * (1 - eta * tr.idx))
+    denom <- tau * sqrt(sum(adx[[d]]^(2*p) * tr.idx))
+    
+    PZ <- numer/denom
+    
+    pval <- pnorm(PZ,lower.tail=FALSE)
+    result[[d]] <- list(statistic=c(PZ=PZ),p.value=pval,
+                        method="Podolskij-Ziggel jump test",
+                        data.names=paste("x",d,sep=""))
+    class(result[[d]]) <- "htest"
+    
+  }
+  
+  return(result)
+}

Modified: pkg/yuima/man/bns.test.Rd
===================================================================
--- pkg/yuima/man/bns.test.Rd	2021-11-23 10:58:23 UTC (rev 763)
+++ pkg/yuima/man/bns.test.Rd	2021-11-28 04:56:30 UTC (rev 764)
@@ -44,7 +44,7 @@
 %%  \item{comp1 }{Description of 'comp1'}
 %%  \item{comp2 }{Description of 'comp2'}
 %% ...
-A list with the same length as the \code{zoo.data} of \code{yuima}. Each components of the list has class \dQuote{\code{htest}} and contains the following components:
+A list with the same length as the \code{zoo.data} of \code{yuima}. Each component of the list has class \dQuote{\code{htest}} and contains the following components:
 \item{statistic}{the value of the test statistic of the corresponding component of the \code{zoo.data} of \code{yuima}.}
 \item{p.value}{an approximate p-value for the test of the corresponding component.}
 \item{method}{the character string \dQuote{\code{Barndorff-Nielsen and Shephard jump test}}.}
@@ -77,10 +77,9 @@
 
 \seealso{
 %% ~~objects to See Also as \code{\link{help}}, ~~~
-\code{\link{mpv}}
+\code{\link{lm.jumptest}}, \code{\link{mpv}}, \code{\link{minrv.test}}, \code{\link{medrv.test}}, \code{\link{pz.test}}
 }
 \examples{
-
 set.seed(123)
 
 # One-dimensional case

Added: pkg/yuima/man/lm.jumptest.Rd
===================================================================
--- pkg/yuima/man/lm.jumptest.Rd	                        (rev 0)
+++ pkg/yuima/man/lm.jumptest.Rd	2021-11-28 04:56:30 UTC (rev 764)
@@ -0,0 +1,114 @@
+\name{lm.jumptest}
+\alias{lm.jumptest}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+%%  ~~function to do ... ~~
+Lee and Mykland's Test for the Presence of Jumps Using Normalized Returns
+}
+\description{
+%%  ~~ A concise (1-5 lines) description of what the function does. ~~
+Performs a test for the null hypothesis that the realized path has no jump following Lee and Mykland (2008).
+}
+\usage{
+lm.jumptest(yuima, K)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+  \item{yuima}{
+%%     ~~Describe \code{yuima} here~~
+an object of  \code{\link{yuima-class}} or \code{\link{yuima.data-class}}.
+}
+  \item{K}{
+%%     ~~Describe \code{K} here~~
+a positive integer indicating the window size to compute local variance estimates. It can be specified as a vector to use different window sizes for different components. The default value is \code{K=pmin(floor(sqrt(252*n)), n)} with \code{n=length(yuima)-1}, following Lee and Mykland (2008) as well as Dumitru and Urga (2012).
+}
+}
+
+\value{
+%%  ~Describe the value returned
+%%  If it is a LIST, use
+%%  \item{comp1 }{Description of 'comp1'}
+%%  \item{comp2 }{Description of 'comp2'}
+%% ...
+A list with the same length as \code{dim(yuima)}. Each component of the list has class \dQuote{\code{htest}} and contains the following components:
+\item{statistic}{the value of the test statistic of the corresponding component of \code{yuima}.}
+\item{p.value}{an approximate p-value for the test of the corresponding component.}
+\item{method}{the character string \dQuote{\code{Lee and Mykland jump test}}.}
+\item{data.name}{the character string \dQuote{\code{xi}}, where \code{i} is the number of the component.}
+}
+\references{
+%% ~put references to the literature/web site here ~
+Dumitru, A.-M. and Urga, G. (2012)
+  Identifying jumps in financial assets: A comparison between nonparametric jump tests.
+  \emph{Journal of Business and Economic Statistics}, \bold{30}, 242--255.
+  
+Lee, S. S. and Mykland, P. A. (2008)
+  Jumps in financial markets: A new nonparametric test and jump dynamics.
+  \emph{Review of Financial Studies}, \bold{21}, 2535--2563.
+  
+Maneesoonthorn, W., Martin, G. M. and Forbes, C. S. (2020)
+  High-frequency jump tests: Which test should we use?
+  \emph{Journal of Econometrics}, \bold{219}, 478--487.
+  
+Theodosiou, M. and Zikes, F. (2011)
+  A comprehensive comparison of alternative tests for jumps in asset prices. 
+  Central Bank of Cyprus Working Paper 2011-2.
+}
+\author{
+%%  ~~who you are~~
+Yuta Koike with YUIMA Project Team
+}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+\seealso{
+%% ~~objects to See Also as \code{\link{help}}, ~~~
+\code{\link{bns.test}}, \code{\link{minrv.test}}, \code{\link{medrv.test}}, \code{\link{pz.test}}
+}
+\examples{
+set.seed(123)
+
+# One-dimensional case
+## Model: dXt=t*dWt+t*dzt, 
+## where zt is a compound Poisson process with intensity 5 and jump sizes distribution N(0,1).
+
+model <- setModel(drift=0,diffusion="t",jump.coeff="t",measure.type="CP",
+                  measure=list(intensity=5,df=list("dnorm(z,0,sqrt(0.1))")),
+                  time.variable="t")
+
+yuima.samp <- setSampling(Terminal = 1, n = 390) 
+yuima <- setYuima(model = model, sampling = yuima.samp) 
+yuima <- simulate(yuima)
+plot(yuima) # The path seems to involve some jumps
+
+lm.jumptest(yuima) # p-value is very small, so the path would have a jump
+lm.jumptest(yuima, K = floor(sqrt(390))) # different value of K
+
+# Multi-dimensional case
+## Model: Bivariate standard BM + CP
+## Only the first component has jumps
+
+mod <- setModel(drift = c(0, 0), diffusion = diag(2),
+                jump.coeff = diag(c(1, 0)),
+                measure = list(intensity = 5, 
+                               df = "dmvnorm(z,c(0,0),diag(2))"),
+                jump.variable = c("z"), measure.type=c("CP"),
+                solve.variable=c("x1","x2"))
+
+samp <- setSampling(Terminal = 1, n = 390) 
+yuima <- setYuima(model = model, sampling = yuima.samp)
+yuima <- simulate(object = mod, sampling = samp)
+plot(yuima)
+
+lm.jumptest(yuima) # test is performed component-wise
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory (show via RShowDoc("KEYWORDS")):
+% \keyword{ ~kwd1 }
+% \keyword{ ~kwd2 }
+\keyword{ts}
+% Use only one keyword per line.
+% For non-standard keywords, use \concept instead of \keyword:
+% \concept{ ~cpt1 }
+% \concept{ ~cpt2 }
+% Use only one concept per line.

Modified: pkg/yuima/man/mpv.Rd
===================================================================
--- pkg/yuima/man/mpv.Rd	2021-11-23 10:58:23 UTC (rev 763)
+++ pkg/yuima/man/mpv.Rd	2021-11-28 04:56:30 UTC (rev 764)
@@ -10,7 +10,7 @@
 }
 \description{
 %%  ~~ A concise (1-5 lines) description of what the function does. ~~
-The function returns the realized MultiPower Variation (mpv), defined in Barndorff-Nielsen and Shephard (2004), for each components.
+The function returns the realized MultiPower Variation (mpv), defined in Barndorff-Nielsen and Shephard (2004), for each component.
 }
 \usage{
 mpv(yuima, r = 2, normalize = TRUE)
@@ -71,7 +71,7 @@
 
 \seealso{
 %% ~~objects to See Also as \code{\link{help}}, ~~~
-\code{\link{setModel}},\code{\link{cce}}
+\code{\link{setData}}, \code{\link{cce}}, \code{\link{minrv}}, \code{\link{medrv}}
 }
 \examples{
 

Added: pkg/yuima/man/ntv.Rd
===================================================================
--- pkg/yuima/man/ntv.Rd	                        (rev 0)
+++ pkg/yuima/man/ntv.Rd	2021-11-28 04:56:30 UTC (rev 764)
@@ -0,0 +1,152 @@
+\name{ntv}
+\alias{ntv}
+\alias{minrv}
+\alias{medrv}
+\alias{minrv.test}
+\alias{medrv.test}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+Volatility Estimation and Jump Test Using Nearest Neighbor Truncation
+%%  ~~function to do ... ~~
+}
+\description{
+%%  ~~ A concise (1-5 lines) description of what the function does. ~~
+\code{minrv} and \code{medrv} respectively compute the MinRV and MedRV estimators introduced in Andersen, Dobrev and Schaumburg (2012).
+
+\code{minrv.test} and \code{medrv.test} respectively perform Haussman type tests for the null hypothesis that the realized path has no jump using the MinRV and MedRV estimators. 
+See Section 4.4 in Andersen, Dobrev and Schaumburg (2014) for a concise discussion. 
+}
+\usage{
+minrv(yuima)
+medrv(yuima)
+
+minrv.test(yuima, type = "ratio", adj = TRUE)
+medrv.test(yuima, type = "ratio", adj = TRUE)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+  \item{yuima}{
+%%     ~~Describe \code{yuima} here~~
+an object of  \code{\link{yuima-class}} or \code{\link{yuima.data-class}}.
+}
+\item{type}{
+%%     ~~Describe \code{type} here~~
+type of the test statistic to use. \code{ratio} is default.
+}
+  \item{adj}{
+%%     ~~Describe \code{adj} here~~
+logical; if \code{TRUE}, the maximum adjustment suggested in Barndorff-Nielsen and Shephard (2004) is applied to the test statistic when \code{type} is equal to either \dQuote{\code{log}} or \dQuote{\code{ratio}}. See also Section 2.5 in Dumitru and Urga (2012).
+}
+}
+\value{
+%%  ~Describe the value returned
+%%  If it is a LIST, use
+%%  \item{comp1 }{Description of 'comp1'}
+%%  \item{comp2 }{Description of 'comp2'}
+%% ...
+\code{minrv} and \code{medrv} return a numeric vector with the same length as \code{dim(yuima)}. Each component of the vector is a volatility estimate for the corresponding component of \code{yuima}.
+
+\code{minrv.test} and \code{medrv.test} return a list with the same length as \code{dim(yuima)}. Each component of the list has class \dQuote{\code{htest}} and contains the following components:
+\item{statistic}{the value of the test statistic of the corresponding component of \code{yuima}.}
+\item{p.value}{an approximate p-value for the test of the corresponding component.}
+\item{method}{the character string \dQuote{\code{Andersen-Dobrev-Schaumburg jump test based on xxx}}, where xxx is either MinRV or MedRV.}
+\item{data.name}{the character string \dQuote{\code{xi}}, where \code{i} is the number of the component.}
+}
+\references{
+%% ~put references to the literature/web site here ~
+Andersen, T. G., Dobrev D. and Schaumburg, E. (2012)
+  Jump-robust volatility estimation using nearest neighbor truncation.
+  \emph{Journal of Econometrics}, \bold{169}, 75--93.
+  
+Andersen, T. G., Dobrev D. and Schaumburg, E. (2014)
+  A robust neighborhood truncation approach to estimation of integrated quarticity.
+  \emph{Econometric Theory}, \bold{30}, 3--59.
+  
+Dumitru, A.-M. and Urga, G. (2012)
+  Identifying jumps in financial assets: A comparison between nonparametric jump tests.
+  \emph{Journal of Business and Economic Statistics}, \bold{30}, 242--255.
+  
+Maneesoonthorn, W., Martin, G. M. and Forbes, C. S. (2020)
+  High-frequency jump tests: Which test should we use?
+  \emph{Journal of Econometrics}, \bold{219}, 478--487.
+  
+Theodosiou, M. and Zikes, F. (2011)
+  A comprehensive comparison of alternative tests for jumps in asset prices. 
+  Central Bank of Cyprus Working Paper 2011-2.
+}
+\author{
+%%  ~~who you are~~
+Yuta Koike with YUIMA Project Team
+}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+\seealso{
+%% ~~objects to See Also as \code{\link{help}}, ~~~
+\code{\link{mpv}}, \code{\link{cce}}, \code{\link{bns.test}}, \code{\link{lm.jumptest}}, \code{\link{pz.test}}
+}
+\examples{
+set.seed(123)
+
+# One-dimensional case
+## Model: dXt=t*dWt+t*dzt, 
+## where zt is a compound Poisson process with intensity 5
+## and jump sizes distribution N(0,1).
+
+model <- setModel(drift=0,diffusion="t",jump.coeff="t",measure.type="CP",
+                  measure=list(intensity=5,df=list("dnorm(z,0,1)")),
+                  time.variable="t")
+
+yuima.samp <- setSampling(Terminal = 1, n = 390) 
+yuima <- setYuima(model = model, sampling = yuima.samp) 
+yuima <- simulate(yuima)
+plot(yuima) # The path evidently has some jumps
+
+## Volatility estimation
+minrv(yuima) # minRV (true value = 1/3)
+medrv(yuima) # medRV (true value = 1/3)
+
+## Jump test
+minrv.test(yuima, type = "standard")
+minrv.test(yuima,type="log")
+minrv.test(yuima,type="ratio")
+
+medrv.test(yuima, type = "standard")
+medrv.test(yuima,type="log")
+medrv.test(yuima,type="ratio")
+
+
+# Multi-dimensional case
+## Model: Bivariate standard BM + CP
+## Only the first component has jumps
+
+mod <- setModel(drift = c(0, 0), diffusion = diag(2),
+                jump.coeff = diag(c(1, 0)),
+                measure = list(intensity = 5, 
+                               df = "dmvnorm(z,c(0,0),diag(2))"),
+                jump.variable = c("z"), measure.type=c("CP"),
+                solve.variable=c("x1","x2"))
+
+samp <- setSampling(Terminal = 1, n = 390) 
+yuima <- setYuima(model = model, sampling = yuima.samp)
+yuima <- simulate(object = mod, sampling = samp)
+plot(yuima)
+
+## Volatility estimation
+minrv(yuima) # minRV (true value = c(1, 1))
+medrv(yuima) # medRV (true value = c(1, 1))
+
+## Jump test
+minrv.test(yuima) # test is performed component-wise
+medrv.test(yuima) # test is performed component-wise
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory (show via RShowDoc("KEYWORDS")):
+\keyword{ts}
+% \keyword{ ~kwd1 }
+% \keyword{ ~kwd2 }
+% Use only one keyword per line.
+% For non-standard keywords, use \concept instead of \keyword:
+% \concept{ ~cpt1 }
+% \concept{ ~cpt2 }
+% Use only one concept per line.

Added: pkg/yuima/man/pz.test.Rd
===================================================================
--- pkg/yuima/man/pz.test.Rd	                        (rev 0)
+++ pkg/yuima/man/pz.test.Rd	2021-11-28 04:56:30 UTC (rev 764)
@@ -0,0 +1,134 @@
+\name{pz.test}
+\alias{pz.test}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+%%  ~~function to do ... ~~
+Podolskij and Ziggel's Test for the Presence of Jumps Using Power Variation with Perturbed Truncation
+}
+\description{
+%%  ~~ A concise (1-5 lines) description of what the function does. ~~
+Performs a test for the null hypothesis that the realized path has no jump following Podolskij and Ziggel (2010).
+}
+\usage{
+pz.test(yuima, p = 4, threshold = "local", tau = 0.05)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+  \item{yuima}{
+%%     ~~Describe \code{yuima} here~~
+an object of  \code{\link{yuima-class}} or \code{\link{yuima.data-class}}.
+}
+  \item{p}{
+%%     ~~Describe \code{p} here~~
+a positive number indicating the exponent of the (truncated) power variation to compute test statistic(s). Theoretically, it must be greater than or equal to 2.
+}
+  \item{threshold}{
+%%     ~~Describe \code{threshold} here~~
+a numeric vector or list indicating the threshold parameter(s). Each of its components indicates the threshold parameter or process to be used for estimating the corresponding component. If it is a numeric vector, the elements in \code{threshold} are recycled if there are two few elements in \code{threshold}. 
+
+Alternatively, you can specify either \code{"PZ"} or \code{"local"} to automatically select a (hopefully) appropriate threshold. When \code{threshold="PZ"}, selection is performed following Section 5.1 in Podolskij and Ziggel (2010). When \code{threshold="local"}, selection is performed following Section 5.1 in Koike (2014). The default is \code{threshold="local"}.
+}
+  \item{tau}{
+%%     ~~Describe \code{tau} here~~
+a probability controlling the strength of perturbation. See Section 2.3 in Podolskij and Ziggel (2010) for details. Podolskij and Ziggel (2010) suggests using a relatively small value for \code{tau}, e.g. \code{tau=0.1} or \code{tau=0.05}.
+}
+}
+\value{
+%%  ~Describe the value returned
+%%  If it is a LIST, use
+%%  \item{comp1 }{Description of 'comp1'}
+%%  \item{comp2 }{Description of 'comp2'}
+%% ...
+A list with the same length as \code{dim(yuima)}. Each component of the list has class \dQuote{\code{htest}} and contains the following components:
+\item{statistic}{the value of the test statistic of the corresponding component of \code{yuima}.}
+\item{p.value}{an approximate p-value for the test of the corresponding component.}
+\item{method}{the character string \dQuote{\code{Podolskij and Ziggel jump test}}.}
+\item{data.name}{the character string \dQuote{\code{xi}}, where \code{i} is the number of the component.}
+}
+\references{
+%% ~put references to the literature/web site here ~
+Dumitru, A.-M. and Urga, G. (2012)
+  Identifying jumps in financial assets: A comparison between nonparametric jump tests.
+  \emph{Journal of Business and Economic Statistics}, \bold{30}, 242--255.
+  
+Koike, Y. (2014)
+  An estimator for the cumulative co-volatility of asynchronously observed semimartingales with jumps,
+  \emph{Scandinavian Journal of Statistics}, \bold{41}, 460--481.
+  
+Maneesoonthorn, W., Martin, G. M. and Forbes, C. S. (2020)
+  High-frequency jump tests: Which test should we use?
+  \emph{Journal of Econometrics}, \bold{219}, 478--487.
+
+Podolskij, M. and Ziggel, D. (2010)
+  New tests for jumps in semimartingale models,
+  \emph{Statistical Inference for Stochastic Processes}, \bold{13}, 15--41.
+  
+Theodosiou, M. and Zikes, F. (2011)
+  A comprehensive comparison of alternative tests for jumps in asset prices. 
+  Central Bank of Cyprus Working Paper 2011-2.
+}
+\author{
+%%  ~~who you are~~
+Yuta Koike with YUIMA Project Team
+}
+\note{
+%%  ~~further notes~~
+Podolskij and Ziggel (2010) also introduce a pre-averaged version of the test to deal with noisy observations. Such a test will be implemented in the future version of the package.
+}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+\seealso{
+%% ~~objects to See Also as \code{\link{help}}, ~~~
+\code{\link{bns.test}}, \code{\link{lm.jumptest}}, \code{\link{minrv.test}}, \code{\link{medrv.test}}
+}
+\examples{
+set.seed(123)
+
+# One-dimensional case
+## Model: dXt=t*dWt+t*dzt, 
+## where zt is a compound Poisson process with intensity 5 and jump sizes distribution N(0,1).
+
+model <- setModel(drift=0,diffusion="t",jump.coeff="t",measure.type="CP",
+                  measure=list(intensity=5,df=list("dnorm(z,0,sqrt(0.1))")),
+                  time.variable="t")
+
+yuima.samp <- setSampling(Terminal = 1, n = 390) 
+yuima <- setYuima(model = model, sampling = yuima.samp) 
+yuima <- simulate(yuima)
+plot(yuima) # The path seems to involve some jumps
+
+#lm.jumptest(yuima) # p-value is very small, so the path would have a jump
+#lm.jumptest(yuima, K = floor(sqrt(390))) # different value of K
+pz.test(yuima) # p-value is very small, so the path would have a jump
+pz.test(yuima, p = 2) # different value of p
+pz.test(yuima, tau = 0.1) # different value of tau
+
+# Multi-dimensional case
+## Model: Bivariate standard BM + CP
+## Only the first component has jumps
+
+mod <- setModel(drift = c(0, 0), diffusion = diag(2),
+                jump.coeff = diag(c(1, 0)),
+                measure = list(intensity = 5, 
+                               df = "dmvnorm(z,c(0,0),diag(2))"),
+                jump.variable = c("z"), measure.type=c("CP"),
+                solve.variable=c("x1","x2"))
+
+samp <- setSampling(Terminal = 1, n = 390) 
+yuima <- setYuima(model = model, sampling = yuima.samp)
+yuima <- simulate(object = mod, sampling = samp)
+plot(yuima)
+
+pz.test(yuima) # test is performed component-wise
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory (show via RShowDoc("KEYWORDS")):
+\keyword{ts}
+% \keyword{ ~kwd1 }
+% \keyword{ ~kwd2 }
+% Use only one keyword per line.
+% For non-standard keywords, use \concept instead of \keyword:
+% \concept{ ~cpt1 }
+% \concept{ ~cpt2 }
+% Use only one concept per line.



More information about the Yuima-commits mailing list