R/investment.R

#' Constant investment
#' 
#' @param prevTransfert
#' @param invAmount
#' @return amount invested this month
constInvest <- function(prevTransfert,
                        invAmount) 
{
  return(invAmount) # money investment does not vary with money already transfered
}

#' Variable investment: only invest what was not already transfered.
#' 
#' @param prevTransfert
#' @param totInvest
#' @return amount invested this month
varInvest<- function(prevTransfert,
                     totInvest)
{
  return(max(0, totInvest - prevTransfert))
}

#' No investment considered
noInvest <- function(prevTransfert,
                     totInvest) {
  return(0.)
}

#' Money flows due to investments.
#' 
#' @param rate interrest rates
#' @param transfer amount of money added to invested capital this month
#' @param capital total capital invested
#' @return list with total capital invested, and interests gained on capital
investStep <- function(rate,
                       transfer,
                       capital)
{
  interest <- rate * capital
  capIncrease <- interest + transfer # interests are reinvested, in addition to new payments
  return (list(capIncrease = capIncrease,
               interest = interest))
}
vkubicki/rfinance documentation built on May 14, 2019, 7:22 p.m.