class FinanceEngine::Time_Value_Money
Public Class Methods
find_fv(hash)
click to toggle source
# File lib/finance_engine/tvm.rb, line 12 def self.find_fv(hash) pv = future_value_cash_flow({cash_flow: hash[:pv], time: hash[:n], rate: hash[:r]}) pmt = fv_annuity(hash[:pmt], hash[:n], hash[:r]) fv = pv.to_f + pmt.to_f return fv end
find_missing_variable(hash)
click to toggle source
# File lib/finance_engine/tvm.rb, line 3 def self.find_missing_variable(hash) # attributes = {pv: present value, r: internal rate of return, fv: future value, n: number of payment periods, pmt: payment amount} return find_fv(hash) if hash[:fv].nil? return find_pv(hash) if hash[:pv].nil? return find_r(hash) if hash[:r].nil? return find_n(hash) if hash[:n].nil? return find_pmt(hash) if hash[:pmt].nil? end
find_pmt(hash)
click to toggle source
Calculates the annuity payment amount given the present value, future value, interest rate and amount of periods.
# File lib/finance_engine/tvm.rb, line 40 def self.find_pmt(hash) # r[(PV - FV)/((1 + r)^n - 1) + PV] # binding.pry pmt = hash[:r] * ((hash[:pv] - hash[:fv])/((1+hash[:r])**(hash[:n])-1) + hash[:pv]) return pmt end
find_pv(hash)
click to toggle source
# File lib/finance_engine/tvm.rb, line 19 def self.find_pv(hash) fv = present_value_cash_flow({cash_flow: hash[:fv], time: hash[:n], rate: hash[:r]}) pmt = pv_annuity(hash[:pmt], hash[:n], hash[:r]) pv = pmt + fv return pv end
future_value_cash_flow(hash)
click to toggle source
Future value of a single cash flow taking in amount, rate and time as factors.
# File lib/finance_engine/tvm.rb, line 60 def self.future_value_cash_flow(hash) cf = hash[:cash_flow] rate = hash[:rate] time = hash[:time] return (cf * ((1 + rate)**time)) end
future_value_cash_flows(years, cashflows, rates, n)
click to toggle source
Future value of a series of cash flows. Assumes payment occur at the end of period (inarrears).
# File lib/finance_engine/tvm.rb, line 68 def self.future_value_cash_flows(years, cashflows, rates, n) future_value = 0 years.each_index do |x| future_value += future_value_cash_flow({cash_flow: cashflows[x].to_f, rate: rates[x].to_f, time: n - years[x].to_f}) end return future_value end
fv_annuity(pmt,time,rate)
click to toggle source
Calculates the future value of an annuity. Both formulas below, non-loop in use.
# File lib/finance_engine/tvm.rb, line 54 def self.fv_annuity(pmt,time,rate) fv = pmt*((1+rate)**time -1)/rate return fv end
present_value_cash_flow(hash)
click to toggle source
Present value of a single cash flow with hash input of amount, rate and time.
# File lib/finance_engine/tvm.rb, line 77 def self.present_value_cash_flow(hash) cf = hash[:cash_flow] rate = hash[:rate] time = hash[:time] return (cf / ((1 + rate)**time)) end
present_value_cash_flows(years, cashflows, rates)
click to toggle source
Present value of a series of cash flows assuming varying interest rates.
# File lib/finance_engine/tvm.rb, line 85 def self.present_value_cash_flows(years, cashflows, rates) present_value = 0 years.each_index do |x| present_value += present_value_cash_flow({cash_flow: cashflows[x].to_f, rate: rates[x].to_f, time: years[x].to_f}) end return present_value end
pv_annuity(pmt,time,rate)
click to toggle source
Calculates the present value of an annuity. Both formulas below, non-loop in use.
# File lib/finance_engine/tvm.rb, line 48 def self.pv_annuity(pmt,time,rate) pv = pmt*(1-(1+rate)**-time)/rate return pv end