@@ -25,6 +25,7 @@ class Loan
2525
2626 # @return [Float] The number of periods to be compounded for. (I.e. Nper())
2727 # Defaults to 1.
28+ # You can use #nper method to calculate value if param is not defined.
2829 attr_accessor :duration
2930
3031 # @return [Float] Future value.
@@ -178,6 +179,29 @@ def fv(payment: nil)
178179 -( ( amount * factor ) + ( final_payment . to_f * second_factor ) )
179180 end
180181
182+ # Pv computes present value.
183+ # Required Loan arguments: nominal_rate, duration, payment, future_value, *ptype
184+ #
185+ # @return [Float] The present value.
186+ #
187+ # @example
188+ # require 'finance_rb'
189+ # Finance::Loan.new(nominal_rate: 0.24, duration: 12, future_value: 1000, payment: -300, ptype: :ending).pv
190+ # #=> 2384.1091906935
191+ #
192+ # @see http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formulaOpenDocument-formula-20090508.odt
193+ # @see [WRW] Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May).
194+ # Open Document Format for Office Applications (OpenDocument)v1.2,
195+ # Part 2: Recalculated Formula (OpenFormula) Format - Annotated Version,
196+ # Pre-Draft 12. Organization for the Advancement of Structured Information
197+ # Standards (OASIS). Billerica, MA, USA. [ODT Document].
198+ def pv
199+ factor = ( 1.0 + monthly_rate ) **duration
200+ second_factor = ( factor - 1 ) * ( 1 + monthly_rate * ptype ) / monthly_rate
201+
202+ -( future_value + ( payment . to_f * second_factor ) ) / factor
203+ end
204+
181205 private
182206
183207 def initialize_payment_type ( ptype )
0 commit comments