AppDividend
Latest Code Tutorials

Numpy pv: How to Use np pv() Method in Python

Python numpy pv() is an inbuilt NumPy financial function that is used to compute the Future Values. Present value (PV) is the current value given a defined rate of return of a future amount of money or cash flow stream.

NumPy pv()

NumPy fv() function is used to compute the future value. Future cash flows are measured at the discount rate, and the higher the discount rate, the lower the potential cash flows ‘present value.

The pv is calculated using the following equation:

fv +pv*(1+rate)**nper +  pmt*(1 + rate*when)/rate*((1 + rate)**nper - 1) == 0

If the rate is equal to 0, then the equation will be:

fv + pv + pmt * nper == 0

Syntax

numpy.pv(rate, nper, pmt, pv, when='end')

This function takes 5 arguments:

  1. rate: This is a decimal value that indicates the rate of interest per period. This can be a scalar or an array.
  2. nper: This indicates a total compounding period. This can be a scalar or an array.
  3. pmt: This parameter indicates the fixed payment. This can be a scalar or an array.
  4. fv: This parameter indicates the future value. This can be a scalar or an array. The default value is 0.0
  5. when: At the beginning (when = {‘begin’, 1}) or the end (when = {‘end’, 0}) of each period.

Return Value

The NumPy pv() function returns a float type value, which indicates the Present Value after the nper period.

Program to show the working of pv() when values are scalar

# Working of pv() when all values are scalar
import numpy as np

# Assigning values to required variables
rate = 0.10
nper = 10 * 12
pmt = -200
fv = 1100

# Now we will calculate Presnt Value based on the given values
print("Future Value after a period of ", nper, " is :")
print(np.fv(rate, nper, pmt, fv, when='end'))

Output

Future Value after a period of  120  is :
83436161.93604787

Explanation

In this example, we can see that we have first initialized the values of rate, nper, pmt, and fv, and then we have called np.pv() to calculate the Present Value. 

We can see that, as our all given values are scalar, the result we got is in scalar and float data type.

Program to show the working of pv() when values are in the array

See the following code.

# Working of pv() when values are in array
import numpy as np

# Assigning values to required variables
rate = np.array((.12, .30, .45))
nper = np.array((100, 120, 50))
pmt = (100, -300, -100)
fv = (-100, 50, 150)

# Now we will calculate Present Value based on the given values
print("Present Value after a period of ", nper, " is :")
print(np.fv(rate, nper, pmt, fv, when='end'))

Output

Present Value after a period of  [100 120  50]  is :
[-6.12488282e+07  4.47636903e+16  8.45416944e+09]

Explanation

In this example, we have initialized the values of rate, nper, pmt, and fv as array values, and then we have called np.pv() to calculate the Present Value. 

As all the given values are in the array, the result we got is in array data type. In this specific example, we have an array size of 3, so the result we got is of size 3.

See also

NumPy identity()

NumPy roll()

NumPy eye()

NumPy npv()

NumPy fv()

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.