aboutsummaryrefslogtreecommitdiffstats
path: root/python/compute_price.py
blob: 2d9f29e863740d06a883a17214b39f3fe27ecbf7 (plain)
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()