diff --git a/README.md b/README.md index a8d2878..186b863 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,19 @@ more functions will be added soon +#### 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( + 6. future_given_annuity + +#### Pending + 1. include more functions + 3. add some test units + ## Installation Add this line to your application's Gemfile: @@ -22,7 +35,6 @@ require "financial_maths" include FinancialMaths -calculate = Credit.new ``` ### Calculate Fixed payment equity @@ -30,7 +42,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 -calculate.fixed_payment_equity(15,100000000,0.0144594763) +fixed_payment_equity(15,100000000,0.0144594763) ``` The result is a hash with the plan of payments, it looks like that @@ -42,6 +54,14 @@ The result is a hash with the plan of payments, it looks like that . ] +The lists of the methods and they params + + future_given_present(present_value, interest, term) + present_given_future(future_value, interest, term) + annuity_given_present(present_value, interest, term) + annuity_given_future(future_value, interest, term) + present_given_annuity(annuity, interest, term) + future_given_annuity(annuity, interest, term) ## Contributing diff --git a/lib/financial_maths.rb b/lib/financial_maths.rb index 7056c2d..96f8a58 100644 --- a/lib/financial_maths.rb +++ b/lib/financial_maths.rb @@ -1,22 +1,61 @@ require "financial_maths/version" module FinancialMaths - class Credit - def fixed_payment_equity(year, amount, year_interest) - years = year*12 - monthly_payments = amount/years - result = [] - result << {:period=> 0, :monthly_payment => nil, :interest => nil, :payment => nil, :balance => amount} - - for i in 1..years - interest = amount * year_interest - month_payment = monthly_payments + interest - amount -= monthly_payments - #date += 1 - result << {:period=> i, :payment => month_payment, :interest => interest, :monthly_payment => monthly_payments, :balance => amount} - end - result + + def fixed_payment_equity(year, amount, year_interest) + years = year*12 + monthly_payments = amount/years + result = [] + result << {:period=> 0, :monthly_payment => nil, :interest => nil, :payment => nil, :balance => amount} + + for i in 1..years + interest = amount * year_interest + month_payment = monthly_payments + interest + amount -= monthly_payments + #date += 1 + result << {:period=> i, + :payment => month_payment, + :interest => interest, + :monthly_payment => monthly_payments, + :balance => amount} end + result + end + + def fixed_payment_amortization(year, amount, year_interest) + + end + + # hallar futuro dado el valor presente + 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 + 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 + 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) + end + + # hallar anualidad dado el valor futuro + 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 + 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 + def future_given_annuity(annuity, interest, term) + (annuity * (((1 + interest.to_f) ** term) -1) / interest.to_f ).round(4) + end + end + + diff --git a/lib/financial_maths/version.rb b/lib/financial_maths/version.rb index 310cb22..9a17e1b 100644 --- a/lib/financial_maths/version.rb +++ b/lib/financial_maths/version.rb @@ -1,3 +1,3 @@ module FinancialMaths - VERSION = "0.0.1" + VERSION = "0.0.3" end