aboutsummaryrefslogtreecommitdiffstats
path: root/python/ctm_allocation.py
blob: 7b6122449de785a57ce1dd376482af90f69a140d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import argparse
import datetime
from serenitas.ops.trade_dataclasses import BondDeal
from serenitas.ops.funds import CTM

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "trade_date",
        type=datetime.date.fromisoformat,
        default=datetime.date.today(),
    )
    args = parser.parse_args()
    with BondDeal._conn.cursor() as c:
        c.execute(
            "SELECT id FROM bonds LEFT JOIN counterparties ON cp_code=code "
            "WHERE trade_date=%s AND ctm_code IS NOT NULL",
            (args.trade_date,),
        )
        for (tid,) in c:
            trade = BondDeal.from_tradeid(tid)
            CTM.stage(trade)
    buf, dest = CTM.build_buffer()
    CTM.upload(buf)