split_window {cryptoQuotes} | R Documentation |
split xts object iteratively in lists of desired intervals
Description
The split_window()
-function is a high level wrapper
of the stats::window()
-function which restricts the intervals between
the first and second index value iteratively
Usage
split_window(xts, by, bounds = "upper")
Arguments
xts |
A xts-object that needs needs to be split. |
by |
A reference |
bounds |
A character vector of length 1.
Has to be one of |
Value
Returns a list of iteratively restricted xts objects
See Also
Other utility:
calibrate_window()
,
remove_bound()
Examples
# script start;
# 1) check index of BTCUSDT and
# the Fear and Greed Index
setequal(
zoo::index(BTC),
zoo::index(FGIndex)
)
# 2) to align the indices,
# we use the convincience functions
# by splitting the FGI by the BTC index.
FGIndex <- cryptoQuotes::split_window(
xts = cryptoQuotes::FGIndex,
by = zoo::index(BTC),
# Remove upper bounds of the
# index to avoid overlap between
# the dates.
#
# This ensures that the FGI is split
# according to start of each weekly
# BTC candle
bounds = 'upper'
)
# 3) as splitWindow returns a list
# it needs to passed into calibrateWindow
# to ensure comparability
FGIndex <- cryptoQuotes::calibrate_window(
list = FGIndex,
# As each element in the list can include
# more than one row, each element needs to be aggregated
# or summarised.
#
# using xts::first gives the first element
# of each list, along with its values
FUN = xts::first
)
# 3) check if candles aligns
# accordingly
stopifnot(
setequal(
zoo::index(BTC),
zoo::index(FGIndex)
)
)
# script end;
[Package cryptoQuotes version 1.3.1 Index]