Skip to content

Commit

Permalink
5 functions more
Browse files Browse the repository at this point in the history
  • Loading branch information
rderoldan1 committed Mar 5, 2013
1 parent d408047 commit 05beff9
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 19 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -22,15 +35,14 @@ require "financial_maths"

include FinancialMaths

calculate = Credit.new
```

### Calculate Fixed payment equity
A credit in a period of 15 years, the amount is $100.000.000 and the interest is 1.44594763%,
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

Expand All @@ -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

Expand Down
71 changes: 55 additions & 16 deletions lib/financial_maths.rb
Original file line number Diff line number Diff line change
@@ -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


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.1"
VERSION = "0.0.3"
end

0 comments on commit 05beff9

Please sign in to comment.