Accuracy of midpoint convention¶

We reproduce the chart of slide 17 of chapter 4 fo my corp fin class.

In [5]:
import numpy as np
import matplotlib.pyplot as plt #graphing module with matlab-like properties
%matplotlib inline 
import math

dis1= lambda x:1/(1+x)**0.5 # this is the midpoint discounting approach
dis2= lambda x:1/np.log(1+x)*(1-(1/(1+x))) # this is the exact discounting when cash-flows are uniform

rrange=np.arange(start=0.01, stop=0.5, step=0.05) # set a range of EARs

plt.plot(rrange,[dis1(r) for r in rrange], label='midpoint')
plt.plot(rrange,[dis2(r) for r in rrange], label='exact')
plt.xlabel('EAR')
plt.ylabel('discount factor')
plt.title('Accuracy of midpoint convention')
plt.legend()
Out[5]:
<matplotlib.legend.Legend at 0x19161c47380>
No description has been provided for this image