lib/financial_maths.rb in financial_maths-0.0.5 vs lib/financial_maths.rb in financial_maths-0.0.6

- old
+ new

@@ -104,37 +104,54 @@ # 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 + # == Conversion rates + + ## + # Description: Find effective rate given nominal rate expired - NVEF + # Formula: ((1 + (NOMINAL RATE / PERIODS)) ^ PERIODS) - 1 + def efective_given_nominal_due(nominal_rate, term) + ((((1+((nominal_rate.to_f/100)/term))**term)-1).round(6))*100 + end + + ## + # Description: Find effective rate given anticipated nominal rate - NAEF + # Formula: ((1 / ((1- (NOMINAL RATE / PERIODS)) ^ PERIODS)) -1 + def efective_given_nominal_anticipated(nominal_rate, term) + (((1/((1-((nominal_rate.to_f/100)/term))**term))-1)*100).round(4) + end + + ## + # Description: Find nominal rate anticipated given effective rate - EFNV + # Formulas: + # nominalRate = (1 + EFFECTIVE RATE)^(1 / PERIODS) - 1 + # toAnticipated = nominalRate / 1 + nominalRate + # Returned -> toAnticipated * PERIODS + 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 + + ## + # Description: Find nominal rate expired given effective rate - EFNV + # Formula: ((1 + EFFECTIVE RATE) ^ (1 / PERIODS) - 1)* PERIODS + 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 + + # == End conversion rates + # 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 def variable_payment(amount, periods) amount.to_f / periods end - end