balances: Calculate Balances Based on Initial Balance and Vector of...

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

View source: R/RcppExports.R

Description

Calculates vector of balances based on initial balance and vector of ratios from one time point to the next (i.e. proportion gains + 1). The formula is simply: initial * cumprod(ratios).

Usage

1
balances(ratios, initial = 10000)

Arguments

ratios

Numeric vector of ratios between subsequent investment prices (i.e. proportion gains + 1). For example, if a stock gained 3%, lost 1%, then lost 2%, ratios would be c(1.03, 0.99, 0.98).

initial

Initial balance.

Value

Numeric vector indicating balance at each time point.

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

final.balance

Examples

1
2
3
4
5
6
7
8
9
# Randomly generate daily stock gains over a 5-year period
set.seed(123)
stockgains <- rnorm(252 * 5, 1.0003, 0.02)

# Create vector of balances if initial balance is $10,000
bals <- balances(stockgains)

# Plot results
plot(bals)

stocks documentation built on May 21, 2017, 1:17 a.m.

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

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

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

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