calc_season: Calculate the intraday seasonality aggregations over a...

View source: R/HighFreq.R

calc_seasonR Documentation

Calculate the intraday seasonality aggregations over a single-column xts time series.

Description

Calculate the intraday seasonality aggregations over a single-column xts time series.

Usage

calc_season(xtsv, endp = format(zoo::index(xtsv), "%H:%M"))

Arguments

xtsv

A single-column xts time series.

endp

A vector of character strings representing points in time, of the same length as the argument xtsv.

Details

The function calc_season() calculates the mean of values observed at the same points in time specified by the argument endp. An example of a daily seasonality aggregation is the average price of a stock between 9:30AM and 10:00AM every day, over many days. The argument endp is passed into function tapply(), and must be the same length as the argument xtsv.

Value

An xts time series with mean aggregations over the seasonality interval.

Examples

# Calculate running variance of each minutely OHLC bar of data
xtsv <- ohlc_variance(HighFreq::SPY)
# Remove overnight variance spikes at "09:31"
endp <- format(index(xtsv), "%H:%M")
xtsv <- xtsv[!endp=="09:31", ]
# Calculate daily seasonality of variance
var_seasonal <- calc_season(xtsv=xtsv)
chart_Series(x=var_seasonal, name=paste(colnames(var_seasonal),
  "daily seasonality of variance"))
  

algoquant/HighFreq documentation built on June 10, 2025, 3:54 p.m.