From noreply at r-forge.r-project.org Mon Jun 1 01:36:08 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 1 Jun 2015 01:36:08 +0200 (CEST) Subject: [Highfrequency-commits] r130 - in pkg/highfrequency: . R Message-ID: <20150531233608.9D3D918780F@r-forge.r-project.org> Author: payseur Date: 2015-06-01 01:36:07 +0200 (Mon, 01 Jun 2015) New Revision: 130 Modified: pkg/highfrequency/DESCRIPTION pkg/highfrequency/R/highfrequencyGSOC.R pkg/highfrequency/R/realized.R Log: Changed the explicit call of plot.zoo to plot.xts. Changed require... to requireNamespace. Modified: pkg/highfrequency/DESCRIPTION =================================================================== --- pkg/highfrequency/DESCRIPTION 2015-05-21 20:08:20 UTC (rev 129) +++ pkg/highfrequency/DESCRIPTION 2015-05-31 23:36:07 UTC (rev 130) @@ -1,13 +1,11 @@ -Package: highfrequency -Version: 0.4 -Date: 2014-11-25 -Title: Tools For Highfrequency Data Analysis -Author: Kris Boudt [aut, cre], Jonathan Cornelissen [aut], Scott Payseur [aut], Giang Nguyen [ctb], Maarten Schermer [ctb] -Maintainer: Kris Boudt - -Description: Provide functionality to manage, clean and match highfrequency trades and quotes data, calculate various liquidity measures, estimate and forecast volatility, and investigate microstructure noise and intraday periodicity. -License: GPL (>= 2) -Depends: R (>= 2.12.0), xts, zoo -Suggests: robustbase, cubature, mvtnorm, chron, timeDate, - quantmod, MASS, sandwich, numDeriv, FKF, BMS, rugarch -LazyLoad: yes +Package: highfrequency +Version: 0.41 +Date: 2014-05-31 +Title: Tools For Highfrequency Data Analysis +Author: Kris Boudt [aut, cre], Jonathan Cornelissen [aut], Scott Payseur [aut], Giang Nguyen [ctb], Maarten Schermer [ctb] +Maintainer: Kris Boudt +Description: Provide functionality to manage, clean and match highfrequency trades and quotes data, calculate various liquidity measures, estimate and forecast volatility, and investigate microstructure noise and intraday periodicity. +License: GPL (>= 2) +Depends: R (>= 2.12.0), xts, zoo +Suggests: robustbase, cubature, mvtnorm, chron, timeDate, quantmod, MASS, sandwich, numDeriv, FKF, BMS, rugarch +LazyLoad: yes Modified: pkg/highfrequency/R/highfrequencyGSOC.R =================================================================== --- pkg/highfrequency/R/highfrequencyGSOC.R 2015-05-21 20:08:20 UTC (rev 129) +++ pkg/highfrequency/R/highfrequencyGSOC.R 2015-05-31 23:36:07 UTC (rev 130) @@ -1429,7 +1429,7 @@ .SEheavyModel = function( paramsvector, data, p, q, backcast, LB, UB, compconst=FALSE, ...) { - require(numDeriv) + requireNamespace('numDeriv') K = ncol(data); #Number of series to model # Set lower and upper-bound if not specified: @@ -1539,7 +1539,7 @@ } - require(sandwich); + requireNamespace('sandwich'); fm = lm(m ~ 0); It = try(sandwich::vcovHAC(fm)) @@ -1556,7 +1556,7 @@ invJ = try(solve(Jt)) if( class(invJ) == "try-error"){ - require("MASS") + requireNamespace("MASS") print("-1*Hessian is not invertible - generalized inverse is used") invJ = MASS::ginv(Jt) } Modified: pkg/highfrequency/R/realized.R =================================================================== --- pkg/highfrequency/R/realized.R 2015-05-21 20:08:20 UTC (rev 129) +++ pkg/highfrequency/R/realized.R 2015-05-31 23:36:07 UTC (rev 130) @@ -83,7 +83,7 @@ #Realized Outlyingness Weighted Variance (ROWVar): univariateoutlyingness = function(rdata,...){ - require('robustbase'); + requireNamespace('robustbase'); if(hasArg(data)){ rdata = data } #computes outlyingness of each obs compared to row location and scale location = 0; @@ -97,9 +97,9 @@ ROWVar = function(rdata, seasadjR = NULL, wfunction = "HR" , alphaMCD = 0.75, alpha = 0.001,...) { - require('robustbase'); + requireNamespace('robustbase'); if(hasArg(data)){ rdata = data } - require(robustbase) + if (is.null(seasadjR)) { seasadjR = rdata; } @@ -350,7 +350,7 @@ } cfactor_RTSCV = function(eta=9){ - require('cubature'); require('mvtnorm') + requireNamespace('cubature'); requireNamespace('mvtnorm') # rho = 1 c1 = pchisq(eta,df=1)/pchisq(eta,df=3) # @@ -1188,7 +1188,7 @@ if( n > 1 ){ rdatacheck(rdata,multi=TRUE); - require(robustbase) + requireNamespace('robustbase') rdata = as.matrix(rdata); seasadjR = as.matrix(seasadjR); intraT = nrow(rdata) N = ncol(rdata) @@ -2018,7 +2018,10 @@ g_range[1] = 0.95*g_range[1]; g_range[2]= 1.05 * g_range[2]; #ind = seq(1,length(fitted),length.out=5); title = paste("Observed and forecasted RV based on HAR Model:",type); - plot.zoo(observed,col="red",lwd=2,main=title, ylim=g_range,xlab="Time",ylab="Realized Volatility"); + #plot.xts(observed,col="red",lwd=2,main=title, ylim=g_range,xlab="Time",ylab="Realized Volatility"); + + # There is an error in plot.xts that prevents colors from being passed. + plot.xts(observed,main=title, ylim=g_range,xlab="Time",ylab="Realized Volatility"); # axis(1,time(b)[ind], format(time(b)[ind],), las=2, cex.axis=0.8); not used anymore # axis(2); lines(fitted,col="blue",lwd=2); @@ -2229,7 +2232,7 @@ convert = function(from, to, datasource, datadestination, trades = TRUE, quotes = TRUE, ticker, dir = FALSE, extension = "txt", header = FALSE, tradecolnames = NULL, quotecolnames = NULL, format = "%Y%m%d %H:%M:%S", onefile=FALSE){ - require("timeDate") + requireNamespace("timeDate") ############# 1.A the data is in the "RTAQ folder" sturcture ############## if( onefile == FALSE ){ @@ -2339,7 +2342,7 @@ uniTAQload = function(ticker,from,to,trades=TRUE,quotes=FALSE,datasource=NULL,variables=NULL){ ##Function to load the taq data from a certain stock #From&to (both included) should be in the format "%Y-%m-%d" e.g."2008-11-30" - require("timeDate") + requireNamespace("timeDate") dates = timeDate::timeSequence(as.character(from),as.character(to), format = "%Y-%m-%d", FinCenter = "GMT") dates = dates[timeDate::isBizday(dates, holidays = timeDate::holidayNYSE(1960:2040))]; @@ -2634,7 +2637,7 @@ ###### Liquidity functions formerly in in RTAQ ###### .check_data = function(data){ # FUNCTION sets column names according to RTAQ format using quantmod conventions, such that all the other functions find the correct information. - require('quantmod'); + requireNamespace('quantmod'); # First step: assign the xts attributes: data = set.AllColumns(data); @@ -3100,7 +3103,7 @@ tradesCleanup = function(from,to,datasource,datadestination,ticker,exchanges,tdataraw=NULL,report=TRUE,selection="median",...){ - require('timeDate') + requireNamespace('timeDate') nresult = rep(0, 5) if(!is.list(exchanges)){ exchanges = as.list(exchanges)} if (is.null(tdataraw)) { From noreply at r-forge.r-project.org Mon Jun 1 15:16:10 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 1 Jun 2015 15:16:10 +0200 (CEST) Subject: [Highfrequency-commits] r132 - in pkg/highfrequency: . R Message-ID: <20150601131610.C8B32187A34@r-forge.r-project.org> Author: payseur Date: 2015-06-01 15:16:10 +0200 (Mon, 01 Jun 2015) New Revision: 132 Modified: pkg/highfrequency/DESCRIPTION pkg/highfrequency/R/realized.R Log: Updated misspelling and commented out harmodel legend to see if it fixes the problem on rforge. Modified: pkg/highfrequency/DESCRIPTION =================================================================== --- pkg/highfrequency/DESCRIPTION 2015-06-01 04:06:51 UTC (rev 131) +++ pkg/highfrequency/DESCRIPTION 2015-06-01 13:16:10 UTC (rev 132) @@ -2,7 +2,7 @@ Version: 0.41 Date: 2015-05-31 Title: Tools for Highfrequency Data Analysis -Author at R: c(person("Kris", "Boudt", role = c("aut", "cre"), +Authors at R: c(person("Kris", "Boudt", role = c("aut", "cre"), email = "Kris.Boudt at econ.kuleuven.be"), person("Jonathan", "Cornelissen", role = "aut"), person("Scott", "Payseur", role = "aut", email = "scott at statblocks.com"), Modified: pkg/highfrequency/R/realized.R =================================================================== --- pkg/highfrequency/R/realized.R 2015-06-01 04:06:51 UTC (rev 131) +++ pkg/highfrequency/R/realized.R 2015-06-01 13:16:10 UTC (rev 132) @@ -2026,7 +2026,7 @@ # axis(2); lines(observed,col="red",lwd=2); lines(fitted,col="blue",lwd=2); - legend("topleft", c("Observed RV","Forecasted RV"), col=c("red","blue"),lty=1, lwd=2, bty="n"); + # legend("topleft", c("Observed RV","Forecasted RV"), col=c("red","blue"),lty=1, lwd=2, bty="n"); } ################################################################################################## From noreply at r-forge.r-project.org Wed Jun 3 00:39:37 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 3 Jun 2015 00:39:37 +0200 (CEST) Subject: [Highfrequency-commits] r133 - in pkg/highfrequency: . R Message-ID: <20150602223937.D29D1183B54@r-forge.r-project.org> Author: payseur Date: 2015-06-03 00:39:37 +0200 (Wed, 03 Jun 2015) New Revision: 133 Modified: pkg/highfrequency/DESCRIPTION pkg/highfrequency/R/realized.R Log: Further DESCRIPTION changes and decided to convert xts to zoo for one plot. Modified: pkg/highfrequency/DESCRIPTION =================================================================== --- pkg/highfrequency/DESCRIPTION 2015-06-01 13:16:10 UTC (rev 132) +++ pkg/highfrequency/DESCRIPTION 2015-06-02 22:39:37 UTC (rev 133) @@ -1,5 +1,5 @@ Package: highfrequency -Version: 0.41 +Version: 0.4-1 Date: 2015-05-31 Title: Tools for Highfrequency Data Analysis Authors at R: c(person("Kris", "Boudt", role = c("aut", "cre"), @@ -8,7 +8,7 @@ person("Scott", "Payseur", role = "aut", email = "scott at statblocks.com"), person("Giang", "Nguyen", role = "ctb"), person("Maarten", "Schermer", role = "ctb")) -Author: Kris Boudt [aut, cre], Jonathan Cornelissen [aut], Scott Payseur [aut], Giang Nguyen [ctb], Maarten Schermer [ctb] +Author: Kris Boudt [aut, cre], Jonathan Cornelissen [aut], Scott Payseur [aut], Giang Nguyen [ctb], Maarten Schermer [ctb] Maintainer: Kris Boudt Description: Provide functionality to manage, clean and match highfrequency trades and quotes data, calculate various liquidity measures, estimate and forecast volatility, and investigate microstructure noise and intraday periodicity. License: GPL (>= 2) Modified: pkg/highfrequency/R/realized.R =================================================================== --- pkg/highfrequency/R/realized.R 2015-06-01 13:16:10 UTC (rev 132) +++ pkg/highfrequency/R/realized.R 2015-06-02 22:39:37 UTC (rev 133) @@ -2008,6 +2008,7 @@ label.pos = c(4, 2), cex.caption = 1){ observed = x$model$y; fitted = x$fitted.values; + names(fitted) = NULL; dates = x$dates; dates = as.POSIXct(dates); observed = xts(observed, order.by=dates); @@ -2021,12 +2022,14 @@ #plot.xts(observed,col="red",lwd=2,main=title, ylim=g_range,xlab="Time",ylab="Realized Volatility"); # There is an error in plot.xts that prevents colors from being passed. - plot.xts(observed,main=title, ylim=g_range,xlab="Time",ylab="Realized Volatility"); # axis(1,time(b)[ind], format(time(b)[ind],), las=2, cex.axis=0.8); not used anymore # axis(2); - lines(observed,col="red",lwd=2); - lines(fitted,col="blue",lwd=2); - # legend("topleft", c("Observed RV","Forecasted RV"), col=c("red","blue"),lty=1, lwd=2, bty="n"); + observed <- as.zoo(observed) + fitted <- as.zoo(fitted) + plot.zoo(observed,main=title, ylim=g_range,xlab="Time",ylab="Realized Volatility", col='red',lwd=2); + lines(fitted,col="blue",lwd=2); + legend("topleft", c("Observed RV","Forecasted RV"), col=c("red","blue"),lty=1, lwd=2, bty="n"); + } ################################################################################################## From noreply at r-forge.r-project.org Fri Jun 5 14:03:29 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 5 Jun 2015 14:03:29 +0200 (CEST) Subject: [Highfrequency-commits] r134 - pkg/highfrequency/R Message-ID: <20150605120329.2A72F1879FD@r-forge.r-project.org> Author: payseur Date: 2015-06-05 14:03:28 +0200 (Fri, 05 Jun 2015) New Revision: 134 Modified: pkg/highfrequency/R/realized.R Log: Back to plot.xts Modified: pkg/highfrequency/R/realized.R =================================================================== --- pkg/highfrequency/R/realized.R 2015-06-02 22:39:37 UTC (rev 133) +++ pkg/highfrequency/R/realized.R 2015-06-05 12:03:28 UTC (rev 134) @@ -2024,12 +2024,19 @@ # There is an error in plot.xts that prevents colors from being passed. # axis(1,time(b)[ind], format(time(b)[ind],), las=2, cex.axis=0.8); not used anymore # axis(2); - observed <- as.zoo(observed) - fitted <- as.zoo(fitted) - plot.zoo(observed,main=title, ylim=g_range,xlab="Time",ylab="Realized Volatility", col='red',lwd=2); + + plot.xts(observed,main=title, ylim=g_range,xlab="Time",ylab="Realized Volatility"); + + if(packageVersion('xts')<='0.9.7'){ + lines(observed,col="red",lwd=2); lines(fitted,col="blue",lwd=2); - legend("topleft", c("Observed RV","Forecasted RV"), col=c("red","blue"),lty=1, lwd=2, bty="n"); + }else{ + lines(observed,col="red",lwd=2, on=1); + lines(fitted,col="blue",lwd=2, on=1); + } + legend("topleft", c("Observed RV","Forecasted RV"), col=c("red","blue"),lty=1, lwd=2, bty="n"); + } ################################################################################################## From noreply at r-forge.r-project.org Sat Jun 6 22:02:40 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 6 Jun 2015 22:02:40 +0200 (CEST) Subject: [Highfrequency-commits] r135 - in pkg/highfrequency: R man Message-ID: <20150606200240.A15291879E7@r-forge.r-project.org> Author: payseur Date: 2015-06-06 22:02:39 +0200 (Sat, 06 Jun 2015) New Revision: 135 Modified: pkg/highfrequency/R/realized.R pkg/highfrequency/man/harModel.Rd Log: added addLegend command. Modified: pkg/highfrequency/R/realized.R =================================================================== --- pkg/highfrequency/R/realized.R 2015-06-05 12:03:28 UTC (rev 134) +++ pkg/highfrequency/R/realized.R 2015-06-06 20:02:39 UTC (rev 135) @@ -2025,18 +2025,26 @@ # axis(1,time(b)[ind], format(time(b)[ind],), las=2, cex.axis=0.8); not used anymore # axis(2); - plot.xts(observed,main=title, ylim=g_range,xlab="Time",ylab="Realized Volatility"); + print(packageVersion('xts')) - if(packageVersion('xts')<='0.9.7'){ + + + if(packageVersion('xts')<='0.9-7'){ + plot.xts(observed,main=title, ylim=g_range,xlab="Time",ylab="Realized Volatility"); lines(observed,col="red",lwd=2); lines(fitted,col="blue",lwd=2); + legend("topleft", c("Observed RV","Forecasted RV"), col=c("red","blue"),lty=1, lwd=2, bty="n"); }else{ - lines(observed,col="red",lwd=2, on=1); + plot.xts(observed,main=title, ylim=g_range,xlab="Time",ylab="Realized Volatility", col="red"); lines(fitted,col="blue",lwd=2, on=1); + addLegend("topright", on=1, + legend.names =c("Observed RV","Forecasted RV"), + lty=c(1, 1), lwd=c(2, 2), + col=c("blue", "red")) } - legend("topleft", c("Observed RV","Forecasted RV"), col=c("red","blue"),lty=1, lwd=2, bty="n"); + } ################################################################################################## Modified: pkg/highfrequency/man/harModel.Rd =================================================================== --- pkg/highfrequency/man/harModel.Rd 2015-06-05 12:03:28 UTC (rev 134) +++ pkg/highfrequency/man/harModel.Rd 2015-06-06 20:02:39 UTC (rev 135) @@ -1,84 +1,84 @@ -\name{harModel} -\Rdversion{1.1} -\alias{harModel} -\title{HAR model estimation (Heterogeneous Autoregressive model for Realized volatility)} - -\description{ -Function returns the estimates for the Heterogeneous Autoregressive model -for Realized volatility discussed in Andersen et al. (2007) and Corsi (2009). -This model is mainly used to forecast the next days'volatility based on the high-frequency returns of the past. Consult the vignette for more information.} - - -\usage{ - harModel(data, periods = c(1, 5, 22), periodsJ = c(1,5,22), leverage=NULL, - RVest = c("rCov", "rBPCov"), type = "HARRV", jumptest = "ABDJumptest", - alpha = 0.05, h = 1, transform = NULL, ...) } - -\arguments{ - \item{data}{ an xts-object containing the intraday (log-)returns.} - \item{periods}{ a vector of integers indicating over how days the realized measures in the model should be aggregated. By default periods = c(1,5,22), which corresponds to one day, one week and one month respectively. This default is in line with Andersen et al. (2007).} - \item{periodsJ}{ a vector of integers indicating over what time periods the jump components in the model should be aggregated. By default periodsJ = c(1,5,22), which corresponds to one day, one week and one month respectively.} - \item{leverage}{ a vector of integers indicating over what periods the negative returns should be aggregated. - See Corsi and Reno (2012) for more information. By default leverage=NULL and the model assumes the absence of a leverage effect. Set leverage= c(1,5,22) to mimic the analysis in Corsi and Reno (2012). - } - \item{RVest}{ a character vector with one or two elements. - The first element refers to the name of the function to estimate the daily integrated variance (non-jump-robust), while the second element refers to the name of the function to estimate the continuous component of daily volatility (jump-robust). By default RVest = c("rCov","rBPCov"), i.e. using the Realized Volatility and Realized Bi-Power Variance.} - \item{type}{ a string referring to the type of HAR model you would like to estimate. By default type = "HARRV", the most basic model. Other valid options are type = "HARRVJ" or type = "HARRVCJ".} - \item{jumptest}{ the function name of a function used to test whether the test statistic which determines whether the jump variability is significant that day. By default jumptest = "ABDJumptest", hence using the test statistic in Equation or Equation (18) of Andersen et al. (2007).} - \item{alpha}{ a real indicating the confidence level used in testing for jumps. By default alpha = 0.05.} - \item{h}{ an integer indicating the number over how many days the dependent variable should be aggregated. - By default, h=1, i.e. no aggregation takes place, you just model the daily realized volatility.} - \item{transform}{ optionally a string referring to a function that transforms both the dependent and explanatory variables in the model. By default transform=NULL, so no transformation is done. Typical other choices in this context would be "log" or "sqrt".} - \item{...}{ extra arguments} -} - -\section{Details}{ -See vignette. -} - -\value{ -The function outputs an object of class \code{harModel} and \code{\link{lm}} (so \code{harModel} is a subclass of \code{\link{lm}}). So far I only added a print method as you can see in the examples. Input here is welcome, what should a plot of an "harmodel" object look like? What other methods are useful? -} - - -\references{ -Andersen, T. G., T. Bollerslev, and F. Diebold (2007). Roughing it up: includ- -ing jump components in the measurement, modelling and forecasting of return -volatility. The Review of Economics and Statistics 89, 701-720. - -Corsi, F. (2009). A simple approximate long memory model of realized volatility. -Journal of Financial Econometrics 7, 174-196. - -Corsi, F. and Reno R. (2012). Discrete-time volatility forecasting with persistent leverage effect and the link with continuous-time volatility modeling. Journal of Business and Economic Statistics, forthcoming. -} - - -\author{ Jonathan Cornelissen and Kris Boudt} -\keyword{forecasting} - -\examples{ - ##### Example 1: HARRVCJ ##### - data("sample_5minprices_jumps"); - data = sample_5minprices_jumps[,1]; - data = makeReturns(data); #Get the high-frequency return data - - x = harModel(data, periods = c(1,5,10), periodsJ=c(1,5,10), RVest = c("rCov","rBPCov"), - type="HARRVCJ",transform="sqrt"); - # Estimate the HAR model of type HARRVCJ - class(x); - x - - ##### Example 2: ##### - # Forecasting daily Realized volatility for DJI 2008 using the basic harModel: HARRV - data(realized_library); #Get sample daily Realized Volatility data - DJI_RV = realized_library$Dow.Jones.Industrials.Realized.Variance; #Select DJI - DJI_RV = DJI_RV[!is.na(DJI_RV)]; #Remove NA's - DJI_RV = DJI_RV['2008']; - - x = harModel(data=DJI_RV , periods = c(1,5,22), RVest = c("rCov"), - type="HARRV",h=1,transform=NULL); - class(x); - x; - summary(x); - plot(x); -} +\name{harModel} +\Rdversion{1.1} +\alias{harModel} +\title{HAR model estimation (Heterogeneous Autoregressive model for Realized volatility)} + +\description{ +Function returns the estimates for the Heterogeneous Autoregressive model +for Realized volatility discussed in Andersen et al. (2007) and Corsi (2009). +This model is mainly used to forecast the next days'volatility based on the high-frequency returns of the past. Consult the vignette for more information.} + + +\usage{ + harModel(data, periods = c(1, 5, 22), periodsJ = c(1,5,22), leverage=NULL, + RVest = c("rCov", "rBPCov"), type = "HARRV", jumptest = "ABDJumptest", + alpha = 0.05, h = 1, transform = NULL, ...) } + +\arguments{ + \item{data}{ an xts-object containing the intraday (log-)returns.} + \item{periods}{ a vector of integers indicating over how days the realized measures in the model should be aggregated. By default periods = c(1,5,22), which corresponds to one day, one week and one month respectively. This default is in line with Andersen et al. (2007).} + \item{periodsJ}{ a vector of integers indicating over what time periods the jump components in the model should be aggregated. By default periodsJ = c(1,5,22), which corresponds to one day, one week and one month respectively.} + \item{leverage}{ a vector of integers indicating over what periods the negative returns should be aggregated. + See Corsi and Reno (2012) for more information. By default leverage=NULL and the model assumes the absence of a leverage effect. Set leverage= c(1,5,22) to mimic the analysis in Corsi and Reno (2012). + } + \item{RVest}{ a character vector with one or two elements. + The first element refers to the name of the function to estimate the daily integrated variance (non-jump-robust), while the second element refers to the name of the function to estimate the continuous component of daily volatility (jump-robust). By default RVest = c("rCov","rBPCov"), i.e. using the Realized Volatility and Realized Bi-Power Variance.} + \item{type}{ a string referring to the type of HAR model you would like to estimate. By default type = "HARRV", the most basic model. Other valid options are type = "HARRVJ" or type = "HARRVCJ".} + \item{jumptest}{ the function name of a function used to test whether the test statistic which determines whether the jump variability is significant that day. By default jumptest = "ABDJumptest", hence using the test statistic in Equation or Equation (18) of Andersen et al. (2007).} + \item{alpha}{ a real indicating the confidence level used in testing for jumps. By default alpha = 0.05.} + \item{h}{ an integer indicating the number over how many days the dependent variable should be aggregated. + By default, h=1, i.e. no aggregation takes place, you just model the daily realized volatility.} + \item{transform}{ optionally a string referring to a function that transforms both the dependent and explanatory variables in the model. By default transform=NULL, so no transformation is done. Typical other choices in this context would be "log" or "sqrt".} + \item{...}{ extra arguments} +} + +\section{Details}{ +See vignette. +} + +\value{ +The function outputs an object of class \code{harModel} and \code{\link{lm}} (so \code{harModel} is a subclass of \code{\link{lm}}). So far I only added a print method as you can see in the examples. Input here is welcome, what should a plot of an "harmodel" object look like? What other methods are useful? +} + + +\references{ +Andersen, T. G., T. Bollerslev, and F. Diebold (2007). Roughing it up: includ- +ing jump components in the measurement, modelling and forecasting of return +volatility. The Review of Economics and Statistics 89, 701-720. + +Corsi, F. (2009). A simple approximate long memory model of realized volatility. +Journal of Financial Econometrics 7, 174-196. + +Corsi, F. and Reno R. (2012). Discrete-time volatility forecasting with persistent leverage effect and the link with continuous-time volatility modeling. Journal of Business and Economic Statistics, forthcoming. +} + + +\author{ Jonathan Cornelissen and Kris Boudt} +\keyword{forecasting} + +\examples{ + ##### Example 1: HARRVCJ ##### + data("sample_5minprices_jumps"); + data = sample_5minprices_jumps[,1]; + data = makeReturns(data); #Get the high-frequency return data + + x = harModel(data, periods = c(1,5,10), periodsJ=c(1,5,10), RVest = c("rCov","rBPCov"), + type="HARRVCJ",transform="sqrt"); + # Estimate the HAR model of type HARRVCJ + class(x); + x + + ##### Example 2: ##### + # Forecasting daily Realized volatility for DJI 2008 using the basic harModel: HARRV + data(realized_library); #Get sample daily Realized Volatility data + DJI_RV = realized_library$Dow.Jones.Industrials.Realized.Variance; #Select DJI + DJI_RV = DJI_RV[!is.na(DJI_RV)]; #Remove NA's + DJI_RV = DJI_RV['2008']; + + x = harModel(data=DJI_RV , periods = c(1,5,22), RVest = c("rCov"), + type="HARRV",h=1,transform=NULL); + class(x); + x; + summary(x); + plot(x); +} From noreply at r-forge.r-project.org Mon Jun 29 14:10:52 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 29 Jun 2015 14:10:52 +0200 (CEST) Subject: [Highfrequency-commits] r136 - pkg/highfrequency/R Message-ID: <20150629121052.AD21A180474@r-forge.r-project.org> 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. From noreply at r-forge.r-project.org Mon Jun 29 14:11:05 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 29 Jun 2015 14:11:05 +0200 (CEST) Subject: [Highfrequency-commits] r137 - pkg/highfrequency/man Message-ID: <20150629121105.B5499186884@r-forge.r-project.org> Author: kboudt Date: 2015-06-29 14:11:05 +0200 (Mon, 29 Jun 2015) New Revision: 137 Modified: pkg/highfrequency/man/BNSjumptest.Rd pkg/highfrequency/man/RQPVar.Rd pkg/highfrequency/man/RTPVar.Rd pkg/highfrequency/man/ivInference.Rd Log: Code update Giang after bug report. Modified: pkg/highfrequency/man/BNSjumptest.Rd =================================================================== --- pkg/highfrequency/man/BNSjumptest.Rd 2015-06-29 12:10:52 UTC (rev 136) +++ pkg/highfrequency/man/BNSjumptest.Rd 2015-06-29 12:11:05 UTC (rev 137) @@ -20,24 +20,20 @@ \mbox{BNSjumptest}= \frac{RV - IVestimator}{\sqrt{(\theta-2)\frac{1}{N} {IQestimator}}} } in which, \eqn{IVestimator} can be: bipower variance (BV), minRV, medRV. -\eqn{IQestimator} can be: tripower quarticity (TP), quadpower quarticity (QP), minRQ, medRQ. +\eqn{IQestimator} can be: tripower quarticity (TPQ), quadpower quarticity (QPQ), minRQ, medRQ. \eqn{\theta}: depends on IVestimator. (Huang and Tauchen (2005)) } \usage{ -BNSjumptest(rdata, IVestimator= "BV", IQestimator= "TP", type= "linear", - logtransform= FALSE, max= FALSE, align.by= NULL, align.period= NULL, - makeReturns = FALSE, ...) +BNSjumptest(rdata, IVestimator= "BV", IQestimator= "TPQ", type= "linear", logtransform= FALSE, + max= FALSE, align.by= NULL, align.period= NULL, makeReturns = FALSE, ...) } \arguments{ \item{rdata}{a zoo/xts object containing all returns in period t for one asset.} - \item{IVestimator}{can be chosen among jump robust integrated variance estimators: BV, minRV, medRV - and corrected threshold bipower variation (CTBV). - If CTBV is chosen, an argument of \eqn{startV}, start point of auxiliary estimators in threshold estimation - (Corsi et al. (2010)) can be included. BV by default.} - \item{IQestimator}{can be chosen among jump robust integrated quarticity estimators: TP, QP, minRQ and medRQ. TP by default.} + \item{IVestimator}{can be chosen among jump robust integrated variance estimators: BV, minRV, medRV and corrected threshold bipower variation (CTBV). If CTBV is chosen, an argument of \eqn{startV}, start point of auxiliary estimators in threshold estimation (Corsi et al. (2010) can be included. BV by default.} + \item{IQestimator}{can be chosen among jump robust integrated quarticity estimators: TPQ, QPQ, minRQ and medRQ. TPQ by default.} \item{type}{a method of BNS testing: can be linear or ratio. Linear by default.} \item{logtransform}{boolean, should be TRUE when QVestimator and IVestimator are in logarith form. FALSE by default.} \item{max}{boolean, should be TRUE when max adjustment in SE. FALSE by default.} @@ -86,4 +82,4 @@ % Add one or more standard keywords, see file 'KEYWORDS' in the % R documentation directory. \keyword{ highfrequency } -\keyword{ BNSjumptest } +\keyword{ BNSjumptest } \ No newline at end of file Modified: pkg/highfrequency/man/RQPVar.Rd =================================================================== --- pkg/highfrequency/man/RQPVar.Rd 2015-06-29 12:10:52 UTC (rev 136) +++ pkg/highfrequency/man/RQPVar.Rd 2015-06-29 12:11:05 UTC (rev 137) @@ -1,17 +1,17 @@ \name{rQPVar} \alias{rQPVar} \title{ -Realized quadpower variation of highfrequency return series. +Realized quad-power variation of highfrequency return series. } \description{ -Function returns the rQPVar, defined in Andersen et al. (2012). +Function returns the realized quad-power variation, defined in Andersen et al. (2012). Assume there is \eqn{N} equispaced returns in period \eqn{t}. Let \eqn{r_{t,i}} be a return (with \eqn{i=1, \ldots,N}) in period \eqn{t}. Then, the rQPVar is given by \deqn{ -\mbox{rQPVar}_{t}=\frac{N}{N-3} \frac{\pi^2}{4} \sum_{i=4}^{N} \mbox(|r_{t,i}| |r_{t,i-1}| |r_{t,i-2}| |r_{t,i-3}|) +\mbox{rQPVar}_{t}=\frac{N}{N-3} \left( 2^{1/4} \frac{\Gamma \left(3/4\right)}{ \Gamma \left(1/2\right)} \right)^{-4} \sum_{i=4}^{N} \mbox({|r_{t,i}|}^{1/2} {|r_{t,i-1}|}^{1/2} {|r_{t,i-2}|}^{1/2} {|r_{t,i-3}|}^{1/2}) } } \usage{ Modified: pkg/highfrequency/man/RTPVar.Rd =================================================================== --- pkg/highfrequency/man/RTPVar.Rd 2015-06-29 12:10:52 UTC (rev 136) +++ pkg/highfrequency/man/RTPVar.Rd 2015-06-29 12:11:05 UTC (rev 137) @@ -1,7 +1,7 @@ \name{rTPVar} \alias{rTPVar} \title{ -Realized tripower variation of highfrequency return series. +Realized tri-power variation of highfrequency return series. } \description{ @@ -11,7 +11,7 @@ Then, the rTPVar is given by \deqn{ -\mbox{rTPVar}_{t}=\frac{N}{N-2} \frac{\Gamma^2 \left(1/2\right)}{4 \Gamma^2 \left(7/6\right)} \sum_{i=3}^{N} \mbox({|r_{t,i}|}^{4/3} {|r_{t,i-1}|}^{4/3} {|r_{t,i-2}|}^{4/3}) +\mbox{rTPVar}_{t}=\frac{N}{N-2} \left( 2^{1/3} \frac{\Gamma \left(5/6\right)}{ \Gamma \left(1/2\right)} \right)^{-3} \sum_{i=3}^{N} \mbox({|r_{t,i}|}^{2/3} {|r_{t,i-1}|}^{2/3} {|r_{t,i-2}|}^{2/3}) } } \usage{ Modified: pkg/highfrequency/man/ivInference.Rd =================================================================== --- pkg/highfrequency/man/ivInference.Rd 2015-06-29 12:10:52 UTC (rev 136) +++ pkg/highfrequency/man/ivInference.Rd 2015-06-29 12:11:05 UTC (rev 137) @@ -40,7 +40,7 @@ \arguments{ \item{rdata}{a zoo/xts object containing all returns in period t for one asset.} \item{IVestimator}{can be chosen among integrated variance estimators: RV, BV, minRV or medRV. RV by default.} - \item{IQestimator}{can be chosen among integrated quarticity estimators: rQuar, TP, QP, minRQ or medRQ. rQuar by default.} + \item{IQestimator}{can be chosen among integrated quarticity estimators: rQuar, realized tri-power quarticity (TPQ), quad-power quarticity (QPQ), minRQ or medRQ. TPQ by default.} \item{confidence}{confidence level set by users. 0.95 by default. } \item{align.by}{a string, align the tick data to "seconds"|"minutes"|"hours"} \item{align.period}{an integer, align the tick data to this many [seconds|minutes|hours].} From noreply at r-forge.r-project.org Mon Jun 29 14:11:26 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 29 Jun 2015 14:11:26 +0200 (CEST) Subject: [Highfrequency-commits] r138 - pkg/highfrequency/man Message-ID: <20150629121126.83BD5186884@r-forge.r-project.org> Author: kboudt Date: 2015-06-29 14:11:26 +0200 (Mon, 29 Jun 2015) New Revision: 138 Added: pkg/highfrequency/man/rQPQuar.Rd pkg/highfrequency/man/rTPQuar.Rd Log: Code update Giang after bug report. Added: pkg/highfrequency/man/rQPQuar.Rd =================================================================== --- pkg/highfrequency/man/rQPQuar.Rd (rev 0) +++ pkg/highfrequency/man/rQPQuar.Rd 2015-06-29 12:11:26 UTC (rev 138) @@ -0,0 +1,49 @@ +\name{rQPQuar} +\alias{rQPQuar} +\title{ +Realized quad-power quarticity of highfrequency return series. +} +\description{ + +Function returns the realized quad-power quarticity, defined in Huang and Tauchen (2005) and Andersen et al. (2012). + +Assume there is \eqn{N} equispaced returns in period \eqn{t}. Let \eqn{r_{t,i}} be a return (with \eqn{i=1, \ldots,N}) in period \eqn{t}. + +Then, the rQPQuar is given by +\deqn{ +\mbox{rQPQuar}_{t}=\frac{N^2}{N-3} \left( 2^{1/2} \frac{\Gamma \left(1 \right)}{ \Gamma \left(1/2\right)} \right)^{-4} \sum_{i=4}^{N} \mbox({|r_{t,i}|} {|r_{t,i-1}|} {|r_{t,i-2}|} {|r_{t,i-3}|}) +} +} +\usage{ +rQPQuar (rdata, align.by=NULL, align.period=NULL, makeReturns=FALSE,...) +} + +\arguments{ + \item{rdata}{a zoo/xts object containing all returns in period t for one asset.} + \item{align.by}{a string, align the tick data to "seconds"|"minutes"|"hours"} + \item{align.period}{an integer, align the tick data to this many [seconds|minutes|hours].} + \item{makeReturns}{boolean, should be TRUE when rdata contains prices instead of returns. FALSE by default.} + \item{...}{additional arguments.} +} + +\value{ +numeric +} +\references{ +Andersen, T. G., D. Dobrev, and E. Schaumburg (2012). Jump-robust volatility estimation using nearest neighbor truncation. Journal of Econometrics, 169(1), 75- 93. + +Huang, X. and Tauchen, G. (2005). The relative contribution of jumps to total price variance. Journal of Financial Econometrics, 3(4), 456-499. +} +\author{ +Giang Nguyen, Jonathan Cornelissen and Kris Boudt +} + +\examples{ +data(sample_tdata) +rQPQuar(rdata= sample_tdata$PRICE, align.by= "minutes", align.period =5, makeReturns= TRUE) +rQPQuar +} +% Add one or more standard keywords, see file 'KEYWORDS' in the +% R documentation directory. +\keyword{ highfrequency } +\keyword{ rQPQuar} Added: pkg/highfrequency/man/rTPQuar.Rd =================================================================== --- pkg/highfrequency/man/rTPQuar.Rd (rev 0) +++ pkg/highfrequency/man/rTPQuar.Rd 2015-06-29 12:11:26 UTC (rev 138) @@ -0,0 +1,49 @@ +\name{rTPQuar} +\alias{rTPQuar} +\title{ +Realized tri-power quarticity of highfrequency return series. +} +\description{ + +Function returns the realized tri-power quarticity, defined in Huang and Tauchen (2005) and Andersen et al. (2012). + +Assume there is \eqn{N} equispaced returns in period \eqn{t}. Let \eqn{r_{t,i}} be a return (with \eqn{i=1, \ldots,N}) in period \eqn{t}. + +Then, the rTPQuar is given by +\deqn{ +\mbox{rTPQuar}_{t}=\frac{N^2}{N-2} \left( 2^{2/3} \frac{\Gamma \left(7/6\right)}{ \Gamma \left(1/2\right)} \right)^{-3} \sum_{i=3}^{N} \mbox({|r_{t,i}|}^{4/3} {|r_{t,i-1}|}^{4/3} {|r_{t,i-2}|}^{4/3}) +} +} +\usage{ +rTPQuar (rdata, align.by=NULL, align.period=NULL, makeReturns=FALSE,...) +} + +\arguments{ + \item{rdata}{a zoo/xts object containing all returns in period t for one asset.} + \item{align.by}{a string, align the tick data to "seconds"|"minutes"|"hours"} + \item{align.period}{an integer, align the tick data to this many [seconds|minutes|hours].} + \item{makeReturns}{boolean, should be TRUE when rdata contains prices instead of returns. FALSE by default.} + \item{...}{additional arguments.} +} + +\value{ +numeric +} +\references{ +Andersen, T. G., D. Dobrev, and E. Schaumburg (2012). Jump-robust volatility estimation using nearest neighbor truncation. Journal of Econometrics, 169(1), 75- 93. + +Huang, X. and Tauchen, G. (2005). The relative contribution of jumps to total price variance. Journal of Financial Econometrics, 3(4), 456-499. +} +\author{ +Giang Nguyen, Jonathan Cornelissen and Kris Boudt +} + +\examples{ +data(sample_tdata) +rTPQuar(rdata= sample_tdata$PRICE, align.by= "minutes", align.period =5, makeReturns= TRUE) +rTPQuar +} +% Add one or more standard keywords, see file 'KEYWORDS' in the +% R documentation directory. +\keyword{ highfrequency } +\keyword{ rTPQuar} From noreply at r-forge.r-project.org Tue Jun 30 09:48:43 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 30 Jun 2015 09:48:43 +0200 (CEST) Subject: [Highfrequency-commits] r139 - pkg/highfrequency Message-ID: <20150630074843.942F21876AF@r-forge.r-project.org> Author: kboudt Date: 2015-06-30 09:48:43 +0200 (Tue, 30 Jun 2015) New Revision: 139 Modified: pkg/highfrequency/NAMESPACE Log: Modified: pkg/highfrequency/NAMESPACE =================================================================== --- pkg/highfrequency/NAMESPACE 2015-06-29 12:11:26 UTC (rev 138) +++ pkg/highfrequency/NAMESPACE 2015-06-30 07:48:43 UTC (rev 139) @@ -68,7 +68,9 @@ heavyModelC, spotvol, getPrice, -has.Qty +has.Qty, +rTPQuar, +rQPQuar )#end exported function S3method(print, harModel); From noreply at r-forge.r-project.org Tue Jun 30 09:49:19 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 30 Jun 2015 09:49:19 +0200 (CEST) Subject: [Highfrequency-commits] r140 - pkg/highfrequency Message-ID: <20150630074919.77A141876AF@r-forge.r-project.org> Author: kboudt Date: 2015-06-30 09:49:19 +0200 (Tue, 30 Jun 2015) New Revision: 140 Modified: pkg/highfrequency/DESCRIPTION Log: Modified: pkg/highfrequency/DESCRIPTION =================================================================== --- pkg/highfrequency/DESCRIPTION 2015-06-30 07:48:43 UTC (rev 139) +++ pkg/highfrequency/DESCRIPTION 2015-06-30 07:49:19 UTC (rev 140) @@ -1,6 +1,6 @@ Package: highfrequency Version: 0.4-1 -Date: 2015-05-31 +Date: 2015-06-30 Title: Tools for Highfrequency Data Analysis Authors at R: c(person("Kris", "Boudt", role = c("aut", "cre"), email = "Kris.Boudt at econ.kuleuven.be"),