prices_rate: Calculate Growth Rate From a Vector of Stock Prices or...

Description Usage Arguments Value Author(s) References See Also Examples

Description

The formula is simply: overall.rate = prices[length(prices)] / prices[1] - 1. If xday is specified, then it converts to x-day growth rate. For example, if prices is a vector of stock prices over a five-day period, say c(100.4, 98.7, 101.3, 101.0, 100.9), then the overall growth rate is approximately 0.0050 over four full trading days. If xday.rate is set to 1, this rate is converted to an average daily rate of approximately

Usage

1
prices.rate(prices, xday.rate = NULL, nas = FALSE)

Arguments

prices

Numeric vector of stock prices or investment balances. Has to be daily prices if you want to calculate x-day rather than overall growth.

xday.rate

Number of days for growth rate calculation. If unspecified, function returns overall growth. If set to 251, function would return annual growth rate.

nas

If TRUE, function finds and removes any missing values (NA's) in prices vector. The default is FALSE to maximize speed for the usual case where there are no missing values.

Value

Numeric value indicating the growth rate.

Author(s)

Dane R. Van Domelen

References

Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.

See Also

gains.rate

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.6% annual growth
prices.rate(prices, 251)


Search within the stocks package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.