Skip to content

Instantly share code, notes, and snippets.

@wabarr
Created May 20, 2019 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wabarr/da142d40d62e5ff7f3e70261ec72cc0d to your computer and use it in GitHub Desktop.
Save wabarr/da142d40d62e5ff7f3e70261ec72cc0d to your computer and use it in GitHub Desktop.
compound <- function(start, growthrate_percent, fees_percent, years=15) {
amount <- start
growthrate_proportion <- growthrate_percent/100
fees_proportion <- fees_percent/100
yearly_vals <- rep(NA, years)
for(year in 1:years) {
amount <- amount*(1+growthrate_proportion) - amount*fees_proportion
yearly_vals[year] <- amount
}
plot(x=1:years,y=yearly_vals, pch=16, cex=2, ylab="total value in dollars", xlab="year", main=sprintf("growing at %.3f%% with fees of $%.3f%%\nstarting value: $%.2f\nending value: $%.2f",growthrate_percent, fees_percent,start, amount))
#plot(x=1:years,y=yearly_vals,add=T, type=line())
return(yearly_vals)
}
compound(start=100, growthrate_percent = 5, fees_percent = 0, years = 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment