From noreply at r-forge.r-project.org Tue Nov 25 09:04:31 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Nov 2014 09:04:31 +0100 (CET) Subject: [Highfrequency-commits] r114 - pkg/highfrequency/R Message-ID: <20141125080431.ACC671877F5@r-forge.r-project.org> Author: kboudt Date: 2014-11-25 09:04:31 +0100 (Tue, 25 Nov 2014) New Revision: 114 Modified: pkg/highfrequency/R/highfrequencyGSOC.R pkg/highfrequency/R/quantmod_patch.R pkg/highfrequency/R/realized.R Log: added timeDate:: etc where needed Modified: pkg/highfrequency/R/highfrequencyGSOC.R =================================================================== --- pkg/highfrequency/R/highfrequencyGSOC.R 2014-09-15 22:35:20 UTC (rev 113) +++ pkg/highfrequency/R/highfrequencyGSOC.R 2014-11-25 08:04:31 UTC (rev 114) @@ -1448,7 +1448,7 @@ # compute the asymptotic covariance matrix of splittedparamsvector - mH = hessian (.heavy_likelihood_ll, x= splittedparams, data=data, p=p, q=q, backcast=backcast, LB=LB, UB=UB, compconst=compconst) + mH = numDeriv::hessian(.heavy_likelihood_ll, x= splittedparams, data=data, p=p, q=q, backcast=backcast, LB=LB, UB=UB, compconst=compconst) T = nrow(data) nm = length(paramsvector) @@ -1464,7 +1464,7 @@ ## Define It # jacobian will be T x length of theta - m = jacobian(.heavy_likelihood_lls, x = splittedparams, data=data, p=p, q=q, backcast=backcast, LB=LB, UB=UB, compconst=compconst) # returns a vector? + m = numDeriv::jacobian(.heavy_likelihood_lls, x = splittedparams, data=data, p=p, q=q, backcast=backcast, LB=LB, UB=UB, compconst=compconst) # returns a vector? It = cov(m) }else{ @@ -1541,11 +1541,11 @@ require(sandwich); fm = lm(m ~ 0); - It = try(vcovHAC(fm)) + It = try(sandwich::vcovHAC(fm)) if(class(It) == "try-error") { - print("HAC estimator is in error. It is replaced by non HAC estimator.") + print("HAC estimator reports an error. It is replaced by non HAC estimator.") It = cov(m) } } @@ -1558,7 +1558,7 @@ if( class(invJ) == "try-error"){ require("MASS") print("-1*Hessian is not invertible - generalized inverse is used") - invJ = ginv(Jt) + invJ = MASS::ginv(Jt) } Modified: pkg/highfrequency/R/quantmod_patch.R =================================================================== --- pkg/highfrequency/R/quantmod_patch.R 2014-09-15 22:35:20 UTC (rev 113) +++ pkg/highfrequency/R/quantmod_patch.R 2014-11-25 08:04:31 UTC (rev 114) @@ -1,334 +1,399 @@ -############################################################################### -# Utility functions for handling price data -############################################################################### - -#' get price column(s) from a timeseries -#' -#' Will attempt to locate price column(s) from a time series with rational defaults. -#' -#' May be subset by symbol and preference. -#' \code{prefer} Preference will be for any commonly used financial time series price description, -#' e.g. 'trade', 'close', 'bid', 'ask' with specific tests and matching for types and column names -#' currently supported in R, but a default grep match will be performed if one of the supported types doesn't match. -#' -#' @param x A data object with columns containing data to be extracted -#' @param symbol text string containing the symbol to extract -#' @param prefer preference for any particular type of price, see Details -#' @param \dots any other passthrough parameters -#' @export -getPrice <- function (x, symbol=NULL, prefer=NULL,...) -{ - # first subset on symbol, if present - if(!is.null(symbol)){ - loc<-grep(symbol, colnames(x)) - if (!identical(loc, integer(0))) { - x<-x[,loc] - } else { - stop(paste("subscript out of bounds: no column name containing",symbol)) - } - } - if(is.null(prefer)){ - # default to trying Price, then Trade, then Close - if(has.Price(x)) prefer='price' - else if(has.Trade(x)) prefer='trade' - else if(has.Cl(x)) prefer='close' - else stop("subscript out of bounds, no price was discernible from the data") - } - if(!is.null(prefer)){ - loc <- NULL - switch(prefer, - Op =, open =, Open = { loc <- has.Op(x,which=TRUE) }, - Hi =, high =, High = { loc <- has.Hi(x,which=TRUE) }, - Lo =, low =, Low = { loc <- has.Lo(x,which=TRUE) }, - Cl =, close =, Close = { loc <- has.Cl(x,which=TRUE) }, - Bid =, bid = { loc <- has.Bid(x,which=TRUE) }, - Ask =, ask =, Offer =, offer = { loc <- has.Ask(x,which=TRUE) }, - Mid =, mid =, Midpoint =, midpoint = { loc <- has.Mid(x,which=TRUE) }, - Trade =, trade = { loc <- has.Trade(x,which=TRUE) }, - Price =, price = { loc <- has.Price(x,which=TRUE) }, -{loc <- grep(prefer,colnames(x))} - ) - if (!identical(loc, integer(0))) return(x[, loc]) - else stop("subscript out of bounds, no price was discernible from the data") - } -} - -#' @export -is.BBO <- function (x) -{ - if (all(has.Bid(x), has.Ask(x))) { - TRUE - } - else FALSE -} - -#' @export -is.TBBO <- function (x) -{ - if (all(has.Trade(x),has.Qty(x),has.Bid(x), has.Ask(x))) { - TRUE - } - else FALSE -} - -#' @export -is.BAM <- function(x) { - if (all(has.Bid(x), has.Ask(x), has.Mid(x))) { - TRUE - } - else FALSE -} - -#' @export -is.BATM <- function(x) { - if (all(has.Bid(x), has.Ask(x), has.Trade(x), has.Mid(x))) { - TRUE - } - else FALSE -} - -#' @export -has.Bid <- function(x, which = FALSE) -{ - colAttr <- attr(x, "Bid") - if(!is.null(colAttr)) - return(if(which) colAttr else TRUE) - #first try with "price" for data that has both bid.size and bid.price - loc <- grep("bid.*price", colnames(x), ignore.case=TRUE) - if (identical(loc, integer(0))) #If no column named bid.price - loc <- grep("bid", colnames(x), ignore.case=TRUE) #look for bid - if (!identical(loc, integer(0))) { - return(if(which) loc else TRUE) - } else FALSE -} - -#' @export -has.BidSize <- function(x, which = FALSE) -{ - colAttr <- attr(x, "BidSize") - if(!is.null(colAttr)) - return(if(which) colAttr else TRUE) - - loc <- grep("bid.*(size|qty|quantity)", colnames(x), ignore.case=TRUE) - if (!identical(loc, integer(0))) { - return(if(which) loc else TRUE) - } - loc <- grep("(bidsize|bidsiz)", colnames(x), ignore.case=TRUE) - if (!identical(loc, integer(0))) { - return(if(which) loc else TRUE) - } - else FALSE -} - -#' @export -has.Ask <- function(x, which = FALSE) -{ - colAttr <- attr(x, "Ask") #case sensitive; doesn't work for SYMBOL.Ask :-( - if(!is.null(colAttr)) - return(if(which) colAttr else TRUE) - #first try with "price" for data that has both ask.size and ask.price - loc <- grep("(ask|offer).*price", colnames(x), ignore.case=TRUE) - if (identical(loc, integer(0))) #if that failed, try to find just "ask|offer" - loc <- grep("(ask|offer|ofr)", colnames(x), ignore.case=TRUE) - if (!identical(loc, integer(0))) { - return(if(which) loc else TRUE) - } else FALSE -} - -#' @export -has.AskSize <- function(x, which = FALSE) -{ - colAttr <- attr(x, "AskSize") - if(!is.null(colAttr)) - return(if(which) colAttr else TRUE) - - loc <- grep("(ask|offer).*(size|qty|quantity)", colnames(x), ignore.case=TRUE) - if (!identical(loc, integer(0))) { - return(if(which) loc else TRUE) - } - loc <- grep("(ofrsize|ofrsiz|offersize|offersiz)", colnames(x), ignore.case=TRUE) - if (!identical(loc, integer(0))) { - return(if(which) loc else TRUE) - } - else FALSE -} - -#' @export -has.Price <- function(x, which = FALSE) -{ - colAttr <- attr(x, "Price") - if(!is.null(colAttr)) - return(if(which) colAttr else TRUE) - - locBidAsk <- c(has.Bid(x, which=TRUE),has.Ask(x, which=TRUE)) - loc <- grep("price", colnames(x), ignore.case=TRUE) - loc <- loc[!(loc %in% locBidAsk)] - if (!identical(loc, integer(0))) { - return(if(which) loc else TRUE) - } else FALSE -} - -#' @export -has.Trade <- function(x, which = FALSE) -{ - colAttr <- attr(x, "Trade") - if(!is.null(colAttr)) - return(if(which) colAttr else TRUE) - - loc <- grep("trade", colnames(x), ignore.case=TRUE) - if (!identical(loc, integer(0))) { - return(if(which) loc else TRUE) - } else FALSE -} - -has.Mid <- function(x, which=FALSE) { - colAttr <- attr(x, "Mid") - if(!is.null(colAttr)) - return(if(which) colAttr else TRUE) - - loc <- grep("Mid", colnames(x), ignore.case = TRUE) - if (!identical(loc, integer(0))) - return(ifelse(which, loc, TRUE)) - ifelse(which, loc, FALSE) -} - -has.Chg <- function(x, which=FALSE) { - colAttr <- attr(x, "Chg") - if(!is.null(colAttr)) - return(if(which) colAttr else TRUE) - loc <- grep("(chg|change)", colnames(x), ignore.case=TRUE) - if (!identical(loc, integer(0))) - return(ifelse(which, loc, TRUE)) - ifelse(which, loc, FALSE) -} - -#has.Un <- function(x, which=FALSE) { -# loc <- grep("Unadj", colnames(x), ignore.case = TRUE) -# if (!identical(loc, integer(0))) -# return(ifelse(which, loc, TRUE)) -# ifelse(which, loc, FALSE) -#} - - - -#' check for Trade, Bid, and Ask/Offer (BBO/TBBO), Quantity, and Price data -#' -#' A set of functions to check for appropriate TBBO/BBO and price column -#' names within a data object, as well as the availability and -#' position of those columns. -#' @param x data object -#' @param which disply position of match -#' @aliases -#' has.Trade -#' has.Ask -#' has.AskSize -#' has.Bid -#' has.BidSize -#' has.Price -#' is.BBO -#' is.TBBO -#' @export - -has.Qty <- function(x, which = FALSE) -{ - colAttr <- attr(x, "Qty") - if(!is.null(colAttr)) - return(if(which) colAttr else TRUE) - - locBidAsk <- c(has.Bid(x, which=TRUE),has.Ask(x, which=TRUE)) - loc <- grep("qty", colnames(x), ignore.case=TRUE) - loc <- loc[!(loc %in% locBidAsk)] - if (!identical(loc, integer(0))) { - return(if(which) loc else TRUE) - } else FALSE -} - -# Column setting functions -set.AllColumns <- function(x) { - cols <- c("Op","Hi","Lo","Cl","Vo","Ad","Price","Trade","Qty", - "Bid","BidSize","Ask","AskSize","Mid","Chg") - for(col in cols) { - try(x <- do.call(paste("set",col,sep="."), list(x)), silent=TRUE ) - } - return(x) -} - -set.Chg <- function(x, error=TRUE) { - if(has.Chg(x)) - attr(x,"Chg") <- has.Chg(x, which=TRUE) - return(x) -} - -set.Mid <- function(x, error=TRUE) { - if(has.Mid(x)) - attr(x,"Mid") <- has.Mid(x, which=TRUE) - return(x) -} - -set.Ad <- function(x, error=TRUE) { - if(has.Ad(x)) - attr(x,"Ad") <- has.Ad(x, which=TRUE) - return(x) -} - - -set.Bid <- function(x, error=TRUE) { - if(has.Bid(x)) - attr(x,"Bid") <- has.Bid(x, which=TRUE) - return(x) -} -set.BidSize <- function(x, error=TRUE) { - if(has.BidSize(x)) - attr(x,"BidSize") <- has.BidSize(x, which=TRUE) - return(x) -} -set.Hi <- function(x, error=TRUE) { - if(has.Hi(x)) - attr(x,"Hi") <- has.Hi(x, which=TRUE) - return(x) -} -set.Lo <- function(x, error=TRUE) { - if(has.Lo(x)) - attr(x,"Lo") <- has.Lo(x, which=TRUE) - return(x) -} -set.Op <- function(x, error=TRUE) { - if(has.Op(x)) - attr(x,"Op") <- has.Op(x, which=TRUE) - return(x) -} -set.Qty <- function(x, error=TRUE) { - if(has.Qty(x)) - attr(x,"Qty") <- has.Qty(x, which=TRUE) - return(x) -} -set.Vo <- function(x, error=TRUE) { - if(has.Vo(x)) - attr(x,"Vo") <- has.Vo(x, which=TRUE) - return(x) -} -set.Ask <- function(x, error=TRUE) { - if(has.Ask(x)) - attr(x,"Ask") <- has.Ask(x, which=TRUE) - return(x) -} -set.AskSize <- function(x, error=TRUE) { - if(has.AskSize(x)) - attr(x,"AskSize") <- has.AskSize(x, which=TRUE) - return(x) -} -set.Cl <- function(x, error=TRUE) { - if(has.Cl(x)) - attr(x,"Cl") <- has.Cl(x, which=TRUE) - return(x) -} -set.Price <- function(x, error=TRUE) { - if(has.Price(x)) - attr(x,"Price") <- has.Price(x, which=TRUE) - return(x) -} -set.Trade <- function(x, error=TRUE) { - if(has.Trade(x)) - attr(x,"Trade") <- has.Trade(x, which=TRUE) - return(x) -} +############################################################################### +# Utility functions for handling price data +############################################################################### + +#' get price column(s) from a timeseries +#' +#' Will attempt to locate price column(s) from a time series with rational defaults. +#' +#' May be subset by symbol and preference. +#' \code{prefer} Preference will be for any commonly used financial time series price description, +#' e.g. 'trade', 'close', 'bid', 'ask' with specific tests and matching for types and column names +#' currently supported in R, but a default grep match will be performed if one of the supported types doesn't match. +#' +#' @param x A data object with columns containing data to be extracted +#' @param symbol text string containing the symbol to extract +#' @param prefer preference for any particular type of price, see Details +#' @param \dots any other passthrough parameters +#' @export +getPrice <- function (x, symbol=NULL, prefer=NULL,...) +{ + # first subset on symbol, if present + if(!is.null(symbol)){ + loc<-grep(symbol, colnames(x)) + if (!identical(loc, integer(0))) { + x<-x[,loc] + } else { + stop(paste("subscript out of bounds: no column name containing",symbol)) + } + } + if(is.null(prefer)){ + # default to trying Price, then Trade, then Close + if(has.Price(x)) prefer='price' + else if(has.Trade(x)) prefer='trade' + else if(has.Cl(x)) prefer='close' + else stop("subscript out of bounds, no price was discernible from the data") + } + if(!is.null(prefer)){ + loc <- NULL + switch(prefer, + Op =, open =, Open = { loc <- has.Op(x,which=TRUE) }, + Hi =, high =, High = { loc <- has.Hi(x,which=TRUE) }, + Lo =, low =, Low = { loc <- has.Lo(x,which=TRUE) }, + Cl =, close =, Close = { loc <- has.Cl(x,which=TRUE) }, + Bid =, bid = { loc <- has.Bid(x,which=TRUE) }, + Ask =, ask =, Offer =, offer = { loc <- has.Ask(x,which=TRUE) }, + Mid =, mid =, Midpoint =, midpoint = { loc <- has.Mid(x,which=TRUE) }, + Trade =, trade = { loc <- has.Trade(x,which=TRUE) }, + Price =, price = { loc <- has.Price(x,which=TRUE) }, +{loc <- grep(prefer,colnames(x))} + ) + if (!identical(loc, integer(0))) return(x[, loc]) + else stop("subscript out of bounds, no price was discernible from the data") + } +} + +#' @export +is.BBO <- function (x) +{ + if (all(has.Bid(x), has.Ask(x))) { + TRUE + } + else FALSE +} + +#' @export +is.TBBO <- function (x) +{ + if (all(has.Trade(x),has.Qty(x),has.Bid(x), has.Ask(x))) { + TRUE + } + else FALSE +} + +#' @export +is.BAM <- function(x) { + if (all(has.Bid(x), has.Ask(x), has.Mid(x))) { + TRUE + } + else FALSE +} + +#' @export +is.BATM <- function(x) { + if (all(has.Bid(x), has.Ask(x), has.Trade(x), has.Mid(x))) { + TRUE + } + else FALSE +} + +#' @export +has.Bid <- function(x, which = FALSE) +{ + colAttr <- attr(x, "Bid") + if(!is.null(colAttr)) + return(if(which) colAttr else TRUE) + #first try with "price" for data that has both bid.size and bid.price + loc <- grep("bid.*price", colnames(x), ignore.case=TRUE) + if (identical(loc, integer(0))) #If no column named bid.price + loc <- grep("bid", colnames(x), ignore.case=TRUE) #look for bid + if (!identical(loc, integer(0))) { + return(if(which) loc else TRUE) + } else FALSE +} + +#' @export +has.BidSize <- function(x, which = FALSE) +{ + colAttr <- attr(x, "BidSize") + if(!is.null(colAttr)) + return(if(which) colAttr else TRUE) + + loc <- grep("bid.*(size|qty|quantity)", colnames(x), ignore.case=TRUE) + if (!identical(loc, integer(0))) { + return(if(which) loc else TRUE) + } + loc <- grep("(bidsize|bidsiz)", colnames(x), ignore.case=TRUE) + if (!identical(loc, integer(0))) { + return(if(which) loc else TRUE) + } + else FALSE +} + +#' @export +has.Ask <- function(x, which = FALSE) +{ + colAttr <- attr(x, "Ask") #case sensitive; doesn't work for SYMBOL.Ask :-( + if(!is.null(colAttr)) + return(if(which) colAttr else TRUE) + #first try with "price" for data that has both ask.size and ask.price + loc <- grep("(ask|offer).*price", colnames(x), ignore.case=TRUE) + if (identical(loc, integer(0))) #if that failed, try to find just "ask|offer" + loc <- grep("(ask|offer|ofr)", colnames(x), ignore.case=TRUE) + if (!identical(loc, integer(0))) { + return(if(which) loc else TRUE) + } else FALSE +} + +#' @export +has.AskSize <- function(x, which = FALSE) +{ + colAttr <- attr(x, "AskSize") + if(!is.null(colAttr)) + return(if(which) colAttr else TRUE) + + loc <- grep("(ask|offer).*(size|qty|quantity)", colnames(x), ignore.case=TRUE) + if (!identical(loc, integer(0))) { + return(if(which) loc else TRUE) + } + loc <- grep("(ofrsize|ofrsiz|offersize|offersiz)", colnames(x), ignore.case=TRUE) + if (!identical(loc, integer(0))) { + return(if(which) loc else TRUE) + } + else FALSE +} + +#' @export +has.Price <- function(x, which = FALSE) +{ + colAttr <- attr(x, "Price") + if(!is.null(colAttr)) + return(if(which) colAttr else TRUE) + + locBidAsk <- c(has.Bid(x, which=TRUE),has.Ask(x, which=TRUE)) + loc <- grep("price", colnames(x), ignore.case=TRUE) + loc <- loc[!(loc %in% locBidAsk)] + if (!identical(loc, integer(0))) { + return(if(which) loc else TRUE) + } else FALSE +} + +#' @export +has.Trade <- function(x, which = FALSE) +{ + colAttr <- attr(x, "Trade") + if(!is.null(colAttr)) + return(if(which) colAttr else TRUE) + + loc <- grep("trade", colnames(x), ignore.case=TRUE) + if (!identical(loc, integer(0))) { + return(if(which) loc else TRUE) + } else FALSE +} + +has.Mid <- function(x, which=FALSE) { + colAttr <- attr(x, "Mid") + if(!is.null(colAttr)) + return(if(which) colAttr else TRUE) + + loc <- grep("Mid", colnames(x), ignore.case = TRUE) + if (!identical(loc, integer(0))) + return(ifelse(which, loc, TRUE)) + ifelse(which, loc, FALSE) +} + +has.Chg <- function(x, which=FALSE) { + colAttr <- attr(x, "Chg") + if(!is.null(colAttr)) + return(if(which) colAttr else TRUE) + loc <- grep("(chg|change)", colnames(x), ignore.case=TRUE) + if (!identical(loc, integer(0))) + return(ifelse(which, loc, TRUE)) + ifelse(which, loc, FALSE) +} + +has.Cl <- function (x, which = FALSE){ + colAttr <- attr(x, "Cl") + if (!is.null(colAttr)) + return(if (which) colAttr else TRUE) + loc <- grep("Close", colnames(x), ignore.case = TRUE) + if (!identical(loc, integer(0))) { + return(if (which) loc else TRUE) + } + else FALSE +} + +has.Ad<-function (x, which = FALSE){ + colAttr <- attr(x, "Ad") + if (!is.null(colAttr)) + return(if (which) colAttr else TRUE) + loc <- grep("Adjusted", colnames(x), ignore.case = TRUE) + if (!identical(loc, integer(0))) { + return(if (which) loc else TRUE) + } + else FALSE +} + +has.Hi<-function (x, which = FALSE) { + colAttr <- attr(x, "Hi") + if (!is.null(colAttr)) + return(if (which) colAttr else TRUE) + loc <- grep("High", colnames(x), ignore.case = TRUE) + if (!identical(loc, integer(0))) { + return(if (which) loc else TRUE) + } + else FALSE +} + +has.Lo<-function (x, which = FALSE){ + colAttr <- attr(x, "Lo") + if (!is.null(colAttr)) + return(if (which) colAttr else TRUE) + loc <- grep("Low", colnames(x), ignore.case = TRUE) + if (!identical(loc, integer(0))) { + return(if (which) loc else TRUE) + } + else FALSE +} + +has.Op<-function (x, which = FALSE) { + colAttr <- attr(x, "Op") + if (!is.null(colAttr)) + return(if (which) colAttr else TRUE) + loc <- grep("Open", colnames(x), ignore.case = TRUE) + if (!identical(loc, integer(0))) { + return(if (which) loc else TRUE) + } + else FALSE +} + +has.Vo<-function (x, which = FALSE){ + colAttr <- attr(x, "Vo") + if (!is.null(colAttr)) + return(if (which) colAttr else TRUE) + loc <- grep("Volume", colnames(x), ignore.case = TRUE) + if (!identical(loc, integer(0))) { + return(if (which) loc else TRUE) + } + else FALSE +} +#has.Un <- function(x, which=FALSE) { +# loc <- grep("Unadj", colnames(x), ignore.case = TRUE) +# if (!identical(loc, integer(0))) +# return(ifelse(which, loc, TRUE)) +# ifelse(which, loc, FALSE) +#} + + + +#' check for Trade, Bid, and Ask/Offer (BBO/TBBO), Quantity, and Price data +#' +#' A set of functions to check for appropriate TBBO/BBO and price column +#' names within a data object, as well as the availability and +#' position of those columns. +#' @param x data object +#' @param which disply position of match +#' @aliases +#' has.Trade +#' has.Ask +#' has.AskSize +#' has.Bid +#' has.BidSize +#' has.Price +#' is.BBO +#' is.TBBO +#' @export + +has.Qty <- function(x, which = FALSE) +{ + colAttr <- attr(x, "Qty") + if(!is.null(colAttr)) + return(if(which) colAttr else TRUE) + + locBidAsk <- c(has.Bid(x, which=TRUE),has.Ask(x, which=TRUE)) + loc <- grep("qty", colnames(x), ignore.case=TRUE) + loc <- loc[!(loc %in% locBidAsk)] + if (!identical(loc, integer(0))) { + return(if(which) loc else TRUE) + } else FALSE +} + +# Column setting functions +set.AllColumns <- function(x) { + cols <- c("Op","Hi","Lo","Cl","Vo","Ad","Price","Trade","Qty", + "Bid","BidSize","Ask","AskSize","Mid","Chg") + for(col in cols) { + try(x <- do.call(paste("set",col,sep="."), list(x)), silent=TRUE ) + } + return(x) +} + +set.Chg <- function(x, error=TRUE) { + if(has.Chg(x)) + attr(x,"Chg") <- has.Chg(x, which=TRUE) + return(x) +} + +set.Mid <- function(x, error=TRUE) { + if(has.Mid(x)) + attr(x,"Mid") <- has.Mid(x, which=TRUE) + return(x) +} + +set.Ad <- function(x, error=TRUE) { + if(has.Ad(x)) + attr(x,"Ad") <- has.Ad(x, which=TRUE) + return(x) +} + + +set.Bid <- function(x, error=TRUE) { + if(has.Bid(x)) + attr(x,"Bid") <- has.Bid(x, which=TRUE) + return(x) +} +set.BidSize <- function(x, error=TRUE) { + if(has.BidSize(x)) + attr(x,"BidSize") <- has.BidSize(x, which=TRUE) + return(x) +} +set.Hi <- function(x, error=TRUE) { + if(has.Hi(x)) + attr(x,"Hi") <- has.Hi(x, which=TRUE) + return(x) +} +set.Lo <- function(x, error=TRUE) { + if(has.Lo(x)) + attr(x,"Lo") <- has.Lo(x, which=TRUE) + return(x) +} +set.Op <- function(x, error=TRUE) { + if(has.Op(x)) + attr(x,"Op") <- has.Op(x, which=TRUE) + return(x) +} +set.Qty <- function(x, error=TRUE) { + if(has.Qty(x)) + attr(x,"Qty") <- has.Qty(x, which=TRUE) + return(x) +} +set.Vo <- function(x, error=TRUE) { + if(has.Vo(x)) + attr(x,"Vo") <- has.Vo(x, which=TRUE) + return(x) +} +set.Ask <- function(x, error=TRUE) { + if(has.Ask(x)) + attr(x,"Ask") <- has.Ask(x, which=TRUE) + return(x) +} +set.AskSize <- function(x, error=TRUE) { + if(has.AskSize(x)) + attr(x,"AskSize") <- has.AskSize(x, which=TRUE) + return(x) +} +set.Cl <- function(x, error=TRUE) { + if(has.Cl(x)) + attr(x,"Cl") <- has.Cl(x, which=TRUE) + return(x) +} +set.Price <- function(x, error=TRUE) { + if(has.Price(x)) + attr(x,"Price") <- has.Price(x, which=TRUE) + return(x) +} +set.Trade <- function(x, error=TRUE) { + if(has.Trade(x)) + attr(x,"Trade") <- has.Trade(x, which=TRUE) + return(x) +} Modified: pkg/highfrequency/R/realized.R =================================================================== --- pkg/highfrequency/R/realized.R 2014-09-15 22:35:20 UTC (rev 113) +++ pkg/highfrequency/R/realized.R 2014-11-25 08:04:31 UTC (rev 114) @@ -106,7 +106,7 @@ rdata = as.vector(rdata); seasadjR = as.vector(seasadjR); intraT = length(rdata); N=1; - MCDcov = as.vector(covMcd( rdata , use.correction = FALSE )$raw.cov) + MCDcov = as.vector(robustbase::covMcd( rdata , use.correction = FALSE )$raw.cov) outlyingness = seasadjR^2/MCDcov k = qchisq(p = 1 - alpha, df = N) outlierindic = outlyingness > k @@ -356,10 +356,10 @@ # rho = 0.001 R = matrix( c(1,rho,rho,1) , ncol = 2 ) - int1 <- function(x) { dmvnorm(x,sigma=R) } + int1 <- function(x) { mvtnorm::dmvnorm(x,sigma=R) } num = adaptIntegrate(int1, c(-3,-3), c(3,3), tol=1e-4)$integral - int2 <- function(x) { x[1]*x[2]*dmvnorm(x,sigma=R) } - denom = adaptIntegrate(int2, c(-3,-3), c(3,3), tol=1e-4)$integral + int2 <- function(x) { x[1]*x[2]*mvtnorm::dmvnorm(x,sigma=R) } + denom = cubature::adaptIntegrate(int2, c(-3,-3), c(3,3), tol=1e-4)$integral c2 = rho*num/denom return( (c1+c2)/2 ) } @@ -2235,8 +2235,8 @@ if( onefile == FALSE ){ # Create trading dates: - dates = timeSequence(from, to, format = "%Y-%m-%d", FinCenter = "GMT") - dates = dates[isBizday(dates, holidays = holidayNYSE(1950:2030))]; + dates = timeDate::timeSequence(from, to, format = "%Y-%m-%d", FinCenter = "GMT") + dates = dates[isBizday(dates, holidays = timeDate::holidayNYSE(1950:2030))]; # Create folder structure for saving: if (dir) { dir.create(datadestination); for (i in 1:length(dates)) {dirname = paste(datadestination, "/", as.character(dates[i]), sep = ""); dir.create(dirname) } } @@ -2339,8 +2339,9 @@ 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" - dates = timeSequence(as.character(from),as.character(to), format = "%Y-%m-%d", FinCenter = "GMT") - dates = dates[isBizday(dates, holidays = holidayNYSE(1960:2040))]; + require("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))]; if(trades){ tdata=NULL; totaldata=NULL; @@ -3099,12 +3100,12 @@ tradesCleanup = function(from,to,datasource,datadestination,ticker,exchanges,tdataraw=NULL,report=TRUE,selection="median",...){ - + require('timeDate') nresult = rep(0, 5) if(!is.list(exchanges)){ exchanges = as.list(exchanges)} if (is.null(tdataraw)) { - dates = timeSequence(from, to, format = "%Y-%m-d") - dates = dates[isBizday(dates, holidays=holidayNYSE(1960:2040))] + dates = timeDate::timeSequence(from, to, format = "%Y-%m-d") + dates = dates[timeDate::isBizday(dates, holidays=timeDate::holidayNYSE(1960:2040))] for (j in 1:length(dates)) { datasourcex = paste(datasource, "/", dates[j], sep = "") datadestinationx = paste(datadestination, "/", dates[j], sep = "") From noreply at r-forge.r-project.org Tue Nov 25 10:35:26 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Nov 2014 10:35:26 +0100 (CET) Subject: [Highfrequency-commits] r115 - pkg/highfrequency Message-ID: <20141125093527.11A7818742B@r-forge.r-project.org> Author: kboudt Date: 2014-11-25 10:35:26 +0100 (Tue, 25 Nov 2014) New Revision: 115 Modified: pkg/highfrequency/DESCRIPTION Log: Modified: pkg/highfrequency/DESCRIPTION =================================================================== --- pkg/highfrequency/DESCRIPTION 2014-11-25 08:04:31 UTC (rev 114) +++ pkg/highfrequency/DESCRIPTION 2014-11-25 09:35:26 UTC (rev 115) @@ -1,8 +1,8 @@ Package: highfrequency Version: 0.4 -Date: 2014-08-31 -Title: highfrequency -Author: Jonathan Cornelissen, Kris Boudt, Scott Payseur +Date: 2014-11-25 +Title: highfrequency: Tools for the analysis of highfrequency data in R +Author: Kris Boudt [aut, cre], Jonathan Cornelissen [aut], Scott Payseur [aut], Giang Nguyen [ctb], Maarten Schermers [ctb] Maintainer: Kris Boudt Description: The highfrequency package contains an extensive toolkit for the use of highfrequency financial data in R. It contains functionality to manage, clean and match highfrequency trades and quotes data. Furthermore, it enables users to: calculate easily various liquidity measures, estimate and forecast volatility, and investigate microstructure noise and intraday periodicity. @@ -10,6 +10,5 @@ Depends: R (>= 2.12.0), xts, zoo Suggests: robustbase, cubature, mvtnorm, chron, timeDate, quantmod, MASS, sandwich, numDeriv, FKF, BMS, rugarch -Contributors: Giang Nguyen, Maarten Schermer Thanks: A special thanks for additional contributions from Chris Blakely, Brian Peterson, Eric Zivot and GSoC LazyLoad: yes From noreply at r-forge.r-project.org Tue Nov 25 11:31:03 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Nov 2014 11:31:03 +0100 (CET) Subject: [Highfrequency-commits] r116 - pkg/highfrequency/man Message-ID: <20141125103103.B2541187418@r-forge.r-project.org> Author: kboudt Date: 2014-11-25 11:31:03 +0100 (Tue, 25 Nov 2014) New Revision: 116 Modified: pkg/highfrequency/man/convert.Rd pkg/highfrequency/man/harModel.Rd pkg/highfrequency/man/rAccumulation.Rd pkg/highfrequency/man/rCumSum.Rd pkg/highfrequency/man/rMarginal.Rd pkg/highfrequency/man/rScatterReturns.Rd pkg/highfrequency/man/rZero.Rd Log: Modified: pkg/highfrequency/man/convert.Rd =================================================================== --- pkg/highfrequency/man/convert.Rd 2014-11-25 09:35:26 UTC (rev 115) +++ pkg/highfrequency/man/convert.Rd 2014-11-25 10:31:03 UTC (rev 116) @@ -71,17 +71,19 @@ #The file should be named "IBM_trades.csv" and can be easily converted into xts #and then saved in RData format by: - convert(from=from, to=to, datasource=datasource, datadestination=datadestination, trades = T, - quotes = T, ticker="IBM", dir = FALSE, extension = "csv", header = TRUE, - tradecolnames = NULL, quotecolnames = NULL, format = format, onefile = TRUE ) +convert(from=from, to=to, datasource=datasource, datadestination=datadestination, + trades = T, quotes = T, ticker="IBM", dir = FALSE, extension = "csv", + header = TRUE, tradecolnames = NULL, quotecolnames = NULL, format = format, + onefile = TRUE ) ####### ASC file from www.tickdata.com #Suppose the datasource folder contains asc files for trades and quotes #from "www.tickdata.com" for GLP. #The files "GLP_quotes.asc" and "GLP_trades.asc" should be saved in datasource folder. - convert(from=from, to=to, datasource=datasource, datadestination=datadestination, trades = T, - quotes = T, ticker="GLP", dir = TRUE, extension = "tickdatacom", header = TRUE, - tradecolnames = NULL, quotecolnames = NULL, format = "%d/%m/%Y %H:%M:%OS", onefile = TRUE ); + convert(from=from, to=to, datasource=datasource, datadestination=datadestination, + trades = T, quotes = T, ticker="GLP", dir = TRUE, extension = "tickdatacom", + header = TRUE, tradecolnames = NULL, quotecolnames = NULL, format = "%d/%m/%Y %H:%M:%OS", + onefile = TRUE ); } } Modified: pkg/highfrequency/man/harModel.Rd =================================================================== --- pkg/highfrequency/man/harModel.Rd 2014-11-25 09:35:26 UTC (rev 115) +++ pkg/highfrequency/man/harModel.Rd 2014-11-25 10:31:03 UTC (rev 116) @@ -10,8 +10,9 @@ \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, ...) } + 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.} @@ -62,7 +63,8 @@ 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 + type="HARRVCJ",transform="sqrt"); + # Estimate the HAR model of type HARRVCJ class(x); x @@ -73,7 +75,8 @@ 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); + x = harModel(data=DJI_RV , periods = c(1,5,22), RVest = c("rCov"), + type="HARRV",h=1,transform=NULL); class(x); x; summary(x); Modified: pkg/highfrequency/man/rAccumulation.Rd =================================================================== --- pkg/highfrequency/man/rAccumulation.Rd 2014-11-25 09:35:26 UTC (rev 115) +++ pkg/highfrequency/man/rAccumulation.Rd 2014-11-25 10:31:03 UTC (rev 116) @@ -6,7 +6,8 @@ Plots the realized estimate as it accumulates over a time interval. } \usage{ -rAccumulation(x, period = 1, y = NULL, align.by="seconds", align.period = 1, plotit = FALSE, cts = TRUE, makeReturns = FALSE) +rAccumulation(x, period = 1, y = NULL, align.by="seconds", align.period = 1, + plotit = FALSE, cts = TRUE, makeReturns = FALSE) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -47,14 +48,16 @@ accum[[3]] <- rAccumulation(sbux.xts, period=30, align.by="seconds", align.period=60) par(mfrow=c(2,1)) -plot(cumm[[1]], xlab="", ylab="Cumulative Ruturns", main="Starbucks (SBUX)", sub='20110701', type="p", col=16, lwd=2) +plot(cumm[[1]], xlab="", ylab="Cumulative Ruturns", main="Starbucks (SBUX)", + sub='20110701', type="p", col=16, lwd=2) lines(cumm[[2]], col=2, lwd=2) lines(cumm[[3]], col=3, lwd=2) lines(cumm[[4]], col=4, lwd=2) -plot(accum[[1]], xlab="", ylab="Realized Accumulation", type="l",main="Starbucks (SBUX)", sub='20110701', col=2, lwd=2) +plot(accum[[1]], xlab="", ylab="Realized Accumulation", type="l",main="Starbucks (SBUX)", + sub='20110701', col=2, lwd=2) lines(accum[[2]], col=3, lwd=2) lines(accum[[3]], col=4, lwd=2) } -\keyword{methods} \ No newline at end of file +\keyword{methods} Modified: pkg/highfrequency/man/rCumSum.Rd =================================================================== --- pkg/highfrequency/man/rCumSum.Rd 2014-11-25 09:35:26 UTC (rev 115) +++ pkg/highfrequency/man/rCumSum.Rd 2014-11-25 10:31:03 UTC (rev 116) @@ -6,7 +6,8 @@ Plots cummulative returns at a certain alignment given a return series. } \usage{ -rCumSum(x, period = 1, align.by="seconds",align.period = 1, plotit = FALSE, type = "l", cts = TRUE, makeReturns = FALSE) +rCumSum(x, period = 1, align.by="seconds",align.period = 1, + plotit = FALSE, type = "l", cts = TRUE, makeReturns = FALSE) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -35,9 +36,10 @@ cumm[[2]] <- rCumSum(sbux.xts, period=10, align.by="seconds", align.period=60) cumm[[3]] <- rCumSum(sbux.xts, period=20, align.by="seconds", align.period=60) cumm[[4]] <- rCumSum(sbux.xts, period=30, align.by="seconds", align.period=60) -plot(cumm[[1]], xlab="", ylab="Cumulative Ruturns", main="Starbucks (SBUX)", sub='20110701', type="p", col=16, lwd=2) +plot(cumm[[1]], xlab="", ylab="Cumulative Ruturns", main="Starbucks (SBUX)", + sub='20110701', type="p", col=16, lwd=2) lines(cumm[[2]], col=2, lwd=2) lines(cumm[[3]], col=3, lwd=2) lines(cumm[[4]], col=4, lwd=2) } -\keyword{methods} \ No newline at end of file +\keyword{methods} Modified: pkg/highfrequency/man/rMarginal.Rd =================================================================== --- pkg/highfrequency/man/rMarginal.Rd 2014-11-25 09:35:26 UTC (rev 115) +++ pkg/highfrequency/man/rMarginal.Rd 2014-11-25 10:31:03 UTC (rev 116) @@ -6,7 +6,8 @@ Plots the marginal contribution to the realized estimate. } \usage{ -rMarginal(x, y = NULL, period,align.by="seconds", align.period = 1, plotit = FALSE, cts = TRUE,makeReturns = FALSE) +rMarginal(x, y = NULL, period,align.by="seconds", align.period = 1, + plotit = FALSE, cts = TRUE,makeReturns = FALSE) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -35,7 +36,10 @@ \examples{ data(sbux.xts) par(mfrow=c(2,1)) -plot(rCumSum(sbux.xts, period=10, align.by="seconds", align.period=60), xlab="", ylab="Cumulative Ruturns", main="Starbucks (SBUX)", sub='20110701', type="p") -barplot(rMarginal(sbux.xts, period=10, align.by="seconds", align.period=60)$y, main="Marginal Contribution Plot") +plot(rCumSum(sbux.xts, period=10, align.by="seconds", align.period=60), + xlab="", ylab="Cumulative Ruturns", main="Starbucks (SBUX)", + sub='20110701', type="p") +barplot(rMarginal(sbux.xts, period=10, align.by="seconds", align.period=60)$y, + main="Marginal Contribution Plot") } \keyword{methods} Modified: pkg/highfrequency/man/rScatterReturns.Rd =================================================================== --- pkg/highfrequency/man/rScatterReturns.Rd 2014-11-25 09:35:26 UTC (rev 115) +++ pkg/highfrequency/man/rScatterReturns.Rd 2014-11-25 10:31:03 UTC (rev 116) @@ -6,7 +6,10 @@ Creates a scatterplot of cross returns. } \usage{ -rScatterReturns(x,y, period, align.by="seconds", align.period=1,numbers=FALSE,xlim= NULL, ylim=NULL, plotit=TRUE, pch=NULL, cts=TRUE, makeReturns=FALSE, scale.size=0, col.change=FALSE,...) +rScatterReturns(x,y, period, align.by="seconds", align.period=1, + numbers=FALSE,xlim= NULL, ylim=NULL, + plotit=TRUE, pch=NULL, cts=TRUE, makeReturns=FALSE, + scale.size=0, col.change=FALSE,...) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -41,7 +44,9 @@ data(sbux.xts) data(lltc.xts) par(mfrow=c(2,1)) -rScatterReturns(sbux.xts,y=lltc.xts, period=1, align.period=20,ylab="LLTC",xlab="SBUX",numbers=FALSE) -rScatterReturns(sbux.xts,y=lltc.xts, period=1, align.period=20,ylab="LLTC",xlab="SBUX",numbers=TRUE) +rScatterReturns(sbux.xts,y=lltc.xts, period=1, align.period=20, + ylab="LLTC",xlab="SBUX",numbers=FALSE) +rScatterReturns(sbux.xts,y=lltc.xts, period=1, align.period=20, + ylab="LLTC",xlab="SBUX",numbers=TRUE) } -\keyword{methods} \ No newline at end of file +\keyword{methods} Modified: pkg/highfrequency/man/rZero.Rd =================================================================== --- pkg/highfrequency/man/rZero.Rd 2014-11-25 09:35:26 UTC (rev 115) +++ pkg/highfrequency/man/rZero.Rd 2014-11-25 10:31:03 UTC (rev 116) @@ -5,7 +5,8 @@ Calculates the percentage of co-zero returns at a specified sampling period. } \usage{ -rZero(rdata, period=1, align.by="seconds", align.period = 1, cts = TRUE, makeReturns = FALSE, ...) +rZero(rdata, period=1, align.by="seconds", align.period = 1, cts = TRUE, + makeReturns = FALSE, ...) } \arguments{ From noreply at r-forge.r-project.org Tue Nov 25 13:36:59 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Nov 2014 13:36:59 +0100 (CET) Subject: [Highfrequency-commits] r117 - pkg/highfrequency Message-ID: <20141125123659.394AE186D18@r-forge.r-project.org> Author: kboudt Date: 2014-11-25 13:36:58 +0100 (Tue, 25 Nov 2014) New Revision: 117 Modified: pkg/highfrequency/DESCRIPTION Log: Modified: pkg/highfrequency/DESCRIPTION =================================================================== --- pkg/highfrequency/DESCRIPTION 2014-11-25 10:31:03 UTC (rev 116) +++ pkg/highfrequency/DESCRIPTION 2014-11-25 12:36:58 UTC (rev 117) @@ -1,7 +1,7 @@ Package: highfrequency Version: 0.4 Date: 2014-11-25 -Title: highfrequency: Tools for the analysis of highfrequency data in R +Title: Tools for Highfrequency Data Analysis Author: Kris Boudt [aut, cre], Jonathan Cornelissen [aut], Scott Payseur [aut], Giang Nguyen [ctb], Maarten Schermers [ctb] Maintainer: Kris Boudt From noreply at r-forge.r-project.org Tue Nov 25 13:48:40 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Nov 2014 13:48:40 +0100 (CET) Subject: [Highfrequency-commits] r118 - pkg/highfrequency/R Message-ID: <20141125124840.6C428187354@r-forge.r-project.org> Author: kboudt Date: 2014-11-25 13:48:39 +0100 (Tue, 25 Nov 2014) New Revision: 118 Modified: pkg/highfrequency/R/highfrequencyGSOC.R Log: Modified: pkg/highfrequency/R/highfrequencyGSOC.R =================================================================== --- pkg/highfrequency/R/highfrequencyGSOC.R 2014-11-25 12:36:58 UTC (rev 117) +++ pkg/highfrequency/R/highfrequencyGSOC.R 2014-11-25 12:48:39 UTC (rev 118) @@ -1484,7 +1484,7 @@ # compute the asymptotic covariance matrix of splittedparamsvector - mH = hessian (.heavy_likelihood_ll, x= splittedparams, data=data, p=p, q=q, backcast=backcast, LB=LB, UB=UB, compconst=compconst) + mH = numDeriv::hessian(.heavy_likelihood_ll, x= splittedparams, data=data, p=p, q=q, backcast=backcast, LB=LB, UB=UB, compconst=compconst) T = nrow(data) nm = length(paramsvector) @@ -1527,7 +1527,7 @@ ## Define It # jacobian will be T x length of theta - m = jacobian(.heavy_likelihood_lls, x = splittedparams, data=data, p=p, q=q, backcast=backcast, LB=LB, UB=UB, compconst=compconst) # returns a matrix of T by L (length of theta) + m = numDeriv::jacobian(.heavy_likelihood_lls, x = splittedparams, data=data, p=p, q=q, backcast=backcast, LB=LB, UB=UB, compconst=compconst) # returns a matrix of T by L (length of theta) start = 1; for (i in 1:K) From noreply at r-forge.r-project.org Tue Nov 25 13:49:06 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Nov 2014 13:49:06 +0100 (CET) Subject: [Highfrequency-commits] r119 - pkg/highfrequency/R Message-ID: <20141125124906.14540187354@r-forge.r-project.org> Author: kboudt Date: 2014-11-25 13:49:05 +0100 (Tue, 25 Nov 2014) New Revision: 119 Modified: pkg/highfrequency/R/realized.R Log: Modified: pkg/highfrequency/R/realized.R =================================================================== --- pkg/highfrequency/R/realized.R 2014-11-25 12:48:39 UTC (rev 118) +++ pkg/highfrequency/R/realized.R 2014-11-25 12:49:05 UTC (rev 119) @@ -357,7 +357,7 @@ rho = 0.001 R = matrix( c(1,rho,rho,1) , ncol = 2 ) int1 <- function(x) { mvtnorm::dmvnorm(x,sigma=R) } - num = adaptIntegrate(int1, c(-3,-3), c(3,3), tol=1e-4)$integral + num = cubature::aadaptIntegrate(int1, c(-3,-3), c(3,3), tol=1e-4)$integral int2 <- function(x) { x[1]*x[2]*mvtnorm::dmvnorm(x,sigma=R) } denom = cubature::adaptIntegrate(int2, c(-3,-3), c(3,3), tol=1e-4)$integral c2 = rho*num/denom @@ -1196,7 +1196,7 @@ select = c(1:N)[perczeroes < 0.5] seasadjRselect = seasadjR[, select] N = ncol(seasadjRselect) - MCDobject = try(covMcd(x = seasadjRselect, alpha = alphaMCD)) + MCDobject = try(robustbase::covMcd(x = seasadjRselect, alpha = alphaMCD)) if (length(MCDobject$raw.mah) > 1) { betaMCD = 1-alphaMCD; asycor = betaMCD/pchisq( qchisq(betaMCD,df=N),df=N+2 ) MCDcov = (asycor*t(seasadjRselect[MCDobject$best,])%*%seasadjRselect[MCDobject$best,])/length(MCDobject$best); @@ -2236,7 +2236,7 @@ # Create trading dates: dates = timeDate::timeSequence(from, to, format = "%Y-%m-%d", FinCenter = "GMT") - dates = dates[isBizday(dates, holidays = timeDate::holidayNYSE(1950:2030))]; + dates = dates[timeDate::isBizday(dates, holidays = timeDate::holidayNYSE(1950:2030))]; # Create folder structure for saving: if (dir) { dir.create(datadestination); for (i in 1:length(dates)) {dirname = paste(datadestination, "/", as.character(dates[i]), sep = ""); dir.create(dirname) } } @@ -3221,7 +3221,7 @@ nresult = rep(0,7); if(is.null(qdataraw)){ dates = timeSequence(from,to, format = "%Y-%m-%d", FinCenter = "GMT"); - dates = dates[isBizday(dates, holidays = holidayNYSE(2004:2010))]; + dates = dates[timeDate::isBizday(dates, holidays = timeDate::holidayNYSE(2004:2010))]; for(j in 1:length(dates)){ datasourcex = paste(datasource,"/",dates[j],sep=""); @@ -3293,8 +3293,8 @@ tradesCleanupFinal = function(from,to,datasource,datadestination,ticker,tdata=NULL,qdata=NULL,...){ if(is.null(tdata)&is.null(qdata)){ - dates = timeSequence(from,to, format = "%Y-%m-%d", FinCenter = "GMT"); - dates = dates[isBizday(dates, holidays = holidayNYSE(2004:2010))]; + dates = timeDate::timeSequence(from,to, format = "%Y-%m-%d", FinCenter = "GMT"); + dates = dates[timeDate::isBizday(dates, holidays = timeDate::holidayNYSE(2004:2010))]; for(j in 1:length(dates)){ datasourcex = paste(datasource,"/",dates[j],sep=""); From noreply at r-forge.r-project.org Tue Nov 25 13:52:12 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Nov 2014 13:52:12 +0100 (CET) Subject: [Highfrequency-commits] r120 - pkg/highfrequency/R Message-ID: <20141125125212.DE9AB187354@r-forge.r-project.org> Author: kboudt Date: 2014-11-25 13:52:12 +0100 (Tue, 25 Nov 2014) New Revision: 120 Modified: pkg/highfrequency/R/realized.R Log: Modified: pkg/highfrequency/R/realized.R =================================================================== --- pkg/highfrequency/R/realized.R 2014-11-25 12:49:05 UTC (rev 119) +++ pkg/highfrequency/R/realized.R 2014-11-25 12:52:12 UTC (rev 120) @@ -357,7 +357,7 @@ rho = 0.001 R = matrix( c(1,rho,rho,1) , ncol = 2 ) int1 <- function(x) { mvtnorm::dmvnorm(x,sigma=R) } - num = cubature::aadaptIntegrate(int1, c(-3,-3), c(3,3), tol=1e-4)$integral + num = cubature::adaptIntegrate(int1, c(-3,-3), c(3,3), tol=1e-4)$integral int2 <- function(x) { x[1]*x[2]*mvtnorm::dmvnorm(x,sigma=R) } denom = cubature::adaptIntegrate(int2, c(-3,-3), c(3,3), tol=1e-4)$integral c2 = rho*num/denom From noreply at r-forge.r-project.org Tue Nov 25 13:53:57 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Nov 2014 13:53:57 +0100 (CET) Subject: [Highfrequency-commits] r121 - pkg/highfrequency/man Message-ID: <20141125125357.9B382187354@r-forge.r-project.org> Author: kboudt Date: 2014-11-25 13:53:57 +0100 (Tue, 25 Nov 2014) New Revision: 121 Modified: pkg/highfrequency/man/TAQload.Rd Log: Modified: pkg/highfrequency/man/TAQload.Rd =================================================================== --- pkg/highfrequency/man/TAQload.Rd 2014-11-25 12:52:12 UTC (rev 120) +++ pkg/highfrequency/man/TAQload.Rd 2014-11-25 12:53:57 UTC (rev 121) @@ -56,7 +56,7 @@ #Load only price data for stocks AA and AAPL \dontrun{xx = TAQLoad(tickers=c("AA","AAPL"),from,to,trades=TRUE, quotes=FALSE,datasource=datasource,variables="PRICE")} -\dontrun{head(xx); } -\dontrun{tail(xx); } +\dontrun{head(xx)}; } +\dontrun{tail(xx)}; } } From noreply at r-forge.r-project.org Tue Nov 25 14:00:59 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Nov 2014 14:00:59 +0100 (CET) Subject: [Highfrequency-commits] r122 - pkg/highfrequency/man Message-ID: <20141125130059.8936518778A@r-forge.r-project.org> Author: kboudt Date: 2014-11-25 14:00:59 +0100 (Tue, 25 Nov 2014) New Revision: 122 Modified: pkg/highfrequency/man/TAQload.Rd Log: Modified: pkg/highfrequency/man/TAQload.Rd =================================================================== --- pkg/highfrequency/man/TAQload.Rd 2014-11-25 12:53:57 UTC (rev 121) +++ pkg/highfrequency/man/TAQload.Rd 2014-11-25 13:00:59 UTC (rev 122) @@ -51,12 +51,9 @@ #TAQLoad: load data for stock AAPL \dontrun{xx = TAQLoad(tickers="AAPL",from,to,trades=TRUE,quotes=FALSE, datasource=datasource,variables=NULL)} -\dontrun{head(xx);} #Load only price data for stocks AA and AAPL \dontrun{xx = TAQLoad(tickers=c("AA","AAPL"),from,to,trades=TRUE, -quotes=FALSE,datasource=datasource,variables="PRICE")} -\dontrun{head(xx)}; } -\dontrun{tail(xx)}; } +quotes=FALSE,datasource=datasource,variables="PRICE")} } From noreply at r-forge.r-project.org Tue Nov 25 14:56:29 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Nov 2014 14:56:29 +0100 (CET) Subject: [Highfrequency-commits] r123 - pkg/highfrequency Message-ID: <20141125135629.17FA9186952@r-forge.r-project.org> Author: kboudt Date: 2014-11-25 14:56:28 +0100 (Tue, 25 Nov 2014) New Revision: 123 Modified: pkg/highfrequency/DESCRIPTION Log: Modified: pkg/highfrequency/DESCRIPTION =================================================================== --- pkg/highfrequency/DESCRIPTION 2014-11-25 13:00:59 UTC (rev 122) +++ pkg/highfrequency/DESCRIPTION 2014-11-25 13:56:28 UTC (rev 123) @@ -1,14 +1,13 @@ Package: highfrequency Version: 0.4 Date: 2014-11-25 -Title: Tools for Highfrequency Data Analysis +Title: Tools For Highfrequency Data Analysis Author: Kris Boudt [aut, cre], Jonathan Cornelissen [aut], Scott Payseur [aut], Giang Nguyen [ctb], Maarten Schermers [ctb] Maintainer: Kris Boudt -Description: The highfrequency package contains an extensive toolkit for the use of highfrequency financial data in R. It contains functionality to manage, clean and match highfrequency trades and quotes data. Furthermore, it enables users to: calculate easily various liquidity measures, estimate and forecast volatility, and investigate microstructure noise and intraday periodicity. +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 -Thanks: A special thanks for additional contributions from Chris Blakely, Brian Peterson, Eric Zivot and GSoC LazyLoad: yes From noreply at r-forge.r-project.org Tue Nov 25 15:54:21 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Nov 2014 15:54:21 +0100 (CET) Subject: [Highfrequency-commits] r124 - pkg/highfrequency/R Message-ID: <20141125145421.F4002183D55@r-forge.r-project.org> Author: kboudt Date: 2014-11-25 15:54:21 +0100 (Tue, 25 Nov 2014) New Revision: 124 Modified: pkg/highfrequency/R/realized.R Log: brian ripley... Modified: pkg/highfrequency/R/realized.R =================================================================== --- pkg/highfrequency/R/realized.R 2014-11-25 13:56:28 UTC (rev 123) +++ pkg/highfrequency/R/realized.R 2014-11-25 14:54:21 UTC (rev 124) @@ -3220,7 +3220,7 @@ quotesCleanup = function(from,to,datasource,datadestination,ticker,exchanges, qdataraw=NULL,report=TRUE,selection="median",maxi=50,window=50,type="advanced",rmoutliersmaxi=10,...){ nresult = rep(0,7); if(is.null(qdataraw)){ - dates = timeSequence(from,to, format = "%Y-%m-%d", FinCenter = "GMT"); + dates = timeDate::timeSequence(from,to, format = "%Y-%m-%d", FinCenter = "GMT"); dates = dates[timeDate::isBizday(dates, holidays = timeDate::holidayNYSE(2004:2010))]; for(j in 1:length(dates)){ From noreply at r-forge.r-project.org Wed Nov 26 11:22:58 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 26 Nov 2014 11:22:58 +0100 (CET) Subject: [Highfrequency-commits] r125 - pkg/highfrequency Message-ID: <20141126102258.79A69187849@r-forge.r-project.org> Author: kboudt Date: 2014-11-26 11:22:57 +0100 (Wed, 26 Nov 2014) New Revision: 125 Modified: pkg/highfrequency/DESCRIPTION Log: Modified: pkg/highfrequency/DESCRIPTION =================================================================== --- pkg/highfrequency/DESCRIPTION 2014-11-25 14:54:21 UTC (rev 124) +++ pkg/highfrequency/DESCRIPTION 2014-11-26 10:22:57 UTC (rev 125) @@ -2,7 +2,7 @@ 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 Schermers [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. From noreply at r-forge.r-project.org Wed Nov 26 11:23:03 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 26 Nov 2014 11:23:03 +0100 (CET) Subject: [Highfrequency-commits] r126 - pkg/highfrequency/vignettes Message-ID: <20141126102303.3C96A18784D@r-forge.r-project.org> Author: kboudt Date: 2014-11-26 11:23:02 +0100 (Wed, 26 Nov 2014) New Revision: 126 Modified: pkg/highfrequency/vignettes/highfrequency.pdf Log: Modified: pkg/highfrequency/vignettes/highfrequency.pdf =================================================================== (Binary files differ) From noreply at r-forge.r-project.org Fri Nov 28 09:52:42 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 28 Nov 2014 09:52:42 +0100 (CET) Subject: [Highfrequency-commits] r127 - in pkg/highfrequency: . R man Message-ID: <20141128085242.55C021875BC@r-forge.r-project.org> Author: kboudt Date: 2014-11-28 09:52:41 +0100 (Fri, 28 Nov 2014) New Revision: 127 Modified: pkg/highfrequency/NAMESPACE pkg/highfrequency/R/quantmod_patch.R pkg/highfrequency/R/spotvol.r pkg/highfrequency/man/highfrequency-package.Rd pkg/highfrequency/man/sample_returns_5min.Rd pkg/highfrequency/man/spotvol.Rd Log: Modified: pkg/highfrequency/NAMESPACE =================================================================== --- pkg/highfrequency/NAMESPACE 2014-11-26 10:23:02 UTC (rev 126) +++ pkg/highfrequency/NAMESPACE 2014-11-28 08:52:41 UTC (rev 127) @@ -66,7 +66,9 @@ rSV, rTPVar, heavyModelC, -spotvol +spotvol, +getPrice, +has.Qty )#end exported function S3method(print, harModel); Modified: pkg/highfrequency/R/quantmod_patch.R =================================================================== --- pkg/highfrequency/R/quantmod_patch.R 2014-11-26 10:23:02 UTC (rev 126) +++ pkg/highfrequency/R/quantmod_patch.R 2014-11-28 08:52:41 UTC (rev 127) @@ -2,20 +2,7 @@ # Utility functions for handling price data ############################################################################### -#' get price column(s) from a timeseries -#' -#' Will attempt to locate price column(s) from a time series with rational defaults. -#' -#' May be subset by symbol and preference. -#' \code{prefer} Preference will be for any commonly used financial time series price description, -#' e.g. 'trade', 'close', 'bid', 'ask' with specific tests and matching for types and column names -#' currently supported in R, but a default grep match will be performed if one of the supported types doesn't match. -#' -#' @param x A data object with columns containing data to be extracted -#' @param symbol text string containing the symbol to extract -#' @param prefer preference for any particular type of price, see Details -#' @param \dots any other passthrough parameters -#' @export + getPrice <- function (x, symbol=NULL, prefer=NULL,...) { # first subset on symbol, if present @@ -53,7 +40,6 @@ } } -#' @export is.BBO <- function (x) { if (all(has.Bid(x), has.Ask(x))) { @@ -62,7 +48,7 @@ else FALSE } -#' @export + is.TBBO <- function (x) { if (all(has.Trade(x),has.Qty(x),has.Bid(x), has.Ask(x))) { @@ -71,7 +57,7 @@ else FALSE } -#' @export + is.BAM <- function(x) { if (all(has.Bid(x), has.Ask(x), has.Mid(x))) { TRUE @@ -79,7 +65,7 @@ else FALSE } -#' @export + is.BATM <- function(x) { if (all(has.Bid(x), has.Ask(x), has.Trade(x), has.Mid(x))) { TRUE @@ -87,7 +73,7 @@ else FALSE } -#' @export + has.Bid <- function(x, which = FALSE) { colAttr <- attr(x, "Bid") @@ -102,7 +88,7 @@ } else FALSE } -#' @export + has.BidSize <- function(x, which = FALSE) { colAttr <- attr(x, "BidSize") @@ -120,7 +106,7 @@ else FALSE } -#' @export + has.Ask <- function(x, which = FALSE) { colAttr <- attr(x, "Ask") #case sensitive; doesn't work for SYMBOL.Ask :-( @@ -135,7 +121,7 @@ } else FALSE } -#' @export + has.AskSize <- function(x, which = FALSE) { colAttr <- attr(x, "AskSize") @@ -153,7 +139,7 @@ else FALSE } -#' @export + has.Price <- function(x, which = FALSE) { colAttr <- attr(x, "Price") @@ -168,7 +154,7 @@ } else FALSE } -#' @export + has.Trade <- function(x, which = FALSE) { colAttr <- attr(x, "Trade") @@ -267,33 +253,8 @@ } else FALSE } -#has.Un <- function(x, which=FALSE) { -# loc <- grep("Unadj", colnames(x), ignore.case = TRUE) -# if (!identical(loc, integer(0))) -# return(ifelse(which, loc, TRUE)) -# ifelse(which, loc, FALSE) -#} - -#' check for Trade, Bid, and Ask/Offer (BBO/TBBO), Quantity, and Price data -#' -#' A set of functions to check for appropriate TBBO/BBO and price column -#' names within a data object, as well as the availability and -#' position of those columns. -#' @param x data object -#' @param which disply position of match -#' @aliases -#' has.Trade -#' has.Ask -#' has.AskSize -#' has.Bid -#' has.BidSize -#' has.Price -#' is.BBO -#' is.TBBO -#' @export - has.Qty <- function(x, which = FALSE) { colAttr <- attr(x, "Qty") Modified: pkg/highfrequency/R/spotvol.r =================================================================== --- pkg/highfrequency/R/spotvol.r 2014-11-26 10:23:02 UTC (rev 126) +++ pkg/highfrequency/R/spotvol.r 2014-11-28 08:52:41 UTC (rev 127) @@ -1,382 +1,3 @@ -#' Spot volatility estimation -#' -#' The \code{spotvolatility} package offers several methods to estimate spot -#' volatility and its intraday seasonality, using high-frequency data. -#' -#' @details -#' The following spot volatility estimation methods have been implemented: -#' -#' @section Deterministic periodicity: -#' The spot volatility is decomposed into a a deterministic periodic factor -#' f_{i} (identical for every day in the sample) and a daily factor s_{t} -#' (identical for all observations within a day). Both components are then -#' estimated separately. For more details, see Taylor and Xu (1997) and -#' Andersen and Bollerslev (1997). The jump robust versions by Boudt et al. -#' (2011) have also been implemented. -#' -#' @section Stochastic periodicity: -#' This method by Beltratti and Morana (2001) assumes the periodicity factor to -#' be stochastic. The spot volatility estimation is split into four components: -#' a random walk, an autoregressive process, a stochastic cyclical process and -#' a deterministic cyclical process. The model is estimated using a -#' quasi-maximum likelihood method based on the Kalman Filter. The package -#' \code{\link[=fkf]{FKF}} is used to apply the Kalman filter. -#' -#' @section Nonparametric filtering: -#' This method by Kristensen (2010) filters the spot volatility in a -#' nonparametric way by applying kernel weights to the standard realized -#' volatility estimator. Different kernels and bandwidths can be used to focus -#' on specific characteristics of the volatility process. -#' -#' @section Piecewise constant volatility: -#' Another nonparametric method is that of Fried (2012), which assumes the -#' volatility to be piecewise constant over local windows. Robust two-sample -#' tests are applied to detect changes in variability between subsequent -#' windows. The spot volatility can then be estimated by evaluating -#' regular realized volatility estimators within each local window. -#' -#' @section GARCH models with intraday seasonality: -#' The package also includes an option to apply GARCH models, implemented by -#' the \code{\link{rugarch}} package, to estimate spot volatility from intraday -#' data. This is done by including external regressors in the model. These -#' regressors are based on a flexible Fourier form, which was also used in the -#' stochastic and deterministic periodicity estimation methods. -#' -#' @template references -#' -#' @docType package -#' @name spotvolatility -NULL - -#' Spot volatility estimation -#' -#' @description -#' -#' The \code{spotvol} function offers several methods to estimate spot -#' volatility and its intraday seasonality, using high-frequency data. It -#' returns an object of class \code{spotvol}, which can contain various outputs, -#' depending on the method used. See 'Details' for a description of each method. -#' In any case, the output will contain the spot volatility estimates. -#' -#' The input can consist of price data or return data, either tick by tick or -#' sampled at set intervals. The data will be converted to equispaced -#' high-frequency returns \eqn{r_{t,i}} (read: the \eqn{i}th return on day -#' \eqn{t}). -#' -#' @details The following estimation methods can be specified in \code{method}: -#' -#' \strong{Deterministic periodicity method (\code{"detper"})} -#' -#' Parameters: -#' \tabular{ll}{ -#' \code{dailyvol} \tab A string specifying the estimation method for the daily -#' component \eqn{s_t}. Possible values are \code{"bipower", "rv", "medrv"}. -#' Default = \code{"bipower"}. \cr -#' \code{periodicvol} \tab A string specifying the estimation method for the -#' component of intraday volatility, that depends in a deterministic way on the -#' intraday time at which the return is observed. Possible values are -#' \code{"TML", "SD", "WSD", "OLS"}. See Boudt et al. (2011) for details. -#' Default = \code{"TML"}.\cr -#' \code{P1} \tab A positive integer corresponding to the number of cosinus -#' terms used in the flexible Fourier specification of the periodicity function, -#' see Andersen et al. (1997) for details. Default = 5. \cr -#' \code{P2} \tab Same as \code{P1}, but for the sinus terms. Default = 5.\cr -#' \code{dummies} \tab Boolean: in case it is \code{TRUE}, the parametric -#' estimator of periodic standard deviation specifies the periodicity function -#' as the sum of dummy variables corresponding to each intraday period. If it -#' is \code{FALSE}, the parametric estimator uses the flexible Fourier -#' specification. Default = \code{FALSE}. -#' } -#' Outputs (see 'Value' for a full description of each component): -#' \itemize{ -#' \item{\code{spot}} -#' \item{\code{daily}} -#' \item{\code{periodic}} -#' } -#' The spot volatility is decomposed into a deterministic periodic factor -#' \eqn{f_{i}} (identical for every day in the sample) and a daily factor -#' \eqn{s_{t}} (identical for all observations within a day). Both components -#' are then estimated separately. For more details, see Taylor and Xu (1997) -#' and Andersen and Bollerslev (1997). The jump robust versions by Boudt et al. -#' (2011) have also been implemented. -#' -#' \strong{Stochastic periodicity method (\code{"stochper"})} -#' -#' Parameters: -#' \tabular{ll}{ -#' \code{P1} \tab A positive integer corresponding to the number of cosinus -#' terms used in the flexible Fourier specification of the periodicity function. -#' Default = 5. \cr -#' \code{P2} \tab Same as \code{P1}, but for the sinus terms. Default = 5.\cr -#' \code{init} \tab A named list of initial values to be used in the -#' optimization routine (\code{"BFGS"} in \code{\link{optim}}). Default = -#' \code{list(sigma = 0.03, sigma_mu = 0.005, sigma_h = 0.005, sigma_k = 0.05, -#' phi = 0.2, rho = 0.98, mu = c(2, -0.5), delta_c = rep(0, max(1,P1)), -#' delta_s = rep(0, max(1,P2)))}. See Beltratti & Morana (2001) for a definition -#' of each parameter. \code{init} can contain any number of these parameters. -#' For parameters not specified in \code{init}, the default initial value will -#' be used.\cr -#' \code{control} \tab A list of options to be passed down to -#' \code{\link{optim}}. -#' } -#' Outputs (see 'Value' for a full description of each component): -#' \itemize{ -#' \item{\code{spot}} -#' \item{\code{par}} -#' } -#' This method by Beltratti and Morana (2001) assumes the periodicity factor to -#' be stochastic. The spot volatility estimation is split into four components: -#' a random walk, an autoregressive process, a stochastic cyclical process and -#' a deterministic cyclical process. The model is estimated using a -#' quasi-maximum likelihood method based on the Kalman Filter. The package -#' \code{\link[=fkf]{FKF}} is used to apply the Kalman filter. In addition to -#' the spot volatility estimates, all parameter estimates are returned. -#' -#' \strong{Nonparametric filtering (\code{"kernel"})} -#' -#' Parameters: -#' \tabular{ll}{ -#' \code{type} \tab String specifying the type of kernel to be used. Options -#' include \code{"gaussian", "epanechnikov", "beta"}. Default = -#' \code{"gaussian"}.\cr -#' \code{h} \tab Scalar or vector specifying bandwidth(s) to be used in kernel. -#' If \code{h} is a scalar, it will be assumed equal throughout the sample. If -#' it is a vector, it should contain bandwidths for each day. If left empty, -#' it will be estimated. Default = \code{NULL}. \cr -#' \code{est} \tab String specifiying the bandwidth estimation method. Possible -#' values include \code{"cv", "quarticity"}. Method \code{"cv"} equals -#' cross-validation, which chooses the bandwidth that minimizes the Integrated -#' Square Error. \code{"quarticity"} multiplies the simple plug-in estimator -#' by a factor based on the daily quarticity of the returns. \code{est} is -#' obsolete if \code{h} has already been specified by the user. Default = -#' \code{"cv"}.\cr -#' \code{lower} \tab Lower bound to be used in bandwidth optimization routine, -#' when using cross-validation method. Default is \eqn{0.1n^{-0.2}}. \cr -#' \code{upper} \tab Upper bound to be used in bandwidth optimization routine, -#' when using cross-validation method. Default is \eqn{n^{-0.2}}. \cr -#' } -#' Outputs (see 'Value' for a full description of each component): -#' \itemize{ -#' \item{\code{spot}} -#' \item{\code{par}} -#' } -#' This method by Kristensen (2010) filters the spot volatility in a -#' nonparametric way by applying kernel weights to the standard realized -#' volatility estimator. Different kernels and bandwidths can -#' be used to focus on specific characteristics of the volatility process. -#' -#' Estimation results heavily depend on the bandwidth parameter \eqn{h}, so it -#' is important that this parameter is well chosen. However, it is difficult to -#' come up with a method that determines the optimal bandwidth for any kind of -#' data or kernel that can be used. Although some estimation methods are -#' provided, it is advised that you specify \eqn{h} yourself, or make sure that -#' the estimation results are appropiate. -#' -#' One way to estimate \eqn{h}, is by using cross-validation. For each day in -#' the sample, \eqn{h} is chosen as to minimize the Integrated Square Error, -#' which is a function of \eqn{h}. However, this function often has multiple -#' local minima, or no minima at all (\eqn{h -> \Inf}). To ensure a reasonable -#' optimum is reached, strict boundaries have to be imposed on \eqn{h}. These -#' can be specified by \code{lower} and \code{upper}, which by default are -#' \eqn{0.1n^{-0.2}} and \eqn{n^{-0.2}} respectively, where \eqn{n} is the -#' number of observations in a day. -#' -#' When using the method \code{"kernel"}, in addition to the spot volatility -#' estimates, all used values of the bandwidth \eqn{h} are returned. -#' -#' \strong{Piecewise constant volatility (\code{"piecewise"})} -#' -#' Parameters: -#' \tabular{ll}{ -#' \code{type} \tab String specifying the type of test to be used. Options -#' include \code{"MDa", "MDb", "DM"}. See Fried (2012) for details. Default = -#' \code{"MDa"}.\cr -#' \code{m} \tab Number of observations to include in reference window. -#' Default = \code{40}. \cr -#' \code{n} \tab Number of observations to include in test window. -#' Default = \code{20}. \cr -#' \code{alpha} \tab Significance level to be used in tests. Note that the test -#' will be executed many times (roughly equal to the total number of -#' observations), so it is advised to use a small value for \code{alpha}, to -#' avoid a lot of false positives. Default = \code{0.005}. \cr -#' \code{volest} \tab String specifying the realized volatility estimator to be -#' used in local windows. Possible values are \code{"bipower", "rv", "medrv"}. -#' Default = \code{"bipower"}. \cr -#' \code{online} \tab Boolean indicating whether estimations at a certain point -#' \eqn{t} should be done online (using only information available at -#' \eqn{t-1}), or ex post (using all observations between two change points). -#' Default = \code{TRUE}. \cr -#' } -#' Outputs (see 'Value' for a full description of each component): -#' \itemize{ -#' \item{\code{spot}} -#' \item{\code{cp}} -#' } -#' -#' This nonparametric method by Fried (2012) assumes the volatility to be -#' piecewise constant over local windows. Robust two-sample tests are applied to -#' detect changes in variability between subsequent windows. The spot volatility -#' can then be estimated by evaluating regular realized volatility estimators -#' within each local window. -#' -#' Along with the spot volatility estimates, this method will return the -#' detected change points in the volatility level. When plotting a -#' \code{spotvol} object containing \code{cp}, these change points will be -#' visualized. -#' -#' \strong{GARCH models with intraday seasonality (\code{"garch"})} -#' -#' Parameters: -#' \tabular{ll}{ -#' \code{model} \tab String specifying the type of test to be used. Options -#' include \code{"sGARCH", "eGARCH"}. See \code{\link{ugarchspec}} in the -#' \code{\link{rugarch}} package. Default = \code{"eGARCH"}. \cr -#' \code{garchorder} \tab Numeric value of length 2, containing the order of -#' the GARCH model to be estimated. Default = \code{c(1,1)}. \cr -#' \code{dist} \tab String specifying the distribution to be assumed on the -#' innovations. See \code{distribution.model} in \code{\link{ugarchspec}} for -#' possible options. Default = \code{"norm"}. \cr -#' \code{solver.control} \tab List containing solver options. -#' See \code{\link{ugarchfit}} for possible values. Default = \code{list()}. \cr -#' \code{P1} \tab A positive integer corresponding to the number of cosinus -#' terms used in the flexible Fourier specification of the periodicity function. -#' Default = 5. \cr -#' \code{P2} \tab Same as \code{P1}, but for the sinus terms. Default = 5.\cr -#' } -#' Outputs (see 'Value' for a full description of each component): -#' \itemize{ -#' \item{\code{spot}} -#' \item{\code{ugarchfit}} -#' } -#' This method generates the external regressors needed to model the intraday -#' seasonality with a Flexible Fourier form. The \code{\link{rugarch}} package -#' is then employed to estimate the specified GARCH(1,1) model. -#' -#' Along with the spot volatility estimates, this method will return the -#' \code{\link{ugarchfit}} object used by the \code{\link{rugarch}} package. -#' -#' @param data Either an \code{\link{xts}} object, containing price data, or a -#' \code{matrix} containing returns. For price data, irregularly spaced -#' observations are allowed. They will be aggregated to the level specified by -#' parameters \code{on} and \code{k}. For return data, the observations are -#' assumed to be equispaced, with the time between them specified by \code{on} -#' and \code{k}. Return data should be in matrix form, where each row -#' corresponds to a day, and each column to an intraday period. The output -#' will be in the same form as the input (\code{xts} or -#' \code{matrix}/\code{numeric}). -#' @param method specifies which method will be used to estimate the spot -#' volatility. Options include \code{"detper"} and \code{"stochper"}. -#' See 'Details'. -#' @param on string indicating the time scale in which \code{k} is expressed. -#' Possible values are: \code{"secs", "seconds", "mins", "minutes", "hours"}. -#' @param k positive integer, indicating the number of periods to aggregate -#' over. E.g. to aggregate an \code{xts} object to the 5 minute frequency, set -#' \code{k = 5} and \code{on = "minutes"}. -#' @param marketopen the market opening time. This should be in the time zone -#' specified by \code{tz}. By default, \code{marketopen = "09:30:00"}. -#' @param marketclose the market closing time. This should be in the time zone -#' specified by \code{tz}. By default, \code{marketclose = "16:00:00"}. -#' @param tz string specifying the time zone to which the times in \code{data} -#' and/or \code{marketopen}/ \code{marketclose} belong. Default = \code{"GMT"}. -#' @param ... method-specific parameters (see 'Details'). -#' -#' @return -#' A \code{spotvol} object, which is a list containing one or more of the -#' following outputs, depending on the method used: -#' -#' \code{spot} -#' -#' An \code{xts} or \code{matrix} object (depending on the input) containing -#' spot volatility estimates \eqn{\sigma_{t,i}}, reported for each interval -#' \eqn{i} between \code{marketopen} and \code{marketclose} for every day -#' \eqn{t} in \code{data}. The length of the intervals is specifiedby \code{k} -#' and \code{on}. Methods that provide this output: All. -#' -#' \code{daily} -#' -#' An \code{xts} or \code{numeric} object (depending on the input) containing -#' estimates of the daily volatility levels for each day \eqn{t} in \code{data}, -#' if the used method decomposed spot volatility into a daily and an intraday -#' component. Methods that provide this output: \code{"detper"}. -#' -#' \code{periodic} -#' -#' An \code{xts} or \code{numeric} object (depending on the input) containing -#' estimates of the intraday periodicity factor for each day interval \eqn{i} -#' between \code{marketopen} and \code{marketclose}, if the spot volatility was -#' decomposed into a daily and an intraday component. If the output is in -#' \code{xts} format, this periodicity factor will be dated to the first day of -#' the input data, but it is identical for each day in the sample. Methods that -#' provide this output: \code{"detper"}. -#' -#' \code{par} -#' -#' A named list containing parameter estimates, for methods that estimate one -#' or more parameters. Methods that provide this output: -#' \code{"stochper", "kernel"}. -#' -#' \code{cp} -#' -#' A vector containing the change points in the volatility, i.e. the observation -#' indices after which the volatility level changed, according to the applied -#' tests. The vector starts with a 0. Methods that provide this output: -#' \code{"piecewise"}. -#' -#' \code{ugarchfit} -#' -#' A \code{\link{ugarchfit}} object, as used by the \code{\link{rugarch}} -#' package, containing all output from fitting the GARCH model to the data. -#' Methods that provide this output: \code{"garch"}. -#' -#' @export -#' @examples -#' data(sample_real5minprices) -#' -#' # default method, deterministic periodicity -#' vol1 <- spotvol(sample_real5minprices) -#' par.def <- par(no.readonly = TRUE) -#' plot(vol1) -#' par(par.def) -#' -#' # compare to stochastic periodicity -#' init = list(sigma = 0.03, sigma_mu = 0.005, sigma_h = 0.007, -#' sigma_k = 0.06, phi = 0.194, rho = 0.986, mu = c(1.87,-0.42), -#' delta_c = c(0.25, -0.05, -0.2, 0.13, 0.02), delta_s = c(-1.2, -#' 0.11, 0.26, -0.03, 0.08)) -#' # next method will take around 110 iterations -#' vol2 <- spotvol(sample_real5minprices, method = "stochper", init = init) -#' plot(as.numeric(vol1$spot[1:780]), type="l") -#' lines(as.numeric(vol2$spot[1:780]), col="red") -#' legend("topright", c("detper", "stochper"), col = c("black", "red"), lty=1) -#' -#' # various kernel estimates -#' h1 = bw.nrd0((1:nrow(sample_returns_5min))*(5*60)) -#' vol3 <- spotvol(sample_returns_5min, method = "kernel", h = h1) -#' vol4 <- spotvol(sample_returns_5min, method = "kernel", est = "quarticity") -#' vol5 <- spotvol(sample_returns_5min, method = "kernel", est = "cv") -#' plot(vol3, length = 2880) -#' lines(as.numeric(t(vol4$spot))[1:2880], col="red") -#' lines(as.numeric(t(vol5$spot))[1:2880], col="blue") -#' legend("topright", c("h = simple estimate", "h = quarticity corrected", -#' "h = crossvalidated"), col = c("black", "red", "blue"), lty=1) -#' par(par.def) -#' -#' # piecewise constant volatility, using an example from Fried (2012) -#' simdata <- matrix(sqrt(5/3)*rt(3000, df = 5), ncol = 500, byrow = TRUE) -#' simdata <- c(1, 1, 1.5, 1.5, 2, 1)*simdata -#' # the volatility of the simulated now changes at 1000, 2000 and 2500 -#' vol6 <- spotvol(simdata, method = "piecewise", m = 200, n = 100, -#' online = FALSE) -#' plot(vol6) -#' -#' # compare regular GARCH(1,1) model to eGARCH, both with external regressors -#' vol7 <- spotvol(sample_returns_5min, method = "garch", model = "sGARCH") -#' vol8 <- spotvol(sample_returns_5min, method = "garch", model = "eGARCH") -#' plot(as.numeric(t(vol7$spot)), type = "l") -#' lines(as.numeric(t(vol8$spot)), col = "red") -#' legend("topleft", c("GARCH", "eGARCH"), col = c("black", "red"), lty=1) -#' -#' @template references spotvol <- function(data, method = "detper", ..., on = "minutes", k = 5, marketopen = "09:30:00", marketclose = "16:00:00", tz = "GMT") @@ -956,7 +577,6 @@ return(out) } -#' @export plot.spotvol <- function(x, ...) { options <- list(...) @@ -1249,23 +869,3 @@ return(ts3) } - -#' Sample prices data -#' -#' 'sample_real5minprices' from highfrequency package -#' -#' @docType data -#' @name sample_real5minprices -#' @usage data(sample_real5minprices) -#' @format xts -NULL - -#' Sample returns data -#' -#' EUR/USD returns from January to September 2004 -#' -#' @docType data -#' @name sample_returns_5min -#' @usage data(sample_returns_5min) -#' @format matrix -NULL \ No newline at end of file Modified: pkg/highfrequency/man/highfrequency-package.Rd =================================================================== --- pkg/highfrequency/man/highfrequency-package.Rd 2014-11-26 10:23:02 UTC (rev 126) +++ pkg/highfrequency/man/highfrequency-package.Rd 2014-11-28 08:52:41 UTC (rev 127) @@ -3,10 +3,13 @@ \alias{highfrequency} \docType{package} \title{ -highfrequency: Toolkit for the analysis of highfrequency financial data in R. +Tools For Highfrequency Data Analysis } \description{ -The highfrequency package contains an extensive toolkit for the use of highfrequency financial data in R. It contains functionality to manage, clean and match highfrequency trades and quotes data. Furthermore, it enables users to: calculate easily various liquidity measures, estimate and forecast volatility, and investigate microstructure noise and intraday periodicity.} +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.} \details{ \tabular{ll}{ Package: \tab highfrequency\cr Modified: pkg/highfrequency/man/sample_returns_5min.Rd =================================================================== --- pkg/highfrequency/man/sample_returns_5min.Rd 2014-11-26 10:23:02 UTC (rev 126) +++ pkg/highfrequency/man/sample_returns_5min.Rd 2014-11-28 08:52:41 UTC (rev 127) @@ -1,4 +1,3 @@ -% Generated by roxygen2 (4.0.1): do not edit by hand \docType{data} \name{sample_returns_5min} \alias{sample_returns_5min} @@ -10,4 +9,4 @@ \description{ EUR/USD returns from January to September 2004 } - +\keyword{datasets} \ No newline at end of file Modified: pkg/highfrequency/man/spotvol.Rd =================================================================== --- pkg/highfrequency/man/spotvol.Rd 2014-11-26 10:23:02 UTC (rev 126) +++ pkg/highfrequency/man/spotvol.Rd 2014-11-28 08:52:41 UTC (rev 127) @@ -1,5 +1,3 @@ - -% Generated by roxygen2 (4.0.1): do not edit by hand \name{spotvol} \alias{spotvol} \title{Spot volatility estimation} From noreply at r-forge.r-project.org Fri Nov 28 09:53:26 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 28 Nov 2014 09:53:26 +0100 (CET) Subject: [Highfrequency-commits] r128 - pkg/highfrequency/man Message-ID: <20141128085326.915F51875BC@r-forge.r-project.org> Author: kboudt Date: 2014-11-28 09:53:26 +0100 (Fri, 28 Nov 2014) New Revision: 128 Added: pkg/highfrequency/man/getPrice.Rd pkg/highfrequency/man/has.Qty.Rd Log: Added: pkg/highfrequency/man/getPrice.Rd =================================================================== --- pkg/highfrequency/man/getPrice.Rd (rev 0) +++ pkg/highfrequency/man/getPrice.Rd 2014-11-28 08:53:26 UTC (rev 128) @@ -0,0 +1,25 @@ +\name{getPrice} +\alias{getPrice} +\title{get price column(s) from a timeseries} +\usage{ +getPrice(x, symbol = NULL, prefer = NULL, ...) +} +\arguments{ +\item{x}{A data object with columns containing data to be extracted} + +\item{symbol}{text string containing the symbol to extract} + +\item{prefer}{preference for any particular type of price, see Details} + +\item{\dots}{any other passthrough parameters} +} +\description{ +Will attempt to locate price column(s) from a time series with rational defaults. +} +\details{ +May be subset by symbol and preference. +\code{prefer} Preference will be for any commonly used financial time series price description, +e.g. 'trade', 'close', 'bid', 'ask' with specific tests and matching for types and column names +currently supported in R, but a default grep match will be performed if one of the supported types doesn't match. +} + Added: pkg/highfrequency/man/has.Qty.Rd =================================================================== --- pkg/highfrequency/man/has.Qty.Rd (rev 0) +++ pkg/highfrequency/man/has.Qty.Rd 2014-11-28 08:53:26 UTC (rev 128) @@ -0,0 +1,25 @@ +\name{has.Qty} +\alias{has.Ask} +\alias{has.AskSize} +\alias{has.Bid} +\alias{has.BidSize} +\alias{has.Price} +\alias{has.Qty} +\alias{has.Trade} +\alias{is.BBO} +\alias{is.TBBO} +\title{check for Trade, Bid, and Ask/Offer (BBO/TBBO), Quantity, and Price data} +\usage{ +has.Qty(x, which = FALSE) +} +\arguments{ +\item{x}{data object} + +\item{which}{disply position of match} +} +\description{ +A set of functions to check for appropriate TBBO/BBO and price column +names within a data object, as well as the availability and +position of those columns. +} +