[Yuima-commits] r132 - in pkg/yuima: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Oct 30 02:11:41 CEST 2010
Author: hinohide
Date: 2010-10-30 02:11:40 +0200 (Sat, 30 Oct 2010)
New Revision: 132
Added:
pkg/yuima/R/llag.R
pkg/yuima/man/llag.Rd
Modified:
pkg/yuima/DESCRIPTION
pkg/yuima/NAMESPACE
pkg/yuima/NEWS
pkg/yuima/man/yuima-class.Rd
pkg/yuima/man/yuima.data-class.Rd
Log:
added llag function
Modified: pkg/yuima/DESCRIPTION
===================================================================
--- pkg/yuima/DESCRIPTION 2010-10-28 09:05:02 UTC (rev 131)
+++ pkg/yuima/DESCRIPTION 2010-10-30 00:11:40 UTC (rev 132)
@@ -1,8 +1,8 @@
Package: yuima
Type: Package
Title: The YUIMA Project package (unstable version)
-Version: 0.1.177
-Date: 2010-10-04
+Version: 0.1.178
+Date: 2010-10-30
Depends: methods, zoo, stats4, utils
Suggests: cubature, mvtnorm
Author: YUIMA Project Team.
Modified: pkg/yuima/NAMESPACE
===================================================================
--- pkg/yuima/NAMESPACE 2010-10-28 09:05:02 UTC (rev 131)
+++ pkg/yuima/NAMESPACE 2010-10-30 00:11:40 UTC (rev 132)
@@ -28,6 +28,7 @@
## "end",
"simulate",
"cce",
+ "llag",
"poisson.random.sampling",
"get.zoo.data",
"initialize",
@@ -66,6 +67,7 @@
export(simulate) # simulates couple of processes
export(subsampling)
export(cce)
+export(llag)
export(poisson.random.sampling)
export(get.zoo.data)
Modified: pkg/yuima/NEWS
===================================================================
--- pkg/yuima/NEWS 2010-10-28 09:05:02 UTC (rev 131)
+++ pkg/yuima/NEWS 2010-10-30 00:11:40 UTC (rev 132)
@@ -1,7 +1,9 @@
+Change in Version 0.1.179
+ o llag function is added.
+
Changes in Version 0.1.177
o cce is now able to accept list style argument.
-
Changes in Version 0.1.14
o added yuima.cbind function to bind yuima.data object by column.
Added: pkg/yuima/R/llag.R
===================================================================
--- pkg/yuima/R/llag.R (rev 0)
+++ pkg/yuima/R/llag.R 2010-10-30 00:11:40 UTC (rev 132)
@@ -0,0 +1,69 @@
+#lead-lag estimation
+
+#x:data plot:T or F
+setGeneric( "llag", function(x) standardGeneric("llag") )
+setMethod( "llag", "yuima", function(x) llag(x at data ))
+setMethod( "llag", "yuima.data", function(x) {
+
+ if(!is(x)=="yuima.data"){
+ if(is(x)=="yuima"){
+ dat <- x at data
+ }else{
+ print("llag:invalid argument")
+ return(NULL)
+ }
+ }else{
+ dat <- x
+ }
+
+## dat <- get.zoo.data(x)
+## dat <- x at data
+
+ data1 <- dat at zoo.data[[1]]
+ data2 <- dat at zoo.data[[2]]
+## data1 <- as.numeric(dat[[1]])
+## data2 <- as.numeric(dat[[2]])
+ time1 <- time(data1)
+ time2 <- time(data2)
+
+ lagcce <- function(theta){
+ stime <- time2 + theta #shifted time
+ time(dat at zoo.data[[2]]) <- stime
+ return(cce(dat))
+ }
+
+
+# calculate the maximum of correlation by substituting theta to lagcce
+
+#n:=2*length(data)
+
+ n <- round(2*max(length(data1),length(data2)))+1
+
+# maximum value of lagcce
+ theta <- as.numeric(time2[1])-as.numeric(time1[1]) # time lag (sec)
+
+ num1 <- as.numeric(time1[length(time1)])-as.numeric(time1[1]) # elapsed time for series 1
+ num2 <- as.numeric(time2[length(time2)])-as.numeric(time2[1]) # elapsed time for series 2
+
+ lagmax <- function(n){
+ y <- seq(-num2-theta,num1-theta,length=n)
+ tmp <- real(n)
+ for(i in 2:(n-1)){
+ tmp[i] <- lagcce(y[i])$covmat[1,2]
+ }
+
+ mat <- cbind(y[2:(n-1)],tmp[2:(n-1)])
+ return(mat)
+ }
+
+
+ mat <- lagmax(n)
+
+ opt <- mat[,1][abs(mat[,2])==max(abs(mat[,2]))][1] # make the first timing of max or min
+
+ covmat <- lagcce(opt)$covmat
+ cormat <- lagcce(opt)$cormat
+
+ return(list(lagcce=opt,covmat=covmat,cormat=cormat,mat=mat))
+})
+
Added: pkg/yuima/man/llag.Rd
===================================================================
--- pkg/yuima/man/llag.Rd (rev 0)
+++ pkg/yuima/man/llag.Rd 2010-10-30 00:11:40 UTC (rev 132)
@@ -0,0 +1,69 @@
+\name{llag}
+\alias{llag}
+\alias{llag,list-method}
+\title{Lead Lag Estimator}
+\description{TBA
+}
+\usage{
+llag(x)
+}
+\arguments{
+ \item{x}{an object of \code{\link{yuima-class}} or \code{\link{yuima.data-class}}.}
+}
+\details{
+ TBA
+}
+\value{
+ \item{value}{estimate of the lag, covariance and correlation matrices}
+}
+\note{TBA
+}
+\references{
+ TBA
+}
+\author{The YUIMA Project Team}
+\examples{
+
+
+# generate two sample paths
+
+ rho <- 0.4 # correlation coefficiant
+
+ diff.coef.matrix <- matrix(c(1,rho,rho,1),2,2)
+ drift <- c("0*x1","0*x2")
+ cor.mod <- setModel(drift = drift, diffusion = diff.coef.matrix,solve.variable = c("x1", "x2"))
+
+ yuima.samp <- setSampling(Terminal = 1, n = 300)
+ yuima <- setYuima(model = cor.mod, sampling = yuima.samp)
+ yuima <- simulate(yuima)
+
+# intentionally displace the second time series
+
+ data2 <- yuima at data@zoo.data[[2]]
+ time <- time(data2)
+
+ theta <- 0.05 # the degree of lag
+
+ stime <- time + theta
+ time(yuima at data@zoo.data[[2]]) <- stime
+
+# estimate lead-lag
+
+ lagcce <- function(theta){
+ stime <- time2 + theta #shifted time
+ time(dat at zoo.data[[2]]) <- stime
+ return(cce(dat))
+ }
+
+# true value must be -theta=0.05
+ret <- llag(yuima)
+print(ret$opt)
+print(ret$covmat)
+print(ret$cormat)
+
+plot(ret$mat,xlab="theta",ylab="U(theta)",type="l")
+
+
+}
+\seealso{\link{cce}}
+\keyword{ts}
Property changes on: pkg/yuima/man/llag.Rd
___________________________________________________________________
Added: svn:executable
+ *
Modified: pkg/yuima/man/yuima-class.Rd
===================================================================
--- pkg/yuima/man/yuima-class.Rd 2010-10-28 09:05:02 UTC (rev 131)
+++ pkg/yuima/man/yuima-class.Rd 2010-10-30 00:11:40 UTC (rev 132)
@@ -6,6 +6,7 @@
\alias{dim,yuima-method}
\alias{length,yuima-method}
\alias{cce,yuima-method}
+\alias{llag,yuima-method}
\alias{initialize,yuima-method}
\alias{simulate,yuima-method}
\alias{poisson.random.sampling,yuima-method}
@@ -77,6 +78,9 @@
\item{cce}{\code{signature(x = "yuima")}: calculates the asyncronous
covariance estimator on the data contained in \code{x at data@zoo.data}.
For more details see \code{\link{cce}}.}
+ \item{llag}{\code{signature(x = "yuima")}: calculates the lead lag estimate
+ r on the data contained in \code{x at data@zoo.data}.
+ For more details see \code{\link{llag}}.}
\item{simulate}{simulation method. For more information see
\code{\link{simulate}}.}
\item{cbind.yuima}{\code{signature(x = "yuima")}: bind yuima.data object.}
Modified: pkg/yuima/man/yuima.data-class.Rd
===================================================================
--- pkg/yuima/man/yuima.data-class.Rd 2010-10-28 09:05:02 UTC (rev 131)
+++ pkg/yuima/man/yuima.data-class.Rd 2010-10-30 00:11:40 UTC (rev 132)
@@ -10,6 +10,7 @@
\alias{dim,yuima.data-method}
\alias{length,yuima.data-method}
\alias{cce,yuima.data-method}
+\alias{llag,yuima.data-method}
\alias{initialize,yuima.data-method}
%\alias{setSampling,yuima.data-method}
\alias{poisson.random.sampling,yuima.data-method}
@@ -86,6 +87,9 @@
\item{cce}{\code{signature(x = "yuima.data")}: calculates asyncronous
covariance estimator on the data contained in \code{x at zoo.data}.
For more details see \code{\link{cce}}.}
+ \item{llag}{\code{signature(x = "yuima.data")}: calculates lead lag estimate
+ on the data contained in \code{x at zoo.data}.
+ For more details see \code{\link{llag}}.}
\item{cbind.yuima}{\code{signature(x = "yuima.data")}: bind yuima.data object.}
}
}
More information about the Yuima-commits
mailing list