diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/handle_default.py | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/python/handle_default.py b/python/handle_default.py index 06b59786..963db31d 100644 --- a/python/handle_default.py +++ b/python/handle_default.py @@ -17,7 +17,7 @@ def affected_indices(company_id: int, seniority: str, conn): sqlstr = ( "SELECT b.*, a.curr_weight*b.indexfactor AS orig_weight " "FROM basket_constituents_current a " - "JOIN (SELECT * FROM index_version WHERE lastdate='infinity') b " + "JOIN (SELECT * FROM index_factors WHERE lastdate='infinity') b " "USING (basketid) " "WHERE company_id=%s AND seniority=%s" ) @@ -29,11 +29,13 @@ def affected_indices(company_id: int, seniority: str, conn): def create_newindices(recordslist, recovery, lastdate, conn): """create the new indices versions and update the old""" - insertstr = """INSERT INTO index_version(Index, Series, Version, IndexFactor, - CumulativeLoss, lastdate) Values(%(index)s, %(series)s, %(version)s, %(indexfactor)s, - %(cumulativeloss)s, %(lastdate)s) RETURNING basketid""" + insertstr = ( + "INSERT INTO index_factors(index_id, version, indexfactor," + "cumulativeloss, lastdate) VALUES(%(index_id)s, %(version)s, %(indexfactor)s," + "%(cumulativeloss)s, %(lastdate)s) RETURNING basketid" + ) - updatestr = "UPDATE index_version SET lastdate=%s WHERE basketid=%s" + updatestr = "UPDATE index_factors SET lastdate=%s WHERE basketid=%s" with conn.cursor() as c: newids = {} @@ -64,29 +66,19 @@ def update_indexmembers(newids, company_id, seniority, conn): conn.commit() -def update_redcodes(index_type, conn): - if index_type == "HY": - index_subfamily = "CDX.NA.HY" - elif index_type == "IG": - index_subfamily = "CDX.NA.IG" - elif index_type == "EU": - index_subfamily = "iTraxx Europe" - elif index_type == "XO": - index_subfamily = "iTraxx Europe Crossover" - elif index_type == "HYBB": - index_subfamily = "CDX.NA.HY.BB" - elif index_type == "BS": - return - +def update_redcodes(conn): with conn.cursor() as c: c.execute( - "UPDATE index_version SET redindexcode=index_version_markit.redindexcode " - "FROM index_version_markit WHERE index_version.series=index_version_markit.series " - "AND index_version.version=index_version_markit.version " - "AND index_version.index=%s " - "AND index_version_markit.indexsubfamily=%s" - "AND index_version.redindexcode IS NULL", - (index_type, index_subfamily), + "UPDATE INDEX_factors SET redindexcode=ivm.redindexcode FROM index_version_markit ivm " + "RIGHT JOIN index_series ON index_series.series=ivm.series AND indexsubfamily=( " + "CASE INDEX " + "WHEN 'HY' THEN 'CDX.NA.HY' " + "WHEN 'IG' THEN 'CDX.NA.IG' " + "WHEN 'EU' THEN 'iTraxx Europe' " + "WHEN 'XO' THEN 'iTraxx Europe Crossover' " + "WHEN 'HYBB' THEN 'CDX.NA.HY.BB' END) " + "WHERE ivm.VERSION=index_factors.VERSION AND index_series.index_id=index_factors.index_id " + "AND index_factors.redindexcode is NULL" ) conn.commit() @@ -111,6 +103,5 @@ For instance: recordslist = affected_indices(company_id, seniority, conn) newids = create_newindices(recordslist, recovery, lastdate, conn) update_indexmembers(newids, company_id, seniority, conn) - for index in set(r.index for r in recordslist): - update_redcodes(index, conn) + update_redcodes(conn) serenitas_pool.putconn(conn) |
