aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics/ir_swaption.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics/ir_swaption.py')
-rw-r--r--python/analytics/ir_swaption.py49
1 files changed, 32 insertions, 17 deletions
diff --git a/python/analytics/ir_swaption.py b/python/analytics/ir_swaption.py
index 762625f4..a83b6cd8 100644
--- a/python/analytics/ir_swaption.py
+++ b/python/analytics/ir_swaption.py
@@ -9,13 +9,24 @@ from quantlib.settings import Settings
from yieldcurve import YC
-class IRSwaption():
+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, yc=None):
- self._qloption = (MakeSwaption(swap_index, option_tenor, strike).
- with_nominal(notional).
- with_underlying_type(SwapType[option_type.title()])())
+
+ def __init__(
+ self,
+ swap_index,
+ option_tenor,
+ strike,
+ option_type="payer",
+ direction="Long",
+ notional=10_000_000,
+ yc=None,
+ ):
+ self._qloption = (
+ MakeSwaption(swap_index, option_tenor, strike)
+ .with_nominal(notional)
+ .with_underlying_type(SwapType[option_type.title()])()
+ )
if type(direction) is bool:
self._direction = 2 * direction - 1
else:
@@ -26,7 +37,7 @@ class IRSwaption():
@property
def direction(self):
- if self._direction == 1.:
+ if self._direction == 1.0:
return "Long"
else:
return "Short"
@@ -34,9 +45,9 @@ class IRSwaption():
@direction.setter
def direction(self, d):
if d == "Long":
- self._direction = 1.
+ self._direction = 1.0
elif d == "Short":
- self._direction = -1.
+ self._direction = -1.0
else:
raise ValueError("Direction needs to be either 'Long' or 'Short'")
@@ -53,17 +64,21 @@ class IRSwaption():
self._sigma.value = s
def from_tradeid(trade_id):
- with dbconn('dawndb') as conn:
+ with dbconn("dawndb") as conn:
with conn.cursor() as c:
- c.execute("SELECT * from swaptions "
- "WHERE id = %s", (trade_id,))
+ c.execute("SELECT * from swaptions " "WHERE id = %s", (trade_id,))
rec = c.fetchone()
- yc = YC(evaluation_date=rec['trade_date'], fixed=True)
- p = Period(int(rec['security_id'].replace("USISDA", "")), Years)
+ yc = YC(evaluation_date=rec["trade_date"], fixed=True)
+ p = Period(int(rec["security_id"].replace("USISDA", "")), Years)
swap_index = UsdLiborSwapIsdaFixAm(p, yc)
- instance = IRSwaption(swap_index, Date.from_datetime(rec['expiration_date']),
- rec['strike'], rec['option_type'], rec['buysell'],
- rec['notional'])
+ instance = IRSwaption(
+ swap_index,
+ Date.from_datetime(rec["expiration_date"]),
+ rec["strike"],
+ rec["option_type"],
+ rec["buysell"],
+ rec["notional"],
+ )
return instance
@property