plot_trading_hours: Plot Time Series During Trading Hours

plot_trading_hoursR Documentation

Plot Time Series During Trading Hours

Description

Plot a time series after removing weekends and specific times of the day.

Usage

plot_trading_hours(x, t = NULL, interval = "5 min",
                   labels = "hours", label.format = NULL,
                   exclude.weekends = TRUE, holidays = NULL,
                   fromHHMMSS = "000000", toHHMMSS = "240000",
                   do.plot.axis = TRUE,
                   ...,
                   from = NULL, to = NULL,
                   do.plot = TRUE,
                   axis1.par = list())

Arguments

x

A numeric vector. Can also be of class zoo.

t

A vector that inherits from class POSIXt. If x inherits from class zoo, then index(x) is used (and any supplied value for t is ignored).

interval

A character string like “num units”, in which num is a number, and units is “sec”, “min”, “hour” or “day”. The space between num and units is mandatory.

labels

A character vector of length one, determining the grid for plot_trading_hours: can be “hour”, “day”, “dayhour” or “month”.

label.format

See strftime.

exclude.weekends

logical: default is TRUE

holidays

a vector of class Date or a character vector in a format that is understood by as.Date.

fromHHMMSS

a character vector of length one in format “HHMMSS”

toHHMMSS

a character vector of length one in format “HHMMSS”

do.plot.axis

logical. Should axis(1) be plotted? Default is TRUE.

...

parameters passed to plot (and typically par)

from

POSIXct: start plot at (if not specified, plot starts at first data point)

to

POSIXct: end plot at (if not specified, plot ends at last data point)

do.plot

logical. Should anything be plotted? Default is TRUE. If FALSE, the function returns a list of points.

axis1.par

a list of named elements

Details

Plot a timeseries during specific times of day.

Value

A list (invisibly if do.plot is TRUE):

list(t, x, axis.pos = pos, axis.labels, timegrid)

t

positions

x

values

axis.pos

positions of x-tickmarks

axis.labels

labels at x-ticks

timegrid

a POSIXct vector

map

a function. See the manual (a link is under References).

Author(s)

Enrico Schumann <es@enricoschumann.net>

References

B.D. Ripley and K. Hornik. Date-Time Classes. R-News, 1(2):8–12, 2001.

E. Schumann (2023) Portfolio Management with R. http://enricoschumann.net/PMwR/; in particular, see
http://enricoschumann.net/R/packages/PMwR/manual/PMwR.html#plot-trading-hours

See Also

DateTimeClasses

Examples

t <- as.POSIXct("2012-08-31 08:00:00") + 0:32400
x <- runif(length(t))

par(tck = 0.001, mgp = c(3,1,0.5), bty = "n")
p <- plot_trading_hours(x, t,
                        interval = "5 min", labels = "hours",
                        xlab = "time", ylab = "random points",
                        col = "blue")


## with ?lines
t <- as.POSIXct("2012-08-31 10:00:00") + 0:9000
x <- seq(0, 1, length.out = 9001)
lines(p$map(t)$t, x[p$map(t)$ix], pch = 19)


enricoschumann/PMwR documentation built on April 13, 2024, 12:18 p.m.