Skip to contents

The momentum() is a generic S3 function that builds upon 'type-safe'-esque workflows limited to classes in in base R, and the package-wide dependencies. Ie. class in, class out. Each method is a soft wrapper of model.frame and therefore the OHLC-V series must be coercible to a data.frame. This rule does not transfer to indicators that uses univariate series, unless passed as a 1-column data.frame or matrix. In such cases, if univariate series is passed as a vector the function calculates the indicator 'as is', and returns a data.frame if the indicator itself is also a univariate series.

The indicator, by default, follows its mathematical definition. However, the cols argument allows for simple rearrangement of the definition by passing relevant columns in a custom order. Refer to the details-section for more on the calculation of the indicators.

Usage

momentum(x, cols, n = 10, ...)

Arguments

x

An OHLC-V series that is coercible to data.frame. The function assumes that all columns are named in lowercase and order invariant.

cols

An optional formula passed into model.frame. If passed into indicators based on univariate series, the function calculates indicators for each element in 'cols'. For indicators based on multivariate series, it will alter the calculation itself. See vignette("talib") for more details.

n

An integer of length 1.

...

Additional parameters passed into model.frame

Value

An object of same class and length of x:

MOM

double

Author

Serkan Korkmaz

Examples

## load Bitcoin (BTC)
## series
data(BTC, package = "talib")

## calculate the indicator
## for Bitcoin (BTC)
output <- talib::momentum(BTC)

## display the results
utils::tail(output)
#>                           MOM
#> 2024-12-26 01:00:00 -10423.41
#> 2024-12-27 01:00:00 -11977.25
#> 2024-12-28 01:00:00  -5041.45
#> 2024-12-29 01:00:00  -3816.01
#> 2024-12-30 01:00:00  -5139.95
#> 2024-12-31 01:00:00  -3839.98

## visualize the indicator
## with candlesticks
##
## see ?talib::chart or ?talib::indicator
## for more details
{
 ## chart OHLC-V
 ## series with candlesticks
 talib::chart(BTC)

 ## chart indicator
 ## with default values
 talib::indicator(
     talib::momentum
 )
}