Class: FinancialCalculator::Ppmt
- Inherits:
-
Object
- Object
- FinancialCalculator::Ppmt
- Includes:
- Validator
- Defined in:
- lib/financial_calculator/ppmt.rb
Overview
Calculates the principal portion of a loan or annuity for a particular period
Instance Attribute Summary collapse
-
#future_value ⇒ Numeric
readonly
The ending value of the annuity.
-
#num_periods ⇒ Numeric
readonly
The number of payments to be made.
-
#pay_at_beginning ⇒ Boolean
readonly
Whether the payment is made at the beginning of the period (true) or end of the period (false).
-
#period ⇒ Numeric
readonly
The amortization period.
-
#present_value ⇒ Numeric
readonly
The current value of the annuity.
-
#rate ⇒ Numeric
readonly
The rate used for calculating the payment amount.
-
#result ⇒ DecNum
readonly
Result of the PMT calculation.
Instance Method Summary collapse
-
#initialize(rate, period, num_periods, present_value, future_value = 0, pay_at_beginning = false) ⇒ FinancialCalculator::Npv
constructor
Create a new object for calculating the periodic payment of an ordinary annuity.
- #inspect ⇒ Object
-
#pays_at_beginning? ⇒ Boolean
Whether the payments are made at the beginning of each period.
Constructor Details
#initialize(rate, period, num_periods, present_value, future_value = 0, pay_at_beginning = false) ⇒ FinancialCalculator::Npv
Create a new object for calculating the periodic payment of an ordinary annuity
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/financial_calculator/ppmt.rb', line 44 def initialize(rate, period, num_periods, present_value, future_value = 0, pay_at_beginning = false) validate_numerics(rate: rate, period: period, num_periods: num_periods, present_value: present_value, future_value: future_value) @rate = Flt::DecNum(rate.to_s) @period = Flt::DecNum(period) @num_periods = Flt::DecNum(num_periods.to_s) @present_value = Flt::DecNum(present_value.to_s) @future_value = Flt::DecNum(future_value.to_s) @pay_at_beginning = pay_at_beginning @result = solve(@rate, @period, @num_periods, @present_value, @future_value, @pay_at_beginning) end |
Instance Attribute Details
#future_value ⇒ Numeric (readonly)
Returns The ending value of the annuity. Defaults to 0.
24 25 26 |
# File 'lib/financial_calculator/ppmt.rb', line 24 def future_value @future_value end |
#num_periods ⇒ Numeric (readonly)
Returns The number of payments to be made.
16 17 18 |
# File 'lib/financial_calculator/ppmt.rb', line 16 def num_periods @num_periods end |
#pay_at_beginning ⇒ Boolean (readonly)
Returns Whether the payment is made at the beginning of the period (true) or end of the period (false).
29 30 31 |
# File 'lib/financial_calculator/ppmt.rb', line 29 def pay_at_beginning @pay_at_beginning end |
#period ⇒ Numeric (readonly)
Returns The amortization period.
12 13 14 |
# File 'lib/financial_calculator/ppmt.rb', line 12 def period @period end |
#present_value ⇒ Numeric (readonly)
Returns The current value of the annuity.
20 21 22 |
# File 'lib/financial_calculator/ppmt.rb', line 20 def present_value @present_value end |
#rate ⇒ Numeric (readonly)
Returns The rate used for calculating the payment amount.
8 9 10 |
# File 'lib/financial_calculator/ppmt.rb', line 8 def rate @rate end |
#result ⇒ DecNum (readonly)
Returns Result of the PMT calculation.
33 34 35 |
# File 'lib/financial_calculator/ppmt.rb', line 33 def result @result end |
Instance Method Details
#inspect ⇒ Object
62 63 64 |
# File 'lib/financial_calculator/ppmt.rb', line 62 def inspect "PPMT(#{result})" end |
#pays_at_beginning? ⇒ Boolean
Returns Whether the payments are made at the beginning of each period.
58 59 60 |
# File 'lib/financial_calculator/ppmt.rb', line 58 def pays_at_beginning? @pay_at_beginning end |