financial_maths 0.0.9 → 0.0.10

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
  SHA1:
3
- metadata.gz: 04b02170a3ad7239e2f09675d5cdd0a7589864c6
4
- data.tar.gz: f8ab2f8c2007857eeb0f042cadc11037e819f0da
3
+ metadata.gz: 13c87971dac11e54b8ea062a728043248cc9dd7c
4
+ data.tar.gz: 00f5e26cb70ecd67eeb78d6622958788f9e98385
5
5
  SHA512:
6
- metadata.gz: 9af1f0dbce744ef3b590262e7505bfcd3472b7495d62a7f159cd9e2c5f3188a1053a899ec12403b023f1b6a0ca07d1029d917db25f1004020fc7a25db89c5236
7
- data.tar.gz: 35021e2b5fe02bae0b64d2405041e785c34c79fe3e138f7f8cdf55da780b4a85ec4ba7d03bdafdbd6b595b716ec728abe0baa901c45a69c120b014cffb08690d
6
+ metadata.gz: eea9ef44b4d44ef4119e7f50be408914b252ad23f75db5401da959c7db0558ee2b8495df92b36c8ce15a3f968150940fa4ec5ceea3fb36dc7b6a4e5ce3e0f2de
7
+ data.tar.gz: b449f2d0c6659624799fb57b49c2da4653f9f95333e2dbfe6161a5628c807403b00dfba119a491e8bc319cfbcb7eb69387bdec6cd20a326924038550cd39a206
@@ -1,3 +1,3 @@
1
1
  module FinancialMaths
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -59,11 +59,13 @@ module FinancialMaths
59
59
 
60
60
  def anticipated_fixed_payment_amortization(periods, amount, rate, payment)
61
61
  result = []
62
- #result << {:period=> 0, :monthly_payment => nil, :interest => nil, :payment => nil, :balance => amount}
62
+ result << {:period=> 0, :monthly_payment => nil,
63
+ :interest => amount * rate, :payment => nil,
64
+ :balance => amount}
63
65
 
64
- for i in 0..periods-1
65
- interest = amount * rate
66
- month_payment = payment - interest
66
+ for i in 1..periods
67
+ month_payment = payment * ((1-rate) ** (periods - i))
68
+ interest = payment - month_payment
67
69
  amount -= month_payment
68
70
  #date += 1
69
71
  result << {:period=> i,
@@ -107,33 +109,33 @@ module FinancialMaths
107
109
  end
108
110
 
109
111
  # == Conversion rates
110
-
111
- ##
112
+
113
+ ##
112
114
  # Description: Find effective rate given nominal rate expired - NVEF
113
115
  # Formula: ((1 + (NOMINAL RATE / PERIODS)) ^ PERIODS) - 1
114
116
  def efective_given_nominal_due(nominal_rate, term)
115
117
  ((((1+((nominal_rate.to_f/100)/term))**term)-1).round(6))*100
116
118
  end
117
-
119
+
118
120
  ##
119
121
  # Description: Find effective rate given anticipated nominal rate - NAEF
120
122
  # Formula: ((1 / ((1- (NOMINAL RATE / PERIODS)) ^ PERIODS)) -1
121
123
  def efective_given_nominal_anticipated(nominal_rate, term)
122
124
  (((1/((1-((nominal_rate.to_f/100)/term))**term))-1)*100).round(4)
123
125
  end
124
-
126
+
125
127
  ##
126
128
  # Description: Find nominal rate anticipated given effective rate - EFNV
127
- # Formulas:
129
+ # Formulas:
128
130
  # nominalRate = (1 + EFFECTIVE RATE)^(1 / PERIODS) - 1
129
131
  # toAnticipated = nominalRate / 1 + nominalRate
130
132
  # Returned -> toAnticipated * PERIODS
131
133
  def nominal_anticipated_given_efective(effective_rate, periods)
132
134
  nominalRate = (1+(effective_rate.to_f/100))**(1/periods.to_f)-1
133
135
  toAnticipated = nominalRate / (1+nominalRate)
134
- (toAnticipated * periods.to_f * 100).round(4)
136
+ (toAnticipated * periods.to_f * 100).round(4)
135
137
  end
136
-
138
+
137
139
  ##
138
140
  # Description: Find nominal rate expired given effective rate - HCUA
139
141
  # Formula: ((1 + EFFECTIVE RATE) ^ (1 / PERIODS) - 1)* PERIODS
@@ -149,11 +151,10 @@ module FinancialMaths
149
151
  end
150
152
 
151
153
  # == End conversion rates
152
-
154
+
153
155
  # Hallar la cuota fija anticipada HCFA
154
156
  def anticipated_fixed_payment(present_value, rate, term)
155
- a_rate = anticipated_interest(rate, term)
156
- ((present_value.to_f * a_rate.to_f) / ((a_rate.to_f + 1) - (1 / (1 + a_rate) ** (term - 1)))).round(4)
157
+ ((present_value.to_f) / ((1 - (1 - rate.to_f ) ** term ) / rate.to_f )).round(4)
157
158
  end
158
159
 
159
160
  def variable_payment(amount, periods)
@@ -161,5 +162,3 @@ module FinancialMaths
161
162
  end
162
163
 
163
164
  end
164
-
165
-
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.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Espinosa
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-11 00:00:00.000000000 Z
12
+ date: 2014-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler