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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 29 14:10:52 CEST 2015


Author: kboudt
Date: 2015-06-29 14:10:52 +0200 (Mon, 29 Jun 2015)
New Revision: 136

Modified:
   pkg/highfrequency/R/highfrequencyGSOC.R
Log:
Code update Giang after bug report. 

Modified: pkg/highfrequency/R/highfrequencyGSOC.R
===================================================================
--- pkg/highfrequency/R/highfrequencyGSOC.R	2015-06-06 20:02:39 UTC (rev 135)
+++ pkg/highfrequency/R/highfrequencyGSOC.R	2015-06-29 12:10:52 UTC (rev 136)
@@ -98,6 +98,8 @@
 
 ####Realized quadpower variation of highfrequency return series####
 
+##Revise current realized quad-power variation function: 
+
 rQPVar = function(rdata, align.by = NULL, align.period = NULL, makeReturns = FALSE,...)
 {
   if (hasArg(data)) 
@@ -124,7 +126,7 @@
     q      = as.numeric(rdata)
     q      = abs(rollapply(q,width=4,FUN=prod,align="left"))
     N      = length(q)+3
-    rQPVar = N/(N-3)*pi^2/4*sum(q)
+    rQPVar = N/(N - 3)* (2^(1/4) * gamma(3/4)/gamma(1/2))^(-4)*sum(q^(1/2))
     return(rQPVar)
   }
 }
@@ -157,13 +159,77 @@
     q      = as.numeric(rdata)
     q      = abs(rollapply(q,width = 3, FUN = prod, align = "left"))
     N      = length(q)+2
-    rTPVar = N/(N-2)*gamma(1/2)^2/(4*gamma(7/6)^2)*sum(q^(4/3))
+    rTPVar = N/(N - 2) * (2^(1/3) * gamma(5/6)/gamma(1/2))^(-3) *sum(q^(2/3))
     return(rTPVar)
   }
 }
 
+##Create new function: realized Tri-power quarticity function: 
+rTPQuar = function(rdata, align.by = NULL, align.period = NULL, makeReturns = FALSE,...)
+{
+  if (hasArg(data)) 
+  {
+    rdata = data
+  }
+  multixts = .multixts(rdata)
+  if (multixts) 
+  {
+    result = apply.daily(rdata, rTPQuar, align.by, align.period,
+                         makeReturns)
+    return(result)
+  }
+  if (!multixts) 
+  {
+    if ((!is.null(align.by)) && (!is.null(align.period))) {
+      rdata = .aggregatets(rdata, on = align.by, k = align.period)
+    }
+    if (makeReturns) 
+    {
+      rdata = makeReturns(rdata)
+    }
+    
+    q      = as.numeric(rdata)
+    q      = abs(rollapply(q,width = 3, FUN = prod, align = "left"))
+    N      = length(q)+2
+    rTPQuar = (N^2)/(N - 2)*(2^(2/3)*gamma(7/6)/gamma(1/2))^(-3) *sum(q^(4/3))
+    return(rTPQuar)
+  }
+}
 
+##Create new function: realized Quad-power quarticity function: 
+rQPQuar = function(rdata, align.by = NULL, align.period = NULL, makeReturns = FALSE,...)
+{
+  if (hasArg(data)) 
+  {
+    rdata = data
+  }
+  multixts = .multixts(rdata)
+  if (multixts) 
+  {
+    result = apply.daily(rdata, rQPQuar, align.by, align.period,
+                         makeReturns)
+    return(result)
+  }
+  if (!multixts) 
+  {
+    if ((!is.null(align.by)) && (!is.null(align.period))) {
+      rdata = .aggregatets(rdata, on = align.by, k = align.period)
+    }
+    if (makeReturns) 
+    {
+      rdata = makeReturns(rdata)
+    }
+    
+    q      = as.numeric(rdata)
+    q      = abs(rollapply(q,width = 4, FUN = prod, align = "left"))
+    N      = length(q)+3
+    rQPQuar = (N^2)/(N - 3)*(2^(1/2)*gamma(1)/gamma(1/2))^(-4) *sum(q);
+    return(rQPQuar)
+  }
+}
 
+
+
 #### Standard error and confidence band of RV measures.####
 # User can choose integrated variance (IV) estimators RV, BV, minRV or medRV; 
 #and integrated quarticity (IQ) estimators: rQuar, TP, QP, minRQ or medRQ.
@@ -171,7 +237,7 @@
 #2) standard error of IVestimator;
 #3) confidence band of IVestimator. 
 
-ivInference = function(rdata, IVestimator = "RV", IQestimator = "rQuar", confidence = 0.95, align.by = NULL, align.period = NULL, makeReturns = FALSE, ...)
+ivInference = function(rdata, IVestimator = "RV", IQestimator = "TPQ", confidence = 0.95, align.by = NULL, align.period = NULL, makeReturns = FALSE, ...)
 {
   if (hasArg(data)){ rdata = data  }
   
@@ -217,11 +283,12 @@
 }
 
 
+
 ####BNSjump-test: Barndorff- Nielsen and Shephard tests for the presence of jumps 
 #in the price series.
 # It includes option of corrected threshold bipower variation (CTBV).
 
-BNSjumptest = function(rdata, IVestimator= "BV", IQestimator= "TP", type= "linear", logtransform= FALSE, 
+BNSjumptest = function(rdata, IVestimator= "BV", IQestimator= "TPQ", type= "linear", logtransform= FALSE, 
                        max= FALSE, align.by= NULL, align.period= NULL, makeReturns = FALSE, ...)
 {
   if (hasArg(data)){  rdata = data  }
@@ -820,13 +887,16 @@
 {
   switch(IQestimator,
          rQuar  = rQuar (rdata),
-         QP     = rQPVar(rdata),
-         TP     = rTPVar(rdata),
+         QPV    = rQPVar(rdata),
+         TPV    = rTPVar(rdata),
+         TPQ    = rTPQuar(rdata),
+         QPQ    = rQPQuar(rdata),
          minRQ  = minRQ (rdata),
          medRQ  = medRQ (rdata))
 }
 
 
+
 ##Standard error of IVestimator: 
 # Reference can be found at: Andersen, T. G., D. Dobrev, and E. Schaumburg (2012). 
 #Jump-robust volatility estimation using nearest neighbor truncation. Journal of Econometrics, 169(1), 75- 93.



More information about the Highfrequency-commits mailing list