knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of irr2 is to calculate IRR and NPV. The related functions inspired by @Ellis2019CBA.
You can install the released version of irr2 from CRAN with:
install.packages("irr2")
And the development version from GitHub with:
# install.packages("devtools") devtools::install_github("JiaxiangBU/irr2")
This is a basic example which shows you how to solve a common problem:
library(irr2) ## basic example code
There is a stream of cash flows, down payment with 2200, and next pay back 752.97 each month. To calcuate the IRR per year.
cf1 <- c(-2200, rep(752.9700, 3)) cf1 irr_m <- irr(cf = cf1) irr_m ((irr_m/100+1)^12-1)*100
If the discount rate is 2%, calcuate NPV of this cash flows. If the discount rate is 1%, calcuate NPV of this cash flows.
npv(discount = 2, cf = cf1) npv(discount = 1.33299, cf = cf1) npv(discount = 1, cf = cf1)
irr2 <- irr(c(-100, 39, 59, 55, 20))/100 irr2 -100 + 39/(1+irr2)^1 + 59/(1+irr2)^2 + 55/(1+irr2)^3 + 20/(1+irr2)^4
citations <- add2pkg::add_zenodo_citation("README.Rmd")
cat(citations$Cite)
cat(paste0("```BibTex\n",citations$BibTex,"\n```"))
cat(citations$Comments)
r add2pkg::add_disclaimer("Jiaxiang Li")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.