get_returns: Calculate Returns From Stock Prices

Description Usage Arguments Value Examples

View source: R/get_returns.R

Description

Stock prices are known for been non-stationary. Use get_returns() as a pre-processing step for econometric modeling.

Usage

1
2
3
4
5
6
7
get_returns(.tbl, .group, .type, .omit_na = FALSE, ...)

## Default S3 method:
get_returns(.tbl, .group, .type, .omit_na = FALSE, ...)

## S3 method for class 'tbl_df'
get_returns(.tbl, .group, .type, .omit_na = FALSE, ...)

Arguments

.tbl

A tidy tibble.

.group

The column in which the data should be grouped. This will often be a column with stock tickers or stocks names.

.type

The method used to calculate returns. One of:

  • log

  • arithmetic

.omit_na

Should NA values be omitted? Default is FALSE (NA's are replaced by 0).

...

The column (or columns) in which the calculation should be conducted.

Value

A tidy tibble.

Examples

1
2
3
4
5
6
7
library(YahooTickers)
library(dplyr)
get_tickers(dow) %>%
  slice(1:3) %>%
  get_stocks(.) %>%
  get_returns(., .group = tickers, .type = arithmetic,
              .omit_na = TRUE, adjusted)

Reckziegel/YahooTickers documentation built on Nov. 29, 2021, 9:45 p.m.