1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| import matplotlib.pyplot as plt
def compute_fv(p, i, n): ''' 计算复利终值 p是本金,i是利率,n是约定期限 ''' return p * (1 + i) ** n
p = 1000 ir = 0.05 n = 20
x = [x for x in range(1, n)] y = [compute_fv(p, ir, x) for x in range(1, n)]
plt.plot(x, y, "b^-", label="ir="+str(ir)) plt.xlabel("year") plt.ylabel("fv") plt.legend() plt.grid() plt.show()
|