diff options
| -rw-r--r-- | python/cds_curve.py | 8 | ||||
| -rw-r--r-- | python/markit/import_quotes.py | 12 | ||||
| -rw-r--r-- | python/thetas-durations.py | 7 | ||||
| -rwxr-xr-x | scripts/curve.sh | 2 |
4 files changed, 18 insertions, 11 deletions
diff --git a/python/cds_curve.py b/python/cds_curve.py index 8875abf8..02e8639e 100644 --- a/python/cds_curve.py +++ b/python/cds_curve.py @@ -63,7 +63,7 @@ if __name__ == "__main__": import os parser = argparse.ArgumentParser() - parser.add_argument("index", help="index type (IG, HY, EU or XO)") + parser.add_argument("index", help="index type (IG, HY, EU, XO or HYBB)") parser.add_argument("series", help="series", type=int) parser.add_argument("--latest", required=False, action="store_true") args = parser.parse_args() @@ -95,7 +95,11 @@ if __name__ == "__main__": logger.addHandler(fh) loggers[1].info(f"filling {index} {series}") - g = calibrate_portfolio(index, series, ["3yr", "5yr", "7yr", "10yr"], start_date) + if index == "HYBB": + tenors = ["5yr"] + else: + tenors = ["3yr", "5yr", "7yr", "10yr"] + g = calibrate_portfolio(index, series, tenors, start_date) with conn.cursor() as c: for id, t in g: c.execute( diff --git a/python/markit/import_quotes.py b/python/markit/import_quotes.py index 22339bfe..568252ec 100644 --- a/python/markit/import_quotes.py +++ b/python/markit/import_quotes.py @@ -179,6 +179,7 @@ def insert_index(engine, workdate=None): name_mapping = { "CDXNAHY": "HY", + "CDX NAHYBB": "HYBB", "CDXNAIG": "IG", "iTraxx Eur": "EU", "iTraxx Eur Xover": "XO", @@ -217,9 +218,7 @@ def insert_index(engine, workdate=None): for col in cols: data[col] = data[col].str.replace("%", "").astype("float") data["tenor"] = data["tenor"].apply(lambda x: x.lower() + "r") - data["index"] = data["index"].apply( - lambda x: name_mapping[x] if x in name_mapping else np.NaN - ) + data["index"] = data["index"].map(name_mapping) data = data.dropna(subset=["index"]) data["close_spread"] *= 100 data["model_spread"] *= 100 @@ -227,9 +226,10 @@ def insert_index(engine, workdate=None): data.loc[data.series.isin([9, 10, 11]) & (data.index == "HY"), "version"] -= 3 # data = data.groupby(['index', 'series', 'tenor', 'date'], as_index=False).last() data["source"] = "MKIT" - data[ext_cols].to_sql( - "index_quotes_pre", engine, if_exists="append", index=False - ) + place_holders = ",".join(["%s"] * len(ext_cols)) + sql_str = (f"INSERT INTO index_quotes_pre({','.join(ext_cols)}) " + f"VALUES({place_holders}) ON CONFLICT DO NOTHING") + engine.execute(sql_str, list(data[ext_cols].itertuples(index=False))) def insert_tranche(engine, workdate=None): diff --git a/python/thetas-durations.py b/python/thetas-durations.py index 89d477e2..feffc869 100644 --- a/python/thetas-durations.py +++ b/python/thetas-durations.py @@ -15,6 +15,7 @@ tenors = { "HY": ("3yr", "5yr", "7yr"), "EU": ("3yr", "5yr", "7yr", "10yr"), "XO": ("3yr", "5yr", "7yr", "10yr"), + "HYBB": ("5yr",), } sql_str = "INSERT INTO index_risk VALUES(%s, %s, %s)" @@ -57,14 +58,16 @@ def index_pv(fl, cl, value_date, step_in_date, cash_settle_date, yc, sc, recover if __name__ == "__main__": conn = serenitas_engine.raw_connection() - for index in ["IG", "HY", "EU", "XO"]: - if index in ["HY", "XO"]: + for index in ["IG", "HY", "EU", "XO", "HYBB"]: + if index in ["HY", "HYBB"]: recoveries = np.full(len(tenors[index]), 0.3) else: recoveries = np.full(len(tenors[index]), 0.4) for series in range(18, 34): if index in ["EU", "XO"] and series == 33: continue + if index == "HYBB" and series != 33: + continue fee_legs, contingent_legs, df = get_legs(index, series, tenors[index]) index_quotes = pd.read_sql_query( diff --git a/scripts/curve.sh b/scripts/curve.sh index 83f18d81..5aafef7f 100755 --- a/scripts/curve.sh +++ b/scripts/curve.sh @@ -8,7 +8,7 @@ #done #done #popd > /dev/null -indices=("EU" "IG" "HY" "XO") +indices=("EU" "IG" "HY" "XO" "HYBB") series=(22 23 24 25 26 27 28 29 30 31 32 33) pushd "$CODE_DIR/python" > /dev/null for index in ${indices[@]}; do |
