Last active
March 27, 2019 03:39
-
-
Save frankandrobot/4cf1969d42433b11fc02f0fdae818f54 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
#' Calculate the real return on an index fund over a single year. | |
#' | |
#' @param yield - percent as a decimal | |
#' @param expense_ratio - percent as a decimal | |
#' @param balance | |
#' | |
#' @return | |
#' @examples | |
real_return <- function(yield, expense_ratio, balance) { | |
# if there was no expense ratio, this would be your new balance | |
return_ <- balance * (1 + yield) | |
# expenses are the difference in the return (with no expenses) | |
# and a return with a yield subtracted by the expense ratio | |
expense <- return_ - balance * (1 + yield - expense_ratio) | |
return_ - expense | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment