Skip to content

Commit

Permalink
new methods, v004
Browse files Browse the repository at this point in the history
  • Loading branch information
rderoldan1 committed Mar 7, 2013
1 parent 05beff9 commit cb60c1f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 17 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -54,14 +63,22 @@ 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)
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)
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

Expand Down
66 changes: 53 additions & 13 deletions lib/financial_maths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


2 changes: 1 addition & 1 deletion lib/financial_maths/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FinancialMaths
VERSION = "0.0.3"
VERSION = "0.0.4"
end

0 comments on commit cb60c1f

Please sign in to comment.