Calculate interest rate of mortgage payment in python

151 Views Asked by At

I am trying to compute the interest rate of mortgage in python .

I have below formula. a/{[(1+r)^n]-1}/[r(1+r)^n]=p

Here I have the value for a ,n , p.

is it possible to calculate r using these values in python. Any pointers will help.

1

There are 1 best solutions below

0
On

You can have a look at Sympy package which could help.

from sympy.solvers import solve
from sympy import Symbol
x = Symbol('x')
solve(x**2 - 1, x)

Replace x**2 - 1 by your equation with respect to r (shift p to the left side).