Skip to content

Commit

Permalink
Add 4 3/8% Treasury Gilt 2028 entries.
Browse files Browse the repository at this point in the history
  • Loading branch information
LateGenXer committed Dec 1, 2024
1 parent 3f4f331 commit d1015d5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
1 change: 1 addition & 0 deletions data/tidm.csv
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ GB00BQC4R999,TG38
GB00BQC82B83,TS29
GB00BQC82C90,TS34
GB00BQC82D08,TG40
GB00BSQNRC93,TE28
GB00BTHH2R79,T25
GB00BYMWG366,TR46
GB00BYVP4K94,TR56
Expand Down
60 changes: 50 additions & 10 deletions data/tidm.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,57 @@
#!/usr/bin/env python3
#
# Copyright (c) 2024 LateGenXer
#
# SPDX-License-Identifier: AGPL-3.0-or-later
#


import csv
import sys
import datetime
import logging
import operator
import os

from gilts.gilts import Issued
from data import lse


for entry in csv.DictReader(open('tests/data/dmo_issued.csv', 'rt')):
isin = entry['ISIN_CODE']
assert lse.is_isin(isin)
try:
tidm = lse.lookup_tidm(isin)
except (IndexError, KeyError):
continue
assert lse.is_tidm(tidm)
sys.stdout.write(f'{isin},{tidm}\n')
def main():
logging.basicConfig(format='%(asctime)s %(name)s %(levelname)s %(message)s', level=logging.INFO)

tidms = {}

for isin, tidm in csv.reader(open('data/tidm.csv', 'rt')):
assert lse.is_isin(isin)
assert lse.is_tidm(tidm)
tidms[isin] = tidm

today = datetime.datetime.now(datetime.timezone.utc).date()

for entry in csv.DictReader(open('tests/data/dmo_issued.csv', 'rt')):
isin = entry['ISIN_CODE']
assert lse.is_isin(isin)
if isin in tidms:
continue
maturity = Issued._parse_date(entry['REDEMPTION_DATE'])
if maturity < today:
continue
try:
tidm = lse.lookup_tidm(isin)
except (IndexError, KeyError):
continue
assert lse.is_tidm(tidm)
tidms[isin] = tidm

# https://realpython.com/sort-python-dictionary/
tidms = dict(sorted(tidms.items(), key=operator.itemgetter(0)))

with open('data/.tidm.csv', 'wt') as stream:
for isin, tidm in tidms.items():
stream.write(f'{isin},{tidm}\n')

os.replace('data/.tidm.csv', 'data/tidm.csv')


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions tests/data/dmo_issued.csv
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ GB00BQC4R999,3¾% Treasury Gilt 2038,2038-01-29,2022-11-09,
GB00BQC82B83,4 1/8% Treasury Gilt 2029,2029-07-22,2024-05-01,
GB00BQC82C90,4¼% Treasury Gilt 2034,2034-07-31,2024-06-12,
GB00BQC82D08,4 3/8% Treasury Gilt 2040,2040-01-31,2024-09-04,
GB00BSQNRC93,4 3/8% Treasury Gilt 2028,2028-03-07,2024-11-14,
GB00BTHH2R79,2% Treasury Gilt 2025,2025-09-07,2015-03-20,
GB00BYMWG366,0 1/8% Index-linked Treasury Gilt 2046,2046-03-22,2015-06-24,257.79000
GB00BYVP4K94,0 1/8% Index-Linked Treasury Gilt 2056,2056-11-22,2016-11-30,264.88333
Expand Down

0 comments on commit d1015d5

Please sign in to comment.