balances {stocks} | R Documentation |
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)
.
balances(ratios, initial = 10000)
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%,
|
initial |
Initial balance. |
Numeric vector indicating balance at each time point.
Dane R. Van Domelen
Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.
# 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)