The goal of irr2 is to calculate IRR and NPV. The related functions inspired by Ellis (2019).
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
#> [1] -2200.00 752.97 752.97 752.97
irr_m <- irr(cf = cf1)
#> Warning in f(arg, ...): The unit of discount is percentage, as xx%.
#> Warning in f(arg, ...): The unit of discount is percentage, as xx%.
#> Warning in f(arg, ...): The unit of discount is percentage, as xx%.
#> Warning in f(arg, ...): The unit of discount is percentage, as xx%.
irr_m
#> [1] 1.33299
((irr_m/100+1)^12-1)*100
#> [1] 17.22232
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)
#> [1] -28.52241
npv(discount = 1.33299, cf = cf1)
#> [1] -0.0004258612
npv(discount = 1, cf = cf1)
#> [1] 14.47363
irr2 <- irr(c(-100, 39, 59, 55, 20))/100
#> Warning in f(arg, ...): The unit of discount is percentage, as xx%.
irr2
#> [1] 0.2809484
-100 +
39/(1+irr2)^1 +
59/(1+irr2)^2 +
55/(1+irr2)^3 +
20/(1+irr2)^4
#> [1] -3.680089e-06
Jiaxiang Li. (2019, November 28). JiaxiangBU/irr2: irr2 0.1.0 (Version v0.1.0). Zenodo. http://doi.org/10.5281/zenodo.3555642
@software{jiaxiang_li_2019_3555642,
author = {Jiaxiang Li},
title = {JiaxiangBU/irr2: irr2 0.1.0},
month = nov,
year = 2019,
publisher = {Zenodo},
version = {v0.1.0},
doi = {10.5281/zenodo.3555642},
url = {https://doi.org/10.5281/zenodo.3555642}
}
If you use irr2, I would be very grateful if you can add a citation in your published work. By citing irr2, beyond acknowledging the work, you contribute to make it more visible and guarantee its growing and sustainability. For citation, please use the BibTex or the citation content.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.