time_value 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +6 -1
- data/lib/solver.rb +2 -2
- data/lib/time_value.rb +5 -6
- data/lib/time_value/version.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9adc69a58238719d597b04365a769516bacaa1a
|
4
|
+
data.tar.gz: 0d522a20351d5c6b85e297c686c9abbd886a60f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa9ebc0a7ff6e09a3e773d9eadab8ee8b3b807db7298cbd6099da16dc7c8273b90b230382dffd30be7ea87abeb42e4486f4843fb72c05882adf10ad230131478
|
7
|
+
data.tar.gz: 538d7e32757dc58e73a1676cf5b91c2c741255004d4ad3e13fe9ff51192371f99db354bcb32f300bab5fde9e5367f1d24fa400e934f9a51399e9a5c52ac95674
|
data/README.md
CHANGED
@@ -11,6 +11,11 @@
|
|
11
11
|
|
12
12
|
## Usage
|
13
13
|
|
14
|
+
Install the gem:
|
15
|
+
```
|
16
|
+
gem install time_value
|
17
|
+
```
|
18
|
+
|
14
19
|
Initialize with values:
|
15
20
|
```
|
16
21
|
time_value = TimeValue.new(n, i, pv, pmt, fv)
|
@@ -31,4 +36,4 @@ Remember to follow a convention for signs of values:
|
|
31
36
|
* Money being paid should have a negative value (-)
|
32
37
|
* Money being received should have a positive value (+)
|
33
38
|
|
34
|
-
Failing to follow this convention may yield unexpected results
|
39
|
+
Failing to follow this convention may yield unexpected results
|
data/lib/solver.rb
CHANGED
@@ -18,7 +18,7 @@ class Solver
|
|
18
18
|
iteration_count += 1
|
19
19
|
begin
|
20
20
|
result = time_value.calc_fv
|
21
|
-
rescue FloatDomainError
|
21
|
+
rescue FloatDomainError
|
22
22
|
return nil
|
23
23
|
end
|
24
24
|
adjust_bounds(result)
|
@@ -39,4 +39,4 @@ class Solver
|
|
39
39
|
end
|
40
40
|
self.guess = ((upper_bound + lower_bound) / 2).round(2)
|
41
41
|
end
|
42
|
-
end
|
42
|
+
end
|
data/lib/time_value.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
require 'byebug'
|
2
1
|
require 'solver'
|
3
2
|
|
4
3
|
class TimeValue
|
5
|
-
|
4
|
+
|
6
5
|
attr_accessor :n, :i, :pv, :pmt, :fv
|
7
|
-
|
6
|
+
|
8
7
|
def initialize(n = 0, i = 0, pv = 0.0, pmt = 0.0, fv = 0.0)
|
9
8
|
@n = n
|
10
9
|
@i = i.to_f
|
@@ -12,7 +11,7 @@ class TimeValue
|
|
12
11
|
@pmt = pmt.to_f
|
13
12
|
@fv = fv.to_f
|
14
13
|
end
|
15
|
-
|
14
|
+
|
16
15
|
#Base formula, ordinary annuity: -PV = [FV/((1+i)^n)] + (PMT/i)*[1-(1/(1+i)^n)]
|
17
16
|
def calc_pv()
|
18
17
|
i = @i / 100.0
|
@@ -24,7 +23,7 @@ class TimeValue
|
|
24
23
|
#Round
|
25
24
|
@pv = (@pv*100).round / 100.0
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
def calc_fv()
|
29
28
|
i = @i / 100.0
|
30
29
|
#Growth of initial contribution
|
@@ -35,7 +34,7 @@ class TimeValue
|
|
35
34
|
#Round
|
36
35
|
@fv = (@fv*100).round / 100.0
|
37
36
|
end
|
38
|
-
|
37
|
+
|
39
38
|
def calc_n()
|
40
39
|
i = @i / 100.0
|
41
40
|
@n = (Math.log((@pmt - (i * @fv))/(@pmt + (i * @pv)))/Math.log(1 + i)).round(0)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_value
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Randall Reed, Jr.
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- README.md
|
37
37
|
- lib/solver.rb
|
38
38
|
- lib/time_value.rb
|
39
|
+
- lib/time_value/version.rb
|
39
40
|
homepage: http://rubygems.org/gems/timevalue
|
40
41
|
licenses:
|
41
42
|
- MIT
|
@@ -56,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
57
|
version: '0'
|
57
58
|
requirements: []
|
58
59
|
rubyforge_project:
|
59
|
-
rubygems_version: 2.
|
60
|
+
rubygems_version: 2.5.1
|
60
61
|
signing_key:
|
61
62
|
specification_version: 4
|
62
63
|
summary: Time value of money financial calculations
|