Module: FinancialMaths
- Defined in:
- lib/financial_maths.rb,
lib/financial_maths/version.rb
Constant Summary collapse
- VERSION =
"0.0.7"
Instance Method Summary collapse
-
#annuity_given_future(future_value, interest, term) ⇒ Object
hallar anualidad dado el valor futuro HADF.
-
#annuity_given_present(present_value, interest, term) ⇒ Object
hallar Anualidad dado el valor presente HADP.
-
#anticipated_fixed_payment(present_value, rate, term) ⇒ Object
Hallar la cuota fija anticipada HCFA.
- #anticipated_fixed_payment_amortization(periods, amount, rate, payment) ⇒ Object
- #anticipated_variable_payment_amortization(periods, amount, rate, payment) ⇒ Object
- #due_fixed_payment_amortization(periods, amount, rate, payment) ⇒ Object
- #due_variable_payment_amortization(periods, amount, rate, payment) ⇒ Object
-
#efective_given_nominal_anticipated(nominal_rate, term) ⇒ Object
Description: Find effective rate given anticipated nominal rate - NAEF Formula: ((1 / ((1- (NOMINAL RATE / PERIODS)) ^ PERIODS)) -1.
-
#efective_given_nominal_due(nominal_rate, term) ⇒ Object
Description: Find effective rate given nominal rate expired - NVEF Formula: ((1 + (NOMINAL RATE / PERIODS)) ^ PERIODS) - 1.
-
#future_given_annuity(annuity, interest, term) ⇒ Object
hallar futuro dado la anualidad HFDA.
-
#future_given_present(present_value, interest, term) ⇒ Object
hallar futuro dado el valor presente HFDP.
-
#nominal_anticipated_given_efective(effective_rate, periods) ⇒ Object
Description: Find nominal rate anticipated given effective rate - EFNV Formulas: nominalRate = (1 + EFFECTIVE RATE)^(1 / PERIODS) - 1 toAnticipated = nominalRate / 1 + nominalRate Returned -> toAnticipated * PERIODS.
-
#nominal_due_given_efective(effective_rate, periods) ⇒ Object
Description: Find nominal rate expired given effective rate - EFNV Formula: ((1 + EFFECTIVE RATE) ^ (1 / PERIODS) - 1)* PERIODS.
-
#present_given_annuity(annuity, interest, term) ⇒ Object
hallar presente dado la anualidad HPDA.
-
#present_given_future(future_value, interest, term) ⇒ Object
hallar presente dado el futuro HPDF.
- #variable_payment(amount, periods) ⇒ Object
Instance Method Details
#annuity_given_future(future_value, interest, term) ⇒ Object
hallar anualidad dado el valor futuro HADF
95 96 97 |
# File 'lib/financial_maths.rb', line 95 def annuity_given_future(future_value, interest, term) (future_value.to_f * (interest.to_f / ((1 + interest) ** term)-1)).round(4) end |
#annuity_given_present(present_value, interest, term) ⇒ Object
hallar Anualidad dado el valor presente HADP
89 90 91 92 |
# File 'lib/financial_maths.rb', line 89 def annuity_given_present(present_value, interest, term) interest = interest.to_f (present_value.to_f * ((interest * (1+interest) ** term) / (((1 + interest) ** term) -1))).round(4) end |
#anticipated_fixed_payment(present_value, rate, term) ⇒ Object
Hallar la cuota fija anticipada HCFA
147 148 149 |
# File 'lib/financial_maths.rb', line 147 def anticipated_fixed_payment(present_value, rate, term) ((present_value.to_f * rate.to_f) / ((rate.to_f + 1) - (1 / (1 + rate) ** (term - 1)))).round(4) end |
#anticipated_fixed_payment_amortization(periods, amount, rate, payment) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/financial_maths.rb', line 60 def anticipated_fixed_payment_amortization(periods, amount, rate, payment) result = [] #result << {:period=> 0, :monthly_payment => nil, :interest => nil, :payment => nil, :balance => amount} for i in 0..periods-1 interest = amount * rate month_payment = payment - interest amount -= month_payment #date += 1 result << {:period=> i, :payment => payment, :interest => interest, :monthly_payment => month_payment, :balance => amount} end result end |
#anticipated_variable_payment_amortization(periods, amount, rate, payment) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/financial_maths.rb', line 23 def anticipated_variable_payment_amortization(periods, amount, rate, payment) result = [] #result << {:period=> 0, :monthly_payment => nil, :interest => nil, :payment => nil, :balance => amount} for i in 0..periods-1 interest = amount * rate month_payment = payment + interest amount -= payment #date += 1 result << {:period=> i, :payment => month_payment, :interest => interest, :monthly_payment => payment, :balance => amount} end result end |
#due_fixed_payment_amortization(periods, amount, rate, payment) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/financial_maths.rb', line 42 def due_fixed_payment_amortization(periods, amount, rate, payment) result = [] result << {:period=> 0, :monthly_payment => nil, :interest => nil, :payment => nil, :balance => amount} for i in 1..periods interest = amount * rate month_payment = payment - interest amount -= month_payment #date += 1 result << {:period=> i, :payment => payment, :interest => interest, :monthly_payment => month_payment, :balance => amount} end result end |
#due_variable_payment_amortization(periods, amount, rate, payment) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/financial_maths.rb', line 5 def due_variable_payment_amortization(periods, amount, rate, payment) result = [] result << {:period=> 0, :monthly_payment => nil, :interest => nil, :payment => nil, :balance => amount} for i in 1..periods interest = amount * rate month_payment = payment + interest amount -= payment #date += 1 result << {:period=> i, :payment => month_payment, :interest => interest, :monthly_payment => payment, :balance => amount} end result end |
#efective_given_nominal_anticipated(nominal_rate, term) ⇒ Object
Description: Find effective rate given anticipated nominal rate - NAEF Formula: ((1 / ((1- (NOMINAL RATE / PERIODS)) ^ PERIODS)) -1
121 122 123 |
# File 'lib/financial_maths.rb', line 121 def efective_given_nominal_anticipated(nominal_rate, term) (((1/((1-((nominal_rate.to_f/100)/term))**term))-1)*100).round(4) end |
#efective_given_nominal_due(nominal_rate, term) ⇒ Object
Description: Find effective rate given nominal rate expired - NVEF Formula: ((1 + (NOMINAL RATE / PERIODS)) ^ PERIODS) - 1
114 115 116 |
# File 'lib/financial_maths.rb', line 114 def efective_given_nominal_due(nominal_rate, term) ((((1+((nominal_rate.to_f/100)/term))**term)-1).round(6))*100 end |
#future_given_annuity(annuity, interest, term) ⇒ Object
hallar futuro dado la anualidad HFDA
105 106 107 |
# File 'lib/financial_maths.rb', line 105 def future_given_annuity(annuity, interest, term) (annuity * (((1 + interest.to_f) ** term) -1) / interest.to_f ).round(4) end |
#future_given_present(present_value, interest, term) ⇒ Object
hallar futuro dado el valor presente HFDP
79 80 81 |
# File 'lib/financial_maths.rb', line 79 def future_given_present(present_value, interest, term) (present_value.to_f * (1 + interest.to_f) ** term).round(4) end |
#nominal_anticipated_given_efective(effective_rate, periods) ⇒ Object
Description: Find nominal rate anticipated given effective rate - EFNV Formulas:
nominalRate = (1 + EFFECTIVE RATE)^(1 / PERIODS) - 1
toAnticipated = nominalRate / 1 + nominalRate
Returned -> toAnticipated * PERIODS
131 132 133 134 135 |
# File 'lib/financial_maths.rb', line 131 def nominal_anticipated_given_efective(effective_rate, periods) nominalRate = (1+(effective_rate.to_f/100))**(1/periods.to_f)-1; toAnticipated = nominalRate / (1+nominalRate) (toAnticipated * periods.to_f * 100).round(4) end |
#nominal_due_given_efective(effective_rate, periods) ⇒ Object
Description: Find nominal rate expired given effective rate - EFNV Formula: ((1 + EFFECTIVE RATE) ^ (1 / PERIODS) - 1)* PERIODS
140 141 142 |
# File 'lib/financial_maths.rb', line 140 def nominal_due_given_efective(effective_rate, periods) ((((1 + (effective_rate.to_f/100))**(1/periods.to_f)-1)*periods.to_f)*100).round(4) end |
#present_given_annuity(annuity, interest, term) ⇒ Object
hallar presente dado la anualidad HPDA
100 101 102 |
# File 'lib/financial_maths.rb', line 100 def present_given_annuity(annuity, interest, term) (annuity.to_f * (((1 + interest.to_f) ** term) -1) / (interest.to_f * (1 + interest.to_f) ** term )).round(4) end |
#present_given_future(future_value, interest, term) ⇒ Object
hallar presente dado el futuro HPDF
84 85 86 |
# File 'lib/financial_maths.rb', line 84 def present_given_future(future_value, interest, term) (future_value.to_f / (1 +interest.to_f) ** term).round(4) end |
#variable_payment(amount, periods) ⇒ Object
151 152 153 |
# File 'lib/financial_maths.rb', line 151 def variable_payment(amount, periods) amount.to_f / periods end |