ichimoku: Auxiliary Functions

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7, fig.height = 5
)
library(ichimoku)

Introduction

This vignette is dedicated to the auxiliary functions exported by the ichimoku package.

Note that these auxiliary functions are programmed for performance and hence stripped of superfluous validation and error-checking code. If they are used outside of their intended scopes then errors may be expected. In particular, input types must match exactly.

Core Auxiliary Functions

tradingDays()

Used to subset a vector of dates to trading days. Note: if the argument 'holidays' is passed to ichimoku(), this is passed through to this function when calculating the dates for the future cloud.

Takes the following arguments:

dates <- seq(from = as.POSIXct("2020-01-01"), by = "1 day", length.out = 7)
dates
tradingDays(dates)
tradingDays(dates, holidays = c("2020-01-02", "2020-01-03"))
tradingDays(dates, holidays = NULL)

look()

Can be used to inspect the informational attributes of R objects.

Takes an object as an optional argument. Called without an argument, .Last.value will be used instead.

For objects created by the ichimoku package, a list of attributes specific to that data type is returned.

For other objects, a list of attributes that are non-standard for matrix / data.frame / xts objects is returned, or else invisible NULL if none are present.

cloud <- ichimoku(sample_ohlc_data, ticker = "TKR")
look(cloud)

strat <- strat(cloud)
look(strat)

grid <- mlgrid(cloud)
look(grid)

Dataframe Constructors

xts_df()

Convert an 'xts' object to 'data.frame'. This function can be an order of magnitude faster than as.data.frame() for an 'xts' object.

Note that for ichimoku objects, a slightly faster, more specific version has been implemented as the S3 method for as.data.frame(). Hence using this utility on an ichimoku object is not necessary.

Takes the following arguments:

cloud <- ichimoku(sample_ohlc_data)
df <- xts_df(cloud)
str(df)

# Preserving custom attributes:
df2 <- xts_df(cloud, keep.attrs = TRUE)
str(df2)

matrix_df()

Convert a matrix to 'data.frame'. This function can be twice as fast as as.data.frame() for a matrix.

Takes the following arguments:

cloud <- ichimoku(sample_ohlc_data)
mcloud <- as.matrix(cloud)
df <- matrix_df(mcloud)
str(df)
str(row.names(df))

Dataframe Utilities

df_merge()

Full join on an arbitrary number of 'data.frame' objects passed as arguments, preserving all unique entries. Can be used to combine historical time series data where each observation is indexed by a unique timestamp and all periods are complete.

Takes an arbitrary number of arguments:

Can be used to join price dataframes retrieved by oanda(). The function is designed to join complete historical data. If the data to be merged contains data with incomplete periods, all entries are preserved rather than updated. If incomplete periods are detected within the data, a warning is issued, and the resulting dataframe should be manually inspected in case it contains unwanted duplicates. Use df_append() for updating dataframes with new values.

data1 <- sample_ohlc_data[1:6, ]
data1
data2 <- sample_ohlc_data[4:10, ]
data2
df_merge(data1, data2)

df_append()

Update a 'data.frame' object with new data. Can be used to append new updated time series data to an existing dataframe, where each observation is indexed by a unique timestamp/identifier in a key column.

Takes 4 arguments:

Can be used to update price dataframes retrieved by oanda(). The function is designed to update existing data with new values as they become available. As opposed to df_merge(), the data in 'new' will overwrite the data in 'old' rather than create duplicates.

If the attribute specified by 'keep.attr' is present in 'new', for example the 'timestamp' in pricing data returned by oanda(), this is retained. If the attribute is not found in 'new', the argument has no effect. All other custom attributes are dropped.

data1 <- sample_ohlc_data[1:8, ]
data1
data2 <- sample_ohlc_data[7:10, ]
data2
df_append(data1, data2)



Try the ichimoku package in your browser

Any scripts or data that you put into this service are public.

ichimoku documentation built on Nov. 2, 2023, 5:36 p.m.