blob: 8bcf96cabe61712c67d20a6e692313feea082e4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
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(
|