aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/calibrate_tranches_BC.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/python/calibrate_tranches_BC.py b/python/calibrate_tranches_BC.py
index e8ce2c2f..bda7ed6f 100644
--- a/python/calibrate_tranches_BC.py
+++ b/python/calibrate_tranches_BC.py
@@ -1,5 +1,5 @@
from utils.db import dbconn
-from analytics import TrancheBasket
+from analytics.tranche_basket import TrancheBasket, MarkitTrancheBasket
from pandas.tseries.offsets import BDay
import datetime
import logging
@@ -23,13 +23,13 @@ def get_lastdate(conn, index, series, tenor):
return date
-def build_sql_str(df):
+def build_sql_str(df, use_markit=False):
cols = ",".join(df.columns)
cols_ex_tranche_id = ",".join([c for c in df.columns if c != "tranche_id"])
cols_excluded = ",".join([f"excluded.{c}" for c in df.columns if c != "tranche_id"])
place_holders = ",".join([f"%({c})s" for c in df.columns])
sql_str = (
- f"INSERT INTO tranche_risk({cols}) "
+ f"INSERT INTO {'markit_' if use_markit else ''}tranche_risk({cols}) "
f"VALUES({place_holders}) ON CONFLICT (tranche_id) DO "
f"UPDATE SET ({cols_ex_tranche_id}) = ({cols_excluded})"
)
@@ -68,8 +68,12 @@ if __name__ == "__main__":
parser.add_argument(
"-s", "--skewtype", action="store", help="skew type", default="bottomup"
)
+ parser.add_argument("-m", "--markit", action="store_true", help="Use Markit quotes")
args = parser.parse_args()
logger.setLevel(logging.DEBUG if args.debug else logging.INFO)
+ if args.markit:
+ TrancheBasket = MarkitTrancheBasket
+
CODE_DIR = Path(os.environ["CODE_DIR"])
if not args.debug:
handler = SerenitasFileHandler(f"calib_tranches_{datetime.date.today()}.log")
@@ -199,7 +203,7 @@ if __name__ == "__main__":
if data:
data = pd.concat(data)
- sql_str = build_sql_str(data)
+ sql_str = build_sql_str(data, args.markit)
with serenitas_conn.cursor() as c:
c.executemany(sql_str, data.to_dict(orient="record"))
serenitas_conn.commit()