diff --git a/.gitignore b/.gitignore index b9d6bd9..e0cdfde 100644 --- a/.gitignore +++ b/.gitignore @@ -213,3 +213,4 @@ pip-log.txt #Mr Developer .mr.developer.cfg +.Rproj.user diff --git a/DESCRIPTION b/DESCRIPTION index 12a52bc..ca6a943 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: FinCal Title: Time Value of Money, Time Series Analysis and Computational Finance Description: Package for time value of money calculation, time series analysis and computational finance. -Version: 0.6.4 -Date: 2017-04-12 +Version: 0.6.5 +Date: 2023-08-05 Author: Felix Yanhui Fan Imports: ggplot2, diff --git a/R/fv.annuity.R b/R/fv.annuity.R index dec8fa7..f8080bb 100644 --- a/R/fv.annuity.R +++ b/R/fv.annuity.R @@ -14,8 +14,12 @@ fv.annuity <- function(r,n,pmt,type=0) { if(type != 0 && type !=1){ print("Error: type should be 0 or 1!") }else{ - fv = (pmt / r * ((1 + r)^n - 1))*(1+r)^type * (-1) - return(fv) + fv = if (isTRUE(all.equal(0.0, r))){ + pmt * n * (-1) + }else{ + (pmt / r * ((1 + r)^n - 1))*(1+r)^type * (-1) + } + return(fv) } } diff --git a/R/n.period.R b/R/n.period.R index 9dc9fea..badd7e4 100644 --- a/R/n.period.R +++ b/R/n.period.R @@ -18,8 +18,12 @@ n.period <- function(r,pv,fv,pmt,type=0){ if(type != 0 && type !=1){ print("Error: type should be 0 or 1!") }else{ - n <- log(-1 * (fv*r-pmt* (1+r)^type)/(pv*r+pmt* (1+r)^type))/log(1+r) - return(n) + n <- if (isTRUE(all.equal(0.0, r))){ + -1 * (fv+pv) / pmt + }else{ + log(-1 * (fv*r-pmt* (1+r)^type)/(pv*r+pmt* (1+r)^type))/log(1+r) + } + return(n) } } diff --git a/R/pmt.R b/R/pmt.R index 68a04dd..5a789f7 100644 --- a/R/pmt.R +++ b/R/pmt.R @@ -19,7 +19,11 @@ pmt <- function(r,n,pv,fv,type=0){ if(type != 0 && type !=1){ print("Error: type should be 0 or 1!") }else{ - pmt <- (pv+fv/(1+r)^n)*r/(1-1/(1+r)^n) * (-1) * (1+r)^(-1 * type) + pmt <- if (isTRUE(all.equal(0.0, r))){ + (pv+fv)/n * (-1) + }else{ + (pv+fv/(1+r)^n)*r/(1-1/(1+r)^n) * (-1) * (1+r)^(-1 * type) + } return(pmt) } } diff --git a/R/pv.annuity.R b/R/pv.annuity.R index c030e7a..080f39b 100644 --- a/R/pv.annuity.R +++ b/R/pv.annuity.R @@ -14,7 +14,11 @@ pv.annuity <- function(r, n, pmt, type=0) { if(type != 0 && type !=1){ print("Error: type should be 0 or 1!") }else{ - pv = (pmt / r * (1 - 1 / (1 + r)^n))*(1 + r)^type * (-1) - return(pv) + pv = if (isTRUE(all.equal(0.0, r))){ + n * pmt * (-1) + }else{ + (pmt / r * (1 - 1 / (1 + r)^n))*(1 + r)^type * (-1) + } + return(pv) } }