1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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()
|