solver 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/README.md +1 -1
- data/lib/solver/tvm.rb +6 -2
- data/lib/solver/version.rb +1 -1
- data/test/test_tvm.rb +10 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee835df68fc47b2f1c1ffa6e69fd2d3c148322de
|
4
|
+
data.tar.gz: 51bed86526a4522ed62ac6d479e9bc150aae508a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e264ceac538609f1c7071f437dbe2e482e768c25df2a703335c4b5f285abe1b84da0185ac958c75d4e693685cad645dd1bfc8a558000dca72e2504b3e112026
|
7
|
+
data.tar.gz: 1e9ec734d2966626d3080b0e8c0d061867b791c6d0964d7c83ecd123853db0462c681a883f61705d6649156ff009363d7c8210cd2aa75b758f2d6489271e79ce
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ Let's define an equation to compute the *Time Value of Money* (i.e. compound int
|
|
42
42
|
tvm_equation = ->(future_value, time, present_value, payment, interest, payments_per_year) {
|
43
43
|
i = interest/100/payments_per_year
|
44
44
|
n = -time
|
45
|
-
k = (i + 1)**n
|
45
|
+
k = (i + 1)**n
|
46
46
|
present_value + payment*(1-k)/i + future_value*k
|
47
47
|
}
|
48
48
|
```
|
data/lib/solver/tvm.rb
CHANGED
@@ -32,7 +32,7 @@ module Flt::Solver
|
|
32
32
|
@var_descriptions
|
33
33
|
end
|
34
34
|
|
35
|
-
# Parameters:
|
35
|
+
# Parameters: (using cash-flow sign convention)
|
36
36
|
# :t time in periods
|
37
37
|
# :p number of periods per year
|
38
38
|
# :i percent yearly interest rate
|
@@ -58,7 +58,11 @@ module Flt::Solver
|
|
58
58
|
n = -t
|
59
59
|
k = @context.exp(lnp1(i)*n) # (i+1)**n
|
60
60
|
# Equation: -m*k = m0 + pmt*(1-k)/i
|
61
|
-
|
61
|
+
if i == 0 # TODO: with tolerance?
|
62
|
+
m0 + pmt*t + m # k == 1
|
63
|
+
else
|
64
|
+
m0 + pmt*(@one-k)/i + m*k
|
65
|
+
end
|
62
66
|
end
|
63
67
|
|
64
68
|
# ln(x+1)
|
data/lib/solver/version.rb
CHANGED
data/test/test_tvm.rb
CHANGED
@@ -40,6 +40,16 @@ class TestTVM < MiniTest::Unit::TestCase
|
|
40
40
|
assert_in_delta @context.Num('331667.006691'), sol[:m], @delta
|
41
41
|
end
|
42
42
|
|
43
|
+
should "work with zero interest" do
|
44
|
+
sol = @tvm.solve(:t=>240, :m0=>10000, :m=>0, :i=>0, :p=>12)
|
45
|
+
assert_equal [:pmt], sol.keys
|
46
|
+
assert_in_delta -10000.0/240, sol[:pmt], @delta
|
47
|
+
|
48
|
+
sol = @tvm.solve(:t=>240, :m0=>10000, :m=>-300, :i=>0, :p=>12)
|
49
|
+
assert_equal [:pmt], sol.keys
|
50
|
+
assert_in_delta -(10000.0-300)/240, sol[:pmt], @delta
|
51
|
+
end
|
52
|
+
|
43
53
|
end
|
44
54
|
|
45
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solver
|
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
|
- Javier Goizueta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: flt
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.2.
|
131
|
+
rubygems_version: 2.5.2.3
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Numeric Solver using Flt
|