Created
May 20, 2019 18:09
-
-
Save wabarr/da142d40d62e5ff7f3e70261ec72cc0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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