exonio 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9595c1bffef30730dadb4b4274742bc3113ef5e
4
- data.tar.gz: 335f53e02bb83504bfcaaa8186d0debfeb7f09cd
3
+ metadata.gz: d7c8540cc0960cf7ecaa4ca890b9fcffa0e83188
4
+ data.tar.gz: 7242e19ab28e0746c164d6d7144763830ddd86a9
5
5
  SHA512:
6
- metadata.gz: e656084a10f77e0d48f7a32be71625863a6427bc34532229daf3692fef734784b9d0ded1ed556f67304ef9cbefb890d659fba7dcb3c6b94fa216cc752d67af02
7
- data.tar.gz: 53bf0c5c0f905d0d86d1f7deb15b3e3c9cbffa4c7134ca6dbd92129ca62c797359688ef74e19943e6b4a7b662e6939935291357107741b481836f446e4816d28
6
+ metadata.gz: 5060942e118057edcd050a004ec2f0a84ba4ed8054f6c0d6021bd9ee121dc25006bbd0b8a65f7bdc4dedf7b2e79c901a4446feddb8a7d82044c0804f775639e6
7
+ data.tar.gz: 220d4df06a167c0966b72f98042e6032a13aef295178f88e1dc8cefa60d4b8055e9e53bfd40ee41d1aa47a6e9c2558bbcff6571605f17267c5dcf871aa031b84
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.3.0
4
+
5
+ * Implements `ipmt` method
6
+
7
+ ## 0.2.0
8
+
9
+ * Implements `pv` method
10
+
3
11
  ## 0.1.1
4
12
 
5
13
  * Remove round from `pmt` and `fv` methods
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exonio (0.2.0)
4
+ exonio (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -43,6 +43,17 @@ By convention, the negative sign represents cash flow out (i.e. money not
43
43
  available today). Thus, saving $100 a month at 5% annual interest leads
44
44
  to $15,692.93 available to spend in 10 years.
45
45
 
46
+ ### IPMT
47
+
48
+ What is the interest part of a payment in the 8th period (i.e., 8th month),
49
+ having a $5,000 loan to be paid in 2 years at an annual interest rate of 7.5%?
50
+
51
+ ```ruby
52
+ Exonio.ipmt(0.075 / 12, 8, 12 * 2, 5_000.00) # ==> -22.612926783996798
53
+ ```
54
+
55
+ So, in the 8th payment, $22.61 are the interest part.
56
+
46
57
  ### NPER
47
58
 
48
59
  If you only had $150/month to pay towards the loan, how long would it take
@@ -91,7 +102,6 @@ There's a lot of formulas to be implemented, including:
91
102
  * AMORLINC
92
103
  * DB
93
104
  * DDB
94
- * IPMT
95
105
  * IRR
96
106
  * MIRR
97
107
  * NPV
@@ -22,6 +22,29 @@ module Exonio
22
22
  -(pv * temp + pmt * fact)
23
23
  end
24
24
 
25
+ # Calculates the payment on interest for an investment based on
26
+ # constant-amount periodic payments and a constant interest rate.
27
+ #
28
+ # @param rate [Float] The interest rate as decimal (not per cent) per period
29
+ # @param per [Integer] The amortization period, in terms of number of periods
30
+ # @param nper [Integer] The number of payments to be made
31
+ # @param pv [Float] The present value
32
+ # @param fv [Float] The future value remaining after the final payment has been made
33
+ # @param end_or_begining [Integer] Whether payments are due at the end (0) or
34
+ # beggining (1) of each period
35
+ #
36
+ # @return [Float]
37
+ #
38
+ # @example
39
+ # Exonio.ipmt(0.075 / 12, 8, 12 * 2, 5000) # ==> -22.612926783996798
40
+ #
41
+ def ipmt(rate, per, nper, pv, fv = 0, end_or_beginning = 0)
42
+ pmt = self.pmt(rate, nper, pv, fv, end_or_beginning)
43
+ fv = self.fv(rate, (per - 1), pmt, pv, end_or_beginning) * rate
44
+ temp = end_or_beginning == 1 ? fv / (1 + rate) : fv
45
+
46
+ (per == 1 && end_or_beginning == 1) ? 0.0 : temp
47
+ end
25
48
 
26
49
  # Calculates the number of payment periods for an investment based on
27
50
  # constant-amount periodic payments and a constant interest rate.
@@ -1,3 +1,3 @@
1
1
  module Exonio
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exonio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Izidoro