get_returns: Calculate Returns From Stock Prices

Description Usage Arguments Value Examples

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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, ...)

## S3 method for class 'tbl_time'
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 shoud 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 May 28, 2019, noon