class FinancialCalculator::Ppmt

Calculates the principal portion of a loan or annuity for a particular period

Attributes

future_value[R]

@return [Numeric] The ending value of the annuity. Defaults to 0 @api public

num_periods[R]

@return [Numeric] The number of payments to be made @api public

pay_at_beginning[R]

@return [Boolean] Whether the payment is made at the beginning of the

period (true) or end of the period (false)

@api public

period[R]

@return [Numeric] The amortization period @api public

present_value[R]

@return [Numeric] The current value of the annuity @api public

rate[R]

@return [Numeric] The rate used for calculating the payment amount @api public

result[R]

@return [DecNum] Result of the PMT calculation @api public

Public Class Methods

new(rate, period, num_periods, present_value, future_value = 0, pay_at_beginning = false) click to toggle source

Create a new object for calculating the periodic payment of an ordinary annuity @param [Numeric] rate The discount (interest) rate @param [Numeric] period The amortization period @param [Numeric] num_periods The number of payments to be made @param [Numeric] present_value The current value of the annuity @param [Numeric] future_value The ending value of the annuity @param [Boolean] pay_at_beginning. Whether the payment is made at the beginning

of the period (true) or end of the period (false)

@return [FinancialCalculator::Npv] An instance of a PMT calculation

# 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

Public Instance Methods

inspect() click to toggle source
# File lib/financial_calculator/ppmt.rb, line 62
def inspect
  "PPMT(#{result})"
end
pays_at_beginning?() click to toggle source

@return [Boolean] Whether the payments are made at the beginning of each period @api public

# File lib/financial_calculator/ppmt.rb, line 58
def pays_at_beginning?
  @pay_at_beginning
end

Private Instance Methods

solve(rate, period, nper, pv, fv, pay_at_beginning) click to toggle source
# File lib/financial_calculator/ppmt.rb, line 68
def solve(rate, period, nper, pv, fv, pay_at_beginning)
  payment = FinancialCalculator::Pmt.new(rate, nper, pv, fv, pay_at_beginning).result
  ipmt = FinancialCalculator::Ipmt.new(rate, period, nper, pv, fv, pay_at_beginning).result
  @result = payment - ipmt
end