from quantlib.indexes.api import UsdLiborSwapIsdaFixAm from quantlib.time.api import Period, Years from yieldcurve import get_yc class IRSwaption(): """ adapter class for the QuantLib code""" def __init__(self, swap_index, option_tenor, strike, option_type="payer", direction="Long", notional=10_000_000): self._qloption = (MakeSwaption(swap_index, option_tenor, strike). withNominal(notional). withUnderlyingType(SwapType[option_type.title()])) def from_tradeid(trade_id): with dbconn('dawndb') as conn: with conn.cursor() as c: c.execute("SELECT * from swaption " "WHERE id = %s", (trade_id,)) rec = c.fetchone() p = Period(int(rec.security_id.replace("USIDA", "")), Years) swap_index = UsdLiborSwapIsdaFixAm(p, yc) MakeSwaption(