aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/compute_price.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/python/compute_price.py b/python/compute_price.py
new file mode 100644
index 00000000..2d9f29e8
--- /dev/null
+++ b/python/compute_price.py
@@ -0,0 +1,22 @@
+from db import dbconn
+from analytics import Index
+serenitasdb = dbconn('serenitasdb')
+to_insert = []
+with serenitasdb.cursor() as c:
+ c.execute("SELECT date, index, series, version, tenor, closespread FROM "
+ "index_quotes WHERE closespread IS NOT NULL and closeprice is NULL")
+ for r in c:
+ index = Index.from_name(r['index'], r['series'], r['tenor'], value_date=r['date'],
+ notional=100)
+ try:
+ index.spread = r['closespread']
+ except ValueError:
+ continue
+ else:
+ to_insert.append(
+ (index.price, r['index'], r['series'], r['tenor'], r['version'], r['date']))
+with serenitasdb.cursor() as c:
+ c.executemany("UPDATE index_quotes SET closeprice=%s WHERE index=%s AND "
+ "series=%s AND tenor=%s AND version=%s AND date=%s",
+ to_insert)
+serenitasdb.commit()