Skip to content

Commit

Permalink
Updated Documentation
Browse files Browse the repository at this point in the history
All built-in data now only has the datasets keyword argument, which comes by default.

The chart_ma()-function has been rewritten to mitigate possible bugs. See for example joshuaulrich/TTR#131. The error is fixed, but its not published to CRAN yet. The new approach is robust against such bug-fixes for univariate series.

All moving average (MA) functions have been redocumented for usage and title sections.
  • Loading branch information
serkor1 committed Apr 25, 2024
1 parent 2cf5092 commit f6d30c4
Show file tree
Hide file tree
Showing 21 changed files with 336 additions and 125 deletions.
29 changes: 21 additions & 8 deletions R/ATOM.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
#' USDT denominated ATOMS with 15m intervals
#' USDT Denominated ATOM (ATOMUSDT) 15-Minute Intervals
#'
#' A xts object with 15m OHLCV of USDT denominated ATOM with 97 rows and 5 columns, from 2023-12-30 to 2023-12-31.
#' @description
#' This dataset contains time-series data for the ATOM cryptocurrency denominated in USDT (Tether),
#' captured in 15-minute intervals (OHLC-V format). The data spans from December 30 to December 31, 2023.
#'
#' @format An [xts::xts()] object with 97 rows and 5 columns structured as follows:
#' \describe{
#' \item{Open}{Opening price}
#' \item{High}{Highest price}
#' \item{Low}{Lowest price}
#' \item{Close}{Closing price}
#' \item{Volume}{Volume}
#' \item{open}{[numeric] Opening price.}
#' \item{high}{[numeric] Highest price.}
#' \item{low}{[numeric] Lowest price.}
#' \item{close}{[numeric] Closing price.}
#' \item{volume}{[numeric] Trading volume.}
#' }
#'
#' @family data
#' @examples
#' # Load the dataset
#' data("ATOM")
#'
#' # candlestick charts
#' chart(
#' ticker = ATOM,
#' main = kline(),
#' sub = list(volume())
#' )
"ATOM"




28 changes: 20 additions & 8 deletions R/BTC.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
#' USDT denominated Bitcoin(BTC) with 1 week intervals
#' USDT Denominated Bitcoin (BTCUSDT) Weekly Intervals
#'
#' A xts object with weekly OHLCV of USDT denominated Bitcoin with 52 rows and 5 columns, from 2023-01-01 to 2023-12-31.
#' @description
#' This dataset contains time-series data for Bitcoin (BTC) denominated in USDT (Tether),
#' captured in weekly intervals (OHLC-V format). The dataset consists of 52 rows and 5 columns,
#' covering the period from January 1, 2023, to December 31, 2023.
#'
#' @format An [xts::xts()] object structured as follows:
#' \describe{
#' \item{Open}{Opening price}
#' \item{High}{Highest price}
#' \item{Low}{Lowest price}
#' \item{Close}{Closing price}
#' \item{Volume}{Volume}
#' \item{open}{[numeric] Opening price of Bitcoin in USDT at the start of each week.}
#' \item{high}{[numeric] Highest price of Bitcoin in USDT during the week.}
#' \item{low}{[numeric] Lowest price of Bitcoin in USDT during the week.}
#' \item{close}{[numeric] Closing price of Bitcoin in USDT at the end of each week.}
#' \item{volume}{[numeric] Trading volume of Bitcoin for the week, measured in units of Bitcoin.}
#' }
#'
#' @examples
#' # Load the dataset
#' data("BTC")
#'
#' @family data
#' # candlestick charts
#' chart(
#' ticker = BTC,
#' main = kline(),
#' sub = list(volume())
#' )
"BTC"
28 changes: 20 additions & 8 deletions R/DOGE.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
#' USDT denominated DOGECOIN in 1m intervals
#' USDT Denominated DOGECOIN (DOGECOINUSDT) 1-Minute Intervals
#'
#' A xts object with 1m OHLCV of USDT denominated Dogecoin with 61 rows and 5 columns.
#' @description
#' This dataset contains time-series data for the DOGECOIN cryptocurrency denominated in USDT (Tether),
#' captured in 1-minute intervals (OHLC-V format). The dataset consists of 61 rows and 5 columns and spans 2022-01-14 07:00:00 CET to 2022-01-14 08:00:00 CET.
#'
#' @format An [xts::xts()] object structured as follows:
#' \describe{
#' \item{Open}{Opening price}
#' \item{High}{Highest price}
#' \item{Low}{Lowest price}
#' \item{Close}{Closing price}
#' \item{Volume}{Volume}
#' \item{open}{[numeric] Opening price}
#' \item{high}{[numeric] Highest price.}
#' \item{low}{[numeric] Lowest price.}
#' \item{close}{[numeric] Closing price.}
#' \item{volume}{[numeric] Trading volume.}
#' }
#'
#' @family data
#' @examples
#' # Load the dataset
#' data("DOGE")
#'
#' # Plot candlestick charts to visualize price movements
#' chart(
#' ticker = DOGE,
#' main = kline(),
#' sub = list(volume())
#' )
"DOGE"
27 changes: 23 additions & 4 deletions R/FGIndex.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
#' Fear and Greed Index Values
#' Fear and Greed Index Values (FGIndex) Daily Intervals
#'
#' A xts object with Fear and Greed Index value. It has 689 rows, and 1 colum. Extracted from 2023-01-01 to 2023-12-31
#' @description
#' This dataset contains daily values of the Fear and Greed Index for the year 2023, which is used to measure the sentiments of investors in the market. The data spans from January 1, 2023, to December 31, 2023.
#'
#' @format An [xts::xts()] object structured as follows:
#' \describe{
#' \item{FGI}{Daily Fear and Greed Index Value}
#' \item{FGI}{[numeric] Daily Fear and Greed Index value.}
#' }
#'
#' @family data
#' @details
#' The Fear and Greed Index goes from 0-100, and can be classified as follows,
#'
#' \describe{
#' \item{0-24}{Extreme Fear}
#' \item{25-44}{Fear}
#' \item{45-55}{Neutral}
#' \item{56-75}{Greed}
#' \item{76-100}{Extreme Greed}
#' }
#'
#'
#' @examples
#' # Load the dataset
#' data("FGIndex")
#'
#' # Get a summary of index values
#' summary(FGIndex)
"FGIndex"
1 change: 1 addition & 0 deletions R/chart_event.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#' @example man/examples/scr_addEvents.R
#'
#' @family chart indicators
#' @keywords internal
#'
#' @author Serkan Korkmaz
#'
Expand Down
105 changes: 94 additions & 11 deletions R/chart_ma.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ chart_ma <- function(
showlegend = TRUE,
name = name,
x = ~index,
y = stats::as.formula(paste("~",y)),
y = stats::as.formula(
# NOTE: to avoid possible naming
# bugs in TTR use names(data)[2].
# names(data)[1] is index as per
# zoo.fortify
paste("~",names(data)[2])
),
line = list(
width = 0.9
)
Expand All @@ -28,14 +34,20 @@ chart_ma <- function(
}


#' Add Simple Moving Averages to the charts
#' Add Simple Moving Averages (SMA) to the charts
#'
#' @description
#'
#' `r lifecycle::badge("experimental")`
#'
#' A high-level [plotly::add_lines()]-wrapper function that interacts with [TTR]'s moving average family of functions.
#'
#' @usage sma(
#' price = "close",
#' n = 10,
#' ...
#' )
#'
#' @inheritParams TTR::SMA
#' @param price A [character]-vector of [length] 1. Close by default. The name of the vector to passed into [TTR::SMA]
#' @param ... For internal use. Please ignore.
Expand Down Expand Up @@ -114,15 +126,24 @@ sma <- function(
}


#' Add Exponentially Weighted Moving Average to the charts
#' Add Exponentially-Weighted Moving Average (EMA) to the charts
#'
#' @usage ema(
#' price = "close",
#' n = 10,
#' wilder = FALSE,
#' ratio = NULL,
#' ...
#' )
#'
#' @param price A [character]-vector of [length] 1. Close by default. The name of the vector to passed into [TTR::EMA]
#' @inheritParams TTR::EMA
#' @inherit sma
#' @family chart indicators
#' @family moving average indicators
#' @export
ema <- function(
price = "Close",
price = "close",
n = 10,
wilder = FALSE,
ratio = NULL,
Expand Down Expand Up @@ -188,7 +209,17 @@ ema <- function(

}

#' Add Double Exponential Moving Average to the chart
#' Add Double Exponential Moving Average (DEMA) to the chart
#'
#' @usage dema(
#' price = "close",
#' n = 10,
#' v = 1,
#' wilder = FALSE,
#' ratio = NULL,
#' ...
#' )
#'
#' @param price A [character]-vector of [length] 1. Close by default. The name of the vector to passed into [TTR::DEMA]
#' @inheritParams TTR::DEMA
#' @inherit sma
Expand Down Expand Up @@ -266,7 +297,17 @@ dema <- function(
}


#' Add Weighted Moving Average to the chart
#' Add Weighted Moving Average (WMA) to the chart
#'
#' @usage wma(
#' price = "close",
#' n = 10,
#' wts = 1:n,
#' wilder = FALSE,
#' ratio = NULL,
#' ...
#' )
#'
#' @param price A [character]-vector of [length] 1. Close by default. The name of the vector to passed into [TTR::WMA]
#' @inheritParams TTR::WMA
#' @inherit sma
Expand All @@ -279,6 +320,9 @@ wma <- function(
wts = 1:n,
...) {

# TODO: Submit PR, WMA has an issue
# too in the naming.

call_stack <- as.character(
lapply(sys.calls(), `[[`, 1)
)
Expand Down Expand Up @@ -339,7 +383,14 @@ wma <- function(
}


#' Add Elastic Volume-weighted Moving Average to the chart
#' Add Elastic Volume-Weighted Moving Average (EVWMA) to the chart
#'
#' @usage evwma(
#' price = "close",
#' n = 10,
#' ...
#' )
#'
#' @param price A [character]-vector of [length] 1. Close by default. The name of the vector to passed into [TTR::EVWMA]
#' @inheritParams TTR::EVWMA
#' @inherit sma
Expand Down Expand Up @@ -409,7 +460,15 @@ evwma <- function(
}


#' Add Zero Lag Exponential Moving Average to the chart
#' Add Zero Lag Exponential Moving Average (ZLEMA) to the chart
#'
#' @usage zlema(
#' price = "close",
#' n = 10,
#' ratio = NULL,
#' ...
#' )
#'
#' @param price A [character]-vector of [length] 1. Close by default. The name of the vector to passed into [TTR::ZLEMA]
#' @inheritParams TTR::ZLEMA
#' @inherit sma
Expand Down Expand Up @@ -480,7 +539,15 @@ zlema <- function(
}


#' Add Volume-weighted Moving Average to the chart
#' Add Volume-Weighted Moving Average (VWAP) to the chart
#'
#' @usage vwap(
#' price = "close",
#' n = 10,
#' ratio = NULL,
#' ...
#' )
#'
#' @param price A [character]-vector of [length] 1. Close by default. The name of the vector to passed into [TTR::VWAP]
#' @inheritParams TTR::VWAP
#' @inherit sma
Expand Down Expand Up @@ -555,7 +622,14 @@ vwap <- function(



#' Add Hull Moving Average to the chart
#' Add Hull Moving Average (HMA) to the chart
#'
#' @usage hma(
#' price = "close",
#' n = 20,
#' ...
#' )
#'
#' @param price A [character]-vector of [length] 1. Close by default. The name of the vector to passed into [TTR::HMA]
#' @inheritParams TTR::HMA
#' @inherit sma
Expand Down Expand Up @@ -623,7 +697,16 @@ hma <- function(

}

#' Add Arnaud Legoux Moving Average to the chart
#' Add Arnaud Legoux Moving Average (ALMA) to the chart
#'
#' @usage alma(
#' price = "close",
#' n = 9,
#' offset = 0.85,
#' sigma = 6,
#' ...
#' )
#'
#' @param price A [character]-vector of [length] 1. Close by default. The name of the vector to passed into [TTR::ALMA]
#' @inheritParams TTR::ALMA
#' @inherit sma
Expand Down
11 changes: 7 additions & 4 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ reference:
- contents: has_concept('supported calls')
- title: Main charts
desc: The main charts
- contents: has_concept(c('charting','price charts'))
- contents:
- has_concept('charting')
- has_concept("price charts")
- title: Subcharts
desc: The family of chart suited for subcharts
- contents:
Expand All @@ -32,14 +34,15 @@ reference:
desc: Adding indicators to charts
- contents:
- has_concept('chart indicators')
- -has_concept('price charts')
- -has_concept('subcharts')
- has_concept('price charts')
- has_concept('subcharts')
- title: Convinience functions
desc: Manipulate and calibrate objects
- contents: has_concept('convinience')
- title: Datasets
desc: Sample datasets returned by ```get_quote()``` and ```get_fgindex()```
- contents: has_concept('data')
- contents:
- has_keyword('datasets')
- title: Decprecated functions
desc: These functions has been deprecated since version 1.3.0, and will be permanently deleted in the subsequent versions
- contents: has_concept('deprecated')
Expand Down
Loading

0 comments on commit f6d30c4

Please sign in to comment.