[Yuima-commits] r486 - pkg/yuima/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Oct 20 09:54:10 CEST 2016


Author: lorenzo
Date: 2016-10-20 09:54:10 +0200 (Thu, 20 Oct 2016)
New Revision: 486

Modified:
   pkg/yuima/R/qmle.R
   pkg/yuima/R/simulate.R
Log:
Modified qmle

Modified: pkg/yuima/R/qmle.R
===================================================================
--- pkg/yuima/R/qmle.R	2016-10-17 02:18:07 UTC (rev 485)
+++ pkg/yuima/R/qmle.R	2016-10-20 07:54:10 UTC (rev 486)
@@ -2088,7 +2088,10 @@
     }
   }
   Vdiag <- -solve(B)[,p]*0.5*sigma^2
-  V <- diag(Vdiag)
+  #V <- diag(Vdiag)
+  if(is(Vdiag,"matrix")){
+    V <- diag(Vdiag)
+  }else{V <- as.matrix(Vdiag)}
   # we insert the values outside the diagonal
   for(i in 1:p){
     for(j in (i+1):p){

Modified: pkg/yuima/R/simulate.R
===================================================================
--- pkg/yuima/R/simulate.R	2016-10-17 02:18:07 UTC (rev 485)
+++ pkg/yuima/R/simulate.R	2016-10-20 07:54:10 UTC (rev 486)
@@ -509,8 +509,8 @@
     #                         sgrid=samp at sgrid, interpolation=samp at interpolation )
 
         aux.samp<-setSampling(Initial = samp at Initial,
-                              Terminal = samp at Terminal[1],
-                              n = samp at n[1])
+                              Terminal = samp at Terminal[1]+samp at delta,
+                              n = samp at n[1]+1)
         auxModel<-setYuima(model=aux.Noise, sampling= aux.samp)
 
       if(length(model at parameter@measure)==0){
@@ -561,10 +561,11 @@
 #                     sgrid=sgrid, interpolation=interpolation)
 
 
-
+    Initial <- samp at Initial[1]
     Terminal <- samp at Terminal[1]
     n <- samp at n[1]
-    Delta <- Terminal/n
+    #Delta <- Terminal/n
+    Delta <- samp at delta
     name.ar <- paste0(info at ar.par,c(1:info at q))
     name.ma <- paste0(info at ma.par,c(1:info at p))
     name.loc <- info at loc.par
@@ -611,7 +612,7 @@
         sim[1,i] <- eval(xinit[i], yuimaEnv)
       }
 
-      for(t in c(2:n)){
+      for(t in c(2:(n+1))){
           #sim[t,3:ncolsim] <- value.a0*expm(AMatrix*Delta)%*%evect*incr.L[2,t-1]+
           #  expm(AMatrix*Delta)%*%(Indent+evect%*%tavect*incr.L[2,t-1])%*%sim[t-1,3:ncolsim]
           #         sim[t,2]<-value.a0+tavect%*%sim[t,3:ncolsim]
@@ -621,9 +622,15 @@
           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]
           sim[t,1]<-sim[t-1,1]+sqrt(sim[t,2])*incr.L[1,t]
       }
-      X <- ts(sim[-(samp at n[1]+1),])
-      Data <- setData(X,delta = Delta)
-      result <- setYuima(data=Data,model=yuimaCogarch at model, sampling=yuimaCogarch at sampling)
+      # t<-t+1
+      # sim[t,2]<-value.a0+tavect%*%sim[t-1,3:ncolsim]
+      # 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]
+      # sim[t,1]<-sim[t-1,1]+sqrt(sim[t,2])*incr.L[1,t]
+    #  X <- ts(sim[-(samp at n[1]+1),])
+    #  X <- sim[-(samp at n[1]+1),]
+      X<-zoo(x=sim, order.by=samp at grid[[1]])
+      Data <- setData(X)
+      result <- setYuima(data=Data,model=yuimaCogarch at model, sampling=samp)
 
 
 
@@ -636,9 +643,10 @@
 
 
   }else{
+    Initial <- samp at Initial[1]
     Terminal <- samp at Terminal[1]
     n <- samp at n[1]
-    Delta <- Terminal/n
+    Delta <- samp at delta
     name.ar <- paste0(info at ar.par,c(1:info at q))
     name.ma <- paste0(info at ma.par,c(1:info at p))
     name.loc <- info at loc.par
@@ -686,7 +694,7 @@
     }
 
     if(yuimaCogarch at model@measure.type=="code"){
-            for(t in c(2:n)){
+            for(t in c(2:(n+1))){
 
 #         sim[t,2]<-value.a0+tavect%*%sim[t,3:ncolsim]
 #         sim[t,1]<-sim[t-1,1]+sqrt(sim[t,2])*incr.L[1,t]
@@ -698,10 +706,13 @@
         sim[t,1]<-sim[t-1,1]+sqrt(sim[t,2])*incr.L[1,t]
 
       }
-      X <- ts(sim[-(samp at n[1]+1),])
-      Data <- setData(X,delta = Delta)
-      result <- setYuima(data=Data,model=yuimaCogarch at model, sampling=yuimaCogarch at sampling)
-    return(result)
+      X<-zoo(x=sim, order.by=samp at grid[[1]])
+      Data <- setData(X)
+      result <- setYuima(data=Data,model=yuimaCogarch at model, sampling=samp)
+
+      # Data <- setData(X,delta = Delta)
+      # result <- setYuima(data=Data,model=yuimaCogarch at model, sampling=yuimaCogarch at sampling)
+  #  return(result)
     }else{
         lambda <- eval(model at measure$intensity, yuimaEnv)
 
@@ -726,7 +737,7 @@
 #         }
 #       }
 
-      while(Time[j] < Terminal){
+      while(Time[j] < (Terminal-Initial)){
         jump_time[j+1]<-rexp(1,rate=intensity)
         Time[j+1]<-Time[j]+jump_time[j+1]
         j<-j+1
@@ -769,8 +780,8 @@
       }
 
 
-        res<-approx(x=c(0,Time), y = c(0,G),
-                    xout=seq(0,Terminal, by=Terminal/n),
+        res<-approx(x=c(Initial,(Time+Initial)), y = c(0,G),
+                    xout=seq(Initial,Terminal, by=Delta),
                     method = "constant")
         sim[,1]<-res$y
         i<-1
@@ -806,9 +817,12 @@
 #         sim[j,2]<-value.a0+as.numeric(tavect%*%expm(AMatrix*(j-Time[N[j]]))%*%Y[,N[j]])
 #       }
     }
-  X <- ts(sim[-1,])
-  Data <- setData(X,delta = Delta)
-  result <- setYuima(data=Data,model=yuimaCogarch at model, sampling=yuimaCogarch at sampling)
+    X<-zoo(x=sim, order.by=samp at grid[[1]])
+    Data <- setData(X)
+    result <- setYuima(data=Data,model=yuimaCogarch at model, sampling=samp)
+  # X <- ts(sim[-1,])
+  # Data <- setData(X,delta = Delta)
+  # result <- setYuima(data=Data,model=yuimaCogarch at model, sampling=yuimaCogarch at sampling)
   }
   if(missing(subsampling))
     return(result)



More information about the Yuima-commits mailing list