diff options
| -rw-r--r-- | python/calibrate_swaption.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/python/calibrate_swaption.py b/python/calibrate_swaption.py index ce145224..19f6150e 100644 --- a/python/calibrate_swaption.py +++ b/python/calibrate_swaption.py @@ -1,3 +1,4 @@ +import logging import pandas as pd from analytics import CreditIndex, Swaption import datetime @@ -50,11 +51,15 @@ def calib(option, ref, strike, pay_bid, pay_offer, rec_bid, rec_offer): else: mid = (rec_bid + rec_offer) / 2 * 1e-4 option.option_type = 'receiver' + if mid == 0.: + logging.info("0. mid, skipping.") + r.append(0.) + continue try: setattr(option, pv_type, mid) except ValueError as e: r.append(None) - print(e) + logging.error(e) else: r.append(option.sigma) return r @@ -79,7 +84,11 @@ def calibrate(index_type=None, series=None, date=None, nproc=4, latest=False): trade_date, index_type, series = k index = CreditIndex(index_type, series, "5yr", trade_date) for expiry, df in v.groupby(['expiry']): - option = Swaption(index, expiry.date(), 100) + try: + option = Swaption(index, expiry.date(), 100) + except ValueError as e: + logging.error(e) + continue mycalib = partial(calib, option) r = pstarmap(mycalib, df[['ref', 'strike', 'pay_bid', 'pay_offer', 'rec_bid', 'rec_offer']]. |
