def bondprice(ytm, period, par, coupon): price_bond = par*coupon/2*(1-(1+ytm/2)**(-2*period))/(ytm/2) + par/(1+ytm/2)**(2*period) return price_bond # create a list of YTMs from 0.01 to 0.50 ytm_list = [x/100 for x in range(1, 51)] print(ytm_list) # create a list of bond prices output = [] for element in ytm_list: output.append(bondprice(ytm=element, period=50, par=1000, coupon=0.10)) print(output) from matplotlib import pyplot as plt plt.plot(ytm_list, output) plt.show()