-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 4 3/8% Treasury Gilt 2028 entries.
- Loading branch information
1 parent
3f4f331
commit d1015d5
Showing
3 changed files
with
52 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters