Class: FinancialCalculator::Npv
- Inherits:
-
Object
- Object
- FinancialCalculator::Npv
- Defined in:
- lib/financial_calculator/npv.rb
Overview
Calculates the present value of a series of equally spaced cashflows of unequal amounts
Instance Attribute Summary collapse
-
#cashflows ⇒ Arrray<Numeric>
readonly
An array of cashflow amounts.
-
#rate ⇒ Numeric
readonly
The rates used for calculating the present value.
-
#result ⇒ DecNum
readonly
Result of the XNPV calculation.
Instance Method Summary collapse
-
#initialize(rate, cashflows) ⇒ FinancialCalculator::Npv
constructor
Create a new net present value calculation.
- #inspect ⇒ Object
Constructor Details
#initialize(rate, cashflows) ⇒ FinancialCalculator::Npv
Create a new net present value calculation
22 23 24 25 26 27 28 |
# File 'lib/financial_calculator/npv.rb', line 22 def initialize(rate, cashflows) raise ArgumentError.new("Rate must be a Numeric. Got #{rate.class} instead") unless rate.is_a? Numeric @rate = rate @cashflows = cashflows @result = solve(rate, cashflows) end |
Instance Attribute Details
#cashflows ⇒ Arrray<Numeric> (readonly)
Returns An array of cashflow amounts.
11 12 13 |
# File 'lib/financial_calculator/npv.rb', line 11 def cashflows @cashflows end |
#rate ⇒ Numeric (readonly)
Returns The rates used for calculating the present value.
7 8 9 |
# File 'lib/financial_calculator/npv.rb', line 7 def rate @rate end |
#result ⇒ DecNum (readonly)
Returns Result of the XNPV calculation.
15 16 17 |
# File 'lib/financial_calculator/npv.rb', line 15 def result @result end |
Instance Method Details
#inspect ⇒ Object
30 31 32 |
# File 'lib/financial_calculator/npv.rb', line 30 def inspect "NPV(#{result})" end |