Skip to content

Commit

Permalink
Build 1.2.2 CRAN release
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Oct 5, 2021
1 parent 858283b commit bafc2f1
Show file tree
Hide file tree
Showing 37 changed files with 801 additions and 337 deletions.
16 changes: 8 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: ichimoku
Type: Package
Title: Visualization and Tools for Ichimoku Kinko Hyo Strategies
Version: 1.2.1
Version: 1.2.2
Description: An implementation of 'Ichimoku Kinko Hyo', also commonly known as
'cloud charts'. Static and interactive visualizations with tools for
creating, backtesting and development of quantitative 'ichimoku' strategies.
As described in Sasaki (1996, ISBN:4925152009), the technique is a refinement
on candlestick charting originating from Japan, now in widespread use in
on candlestick charting, originating from Japan and now in widespread use in
technical analysis worldwide. Translating as 'one-glance equilibrium chart',
it allows the price action and market structure of financial securities to
be determined 'at-a-glance'. Incorporates an interface with the OANDA
Expand All @@ -27,23 +27,23 @@ LazyData: true
Depends:
R (>= 3.2)
Imports:
grid,
stats,
curl,
ggplot2,
grid,
gtable,
jsonlite,
stats,
xts,
zoo
LinkingTo:
LinkingTo:
cpp11
Suggests:
covr,
shiny,
openssl,
keyring,
knitr,
openssl,
rmarkdown,
shiny,
covr,
testthat (>= 3.0.0)
SystemRequirements: C++11
VignetteBuilder: knitr
Expand Down
7 changes: 6 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ export(mlgrid)
export(oanda)
export(oanda_chart)
export(oanda_instruments)
export(oanda_positions)
export(oanda_quote)
export(oanda_set_key)
export(oanda_stream)
export(oanda_studio)
export(oanda_switch)
export(oanda_view)
export(strat)
export(stratcombine)
export(tradingDays)
Expand All @@ -45,14 +48,17 @@ importFrom(curl,new_handle)
importFrom(ggplot2,"%+replace%")
importFrom(ggplot2,aes)
importFrom(ggplot2,autoplot)
importFrom(ggplot2,coord_flip)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_line)
importFrom(ggplot2,element_rect)
importFrom(ggplot2,element_text)
importFrom(ggplot2,geom_col)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_rect)
importFrom(ggplot2,geom_ribbon)
importFrom(ggplot2,geom_segment)
importFrom(ggplot2,geom_vline)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggplotGrob)
importFrom(ggplot2,guides)
Expand All @@ -62,7 +68,6 @@ importFrom(ggplot2,rel)
importFrom(ggplot2,scale_color_manual)
importFrom(ggplot2,scale_fill_manual)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,scale_x_datetime)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_grey)
Expand Down
19 changes: 19 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# ichimoku 1.2.2

#### New features:

* New `oanda_quote()` function outputs the latest quote for an instrument along with intraday trading statistics to the console.
* New `oanda_view()` function provides the latest overview of an entire market - showing the relative performance of constituents.
* New `oanda_positions()` function provides the OANDA fxTrade position book (% longs and shorts at each price level) for certain major currency pairs.
* `archive()` easier to use by allowing files to be chosen interactively using a system dialog - simply call with no arguments.
* `df_append()` utility is now faster and gains the arguments 'key' and 'keep.attr'.

#### Updates:

* Accessibility improvements: default 'original' theme adjusted to accommodate colour vision deficiency.
* All OANDA functions now prompt for missing required arguments instead of returning errors.
* For ease of use, the 'instrument' argument in all OANDA functions is now case-insensitive and the delimiter may be supplied as either '_' or '-', so both `oanda("usd-jpy")` and `oanda("USD_JPY")` are acceptable.
* `tradingDays()` argument 'noholidays' removed in favour of 'holidays = NULL'. Logic changed slightly so that default holidays are applied only if 'holidays' is not specified.
* Minor performance improvements to OANDA and ML layer functions.
* Documentation refresh

# ichimoku 1.2.1

#### Updates:
Expand Down
17 changes: 13 additions & 4 deletions R/archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#'
#' For write operations: invisible NULL. 'object' is written to 'file'.
#'
#' @details For read operations: specify only 'file'. 'file' is read and the
#' return value may be assigned to an object. A confirmation message is
#' issued if the file read operation has been successful.
#' @details For read operations: specify only 'file', or alternatively if no
#' arguments are specified, a system dialog will be opened allowing a file
#' to be chosen interactively. 'file' is read and the return value may be
#' assigned to an object. A confirmation message is issued if the file read
#' operation has been successful.
#'
#' For write operations: specify both 'object' and 'file'. 'object' will be
#' written to 'file'. A confirmation message is issued if the file write
Expand Down Expand Up @@ -45,6 +47,11 @@
#'
#' unlink(file)
#'
#' if (interactive()) {
#' # Only run example in interactive R sessions
#' object <- archive()
#' }
#'
#' @export
#'
archive <- function(..., object, file) {
Expand All @@ -63,10 +70,12 @@ archive <- function(..., object, file) {
file <- dots[[2L]]
writeArchive(object = object, file = file)

} else if (dlen == 0L) {
readArchive(file = file.choose())

} else {
stop(dlen, " arguments passed to archive() which requires 1 or 2",
"\nFor read operations specify 'file' only, write operations both 'object' and 'file'", call. = FALSE)

}

} else if (!missing(file)) {
Expand Down
66 changes: 33 additions & 33 deletions R/ichimoku-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,26 @@
#' An implementation of 'Ichimoku Kinko Hyo', also commonly known as 'cloud
#' charts'. Static and interactive visualizations with tools for creating,
#' backtesting and development of quantitative 'ichimoku' strategies. As
#' described in Sasaki (1996, ISBN:4925152009), the technique is a
#' refinement on candlestick charting originating from Japan, now in
#' widespread use in technical analysis worldwide. Translating as
#' 'one-glance equilibrium chart', it allows the price action and market
#' structure of financial securities to be determined 'at-a-glance'.
#' Incorporates an interface with the OANDA fxTrade API
#' \url{https://developer.oanda.com/} for retrieving historical and live
#' streaming price data for major currencies, metals, commodities,
#' government bonds and stock indices.
#' described in Sasaki (1996, ISBN:4925152009), the technique is a refinement
#' on candlestick charting, originating from Japan and now in widespread use
#' in technical analysis worldwide. Translating as 'one-glance equilibrium
#' chart', it allows the price action and market structure of financial
#' securities to be determined 'at-a-glance'. Incorporates an interface with
#' the OANDA fxTrade API \url{https://developer.oanda.com/} for retrieving
#' historical and live streaming price data for major currencies, metals,
#' commodities, government bonds and stock indices.
#'
#' @section Principal ichimoku functions:
#' Data
#' Data & Visualization
#' \itemize{
#' \item{\code{\link{ichimoku}}} {to create an ichimoku object from price
#' data.}
#' \item{\code{\link{plot.ichimoku}} / \code{\link{iplot}}} {to plot
#' (interactive) cloud charts from ichimoku objects.}
#' \item{\code{\link{archive}}} {for reading/writing objects to/from archive
#' files with data verification.}
#' \item{\code{\link{oanda}}} {to retrieve price data from the OANDA fxTrade
#' API.}
#' \item{\code{\link{oanda_stream}}} {to stream a live data feed from the
#' OANDA fxTrade API.}
#' }
#' Visualization
#' \itemize{
#' \item{\code{\link{plot.ichimoku}}} {to plot a cloud chart from an
#' ichimoku object.}
#' \item{\code{\link{iplot}}} {to plot an interactive cloud chart from an
#' ichimoku object.}
#' \item{\code{\link{oanda_chart}}} {to plot real-time ichimoku cloud
#' charts using OANDA data.}
#' \item{\code{\link{oanda_studio}}} {a complete live analysis environment
#' using OANDA data implemented in R Shiny.}
#' }
#' Strategies & ML
#' \itemize{
Expand All @@ -46,6 +34,18 @@
#' \item{\code{\link{mlgrid}}} {to generate a numeric representation of the
#' relationship between ichimoku cloud chart elements.}
#' }
#' Real-time
#' \itemize{
#' \item{\code{\link{oanda_chart}}} {to plot real-time ichimoku cloud
#' charts using OANDA data.}
#' \item{\code{\link{oanda_studio}}} {a complete live analysis environment
#' using OANDA data implemented in R Shiny.}
#' \item{\code{\link{oanda_stream}} / \code{\link{oanda_quote}}} {to obtain
#' the latest live data stream / quote from the OANDA fxTrade API.}
#' \item{\code{\link{oanda_view}}} {for a market overview showing the
#' relative performance of constituents.}
#' }
#'
#' @encoding UTF-8
#' @author Charlie Gao \email{charlie.gao@@shikokuchuo.net}
#' (\href{https://orcid.org/0000-0002-0750-061X}{ORCID})
Expand All @@ -56,23 +56,23 @@
#' unaffiliated with the ichimoku package.
#'
#' Gao, C. (2021), \emph{ichimoku: Visualization and Tools for Ichimoku
#' Kinko Hyo Strategies}. R package version 1.2.1,
#' Kinko Hyo Strategies}. R package version 1.2.2,
#' \url{https://CRAN.R-project.org/package=ichimoku}.
#'
#' @useDynLib ichimoku, .registration = TRUE
#' @importFrom curl curl_fetch_memory curl_fetch_stream new_handle
#' handle_setheaders
#' @importFrom ggplot2 autoplot ggplot aes geom_ribbon geom_line geom_segment
#' geom_rect scale_color_manual scale_fill_manual guides scale_x_datetime
#' scale_x_continuous scale_y_continuous labs theme_grey theme rel margin
#' element_rect element_line element_text element_blank ggplotGrob
#' %+replace%
#' @importFrom curl curl_fetch_memory curl_fetch_stream handle_setheaders
#' new_handle
#' @importFrom ggplot2 aes autoplot coord_flip element_blank element_line
#' element_rect element_text geom_col geom_line geom_rect geom_ribbon
#' geom_segment geom_vline ggplot ggplotGrob guides labs margin rel
#' scale_color_manual scale_fill_manual scale_x_continuous
#' scale_y_continuous theme theme_grey %+replace%
#' @importFrom grid grid.draw grid.newpage unit
#' @importFrom gtable gtable gtable_add_grob
#' @importFrom jsonlite parse_json
#' @importFrom stats na.omit setNames
#' @importFrom xts xts endpoints
#' @importFrom zoo index coredata
#' @importFrom xts endpoints xts
#' @importFrom zoo coredata index
#'
#' @docType package
#' @name ichimoku-package
Expand Down
10 changes: 5 additions & 5 deletions R/ichimoku.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' values for the cloud top and cloud base.
#'
#' @param x a data.frame or other compatible object, which includes xts,
#' data.table, tibble, and matrix.
#' data.table, tibble, tsibble, and matrix.
#' @param ticker (optional) specify a ticker to identify the instrument,
#' otherwise this is set to the name of the input object.
#' @param periods [default c(9L, 26L, 52L)] a vector defining the length of
Expand Down Expand Up @@ -161,11 +161,11 @@ ichimoku.data.frame <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data,
coli <- grep("index|date|time", cnames, ignore.case = TRUE, perl = TRUE)[1L]
if (!is.na(coli)) {
index <- tryCatch(as.POSIXct(.subset2(x, coli)), error = function(e) {
stop("Column '", cnames[coli], "' is not convertible to a POSIXct date-time format", call. = FALSE)
stop("column '", cnames[coli], "' is not convertible to a POSIXct date-time format", call. = FALSE)
})
} else {
index <- tryCatch(as.POSIXct(attr(x, "row.names")), error = function(e) {
stop("Valid date-time index not found. Perhaps check column names?", call. = FALSE)
stop("valid date-time index not found. Perhaps check column names?", call. = FALSE)
})
}

Expand All @@ -174,7 +174,7 @@ ichimoku.data.frame <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data,
colc <- grep("close", cnames, ignore.case = TRUE, perl = TRUE)[1L]
if (anyNA(c(colh, coll, colc))) {
colp <- grep("price|value|close", cnames, ignore.case = TRUE, perl = TRUE)[1L]
if (is.na(colp)) stop("Price data not found. Perhaps check column names?", call. = FALSE)
if (is.na(colp)) stop("price data not found. Perhaps check column names?", call. = FALSE)
close <- as.numeric(.subset2(x, colp))
open <- c(NA, close[1:(xlen - 1L)])
high <- pmax.int(open, close)
Expand Down Expand Up @@ -205,7 +205,7 @@ ichimoku.data.frame <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data,
p1 <- periods[1L]
p2 <- periods[2L]
p3 <- periods[3L]
if (p2 >= xlen) stop("Dataset must be longer than the medium cloud period '", p2, "'", call. = FALSE)
if (p2 >= xlen) stop("dataset must be longer than the medium cloud period '", p2, "'", call. = FALSE)

cd <- numeric(xlen)
cd[open < close] <- 1
Expand Down
10 changes: 3 additions & 7 deletions R/look.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,12 @@ look <- function(x, which) {
lk <- attributes(x)
lk$autostrat <- NULL
lk
} else if (!is.numeric(which)) {
} else if (is.numeric(which) && which %in% seq_len(length(x))) {
x[[which]]
} else {
stop("'", which, "' is not a valid value for 'which'\n",
"'which' should be an integer value specifying one of the strategies 1 to ",
length(x), call. = FALSE)
} else {
tryCatch(x[[which]], error = function(e) {
stop(which, " is not a valid value for 'which'\n",
"'which' should be an integer value specifying one of the strategies 1 to ",
length(x), call. = FALSE)
})
}
}

Expand Down
Loading

0 comments on commit bafc2f1

Please sign in to comment.