<jupyter_start><jupyter_text>Read IRSM FORM<jupyter_code>irsmform, irsmout = [xml_parser.get_files(regex, 'monocurve') for regex in ['irsmform', 'irsmout']]

debug_df = pd.DataFrame()
main_curve, sprds = xml_parser.get_rate_curves(irsmform)
dsc_curve = main_curve

try:
    estim_curve = sprds[0]
except TypeError:
    estim_curve = main_curve

cal_basket = list(xml_parser.get_calib_basket(irsmform))
mr = xml_parser.get_hw_params(irsmform).meanR<jupyter_output><empty_output><jupyter_text>READ IRSM OUT<jupyter_code>ref_swos = list(xml_parser.get_calib_basket(irsmout))
ref_mr = mr
ref_sigmas = xml_parser.get_hw_params(irsmout).hw_volatility<jupyter_output><empty_output><jupyter_text>Hernard pricer with its ref sigma<jupyter_code>calib_premiumsH = []


for swo in cal_basket:

    henr_price, debug = henr.hw_swo(swo, ref_mr, ref_sigmas, dsc_curve, estim_curve)
    debug_df = pd.concat([debug_df, pd.DataFrame(data=debug)], sort=False)
    calib_premiumsH.append(henr_price)

calib_premiumsH
cal_basket<jupyter_output><empty_output><jupyter_text>HW Calibration<jupyter_code>sigma_hw_henr, debug_H = hw_calib.calibrate_sigma_hw(cal_basket, ref_mr, dsc_curve, estim_curve, IsJamsh=False)
sigma_hw_henr
df = pd.DataFrame(debug_H)
df
df.mkt_var
df.tvar_schrager
df.var_hw
from collections import namedtuple
a = namedtuple('calib_debug', 'expiries sigma_hw schrager var_hw black_price')
len('expiries sigma_hw schrager var_hw black_price'.split())
sigma_hw_henr.values - ref_sigmas.values
fig = plt.figure()
plt.figure(figsize=(15,5))

# plt.step(sigma_hw_jamsh.buckets, sigma_hw_jamsh.values, label = 'Jamshidian', marker='o', where='post')
plt.step(sigma_hw_henr.buckets[:-1],   sigma_hw_henr.values[:-1],   label = 'Henrard', marker='o', where='pre')
plt.step(ref_sigmas.buckets[:-1], ref_sigmas.values[:-1], label = 'ref log', marker='o', where='pre')

# plt.ylim(0)
plt.legend(loc='lower right')
plt.title('calibrated Hull White piecewise constant volatility')
plt.xlabel('expiries')
plt.ylabel('volatility')
pricesH = []
for swo in cal_basket:
    henr_price, debug = henr.hw_swo(swo, ref_mr, sigma_hw_henr, dsc_curve, estim_curve)
    pricesH.append(henr_price)
pricesJ = []
for swo in cal_basket:
    jamsh_price, debug = jamsh.hw_swo(swo, ref_mr, sigma_hw_jamsh, dsc_curve, estim_curve)
    pricesJ.append(jamsh_price)
fig = plt.figure()
plt.figure(figsize=(20,10))

ref_calib_prices = [ref_swo.cal_premium for ref_swo in ref_swos]
black_prices = pd.DataFrame(data=debug_H).black_price

prices_dict = { 'Jamshidian (calibrated sigma)': array(pricesJ),
               
               'Henrard (calibrated sigma)':array(pricesH),
               'Henrard(<RefSigma>)': array(calib_premiumsH),
               
               '<CalibratedPrice>': array(ref_calib_prices),        
#                'Black': array(black_prices)
              }
              
for lbl, prices in prices_dict.items():
    plt.plot([swo.expiry for swo in cal_basket], prices - black_prices,  label = lbl, linestyle=choice([':', '--', '-.']), marker = 'o')

plt.title('Black difference ')
plt.legend(loc='lower right')
array(ref_calib_prices) - array(pricesH)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup