Class: FinancialCalculator::Pmt
- Inherits:
-
Object
- Object
- FinancialCalculator::Pmt
- Includes:
- Validator
- Defined in:
- lib/financial_calculator/pmt.rb
Overview
Calculates the payment of an ordinary annuity
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).
-
#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, 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, 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
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/financial_calculator/pmt.rb', line 39 def initialize(rate, num_periods, present_value, future_value = 0, pay_at_beginning = false) validate_numerics(rate: rate, num_periods: num_periods, present_value: present_value, future_value: future_value) @rate = Flt::DecNum(rate.to_s) @num_periods = Flt::DecNum(num_periods.to_s) @present_value = Flt::DecNum(present_value.to_s) @future_value = Flt::DecNum(future_value || "0") @pay_at_beginning = pay_at_beginning || false @result = solve(@rate, @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.
20 21 22 |
# File 'lib/financial_calculator/pmt.rb', line 20 def future_value @future_value end |
#num_periods ⇒ Numeric (readonly)
Returns The number of payments to be made.
12 13 14 |
# File 'lib/financial_calculator/pmt.rb', line 12 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).
25 26 27 |
# File 'lib/financial_calculator/pmt.rb', line 25 def pay_at_beginning @pay_at_beginning end |
#present_value ⇒ Numeric (readonly)
Returns The current value of the annuity.
16 17 18 |
# File 'lib/financial_calculator/pmt.rb', line 16 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/pmt.rb', line 8 def rate @rate end |
#result ⇒ DecNum (readonly)
Returns Result of the PMT calculation.
29 30 31 |
# File 'lib/financial_calculator/pmt.rb', line 29 def result @result end |
Instance Method Details
#inspect ⇒ Object
56 57 58 |
# File 'lib/financial_calculator/pmt.rb', line 56 def inspect "PMT(#{result})" end |
#pays_at_beginning? ⇒ Boolean
Returns Whether the payments are made at the beginning of each period.
52 53 54 |
# File 'lib/financial_calculator/pmt.rb', line 52 def pays_at_beginning? @pay_at_beginning end |