financial_math 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20641fba71319f1c2aae1437a3de7f688d318d3e7a955476ed7bd4bb06c2b36f
4
- data.tar.gz: 58df98336b4d773e3338082a3385082f1bea36cb3ddcdac2e0307bd5da14cf14
3
+ metadata.gz: b602a59e8cb6248be2b0620edcbbc24d37d7367acb3eb5b5342ccf49ebce3e92
4
+ data.tar.gz: fe86b90b686a54f8f462b8a604e0b7f53de9f066c2f7c20d4f2110d49b23ea88
5
5
  SHA512:
6
- metadata.gz: 263a95425d62390f85ca156ae2c1e1531d4f2eecfc1e7478fa26393f69d23bfca6faa4b8c6ab3739633fc032be11aad14d1bf74d445355e61b5ae1cfad50fa7d
7
- data.tar.gz: af5ef11638690f2de51c89de3e3c29192ca7afe882743525445f6e49e653277b1cfe4fa6953bf3e6918c2eff16ed8fa2ac679a22bd97bc1bf9083cefa9a0fbbd
6
+ metadata.gz: '09bf54f268a2fea8911f933767392f03ba6caf27a30ea85a22dce431df0ae44362c1c9c1d41d49555eba049d99b2ffb486f9e34bf4cb4131a763125258bdf8ce'
7
+ data.tar.gz: ac11588d785b2b00f7bfc67f878f49dc958458449fc50800692f47b21f365f8f49fe724f8a7e9c6c4bacc4198fbce99c5a89beff3e18ab6a484c4beb5d1ce958
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- financial_math (0.5.0)
4
+ financial_math (0.6.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -57,6 +57,13 @@ args = { present_value: 100_000.0, interest_rate: 0.05, periods: 3 }
57
57
  simple_interest = FinancialMath::SimpleInterest.new(args)
58
58
  simple_interest.future_value
59
59
  ```
60
+ 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
+
62
+ ```ruby
63
+ args = { present_value: 1500.0, interest_rate: 0.45, periods: 73, frequency: 360 }
64
+ simple_interest = FinancialMath::SimpleInterest.new(args)
65
+ simple_interest.future_value
66
+ ```
60
67
 
61
68
  ## Development
62
69
 
@@ -69,6 +76,10 @@ $ gem install financial_math --dev
69
76
  This command will get the development dependencies installed too.
70
77
 
71
78
  ## Release History
79
+
80
+ * 0.6.0
81
+ * ADD: Add `@frequency` to `SimpleInterest` class
82
+ * CHANGE: Change the `periods_in_days` mehtod to `factor` in `SimpleInterest`
72
83
  * 0.5.0
73
84
  * ADD: Add `average_growth_rate` and `continous_future_value` public methods to `CompoundInterest` class
74
85
  * 0.4.1
@@ -5,6 +5,8 @@ module FinancialMath
5
5
  def initialize(args)
6
6
  @present_value = args.fetch(:present_value, 0)
7
7
  @periods = args.fetch(:periods, 0)
8
+ # frequency of conversions
9
+ @frequency = args.fetch(:frequency, 1.0)
8
10
  @interest_rate = args.fetch(:interest_rate, 0)
9
11
  @future_value = args.fetch(:future_value, 0)
10
12
  @bank_discount_rate = args.fetch(:bank_discount_rate, 0)
@@ -19,45 +21,37 @@ module FinancialMath
19
21
  end
20
22
 
21
23
  def future_value
22
- @future_value = (@present_value * (1 + periods * @interest_rate)).round(2)
23
- end
24
-
25
- def future_value_in_days
26
- @future_value = @present_value * (1 + @interest_rate * periods_in_days)
24
+ @future_value = @present_value * (1 + @interest_rate * factor)
27
25
  @future_value.round(2)
28
26
  end
29
27
 
30
28
  def present_value
31
- @present_value = (@future_value / (1 + periods * @interest_rate)).round(2)
32
- end
33
-
34
- def present_value_in_days
35
- @present_value = @future_value / (1 + @interest_rate * periods_in_days)
29
+ @present_value = @future_value / (1 + @interest_rate * factor)
36
30
  @present_value.round(2)
37
31
  end
38
32
 
39
- def rational_discount_in_days
40
- (@present_value * @interest_rate * @periods_in_days).round(2)
33
+ def rational_discount
34
+ (@present_value * @interest_rate * factor).round(2)
41
35
  end
42
36
 
43
- def bank_discount_in_days
44
- (@future_value * @bank_discount_rate * @periods_in_days).round(2)
37
+ def bank_discount
38
+ (@future_value * @bank_discount_rate * factor).round(2)
45
39
  end
46
40
 
47
41
  def interest_rate_given_discount_rate
48
- divisor = 1 - @bank_discount_rate * periods_in_days
42
+ divisor = 1 - @bank_discount_rate * factor
49
43
  @interest_rate = (@bank_discount_rate / divisor).round(2)
50
44
  end
51
45
 
52
46
  def discount_rate_given_interest_rate
53
- divisor = 1 + @interest_rate * periods_in_days
47
+ divisor = 1 + @interest_rate * factor
54
48
  @bank_discount_rate = (@interest_rate / divisor).round(2)
55
49
  end
56
50
 
57
51
  private
58
52
 
59
- def periods_in_days
60
- periods / 360.0
53
+ def factor
54
+ periods / @frequency.to_f
61
55
  end
62
56
  end
63
57
  end
@@ -1,3 +1,3 @@
1
1
  module FinancialMath
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
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.5.0
4
+ version: 0.6.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: 2018-10-17 00:00:00.000000000 Z
11
+ date: 2018-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler