aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/handle_default.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/python/handle_default.py b/python/handle_default.py
index 4f82c629..daf2fbf1 100644
--- a/python/handle_default.py
+++ b/python/handle_default.py
@@ -1,6 +1,7 @@
-from db import serenitasdb
+from db import dbconn
import datetime
from sys import argv
+from __future__ import division
def affected_indices(company_id):
"""returns the list of indices containing company_id"""
@@ -25,9 +26,9 @@ def create_newindices(recordslist, lastdate, nissuers):
with serenitasdb.cursor() as c:
newids = {}
for r in recordslist:
- r['indexfactor'] -= 1
+ r['indexfactor'] -= 100/nissuers
r['version'] += 1
- r['cumulativeloss'] += 1-recovery/float(nissuers)
+ r['cumulativeloss'] += 1/float(nissuers)(1-recovery/100)
r['lastdate'] = 'infinity'
c.execute(insertstr, r)
newids[r['basketid']] = c.fetchone()[0]
@@ -51,11 +52,11 @@ if __name__=="__main__":
For instance:
python handle_default.py 210065 2015-02-19 15.875 100""")
else:
- company_id = int(argv[1])
- lastdate = datetime.datetime.strptime(argv[2], "%Y-%m-%d")
- recovery = float(argv[3])
- n_issuers = float(argv[4])
- recordslist = affected_indices(company_id)
- newids = create_newindices(recordslist, lastdate, n_issuers)
- update_indexmembers(newids, company_id)
- serenitasdb.close()
+ with dbconn('serenitasdb') as serenitasdb:
+ company_id = int(argv[1])
+ lastdate = datetime.datetime.strptime(argv[2], "%Y-%m-%d")
+ recovery = float(argv[3])
+ n_issuers = float(argv[4])
+ recordslist = affected_indices(company_id)
+ newids = create_newindices(recordslist, lastdate, n_issuers)
+ update_indexmembers(newids, company_id)