Skip to content

Instantly share code, notes, and snippets.

@frankandrobot
Last active March 27, 2019 03:39
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 frankandrobot/4cf1969d42433b11fc02f0fdae818f54 to your computer and use it in GitHub Desktop.
Save frankandrobot/4cf1969d42433b11fc02f0fdae818f54 to your computer and use it in GitHub Desktop.
#' 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