diff options
| -rw-r--r-- | python/analytics/basket_index.py | 5 | ||||
| -rw-r--r-- | python/cds_curve.py | 11 | ||||
| -rwxr-xr-x | scripts/curve.sh | 1 |
3 files changed, 13 insertions, 4 deletions
diff --git a/python/analytics/basket_index.py b/python/analytics/basket_index.py index 612fb733..6e4ec262 100644 --- a/python/analytics/basket_index.py +++ b/python/analytics/basket_index.py @@ -8,13 +8,14 @@ from pyisda.date import previous_twentieth from typing import List from yieldcurve import get_curve import datetime +import logging import numpy as np import pandas as pd from math import exp from scipy.optimize import brentq from pandas.tseries.offsets import Day, BDay - +logger = logging.getLogger(__name__) def make_index(t, d, args): instance = t.__new__(t) @@ -261,7 +262,7 @@ class BasketIndex(CreditIndex): else: break else: - print(f"couldn't calibrate for date: {self.value_date} and maturity: {m}") + logger.warning(f"couldn't calibrate for date: {self.value_date} and maturity: {m}") self.tweaks.append(np.NaN) continue self.tweaks.append(eps) diff --git a/python/cds_curve.py b/python/cds_curve.py index 1c1c2418..69157513 100644 --- a/python/cds_curve.py +++ b/python/cds_curve.py @@ -49,7 +49,8 @@ def calibrate_portfolio(index_type, series, tenors=['3yr', '5yr', '7yr', '10yr'] if __name__ == "__main__": enable_logging() import argparse - import sys + import logging + import os parser = argparse.ArgumentParser() parser.add_argument('index', help="index type (IG, HY, EU or XO)") parser.add_argument('series', help="series", type=int) @@ -68,7 +69,15 @@ if __name__ == "__main__": start_date, = c.fetchone() else: start_date = None + fh = logging.FileHandler(filename=os.path.join(os.getenv("LOG_DIR"), "index_curves.log")) + formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") + fh.setFormatter(formatter) + loggers = [logging.getLogger("analytics"), logging.getLogger("index_curves")] + for logger in loggers: + logger.setLevel(logging.INFO) + logger.addHandler(fh) + loggers[1].info(f"filling {index} {series}") g = calibrate_portfolio(index, series, ['3yr', '5yr', '7yr', '10yr'], start_date) with conn.cursor() as c: diff --git a/scripts/curve.sh b/scripts/curve.sh index 7b77deb3..4e854aeb 100755 --- a/scripts/curve.sh +++ b/scripts/curve.sh @@ -13,7 +13,6 @@ series=(22 23 24 25 26 27 28 29 30 31 32) pushd "$CODE_DIR/python" > /dev/null for index in ${indices[@]}; do for s in ${series[@]}; do - echo "filling $index$s" sem -j 4 "python cds_curve.py $index $s --latest" done done |
