financial_maths 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.project +14 -0
- data/CHANGELOG.md +26 -0
- data/Gemfile +2 -1
- data/README.md +95 -51
- data/lib/financial_maths/version.rb +1 -1
- data/lib/financial_maths.rb +37 -20
- data/spec/spec_helper.rb +2 -0
- data/spec/test_payment_spec.rb +58 -3
- metadata +6 -5
- data/.DS_Store +0 -0
data/.gitignore
CHANGED
data/.project
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>financial_maths</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
</buildSpec>
|
9
|
+
<natures>
|
10
|
+
<nature>com.aptana.projects.webnature</nature>
|
11
|
+
<nature>org.radrails.rails.core.railsnature</nature>
|
12
|
+
<nature>com.aptana.ruby.core.rubynature</nature>
|
13
|
+
</natures>
|
14
|
+
</projectDescription>
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
#### [Current]
|
3
|
+
|
4
|
+
####
|
5
|
+
* [29d39cb](../../commit/29d39cb) - __(Ruben Espinosa)__ Coderwalll profile
|
6
|
+
* [d39af4e](../../commit/d39af4e) - __(Ruben Espinosa)__ readme updated
|
7
|
+
* [799e918](../../commit/799e918) - __(Ruben Espinosa)__ Gem version budget
|
8
|
+
* [955354e](../../commit/955354e) - __(Ruben Espinosa)__ coverals icon
|
9
|
+
* [fd9f8d7](../../commit/fd9f8d7) - __(Ruben Espinosa)__ using coverals
|
10
|
+
* [1e00856](../../commit/1e00856) - __(Ruben Espinosa)__ delete unnecesary file
|
11
|
+
* [6566d95](../../commit/6566d95) - __(Ruben Espinosa)__ new unit tests
|
12
|
+
* [d67e8cb](../../commit/d67e8cb) - __(Ruben Espinosa)__ improve in readme
|
13
|
+
* [c83fd63](../../commit/c83fd63) - __(Ruben Espinosa)__ new test
|
14
|
+
* [17d4a56](../../commit/17d4a56) - __(Ruben Espinosa)__ amotizations anticipated and dues
|
15
|
+
* [6abcd52](../../commit/6abcd52) - __(Ruben Espinosa)__ new unit test
|
16
|
+
* [0105bc3](../../commit/0105bc3) - __(Ruben Espinosa)__ rspec
|
17
|
+
* [7facdde](../../commit/7facdde) - __(Ruben Espinosa)__ travis_ci
|
18
|
+
* [1c51a1c](../../commit/1c51a1c) - __(Ruben Espinosa)__ travis_ci
|
19
|
+
* [eff10c6](../../commit/eff10c6) - __(Ruben Espinosa)__ travis_ci
|
20
|
+
* [8ac3465](../../commit/8ac3465) - __(Ruben Espinosa)__ travis_ci
|
21
|
+
* [cb60c1f](../../commit/cb60c1f) - __(Ruben Espinosa)__ new methods, v004
|
22
|
+
* [05beff9](../../commit/05beff9) - __(Ruben Espinosa)__ 5 functions more
|
23
|
+
* [d408047](../../commit/d408047) - __(Ruben Espinosa)__ update gemspec
|
24
|
+
* [08810e5](../../commit/08810e5) - __(Ruben Espinosa)__ Update README.md
|
25
|
+
* [a59eb54](../../commit/a59eb54) - __(Ruben Espinosa)__ updated readme
|
26
|
+
* [37b9aaf](../../commit/37b9aaf) - __(Ruben Espinosa)__ first commit
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,24 +1,14 @@
|
|
1
|
-
|
1
|
+
## FinancialMaths
|
2
2
|
[![Build Status](https://travis-ci.org/rderoldan1/financial_maths.png?branch=master)](https://travis-ci.org/rderoldan1/financial_maths)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/rderoldan1/financial_maths/badge.png?branch=master)](https://coveralls.io/r/rderoldan1/financial_maths)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/financial_maths.png)](http://badge.fury.io/rb/financial_maths)
|
5
|
+
[![endorse](https://api.coderwall.com/rderoldan1/endorsecount.png)](https://coderwall.com/rderoldan1)
|
3
6
|
more functions will be added soon
|
4
7
|
|
5
|
-
#### New in version 0.0.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
3. efective_given_nominal_antipipated
|
10
|
-
4. nominal_antipiated_given_efective
|
11
|
-
5. nominal_due_given_efective
|
12
|
-
6. anticipated_fixed_payment
|
13
|
-
|
14
|
-
#### New in version 0.0.3
|
15
|
-
|
16
|
-
1. future_given_present
|
17
|
-
2. present_given_future
|
18
|
-
3. annuity_given_present
|
19
|
-
4. annuity_given_future
|
20
|
-
5. present_given_annuity
|
21
|
-
6. future_given_annuity
|
8
|
+
#### New in version 0.0.5
|
9
|
+
1. New functions for loan amortizations
|
10
|
+
2. New payments calculations
|
11
|
+
3. New unit tests
|
22
12
|
|
23
13
|
#### Pending
|
24
14
|
1. include more functions
|
@@ -46,39 +36,93 @@ include FinancialMaths
|
|
46
36
|
|
47
37
|
```
|
48
38
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
39
|
+
## The lists of the methods and their params
|
40
|
+
|
41
|
+
#### Variable amortization payment due
|
42
|
+
due_variable_payment_amortization (periods, amount, rate, payment)
|
43
|
+
|
44
|
+
$ due_variable_payment_amortization(5,10000,1.8,2000)
|
45
|
+
$ [{:period=>0, :monthly_payment=>nil, :interest=>nil, :payment=>nil, :balance=>10000},
|
46
|
+
{:period=>1, :payment=>20000.0, :interest=>18000.0, :monthly_payment=>2000, :balance=>8000},
|
47
|
+
{:period=>2, :payment=>16400.0, :interest=>14400.0, :monthly_payment=>2000, :balance=>6000},
|
48
|
+
{:period=>3, :payment=>12800.0, :interest=>10800.0, :monthly_payment=>2000, :balance=>4000},
|
49
|
+
{:period=>4, :payment=>9200.0, :interest=>7200.0, :monthly_payment=>2000, :balance=>2000},
|
50
|
+
{:period=>5, :payment=>5600.0, :interest=>3600.0, :monthly_payment=>2000, :balance=>0}]
|
51
|
+
|
52
|
+
|
53
|
+
#### Variable payment amortization anticipated
|
54
|
+
anticipated_variable_payment_amortization (periods, amount, rate, payment)
|
55
|
+
|
56
|
+
$ anticipated_variable_payment_amortization(5,10000,1.8,2000)
|
57
|
+
$ [{:period=>0, :payment=>20000.0, :interest=>18000.0, :monthly_payment=>2000, :balance=>8000},
|
58
|
+
{:period=>1, :payment=>16400.0, :interest=>14400.0, :monthly_payment=>2000, :balance=>6000},
|
59
|
+
{:period=>2, :payment=>12800.0, :interest=>10800.0, :monthly_payment=>2000, :balance=>4000},
|
60
|
+
{:period=>3, :payment=>9200.0, :interest=>7200.0, :monthly_payment=>2000, :balance=>2000},
|
61
|
+
{:period=>4, :payment=>5600.0, :interest=>3600.0, :monthly_payment=>2000, :balance=>0}]
|
62
|
+
|
63
|
+
#### Amortization with fixed payment due
|
64
|
+
due_fixed_payment_amortization (periods, amount, rate, payment)
|
65
|
+
|
66
|
+
$ due_fixed_payment_amortization(5,10000,1.8,2109)
|
67
|
+
$ [{:period=>0, :monthly_payment=>nil, :interest=>nil, :payment=>nil, :balance=>10000},
|
68
|
+
{:period=>1, :payment=>2109, :interest=>18000.0, :monthly_payment=>-15891.0, :balance=>25891.0},
|
69
|
+
{:period=>2, :payment=>2109, :interest=>46603.8, :monthly_payment=>-44494.8, :balance=>70385.8},
|
70
|
+
{:period=>3, :payment=>2109, :interest=>126694.44, :monthly_payment=>-124585.44, :balance=>194971.24},
|
71
|
+
{:period=>4, :payment=>2109, :interest=>350948.232, :monthly_payment=>-348839.232, :balance=>543810.4720000001},
|
72
|
+
{:period=>5, :payment=>2109, :interest=>978858.8496000002, :monthly_payment=>-976749.8496000002, :balance=>1520560.3216000004}]
|
73
|
+
|
74
|
+
|
75
|
+
#### Variable payment amortization anticipated
|
76
|
+
anticipated_fixed_payment_amortization (periods, amount, rate, payment)
|
77
|
+
|
78
|
+
|
79
|
+
#### Find future given the present value
|
80
|
+
future_given_present (present_value, interest, term)
|
81
|
+
|
82
|
+
$ future_given_present(10000,1.8,5)
|
83
|
+
$ 1721036.8
|
84
|
+
|
85
|
+
#### Find present given the future
|
86
|
+
present_given_future (future_value, interest, term)
|
87
|
+
|
88
|
+
$ present_given_future(10000,1.8,5)
|
89
|
+
$ 58.1045
|
90
|
+
|
91
|
+
#### Find annuity present value given
|
92
|
+
annuity_given_present (present_value, interest, term)
|
93
|
+
|
94
|
+
$ annuity_given_present(10000,1.8,5)
|
95
|
+
$ 18105.1994
|
96
|
+
|
97
|
+
#### Find the future value annuity given
|
98
|
+
annuity_given_future (future_value, interest, term)
|
99
|
+
|
100
|
+
#### Find present given the annuity
|
101
|
+
present_given_annuity (annuity, interest, term)
|
102
|
+
|
103
|
+
#### Find future given the annuity
|
104
|
+
future_given_annuity (annuity, interest, term)
|
105
|
+
|
106
|
+
#### Find effective rate given the nominal rate due
|
107
|
+
efective_given_nominal_due (nominal_rate, term)
|
108
|
+
|
109
|
+
#### Find effective rate given the nominal rate anticipated
|
110
|
+
efective_given_nominal_antipipated (nominal_rate, term)
|
111
|
+
|
112
|
+
#### Find effective nominal rate given anticipated
|
113
|
+
nominal_antipiated_given_efective (nominal_rate, term)
|
114
|
+
|
115
|
+
#### Find effective nominal rate given anticipated
|
116
|
+
nominal_due_given_efective (nominal_rate, term)
|
117
|
+
|
118
|
+
#### Find the fixed anticipated
|
119
|
+
anticipated_fixed_payment (present_value, rate, term)
|
120
|
+
|
121
|
+
#### Finding variable amount
|
122
|
+
variable_payment (amount, periods)
|
123
|
+
|
124
|
+
$ variable_payment(10000,5)
|
125
|
+
$ 2000.0
|
82
126
|
|
83
127
|
## Contributing
|
84
128
|
|
data/lib/financial_maths.rb
CHANGED
@@ -106,25 +106,43 @@ module FinancialMaths
|
|
106
106
|
(annuity * (((1 + interest.to_f) ** term) -1) / interest.to_f ).round(4)
|
107
107
|
end
|
108
108
|
|
109
|
-
#
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
109
|
+
# == Conversion rates
|
110
|
+
|
111
|
+
##
|
112
|
+
# Description: Find effective rate given nominal rate expired - NVEF
|
113
|
+
# Formula: ((1 + (NOMINAL RATE / PERIODS)) ^ PERIODS) - 1
|
114
|
+
def efective_given_nominal_due(nominal_rate, term)
|
115
|
+
((((1+((nominal_rate.to_f/100)/term))**term)-1).round(6))*100
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# Description: Find effective rate given anticipated nominal rate - NAEF
|
120
|
+
# Formula: ((1 / ((1- (NOMINAL RATE / PERIODS)) ^ PERIODS)) -1
|
121
|
+
def efective_given_nominal_anticipated(nominal_rate, term)
|
122
|
+
(((1/((1-((nominal_rate.to_f/100)/term))**term))-1)*100).round(4)
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# Description: Find nominal rate anticipated given effective rate - EFNV
|
127
|
+
# Formulas:
|
128
|
+
# nominalRate = (1 + EFFECTIVE RATE)^(1 / PERIODS) - 1
|
129
|
+
# toAnticipated = nominalRate / 1 + nominalRate
|
130
|
+
# Returned -> toAnticipated * PERIODS
|
131
|
+
def nominal_anticipated_given_efective(effective_rate, periods)
|
132
|
+
nominalRate = (1+(effective_rate.to_f/100))**(1/periods.to_f)-1;
|
133
|
+
toAnticipated = nominalRate / (1+nominalRate)
|
134
|
+
(toAnticipated * periods.to_f * 100).round(4)
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# Description: Find nominal rate expired given effective rate - EFNV
|
139
|
+
# Formula: ((1 + EFFECTIVE RATE) ^ (1 / PERIODS) - 1)* PERIODS
|
140
|
+
def nominal_due_given_efective(effective_rate, periods)
|
141
|
+
((((1 + (effective_rate.to_f/100))**(1/periods.to_f)-1)*periods.to_f)*100).round(4)
|
142
|
+
end
|
143
|
+
|
144
|
+
# == End conversion rates
|
145
|
+
|
128
146
|
# Hallar la cuota fija anticipada HCFA
|
129
147
|
def anticipated_fixed_payment(present_value, rate, term)
|
130
148
|
((present_value.to_f * rate.to_f) / ((rate.to_f + 1) - (1 / (1 + rate) ** (term - 1)))).round(4)
|
@@ -134,7 +152,6 @@ module FinancialMaths
|
|
134
152
|
amount.to_f / periods
|
135
153
|
end
|
136
154
|
|
137
|
-
|
138
155
|
end
|
139
156
|
|
140
157
|
|
data/spec/spec_helper.rb
CHANGED
data/spec/test_payment_spec.rb
CHANGED
@@ -2,10 +2,65 @@ require 'rspec'
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe "fixed payment test" do
|
5
|
-
|
6
5
|
it 'should be the monthly payment' do
|
7
|
-
|
8
6
|
annuity_given_present(100000000, 0.0144594763, 180).should eq(1563975.1395)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "variable payment test" do
|
11
|
+
it "should be the monthly variable payment" do
|
12
|
+
variable_payment(10000000.0,40).should eq(250000)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "due variable payment amortization" do
|
17
|
+
it "should be a hash of payments" do
|
18
|
+
due_variable_payment_amortization(5,10000,1.8,2000).should be_an(Array)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "anticipated vabiable payment amortization" do
|
23
|
+
it "should be a hash of payments" do
|
24
|
+
anticipated_variable_payment_amortization(5,10000,1.8,2000).should be_an(Array)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "due fixed payment amortization" do
|
29
|
+
it "should be a hash of payments" do
|
30
|
+
due_fixed_payment_amortization(5,10000,1.8,2000).should be_an(Array)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "anticipated fixed payment amortization" do
|
35
|
+
it "should be a hash of payments" do
|
36
|
+
anticipated_fixed_payment_amortization(5,10000,1.8,2000).should be_an(Array)
|
37
|
+
end
|
38
|
+
end
|
9
39
|
|
40
|
+
describe "conversion rates" do
|
41
|
+
describe "Find effective rate given nominal rate expired" do
|
42
|
+
it "should be the respective rate in effective format" do
|
43
|
+
efective_given_nominal_due(15,12).should eql(16.0755)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "Find effective rate given anticipated nominal rate" do
|
48
|
+
it "should be the respective rate in effective format" do
|
49
|
+
nominal_anticipated_given_efective(15,12).should eql(13.8951)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "Find nominal rate anticipated given effective rate" do
|
54
|
+
it "should be the respective rate in nominal format" do
|
55
|
+
nominal_due_given_efective(15,12).should eql(14.0579)
|
56
|
+
end
|
10
57
|
end
|
11
|
-
|
58
|
+
|
59
|
+
describe "Find nominal rate expired given effective rate" do
|
60
|
+
it "should be the respective rate in nominal format" do
|
61
|
+
efective_given_nominal_anticipated(15,12).should eql(16.2933)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: financial_maths
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -51,10 +51,11 @@ extensions: []
|
|
51
51
|
extra_rdoc_files:
|
52
52
|
- README.md
|
53
53
|
files:
|
54
|
-
- .DS_Store
|
55
54
|
- .gitignore
|
55
|
+
- .project
|
56
56
|
- .rspec
|
57
57
|
- .travis.yml
|
58
|
+
- CHANGELOG.md
|
58
59
|
- Gemfile
|
59
60
|
- LICENSE.txt
|
60
61
|
- README.md
|
@@ -81,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
82
|
version: '0'
|
82
83
|
segments:
|
83
84
|
- 0
|
84
|
-
hash:
|
85
|
+
hash: -4218256195000384150
|
85
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
87
|
none: false
|
87
88
|
requirements:
|
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
91
|
version: '0'
|
91
92
|
segments:
|
92
93
|
- 0
|
93
|
-
hash:
|
94
|
+
hash: -4218256195000384150
|
94
95
|
requirements: []
|
95
96
|
rubyforge_project:
|
96
97
|
rubygems_version: 1.8.25
|
data/.DS_Store
DELETED
Binary file
|