Skip to content

Commit

Permalink
Build 1.2.4 CRAN release
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Oct 18, 2021
1 parent 642cebf commit 71a377c
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 172 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ichimoku
Type: Package
Title: Visualization and Tools for Ichimoku Kinko Hyo Strategies
Version: 1.2.3
Version: 1.2.4
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.
Expand Down Expand Up @@ -36,12 +36,12 @@ Imports:
LinkingTo:
cpp11
Suggests:
shiny,
openssl,
keyring,
openssl,
shiny,
covr,
knitr,
rmarkdown,
covr,
testthat (>= 3.0.0)
SystemRequirements: C++11
VignetteBuilder: knitr
Expand Down
12 changes: 6 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# ichimoku 1.2.3
# ichimoku 1.2.4

#### New features:

* New `relative()` function produces a statistical summary of the latest ichimoku cloud chart numeric representation relative to historical values, for determining whether trading falls within or outside of normal ranges.
* `oanda_studio()` gains the argument 'new.process', which when set to TRUE, starts the shiny session in a new R process, unblocking the current process and allowing continued use of the console.
* `mlgrid()` gains the argument `y = 'none'` for a grid with the latest cloud representation and without 'y'.
* `autostrat()`, `relative()` and `oanda()` gain the argument 'quietly' which suppresses additional console output if set to TRUE.
* `mlgrid()` gains the argument `y = 'none'` for a grid with the latest values and without 'y'.
* Improved time index handling for `ichimoku()`: where conversion by `as.POSIXct()` fails, will convert numeric values as POSIX times (with an appropriate warning).
* Optimised 'ichimoku' methods for `coredata()` and `index()` - these are no longer simple re-exports from the 'zoo' package.
* `as.data.frame.ichimoku()` S3 method is implemented as a marginally faster version of `xts_df()` for ichimoku objects.
* Implement custom `str()` and `summary()` methods for ichimoku objects.
* Optimised 'ichimoku' methods for `coredata()` and `index()` generic functions.
* 'ichimoku' method for `as.data.frame()` implemented as a marginally faster version of `xts_df()` for ichimoku objects.
* More informative custom `str()` and `summary()` methods implemented for ichimoku objects.

#### Updates:

Expand All @@ -30,7 +30,7 @@
* 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.
* `archive()` now allows files to be chosen interactively using a system dialog - call the function with no arguments.
* `df_append()` utility is now faster and gains the arguments 'key' and 'keep.attr'.

#### Updates:
Expand Down
2 changes: 1 addition & 1 deletion R/ichimoku-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#' unaffiliated with the ichimoku package.
#'
#' Gao, C. (2021), \emph{ichimoku: Visualization and Tools for Ichimoku
#' Kinko Hyo Strategies}. R package version 1.2.3,
#' Kinko Hyo Strategies}. R package version 1.2.4,
#' \url{https://CRAN.R-project.org/package=ichimoku}.
#'
#' @useDynLib ichimoku, .registration = TRUE
Expand Down
184 changes: 96 additions & 88 deletions R/ichimoku.R
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ ichimoku.data.frame <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data,
}))
used <- used[!is.na(used)]
keep <- if (!is.null(used)) cnames[-used]
kmatrix <- do.call(cbind, setNames(lapply(keep, function(k) {
c(as.numeric(.subset2(x, k)), rep(NA, p2 - 1L))
}), keep))
kmatrix <- do.call(cbind, lapply(.subset(x, keep), function(x) c(as.numeric(x), rep(NA, p2 - 1L))))
lk <- look(x)
lk$periods <- lk$periodicity <- lk$ticker <- NULL
}
Expand Down Expand Up @@ -284,8 +282,7 @@ ichimoku.default <- function(x, ticker, periods = c(9L, 26L, 52L), keep.data, ..

is.character(x) || stop("cannot create an ichimoku object from a '", class(x)[1L], "' object", call. = FALSE)
exists(x) || stop("object '", x, "' not found", call. = FALSE)
object <- get(x)
identical(x, object) && stop("cannot create an ichimoku object from a 'character' object", call. = FALSE)
identical(x, object <- get(x)) && stop("cannot create an ichimoku object from a 'character' object", call. = FALSE)

if (missing(ticker)) {
ichimoku(object, ticker = x, periods = periods, keep.data = keep.data, ...)
Expand Down Expand Up @@ -335,6 +332,66 @@ print.ichimoku <- function(x, plot = TRUE, ...) {

}

#' Display the Structure of Ichimoku Objects
#'
#' Compactly display the internal structure of ichimoku objects.
#'
#' @param object an object of class 'ichimoku'.
#' @param ... arguments passed to or from other methods.
#'
#' @return Invisible NULL. A compact display of the structure of the object is
#' output to the console.
#'
#' @details This function is an S3 method for the generic function str()
#' for class 'ichimoku'. It can be invoked by calling str(x) on an
#' object 'x' of class 'ichimoku'.
#'
#' For further details please refer to the reference vignette by calling:
#' \code{vignette("reference", package = "ichimoku")}
#'
#' @examples
#' cloud <- ichimoku(sample_ohlc_data, ticker = "TKR")
#' str(cloud)
#'
#' strat <- strat(cloud)
#' str(strat)
#'
#' @rdname str.ichimoku
#' @method str ichimoku
#' @export
#'
str.ichimoku <- function (object, ...) {

index <- index.ichimoku(object)
if (is.null(dims <- attr(object, "dim"))) {
cat("ichimoku object with no dimensions")
dates <- format.POSIXct(c(index[1L], index[xlen <- length(index)]))
cat("\nVector <numeric> w/ length:", xlen)
cat("\n index: <POSIXct>", dates[1L], "...", dates[2L])
} else {
dates <- format.POSIXct(c(index[1L], index[dim1 <- dims[1L]]))
cat("ichimoku object [", dates[1L], " / ", dates[2L], "]", if (hasStrat(object)) " w/ strat", sep = "")
cat("\nMatrix <numeric> w/ dim: (", dim1, " rows, ", dims[2L], " cols)\n dimnames[[2L]]: $", sep = "")
cat(attr(object, "dimnames")[[2L]], sep = " $")
cat("\n index: <POSIXct>", dates[1L], "...", dates[2L])
}
cat("\nAttributes:\n periods:", attr(object, "periods"),
"\n periodicity:",
if ((periodicity <- attr(object, "periodicity")) >= 86400) {
paste0(round(periodicity / 86400, digits = 1), " days")
} else if (periodicity >= 3600) {
paste0(round(periodicity / 3600, digits = 1), " hours")
} else if (periodicity >= 60) {
paste0(round(periodicity / 60, digits = 1), " mins")
} else {
paste0(periodicity, " secs")
},
"\n ticker:", attr(object, "ticker"), "\n")
if (hasStrat(object)) cat(" strat: [strategy: ", attr(object, "strat")["Strategy", ][[1L]],
" w/ direction: ", attr(object, "strat")["Direction", ][[1L]], "... ]\n", sep = "")

}

#' Summary of Ichimoku Objects and Strategies
#'
#' Display summary information for an ichimoku object or its strategy.
Expand All @@ -352,9 +409,8 @@ print.ichimoku <- function(x, plot = TRUE, ...) {
#' class 'ichimoku'. It can be invoked by calling summary(x) on an object 'x'
#' of class 'ichimoku'.
#'
#' Where a subset or partial ichimoku object is passed to summary() such
#' that the object summary may not render correctly, the function will fall
#' back to the str() method to display a compact structure of the object.
#' Performs basic validation for an ichimoku object and will inform if an
#' ichimoku object contains invalid information.
#'
#' For further details please refer to the reference vignette by calling:
#' \code{vignette("reference", package = "ichimoku")} and the strategies
Expand All @@ -373,28 +429,39 @@ print.ichimoku <- function(x, plot = TRUE, ...) {
summary.ichimoku <- function(object, strat = TRUE, ...) {

if (hasStrat(object) && isTRUE(strat)) {
attr(object, "strat")
summary <- NULL
tryCatch(attr(object, "strat")["Strategy", ],
error = function(e) cat(summary <<- "ichimoku object with invalid strategy"))
if (is.null(summary)) attr(object, "strat") else invisible(summary)

} else {
dims <- attr(object, "dim")
(is.null(dims) || (dim1 <- dims[1L]) == 0 || (dim2 <- dims[2L]) < 12) &&
return(str(object))
cat(summary <- paste0("ichimoku object with dimensions (", dim1, ", ", dim2, ")"))

idx <- index.ichimoku(object)
core <- coredata.ichimoku(object)
end <- sum(!is.na(core[, "close"]))
high <- which.max(core[1:end, "high"])
low <- which.min(core[1:end, "low"])
dates <- format.POSIXct(c(idx[1L], idx[high], idx[low], idx[end]))
cat("\n\n Max: ", dates[2L], " [", core[high, "high"],
"]\nStart: ", dates[1L], " [", core[1L, "open"],
"] End: ", dates[4L], " [", core[end, "close"],
"]\n Min: ", dates[3L], " [", core[low, "low"], "]", sep = "")

cat("\n\nCloud periods:", attr(object, "periods"),
"\nPeriodicity:",
if ((periodicity <- attr(object, "periodicity")) >= 86400) {
(!is.integer(periods <- attr(object, "periods")) || length(periods) != 3L ||
!is.numeric(periodicity <- attr(object, "periodicity")) || length(periodicity) != 1L) && {
cat(summary <- "ichimoku object with invalid attributes")
return(invisible(summary))
}
if (is.null(dims <- attr(object, "dim"))) {
cat(summary <- "ichimoku object with no dimensions", "\n")
} else if ((dim2 <- dims[2L]) < 12L) {
cat(summary <- "incomplete ichimoku object (partial or subset)", "\n")
} else {
cat(summary <- paste0("ichimoku object with dimensions (", dim1 <- dims[1L], ", ", dim2, ")"), "\n")
if (dim1 != 0L) {
idx <- index.ichimoku(object)
core <- coredata.ichimoku(object)
end <- sum(!is.na(core[, "close"]))
high <- which.max(core[1:end, "high"])
low <- which.min(core[1:end, "low"])
dates <- format.POSIXct(c(idx[1L], idx[high], idx[low], idx[end]))
cat("\n Max: ", dates[2L], " [", core[high, "high"],
"]\nStart: ", dates[1L], " [", core[1L, "open"],
"] End: ", dates[4L], " [", core[end, "close"],
"]\n Min: ", dates[3L], " [", core[low, "low"], "]\n", sep = "")
}
}

cat("\nCloud periods:", periods, "\nPeriodicity:",
if (periodicity >= 86400) {
paste0(round(periodicity / 86400, digits = 1), " days")
} else if (periodicity >= 3600) {
paste0(round(periodicity / 3600, digits = 1), " hours")
Expand All @@ -406,6 +473,7 @@ summary.ichimoku <- function(object, strat = TRUE, ...) {
"\nTicker:", attr(object, "ticker"))

invisible(summary)

}

}
Expand Down Expand Up @@ -541,66 +609,6 @@ index.ichimoku <- function(x, ...) {
idx
}

#' Display the Structure of Ichimoku Objects
#'
#' Compactly display the internal structure of ichimoku objects.
#'
#' @param object an object of class 'ichimoku'.
#' @param ... arguments passed to or from other methods.
#'
#' @return Invisible NULL. A compact display of the structure of the object is
#' output to the console.
#'
#' @details This function is an S3 method for the generic function str()
#' for class 'ichimoku'. It can be invoked by calling str(x) on an
#' object 'x' of class 'ichimoku'.
#'
#' For further details please refer to the reference vignette by calling:
#' \code{vignette("reference", package = "ichimoku")}
#'
#' @examples
#' cloud <- ichimoku(sample_ohlc_data, ticker = "TKR")
#' str(cloud)
#'
#' strat <- strat(cloud)
#' str(strat)
#'
#' @rdname str.ichimoku
#' @method str ichimoku
#' @export
#'
str.ichimoku <- function (object, ...) {

dims <- attr(object, "dim")
if (is.null(dims)) {
cat("ichimoku object with no dimensions\n")

} else {
index <- index.ichimoku(object)
dates <- format.POSIXct(c(index[1L], index[dim1 <- dims[1L]]))
cat("ichimoku object [", dates[1L], " / ", dates[2L], "]", if (hasStrat(object)) " w/ strat", sep = "")
cat("\nMatrix <numeric> w/ dim: (", dim1, " rows, ", dims[2L], " cols)\n dimnames[[2L]]: $", sep = "")
cat(attr(object, "dimnames")[[2L]], sep = " $")
cat("\n index: <POSIXct>", dates[1L], "...", dates[2L],
"\nAttributes:\n periods:", attr(object, "periods"),
"\n periodicity:",
if ((periodicity <- attr(object, "periodicity")) >= 86400) {
paste0(round(periodicity / 86400, digits = 1), " days")
} else if (periodicity >= 3600) {
paste0(round(periodicity / 3600, digits = 1), " hours")
} else if (periodicity >= 60) {
paste0(round(periodicity / 60, digits = 1), " mins")
} else {
paste0(periodicity, " secs")
},
"\n ticker:", attr(object, "ticker"))
if (hasStrat(object)) cat("\n strat: [strategy: ", attr(object, "strat")["Strategy", ][[1L]],
" w/ direction: ", attr(object, "strat")["Direction", ][[1L]], "... ]", sep = "")

}

}

#' is.ichimoku
#'
#' A function for checking if an object is an ichimoku object.
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
7 changes: 4 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ knitr::opts_chunk$set(
)
```

# ichimoku <img src='man/figures/logo.png' align="right" />
# ichimoku <img src="man/figures/logo.png" alt="ichimoku logo" style="float:right" />

<!-- badges: start -->
[![CRAN Status](https://www.r-pkg.org/badges/version/ichimoku?color=0b800e)](https://CRAN.R-project.org/package=ichimoku)
[![r-universe](https://shikokuchuo.r-universe.dev/badges/ichimoku?color=6bd54f)](https://shikokuchuo.r-universe.dev/)
[![R-CMD-check](https://github.com/shikokuchuo/ichimoku/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/shikokuchuo/ichimoku/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/shikokuchuo/ichimoku/branch/main/graph/badge.svg)](https://codecov.io/gh/shikokuchuo/ichimoku?branch=main)
[![Codecov test coverage](https://codecov.io/gh/shikokuchuo/ichimoku/branch/main/graph/badge.svg)](https://app.codecov.io/gh/shikokuchuo/ichimoku)
<!-- badges: end -->

Visualization and Tools for Ichimoku Kinko Hyo Strategies
Expand Down Expand Up @@ -61,6 +61,7 @@ Simply `ichimoku()` and `plot()`:
cloud <- ichimoku(TKR)
plot(cloud, window = "2020-05/")
```
<!-- alt="ichimoku kinko hyo" -->

`autostrat()` to automatically evaluate and rank top-performing strategies:

Expand Down Expand Up @@ -118,7 +119,7 @@ Sasaki, H. 佐々木 英信 (1996), *一目均衡表の研究 [ichimoku kinkouhy

'OANDA' and 'fxTrade' are trademarks owned by OANDA Corporation, an entity unaffiliated with the ichimoku package.

Gao, C. (2021), *ichimoku: Visualization and Tools for Ichimoku Kinko Hyo Strategies*. R package version 1.2.3, <https://CRAN.R-project.org/package=ichimoku>.
Gao, C. (2021), *ichimoku: Visualization and Tools for Ichimoku Kinko Hyo Strategies*. R package version 1.2.4, <https://CRAN.R-project.org/package=ichimoku>.

--

Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# ichimoku <img src='man/figures/logo.png' align="right" />
# ichimoku <img src="man/figures/logo.png" alt="ichimoku logo" style="float:right" />

<!-- badges: start -->

Expand All @@ -10,7 +10,7 @@ Status](https://www.r-pkg.org/badges/version/ichimoku?color=0b800e)](https://CRA
[![r-universe](https://shikokuchuo.r-universe.dev/badges/ichimoku?color=6bd54f)](https://shikokuchuo.r-universe.dev/)
[![R-CMD-check](https://github.com/shikokuchuo/ichimoku/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/shikokuchuo/ichimoku/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/shikokuchuo/ichimoku/branch/main/graph/badge.svg)](https://codecov.io/gh/shikokuchuo/ichimoku?branch=main)
coverage](https://codecov.io/gh/shikokuchuo/ichimoku/branch/main/graph/badge.svg)](https://app.codecov.io/gh/shikokuchuo/ichimoku)
<!-- badges: end -->

Visualization and Tools for Ichimoku Kinko Hyo Strategies
Expand Down Expand Up @@ -64,7 +64,8 @@ cloud <- ichimoku(TKR)
plot(cloud, window = "2020-05/")
```

<img src="man/figures/README-ichimoku-1.png" />
<img src="man/figures/README-ichimoku-1.png" alt="ichimoku kinko hyo" />
<!-- alt="ichimoku kinko hyo" -->

`autostrat()` to automatically evaluate and rank top-performing
strategies:
Expand Down Expand Up @@ -172,7 +173,7 @@ no kenkyuu]*. Tokyo, Japan: Toushi Radar.
entity unaffiliated with the ichimoku package.

Gao, C. (2021), *ichimoku: Visualization and Tools for Ichimoku Kinko
Hyo Strategies*. R package version 1.2.3,
Hyo Strategies*. R package version 1.2.4,
<https://CRAN.R-project.org/package=ichimoku>.

Expand Down
2 changes: 1 addition & 1 deletion data-raw/internal_sysdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ x_oanda_instruments <- data.frame(
"METAL","CURRENCY")
)

x_user_agent <- "r-ichimoku/1.2.3"
x_user_agent <- "r-ichimoku/1.2.4"

usethis::use_data(ichimoku_themes, x_oanda_instruments, x_user_agent, internal = TRUE, overwrite = TRUE)
2 changes: 1 addition & 1 deletion man/ichimoku-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/summary.ichimoku.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 71a377c

Please sign in to comment.