Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle zero discount rate #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -213,3 +213,4 @@ pip-log.txt

#Mr Developer
.mr.developer.cfg
.Rproj.user
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 <nolanfyh@gmail.com>
Imports:
ggplot2,
8 changes: 6 additions & 2 deletions R/fv.annuity.R
Original file line number Diff line number Diff line change
@@ -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)
}
}

8 changes: 6 additions & 2 deletions R/n.period.R
Original file line number Diff line number Diff line change
@@ -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)
}
}

6 changes: 5 additions & 1 deletion R/pmt.R
Original file line number Diff line number Diff line change
@@ -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)
}
}
8 changes: 6 additions & 2 deletions R/pv.annuity.R
Original file line number Diff line number Diff line change
@@ -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)
}
}