From cb60c1f7baf55fcb51eb0ccbd82a6cc1acf9affa Mon Sep 17 00:00:00 2001 From: Ruben Espinosa Date: Thu, 7 Mar 2013 14:08:31 -0500 Subject: [PATCH] new methods, v004 --- README.md | 23 ++++++++++-- lib/financial_maths.rb | 66 +++++++++++++++++++++++++++------- lib/financial_maths/version.rb | 2 +- 3 files changed, 74 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 186b863..8957fb9 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,22 @@ more functions will be added soon +#### New in version 0.0.4 + + 1. Amortization tables + 2. efective_given_nominal_due(nominal_rate, term) + 3. efective_given_nominal_antipipated + 4. nominal_antipiated_given_efective + 5. nominal_due_given_efective + 6. anticipated_fixed_payment + #### New in version 0.0.3 1. future_given_present 2. present_given_future 3. annuity_given_present 4. annuity_given_future - 5. present_given_annuity( + 5. present_given_annuity 6. future_given_annuity #### Pending @@ -42,7 +51,7 @@ A credit in a period of 15 years, the amount is $100.000.000 and the interest is call the method following the next instruction. ```ruby -fixed_payment_equity(15,100000000,0.0144594763) +variable_payment_amortization(15,100000000,0.0144594763) ``` The result is a hash with the plan of payments, it looks like that @@ -54,7 +63,7 @@ The result is a hash with the plan of payments, it looks like that . ] -The lists of the methods and they params +The lists of the methods and their params future_given_present(present_value, interest, term) present_given_future(future_value, interest, term) @@ -62,6 +71,14 @@ The lists of the methods and they params annuity_given_future(future_value, interest, term) present_given_annuity(annuity, interest, term) future_given_annuity(annuity, interest, term) + efective_given_nominal_due(nominal_rate, term) + efective_given_nominal_antipipated(nominal_rate, term) + nominal_antipiated_given_efective(nominal_rate, term) + nominal_due_given_efective(nominal_rate, term) + anticipated_fixed_payment(present_value, rate, term) + + variable_payment_amortization(periods, amount, rate) + fixed_payment_amortization(periods, amount, rate, payment) ## Contributing diff --git a/lib/financial_maths.rb b/lib/financial_maths.rb index 96f8a58..5242797 100644 --- a/lib/financial_maths.rb +++ b/lib/financial_maths.rb @@ -2,14 +2,14 @@ module FinancialMaths - def fixed_payment_equity(year, amount, year_interest) - years = year*12 - monthly_payments = amount/years + def variable_payment_amortization(periods, amount, rate) + + monthly_payments = amount/periods result = [] result << {:period=> 0, :monthly_payment => nil, :interest => nil, :payment => nil, :balance => amount} - for i in 1..years - interest = amount * year_interest + for i in 1..periods + interest = amount * rate month_payment = monthly_payments + interest amount -= monthly_payments #date += 1 @@ -22,40 +22,80 @@ def fixed_payment_equity(year, amount, year_interest) result end - def fixed_payment_amortization(year, amount, year_interest) + def 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 - # hallar futuro dado el valor presente + # hallar futuro dado el valor presente HFDP def future_given_present(present_value, interest, term) (present_value.to_f * (1 + interest.to_f) ** term).round(4) end - # hallar presente dado el futuro + # hallar presente dado el futuro HPDF def present_given_future(future_value, interest, term) (future_value.to_f / (1 +interest.to_f) ** term).round(4) end - # hallar Anualidad dado el valor presente + # hallar Anualidad dado el valor presente HADP def annuity_given_present(present_value, interest, term) - (present_value.to_f * ((interest *(1+interest.to_f) ** term) / ((1 + interest.to_f) ** term) -1)).round(4) + interest = interest.to_f + (present_value.to_f * ((interest * (1+interest) ** term) / (((1 + interest) ** term) -1))).round(4) end - # hallar anualidad dado el valor futuro + # hallar anualidad dado el valor futuro HADF def annuity_given_future(future_value, interest, term) (future_value.to_f * (interest.to_f / ((1 + interest) ** term)-1)).round(4) end - # hallar presente dado la anualidad + # hallar presente dado la anualidad HPDA 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 - # hallar futuro dado la anualidad + # hallar futuro dado la anualidad HFDA def future_given_annuity(annuity, interest, term) (annuity * (((1 + interest.to_f) ** term) -1) / interest.to_f ).round(4) end + # hallar tasa efectiva dado la tasa nominal vencida NVEF + def efective_given_nominal_due(nominal_rate, term) + (((1 + nominal_rate.to_f) ** term)-1).round(4) + end + + # hallar tasa efectiva dado la tasa nominal anticipada NAEF + def efective_given_nominal_antipipated(nominal_rate, term) + (1 / ((1 - nominal_rate.to_f) ** term)).round(4) - 1 + end + + # hallar tasa nominal anticipada dado efectiva EFNV + def nominal_antipiated_given_efective(nominal_rate, term) + (1 - (1 / (1 + nominal_rate.to_f) ** (1 / term))).round(4) + end + + # hallar tasa nominal anticipada dado efectiva EFNV + def nominal_due_given_efective(nominal_rate, term) + ((nominal_rate.to_f + 1) ** (1 / term)).round(4) + end + # Hallar la cuota fija anticipada HCFA + 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 + + end diff --git a/lib/financial_maths/version.rb b/lib/financial_maths/version.rb index 9a17e1b..8b6b83d 100644 --- a/lib/financial_maths/version.rb +++ b/lib/financial_maths/version.rb @@ -1,3 +1,3 @@ module FinancialMaths - VERSION = "0.0.3" + VERSION = "0.0.4" end