finance_rb 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +1 -1
- data/lib/finance/loan.rb +16 -0
- data/lib/finance/version.rb +1 -1
- data/spec/finance/loan_spec.rb +20 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52d806b7797622aa42c8a3d13197ddd3e66817dd41199751cc402d2e2ede4741
|
4
|
+
data.tar.gz: 3404f5b73ededdd707d82f976a61bed2b575a3e00b448c1b056a06c92169bd5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2114092617e4120fc0b4e61d5e98cd0c227c882605e10fb0bfafdeb761f8c6dc8124a82ac729b548f4365f1a7fa17b061ad14a1e8d1befb6608ced7f4d68634
|
7
|
+
data.tar.gz: c42f87903359390b44fdb6472baacf24f6fc60934961cd16c007675e1adb231c0122bfca514c4ceffab7506f66b13b95736474c85ae23b4d4d103259f747f718
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## [0.2.1] - 2021-05-01
|
2
|
+
|
3
|
+
### Added
|
4
|
+
* Implement `Finance::Loan#nper`
|
5
|
+
|
6
|
+
## [0.2.0] - 2021-04-30
|
7
|
+
|
8
|
+
### Added
|
9
|
+
* Implement `Finance::Loan#ppmt`
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
* By default `Finance::Loan#pmt` returns negative values.
|
13
|
+
|
1
14
|
## [0.1.2] - 2021-04-05
|
2
15
|
|
3
16
|
### Added
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ which are as follows:
|
|
15
15
|
| ipmt | ✅ | Computes interest payment for a loan|
|
16
16
|
| pmt | ✅ | Computes the fixed periodic payment(principal + interest) made against a loan amount|
|
17
17
|
| ppmt | ✅ | Computes principal payment for a loan|
|
18
|
-
| nper |
|
18
|
+
| nper | ✅ | Computes the number of periodic payments|
|
19
19
|
| pv | | Computes the present value of a payment|
|
20
20
|
| rate | | Computes the rate of interest per period|
|
21
21
|
| irr | ✅ | Computes the internal rate of return|
|
data/lib/finance/loan.rb
CHANGED
@@ -132,6 +132,22 @@ module Finance
|
|
132
132
|
pmt - ipmt
|
133
133
|
end
|
134
134
|
|
135
|
+
# Nper computes the number of periodic payments.
|
136
|
+
#
|
137
|
+
# Required Loan arguments: payment, nominal_rate, period, amount, future_value*
|
138
|
+
#
|
139
|
+
# @return [Float] Number of periodic payments.
|
140
|
+
#
|
141
|
+
# @example
|
142
|
+
# require 'finance_rb'
|
143
|
+
# Finance::Loan.new(nominal_rate: 0.07, amount: 8000, payment: -150).nper
|
144
|
+
# #=> 64.0733487706618586
|
145
|
+
def nper
|
146
|
+
z = payment * (1.0 + monthly_rate * ptype) / monthly_rate
|
147
|
+
|
148
|
+
Math.log(-future_value + z / (amount + z)) / Math.log(1.0 + monthly_rate)
|
149
|
+
end
|
150
|
+
|
135
151
|
# Fv computes future value at the end of some periods (duration).
|
136
152
|
# Required Loan arguments: nominal_rate, duration, payment, amount*
|
137
153
|
#
|
data/lib/finance/version.rb
CHANGED
data/spec/finance/loan_spec.rb
CHANGED
@@ -146,4 +146,24 @@ RSpec.describe Finance::Loan do
|
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|
149
|
+
|
150
|
+
describe '#nper' do
|
151
|
+
context 'with normal arguments' do
|
152
|
+
it 'calculates correct nper value' do
|
153
|
+
loan = Finance::Loan.new(
|
154
|
+
nominal_rate: 0.07, amount: 8000, payment: -150, future_value: 0
|
155
|
+
)
|
156
|
+
expect(loan.nper).to eq(64.0733487706618586)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'with incorrect arguments' do
|
161
|
+
it 'raises Math::DomainError' do
|
162
|
+
loan = Finance::Loan.new(
|
163
|
+
nominal_rate: 1e100, amount: 8000, payment: -150, future_value: 0
|
164
|
+
)
|
165
|
+
expect { loan.nper }.to raise_error(Math::DomainError)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
149
169
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: finance_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad Dyachenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A ruby port of numpy-financial functions. This library provides a Ruby
|
14
14
|
interface for working with interest rates, mortgage amortization, and cashflows
|