def fivepointtostrikevol(fwd, atm, rr25, fly25, rr10, fly10, mat): ''' create volslice with atm vol transform strikes with a quadratic ''' strikevol = fivepointsmile(fwd, atm, rr25, fly25, rr10, fly10, mat) strikevolbase = fivepointsmile(fwd, atm, 0, 0, 0, 0, mat) strikevolmap = interpolate.interp1d(np.log(strikevolbase[:, 0]), np.log(strikevol[:, 0]), fill_value="extrapolate", kind=2) lbound = BS.blackstrikefordelta(atm, strikevol[0, 0], mat, -1, 0.01) ubound = BS.blackstrikefordelta(atm, strikevol[-1, 0], mat, 1, 0.01) stvol = np.ones([1000, 2]) stvol[:, 0] = np.linspace(lbound, ubound, 1000) stvol[:, 1] = atm vol = logvolslice(stvol, fwd, mat) baseprob = vol.cumdf.strikeprob prob = baseprob.copy() prob[:, 0] = [np.exp(strikevolmap(np.log(stri))) for stri in baseprob[:, 0]] prob[:, 1] = baseprob[:, 1] plt.plot(prob[:, 0], prob[:, 1], label="smile") plt.plot(baseprob[:, 0], baseprob[:, 1], label="nonsmile") plt.title("smile") plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) plt.show() strikevol = cdf(prob).getstrikevol(prob[:, 0], mat) return strikevol
def fivepointsmile(fwd, atm, rr25, fly25, rr10, fly10, mat): c25 = 0.5 * (rr25 + 2 * fly25 + 2 * atm) p25 = c25 - rr25 c10 = 0.5 * (rr10 + 2 * fly10 + 2 * atm) p10 = c10 - rr10 kc25 = BS.blackstrikefordelta(c25, fwd, mat, 1, 0.25) kc10 = BS.blackstrikefordelta(c10, fwd, mat, 1, 0.1) kp25 = BS.blackstrikefordelta(p25, fwd, mat, -1, 0.25) kp10 = BS.blackstrikefordelta(p10, fwd, mat, -1, 0.1) strikevol = np.ones((5, 2)) strikevol[0, 0] = kp10 strikevol[0, 1] = p10 strikevol[1, 0] = kp25 strikevol[1, 1] = p25 strikevol[2, 0] = fwd strikevol[2, 1] = atm strikevol[3, 0] = kc25 strikevol[3, 1] = c25 strikevol[4, 0] = kc10 strikevol[4, 1] = c10 return strikevol