prices_rate: Calculate Growth Rate From a Vector of Prices

Description Usage Arguments Value Examples

View source: R/prices_rate.R

Description

The formula is simply: prices[length(prices)] / prices[1] - 1. If units.rate is specified, then it converts to x-unit growth rate.

Usage

1
prices_rate(prices, units.rate = NULL)

Arguments

prices

Numeric matrix with 1 column of prices for each investment (can be a vector if there is only one).

units.rate

Numeric value specifying the number of units for growth rate calculation, if you want something other than total growth. For annualized growth rate, set to 252 if prices has daily prices, 12 if prices has monthly prices, etc.

Value

Numeric value if prices is a vector, numeric matrix if prices is a matrix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Create vector of daily closing prices for a hypothetical stock
prices <- c(100.4, 98.7, 101.3, 101.0, 100.9)

# Overall growth is 0.50%
prices_rate(prices)

# Average daily growth is 0.12%
prices_rate(prices, 1)

# Corresponds to 36.7% annualized growth
prices_rate(prices, 252)

vandomed/stocks documentation built on Sept. 2, 2018, 10:10 a.m.