exonio 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7c8540cc0960cf7ecaa4ca890b9fcffa0e83188
4
- data.tar.gz: 7242e19ab28e0746c164d6d7144763830ddd86a9
3
+ metadata.gz: b41d64738c1775bc0b495caecdf951a4a4021724
4
+ data.tar.gz: 9983f55a871c45c3df8e7588ab33c4bfd635da3f
5
5
  SHA512:
6
- metadata.gz: 5060942e118057edcd050a004ec2f0a84ba4ed8054f6c0d6021bd9ee121dc25006bbd0b8a65f7bdc4dedf7b2e79c901a4446feddb8a7d82044c0804f775639e6
7
- data.tar.gz: 220d4df06a167c0966b72f98042e6032a13aef295178f88e1dc8cefa60d4b8055e9e53bfd40ee41d1aa47a6e9c2558bbcff6571605f17267c5dcf871aa031b84
6
+ metadata.gz: c5f39c4732cb7cb0e44ed923bebfc05d21936cd2e17ae5d2c3b47cfc78b7c587c958aa6aa4065bcfb79a6bb7d157b3000c533326e30fd567a5b45a292aeeb3a8
7
+ data.tar.gz: b547a202794b5acab4317d5aee0b8c80e56ad37ed7d624c5147e6cabea88b149caaa380eea3f26ae83d542efb20d3810b6409cdeb6e3f7ad60db97fae03b4c13
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.0
4
+
5
+ * Implements `rate` method
6
+
3
7
  ## 0.3.0
4
8
 
5
9
  * Implements `ipmt` method
@@ -1,12 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exonio (0.3.0)
4
+ exonio (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ byebug (8.2.1)
10
+ coderay (1.1.0)
9
11
  diff-lcs (1.2.5)
12
+ method_source (0.8.2)
13
+ pry (0.10.3)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.8.1)
16
+ slop (~> 3.4)
17
+ pry-byebug (3.3.0)
18
+ byebug (~> 8.0)
19
+ pry (~> 0.10)
10
20
  rake (10.5.0)
11
21
  rspec (3.4.0)
12
22
  rspec-core (~> 3.4.0)
@@ -21,6 +31,7 @@ GEM
21
31
  diff-lcs (>= 1.2.0, < 2.0)
22
32
  rspec-support (~> 3.4.0)
23
33
  rspec-support (3.4.1)
34
+ slop (3.6.0)
24
35
 
25
36
  PLATFORMS
26
37
  ruby
@@ -28,6 +39,7 @@ PLATFORMS
28
39
  DEPENDENCIES
29
40
  bundler (~> 1.11)
30
41
  exonio!
42
+ pry-byebug (~> 3.3.0)
31
43
  rake (~> 10.0)
32
44
  rspec (~> 3.0)
33
45
 
data/README.md CHANGED
@@ -92,6 +92,17 @@ By convention, the negative sign represents cash flow out (i.e., money not avail
92
92
  Thus, to end up with $20,000.00 in 10 years saving $100 a month at 5% annual
93
93
  interest, an initial deposit of $2715,09 should be made.
94
94
 
95
+ ### RATE
96
+
97
+ Suppose you take a loan of $50,000.00 to pay in 3 years with a monthly payment of $2,500.00.
98
+ What is the rate applied to this loan?
99
+
100
+ ```ruby
101
+ Exonio.rate(12 * 3, 2_500, -50_000) # ==> 0.036006853458478955
102
+ ```
103
+
104
+ So, the rate applied is 3.60%.
105
+
95
106
  ## TODO
96
107
 
97
108
  There's a lot of formulas to be implemented, including:
@@ -106,7 +117,6 @@ There's a lot of formulas to be implemented, including:
106
117
  * MIRR
107
118
  * NPV
108
119
  * PPMT
109
- * RATE
110
120
  * SLN
111
121
  * SYD
112
122
  * VDB
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.11"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "pry-byebug", "~> 3.3.0"
24
25
  end
@@ -111,5 +111,48 @@ module Exonio
111
111
 
112
112
  -(fv + pmt * fact) / temp
113
113
  end
114
+
115
+ # Calculates the interest rate of an annuity investment based on
116
+ # constant-amount periodic payments and the assumption of a constant interest rate.
117
+ #
118
+ # @param nper [Integer] The number of payments to be made (number of periods)
119
+ # @param pmt [Float] The amount per period to be paid
120
+ # @param pv [Float] The present value
121
+ # @param fv [Float] The future value remaining after the final payment has been made
122
+ # @param end_or_begining [Integer] Whether payments are due at the end (0) or
123
+ # beggining (1) of each period
124
+ # @param rate_guess [Float] An estimate for what the interest rate will be
125
+ #
126
+ # @return [Float]
127
+ #
128
+ # @example
129
+ # Exonio.rate(12, 363.78, -3056.00) # ==> 0.05963422268883278
130
+ #
131
+ def rate(nper, pmt, pv, fv = 0, end_or_beginning = 0, rate_guess = 0.10)
132
+ guess = rate_guess
133
+ tolerancy = 1e-6
134
+ close = false
135
+
136
+ begin
137
+ temp = newton_iter(guess, nper, pmt, pv, fv, end_or_beginning)
138
+ next_guess = guess - temp
139
+ diff = (next_guess - guess).abs
140
+ close = diff < tolerancy
141
+ guess = next_guess
142
+ end while !close
143
+
144
+ next_guess
145
+ end
146
+
147
+ private
148
+
149
+ # This method was borrowed from the NumPy rate formula
150
+ # which was generated by Sage
151
+ #
152
+ def newton_iter(r, n, p, x, y, w)
153
+ t1 = (r+1)**n
154
+ t2 = (r+1)**(n-1)
155
+ ((y + t1*x + p*(t1 - 1)*(r*w + 1)/r) / (n*t2*x - p*(t1 - 1)*(r*w + 1)/(r**2) + n*p*t2*(r*w + 1)/r + p*(t1 - 1)*w/r))
156
+ end
114
157
  end
115
158
  end
@@ -1,3 +1,3 @@
1
1
  module Exonio
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exonio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Izidoro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-26 00:00:00.000000000 Z
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.3.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.3.0
55
69
  description: This gem implements some useful Excel formulas like PMT, IPMT, NPER,
56
70
  PV, etc...
57
71
  email: