financial_math 0.7.0 → 1.0.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 +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +26 -10
- data/compound_interest.png +0 -0
- data/lib/financial_math/compound_interest.rb +34 -45
- data/lib/financial_math/simple_interest.rb +24 -39
- data/lib/financial_math/version.rb +1 -1
- data/simple_interest.png +0 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8a226f837f60b5914eef9fed600c8f386743d332349b11374820d197085866d
|
|
4
|
+
data.tar.gz: a52019ef71d5bb4bf42fa14124fda09caa84fe991a22c0217332257dd0590a56
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d2b9a9c1c079011e09f1d67e3a2057ffc944d8d1fad3714aa7ac0d94a7f114221e87f9093211eb373f1b33b10ebaf7b517eed02fc9b57fce7178fa7f7a2b5986
|
|
7
|
+
data.tar.gz: d9482771823b46809357dd47ae3d31c9cff17d4c749280b0663686aa89ad0cbe10ccbecc899aa0fcc9265cfc7efb2413deb1656445ccee8458177f521b43236b
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -45,26 +45,39 @@ More content will be added, soon, like:
|
|
|
45
45
|
To calculate the last item of a geometric progression:
|
|
46
46
|
|
|
47
47
|
```ruby
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
geometric_progression.last_item
|
|
48
|
+
progression = FinancialMath::GeometricProgression.new(initial_value: 1100, ratio: 1.1, times: 5)
|
|
49
|
+
progression.last_item
|
|
51
50
|
```
|
|
52
51
|
|
|
53
52
|
To calculate the future value:
|
|
54
53
|
|
|
55
54
|
```ruby
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
class Accountant
|
|
56
|
+
include FinancialMath::SimpleInterest
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
accountant = Accountant.new
|
|
60
|
+
accountant.future_value(present_value: 100_000.0, interest_rate: 0.05, periods: 3)
|
|
59
61
|
```
|
|
60
62
|
The interest rate must be in terms of years, if your problem is expressed in terms of days or months, provide the frequency of conversion and the periods in terms of days.
|
|
61
63
|
|
|
62
64
|
```ruby
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
class Accountant
|
|
66
|
+
include FinancialMath::SimpleInterest
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
accountant = Accountant.new
|
|
70
|
+
accountant.future_value(present_value: 1500.0, interest_rate: 0.45, periods: 3, frequency: 360)
|
|
66
71
|
```
|
|
67
72
|
|
|
73
|
+
## Available simple interest formulas
|
|
74
|
+
|
|
75
|
+

|
|
76
|
+
|
|
77
|
+
## Available compound interest formulas
|
|
78
|
+
|
|
79
|
+

|
|
80
|
+
|
|
68
81
|
## Development
|
|
69
82
|
|
|
70
83
|
If want test this gem without clone this repo, type:
|
|
@@ -78,6 +91,9 @@ This command will get the development dependencies installed too.
|
|
|
78
91
|
## Release History
|
|
79
92
|
|
|
80
93
|
|
|
94
|
+
* 1.0.0
|
|
95
|
+
* CHANGE: Remove `SimpleInterest()`
|
|
96
|
+
* CHANGE: Remove `CompoundInterest()`
|
|
81
97
|
* 0.7.0
|
|
82
98
|
* ADD: Add `present_value`, `continous_present_value` to `CompoundInterest` as public methods
|
|
83
99
|
* ADD: Add `internal_rate_of_return`, `real_rate_of_return` and `a_good_investment?` to `CompoundInterest` as public methods
|
|
@@ -95,7 +111,7 @@ This command will get the development dependencies installed too.
|
|
|
95
111
|
* 0.3.0
|
|
96
112
|
* ADD: Add `SimpleInterest` class
|
|
97
113
|
* 0.3.0
|
|
98
|
-
* ADD: Add `GEometricProgression` class
|
|
114
|
+
* ADD: Add `GEometricProgression` class
|
|
99
115
|
* 0.2.0
|
|
100
116
|
* ADD: Add `ArithemeticProgression` class
|
|
101
117
|
* 0.1.0
|
|
Binary file
|
|
@@ -1,73 +1,62 @@
|
|
|
1
1
|
module FinancialMath
|
|
2
|
-
|
|
3
|
-
def
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@frequency = args.fetch(:frequency, 1.0)
|
|
8
|
-
@interest_rate = args.fetch(:interest_rate, 0.0)
|
|
9
|
-
@nominal_rate = args.fetch(:nominal_rate, 0.0)
|
|
10
|
-
@effective_rate = args.fetch(:effective_rate, 0.0)
|
|
11
|
-
@future_value = args.fetch(:future_value, 0.0)
|
|
12
|
-
@inflation_rate = args.fetch(:inflation_rate, 0.0)
|
|
2
|
+
module CompoundInterest
|
|
3
|
+
def present_value(future_value:, interest_rate:, frequency: 1.0, periods: 1)
|
|
4
|
+
factor_val = factor(interest_rate: interest_rate,
|
|
5
|
+
frequency: frequency, periods: periods)
|
|
6
|
+
(future_value / factor_val).round(2)
|
|
13
7
|
end
|
|
14
8
|
|
|
15
|
-
def
|
|
16
|
-
|
|
9
|
+
def future_value(present_value:, interest_rate:, frequency: 1.0, periods: 1)
|
|
10
|
+
factor_val = factor(interest_rate: interest_rate,
|
|
11
|
+
frequency: frequency, periods: periods)
|
|
12
|
+
(present_value * factor_val).round(2)
|
|
17
13
|
end
|
|
18
14
|
|
|
19
|
-
def
|
|
20
|
-
|
|
15
|
+
def effective_rate(nominal_rate:, frequency: 1)
|
|
16
|
+
effective_rate = (1 + nominal_rate / frequency)**frequency - 1
|
|
17
|
+
effective_rate.round(4)
|
|
21
18
|
end
|
|
22
19
|
|
|
23
|
-
def
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
def nominal_rate(effective_rate:, frequency: 1.0)
|
|
21
|
+
root = nth_root(frequency: frequency)
|
|
22
|
+
nominal_rate = ((1 + effective_rate)**root - 1) * frequency
|
|
23
|
+
nominal_rate.round(4)
|
|
26
24
|
end
|
|
27
25
|
|
|
28
|
-
def
|
|
29
|
-
|
|
30
|
-
@present_value.round(2)
|
|
26
|
+
def period_of_capital_duplication(interest_rate:)
|
|
27
|
+
(Math.log10(2) / Math.log10(1 + interest_rate)).round(2)
|
|
31
28
|
end
|
|
32
29
|
|
|
33
|
-
def
|
|
34
|
-
|
|
35
|
-
@effective_rate.round(4)
|
|
30
|
+
def average_growth_rate(future_value:, present_value:, periods: 1)
|
|
31
|
+
((future_value / present_value)**(1.0 / periods) - 1).round(4)
|
|
36
32
|
end
|
|
37
33
|
|
|
38
|
-
def
|
|
39
|
-
|
|
34
|
+
def continous_future_value(present_value:, interest_rate:, periods: 1)
|
|
35
|
+
future_value = present_value * Math.exp(interest_rate * periods)
|
|
36
|
+
future_value.round(2)
|
|
40
37
|
end
|
|
41
38
|
|
|
42
|
-
def
|
|
43
|
-
|
|
39
|
+
def continous_present_value(future_value:, interest_rate:, periods: 1)
|
|
40
|
+
present_value = future_value / Math.exp(interest_rate * periods)
|
|
41
|
+
present_value.round(2)
|
|
44
42
|
end
|
|
45
43
|
|
|
46
|
-
def
|
|
47
|
-
((
|
|
44
|
+
def real_rate_of_return(interest_rate:, inflation_rate:)
|
|
45
|
+
((interest_rate - inflation_rate) / (1 + inflation_rate)).round 4
|
|
48
46
|
end
|
|
49
47
|
|
|
50
|
-
def present_value
|
|
51
|
-
(
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def nominal_rate
|
|
55
|
-
@nominal_rate = ((1 + @effective_rate)**nth_rooth - 1) * @frequency
|
|
56
|
-
@nominal_rate.round(4)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def real_rate_of_return
|
|
60
|
-
((@interest_rate - @inflation_rate) / (1 + @inflation_rate)).round 4
|
|
48
|
+
def internal_rate_of_return(future_value:, present_value:, periods: 1)
|
|
49
|
+
((future_value / present_value)**(1.0 / periods) - 1).round(4)
|
|
61
50
|
end
|
|
62
51
|
|
|
63
52
|
private
|
|
64
53
|
|
|
65
|
-
def factor
|
|
66
|
-
(1.0 +
|
|
54
|
+
def factor(interest_rate:, frequency: 1.0, periods: 1)
|
|
55
|
+
(1.0 + interest_rate / frequency)**(frequency * periods).to_f
|
|
67
56
|
end
|
|
68
57
|
|
|
69
|
-
def
|
|
70
|
-
1.0 /
|
|
58
|
+
def nth_root(frequency: 1)
|
|
59
|
+
1.0 / frequency
|
|
71
60
|
end
|
|
72
61
|
end
|
|
73
62
|
end
|
|
@@ -1,57 +1,42 @@
|
|
|
1
1
|
module FinancialMath
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@present_value = args.fetch(:present_value, 0)
|
|
7
|
-
@periods = args.fetch(:periods, 0)
|
|
8
|
-
# frequency of conversions
|
|
9
|
-
@frequency = args.fetch(:frequency, 1.0)
|
|
10
|
-
@interest_rate = args.fetch(:interest_rate, 0)
|
|
11
|
-
@future_value = args.fetch(:future_value, 0)
|
|
12
|
-
@bank_discount_rate = args.fetch(:bank_discount_rate, 0)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def bank_discount_rate
|
|
16
|
-
@bank_discount_rate = (discount / future_value).round(2)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def discount
|
|
20
|
-
(@future_value - @present_value).round(2)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def future_value
|
|
24
|
-
@future_value = @present_value * (1 + @interest_rate * factor)
|
|
25
|
-
@future_value.round(2)
|
|
2
|
+
module SimpleInterest
|
|
3
|
+
def future_value(present_value:, interest_rate:, periods: 0, frequency: 1)
|
|
4
|
+
factor_val = factor(periods: periods, frequency: frequency)
|
|
5
|
+
(present_value * (1 + interest_rate * factor_val)).round(2)
|
|
26
6
|
end
|
|
27
7
|
|
|
28
|
-
def present_value
|
|
29
|
-
|
|
30
|
-
|
|
8
|
+
def present_value(future_value:, interest_rate:, periods: 0, frequency: 1)
|
|
9
|
+
factor_val = factor(periods: periods, frequency: frequency)
|
|
10
|
+
(future_value / (1 + interest_rate * factor_val)).round(2)
|
|
31
11
|
end
|
|
32
12
|
|
|
33
|
-
def
|
|
34
|
-
|
|
13
|
+
def interest_rate(discount_rate:, periods: 0, frequency: 1)
|
|
14
|
+
divisor = 1 - discount_rate * factor(periods: periods,
|
|
15
|
+
frequency: frequency)
|
|
16
|
+
(discount_rate / divisor).round(2)
|
|
35
17
|
end
|
|
36
18
|
|
|
37
|
-
def
|
|
38
|
-
|
|
19
|
+
def discount_rate(interest_rate:, periods: 0, frequency: 1)
|
|
20
|
+
divisor = 1 + interest_rate * factor(periods: periods,
|
|
21
|
+
frequency: frequency)
|
|
22
|
+
(interest_rate / divisor).round(2)
|
|
39
23
|
end
|
|
40
24
|
|
|
41
|
-
def
|
|
42
|
-
|
|
43
|
-
|
|
25
|
+
def rational_discount(present_value:, interest_rate:,
|
|
26
|
+
periods: 0, frequency: 1)
|
|
27
|
+
factor_val = factor(periods: periods, frequency: frequency)
|
|
28
|
+
(present_value * interest_rate * factor_val).round(2)
|
|
44
29
|
end
|
|
45
30
|
|
|
46
|
-
def
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
def bank_discount(future_value:, discount_rate:, periods: 0, frequency: 1)
|
|
32
|
+
factor_val = factor(periods: periods, frequency: frequency)
|
|
33
|
+
(future_value * discount_rate * factor_val).round(2)
|
|
49
34
|
end
|
|
50
35
|
|
|
51
36
|
private
|
|
52
37
|
|
|
53
|
-
def factor
|
|
54
|
-
periods /
|
|
38
|
+
def factor(periods: 0, frequency: 1)
|
|
39
|
+
periods / frequency.to_f
|
|
55
40
|
end
|
|
56
41
|
end
|
|
57
42
|
end
|
data/simple_interest.png
ADDED
|
Binary file
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: financial_math
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Omar Vergara Pérez
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-03-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -70,6 +70,7 @@ files:
|
|
|
70
70
|
- Rakefile
|
|
71
71
|
- bin/console
|
|
72
72
|
- bin/setup
|
|
73
|
+
- compound_interest.png
|
|
73
74
|
- financial_math.gemspec
|
|
74
75
|
- lib/financial_math.rb
|
|
75
76
|
- lib/financial_math/arithmetic_progression.rb
|
|
@@ -78,6 +79,7 @@ files:
|
|
|
78
79
|
- lib/financial_math/geometric_progression.rb
|
|
79
80
|
- lib/financial_math/simple_interest.rb
|
|
80
81
|
- lib/financial_math/version.rb
|
|
82
|
+
- simple_interest.png
|
|
81
83
|
homepage: https://github.com/dany2691/financial_math
|
|
82
84
|
licenses:
|
|
83
85
|
- MIT
|
|
@@ -97,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
97
99
|
- !ruby/object:Gem::Version
|
|
98
100
|
version: '0'
|
|
99
101
|
requirements: []
|
|
100
|
-
|
|
101
|
-
rubygems_version: 2.7.7
|
|
102
|
+
rubygems_version: 3.0.1
|
|
102
103
|
signing_key:
|
|
103
104
|
specification_version: 4
|
|
104
105
|
summary: Financial equations
|