[Highfrequency-commits] r34 - pkg/highfrequency/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 14 04:13:08 CEST 2012


Author: jonathan
Date: 2012-08-14 04:13:07 +0200 (Tue, 14 Aug 2012)
New Revision: 34

Modified:
   pkg/highfrequency/R/realized.R
Log:
heavyModel, make output more usrfriendly using xts for cond vars and likelihoods, etc

Modified: pkg/highfrequency/R/realized.R
===================================================================
--- pkg/highfrequency/R/realized.R	2012-08-13 22:21:21 UTC (rev 33)
+++ pkg/highfrequency/R/realized.R	2012-08-14 02:13:07 UTC (rev 34)
@@ -3990,17 +3990,16 @@
   # Estimate the parameters: 
   # Set constraints: 
   KKK  = length(startingvalues);    
-  ui   = diag(rep(1,KKK));          #All parameters should be larger than zero, add extra constraints with rbind...  
+  ui   = diag(rep(1,KKK)); #All parameters should be larger than zero, add extra constraints with rbind...  
   ci   = rep(0,dim(ui)[2]);  
   
-  # x = try(optim( par = startingvalues, fn = heavy_likelihood,
-  #           data=data, p=p, q=q,backcast=backcast,UB=UB,LB=LB, compconst = compconst ) ); # ADJUST maxit ?!!
-  x = try(constrOptim( theta = startingvalues, f = heavy_likelihood, 
-                       grad = NULL,
-                       ui = ui, 
-                       ci = ci, 
-                       method = "L-BFGS-B",
-                       data=data, p=p, q=q,backcast=backcast,UB=UB,LB=LB, compconst = compconst));
+  x = try(optim( par = startingvalues, fn = heavy_likelihood,
+                 data=data, p=p, q=q,backcast=backcast,UB=UB,LB=LB, compconst = compconst ) ); # ADJUST maxit ?!!
+  #x = try(constrOptim( theta = startingvalues, f = heavy_likelihood, 
+  #                     grad = NULL,
+  #                     ui = ui, 
+  #                     ci = ci, 
+  #                     data=data, p=p, q=q,backcast=backcast,UB=UB,LB=LB, compconst = compconst));
   
   if( class(x)=="try-error"){
     print("Error in likelihood optimization")
@@ -4016,12 +4015,31 @@
   
   # Get the list with: total-log-lik, daily-log-lik, condvars
   xx = heavy_likelihood(par = estparams, data=data, p=p, q=q, backcast=backcast, LB=LB, UB=UB, foroptim=FALSE, compconst = compconst);
-  xx$estparams =  estparams;
+  
+  # Add the timestamps and make xts: condvar and likelihoods:
+  if( ! is.null(rownames(data)) ){
+    xx$condvar    = xts( t(xx$condvar),  order.by   = as.POSIXct( rownames(data),tz="GMT") );     
+    xx$likelihoods = xts( xx$likelihoods, order.by = as.POSIXct( rownames(data),tz="GMT"));
+  }
+  
+  # 
+  xx$estparams = matrix(estparams,ncol=1); 
+  rownames(xx$estparams) = .get_param_names(estparams,p,q);
   xx$convergence = x$convergence
   
   return(xx)
 }
 
+.get_param_names = function( estparams, p, q){
+  K = dim(p)[2];
+  nAlpha =  sum(p);
+  nBeta  =  sum(q);
+  omegas = paste("omega",1:K,sep="");
+  alphas = paste("alpha",1:nAlpha,sep="");
+  betas  = paste("beta", 1:nBeta,sep="");
+  names  = c(omegas,alphas,betas);
+  
+}
 
 transformparams = function( p, q, paramsvector ){
   K = dim(p)[1]; 



More information about the Highfrequency-commits mailing list