diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/db.py | 5 | ||||
| -rw-r--r-- | python/insert_index.py | 64 | ||||
| -rw-r--r-- | python/yieldcurve.py | 8 |
3 files changed, 46 insertions, 31 deletions
diff --git a/python/db.py b/python/db.py index 5a4e10c8..38a152c3 100644 --- a/python/db.py +++ b/python/db.py @@ -7,6 +7,11 @@ conn = psycopg2.connect(database="ET", host="debian", cursor_factory=DictCursor) +connmlpdb = psycopg2.connect(database="mlpdb", + user="mlpdb_user", + password="Serenitas1", + host="debian", + cursor_factory=DictCursor) def with_connection(f): def with_connection_(*args, **kwargs): # or use a pool, or a factory function... diff --git a/python/insert_index.py b/python/insert_index.py index 1223b0f0..ce130fcd 100644 --- a/python/insert_index.py +++ b/python/insert_index.py @@ -6,11 +6,11 @@ metadata = MetaData(bind = engine) index_desc = Table('index_desc', metadata, autoload=True)
index_ins = index_desc.insert()
-offset=182970
-# index = [[offset, 'EU', 19, datetime.date(2016, 06, 20), 'Y3', 100, 0],
-# [offset, 'EU', 19, datetime.date(2018, 06, 20), 'Y5', 100, 0],
-# [offset, 'EU', 19, datetime.date(2020, 06, 20), 'Y7', 100, 0],
-# [offset, 'EU', 19, datetime.date(2023, 06, 20), 'Y10', 100, 0]]
+offset=183000
+index = [[offset, 'EU', 21, datetime.date(2017, 6, 20), 'Y3', 100, 0],
+ [offset, 'EU', 21, datetime.date(2019, 6, 20), 'Y5', 100, 0],
+ [offset, 'EU', 21, datetime.date(2021, 6, 20), 'Y7', 100, 0],
+ [offset, 'EU', 21, datetime.date(2024, 6, 20), 'Y10', 100, 0]]
# index = [[offset, 'HY', 21, datetime.date(2016, 12, 20), 'Y3', 100, 0],
# [offset, 'HY', 21, datetime.date(2018, 12, 20), 'Y5', 100, 0],
@@ -38,31 +38,41 @@ for line in index: tranche_desc = Table('tranche_desc', metadata, autoload = True)
tranche_ins = tranche_desc.insert()
-igbasketid = 182990
-igattach = [0, 3, 7, 15, 100]
-igtenors = ['Y3', 'Y5', 'Y7', 'Y10']
-for tenor in igtenors:
- for i, (attach, detach) in enumerate(zip(igattach[:-1], igattach[1:])):
- with engine.begin() as conn:
- conn.execute(tranche_ins,
- trancheid = igbasketid+i,
- basketid = igbasketid,
- tenor = tenor,
- attach=attach,
- detach = detach)
+# igbasketid = 182990
+# igattach = [0, 3, 7, 15, 100]
+# igtenors = ['Y3', 'Y5', 'Y7', 'Y10']
+# for tenor in igtenors:
+# for i, (attach, detach) in enumerate(zip(igattach[:-1], igattach[1:])):
+# with engine.begin() as conn:
+# conn.execute(tranche_ins,
+# trancheid = igbasketid+i,
+# basketid = igbasketid,
+# tenor = tenor,
+# attach=attach,
+# detach = detach)
+
+# hybasketid = 182970
+# hyattach = [0, 15, 25, 35, 100]
+# hytenors = ['Y3', 'Y5', 'Y7']
+# for tenor in hytenors:
+# for i, (attach, detach) in enumerate(zip(hyattach[:-1], hyattach[1:])):
+# with engine.begin() as conn:
+# conn.execute(tranche_ins,
+# trancheid = hybasketid+i,
+# basketid = hybasketid,
+# tenor = tenor,
+# attach = attach,
+# detach = detach)
-hybasketid = 182970
-hyattach = [0, 15, 25, 35, 100]
-hytenors = ['Y3', 'Y5', 'Y7']
-for tenor in hytenors:
- for i, (attach, detach) in enumerate(zip(hyattach[:-1], hyattach[1:])):
+eubasketid = 183000
+euattach = [0, 3, 6, 12, 100]
+eutenors = ['Y3', 'Y5']
+for tenor in eutenors:
+ for i, (attach, detach) in enumerate(zip(euattach[:-1], euattach[1:])):
with engine.begin() as conn:
conn.execute(tranche_ins,
- trancheid = hybasketid+i,
- basketid = hybasketid,
+ trancheid =eubasketid+i,
+ basketid = eubasketid,
tenor = tenor,
attach = attach,
detach = detach)
-
-# euattach = [0, 3, 6, 9, 12, 22, 100]
-# eutenors = ['Y3', 'Y5', 'Y7']
diff --git a/python/yieldcurve.py b/python/yieldcurve.py index 50588aa6..23f411a8 100644 --- a/python/yieldcurve.py +++ b/python/yieldcurve.py @@ -50,15 +50,15 @@ def YC(date = datetime.date.today(), MarkitData=None, futures = None): futures = get_futures_data(date.date()) m = libor_market('USD(NY)') quotes = [('ED',i+1, v) for i, v in enumerate(futures)] - # if next_imm_date(date, 9) == pydate_to_qldate(date) + Period('2Yr'): - # quotes.pop(8) + if next_imm_date(date, 9) == m.settle_date + Period('2Yr'): + quotes.pop(7) quotes += [('SWAP', k, v) for k, v in MarkitData['swaps'].items()] m.set_quotes(date, quotes) - ts = m.bootstrap_term_structure(interpolator='linear') + ts = m.bootstrap_term_structure() return ts if __name__=="__main__": - date = datetime.date(2013, 12, 23) + date = datetime.datetime(2014, 4, 29) ts = YC(date) cal = Calendar.from_name('USA') p1 = Period('1Mo') |
