Class: FinanceMath::Loan
- Inherits:
-
Object
- Object
- FinanceMath::Loan
- Defined in:
- lib/finance_math/loan.rb
Overview
the Loan class provides an interface for working with interest rates.
Instance Attribute Summary collapse
-
#amount ⇒ Float
The amount of loan request.
-
#currency_protection ⇒ DecNum
readonly
The currency protection.
-
#duration ⇒ Integer
The duration for which the rate is valid, in months.
-
#fee ⇒ Float
readonly
Fee.
-
#monthly_rate ⇒ DecNum
readonly
The monthly rate.
-
#nominal_rate ⇒ Float
The nominal annual rate.
-
#principal ⇒ DecNum
readonly
P principal.
-
#structure_fee ⇒ DecNum
readonly
The fee for the bank/market.
Instance Method Summary collapse
- #apr ⇒ Object
-
#initialize(options = {}) ⇒ Loan
constructor
create a new Loan instance.
- #pmt(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Loan
create a new Loan instance
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/finance_math/loan.rb', line 49 def initialize( = {}) @nominal_rate = .fetch(:nominal_rate).to_f @duration = .fetch(:duration).to_f @amount = .fetch(:amount).to_f @structure_fee = .fetch(:structure_fee, 5).to_f @currency_protection = .fetch(:currency_protection, 3).to_f @fee = .fetch(:fee, 0).to_f @nominal_rate, @amount, @duration, @structure_fee, @currency_protection, @fee = nominal_rate.to_f, amount, duration, structure_fee.to_f, currency_protection.to_f, fee.to_f @principal = principal_calculation @monthly_rate = @nominal_rate / 100 / 12 end |
Instance Attribute Details
#amount ⇒ Float
Returns the amount of loan request.
11 12 13 |
# File 'lib/finance_math/loan.rb', line 11 def amount @amount end |
#currency_protection ⇒ DecNum (readonly)
Returns the currency protection.
23 24 25 |
# File 'lib/finance_math/loan.rb', line 23 def currency_protection @currency_protection end |
#duration ⇒ Integer
Returns the duration for which the rate is valid, in months.
7 8 9 |
# File 'lib/finance_math/loan.rb', line 7 def duration @duration end |
#fee ⇒ Float (readonly)
Returns fee.
35 36 37 |
# File 'lib/finance_math/loan.rb', line 35 def fee @fee end |
#monthly_rate ⇒ DecNum (readonly)
Returns the monthly rate.
19 20 21 |
# File 'lib/finance_math/loan.rb', line 19 def monthly_rate @monthly_rate end |
#nominal_rate ⇒ Float
Returns the nominal annual rate.
15 16 17 |
# File 'lib/finance_math/loan.rb', line 15 def nominal_rate @nominal_rate end |
#principal ⇒ DecNum (readonly)
Returns P principal.
31 32 33 |
# File 'lib/finance_math/loan.rb', line 31 def principal @principal end |
#structure_fee ⇒ DecNum (readonly)
Returns the fee for the bank/market.
27 28 29 |
# File 'lib/finance_math/loan.rb', line 27 def structure_fee @structure_fee end |
Instance Method Details
#apr ⇒ Object
67 68 69 |
# File 'lib/finance_math/loan.rb', line 67 def apr @apr ||= calculate_apr end |
#pmt(options = {}) ⇒ Object
61 62 63 64 65 |
# File 'lib/finance_math/loan.rb', line 61 def pmt( = {}) future_value = .fetch(:future_value, 0) type = .fetch(:type, 0) ((@amount * interest(@monthly_rate, @duration) - future_value ) / ((1.0 + @monthly_rate * type) * fvifa(@monthly_rate, duration))) end |