aboutsummaryrefslogtreecommitdiffstats
path: root/python/insert_fx_id.py
blob: de9cda36d37cd70b3af413d028497a2fd1a617ad (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import argparse
import datetime
import pandas as pd
from serenitas.utils.env import DAILY_DIR
from serenitas.analytics.dates import prev_business_day
from serenitas.utils.db import dawn_engine
from collateral.baml_isda import load_excel


FX_REPORT_COLUMNS = [
    "cpty_id",
    "trade_date",
    "settle_date",
    "buy_currency",
    "buy_amount",
    "sell_currency",
    "sell_amount",
]


def get_tag(fund):
    if fund == "Serenitas":
        return "TSLP"
    elif fund == "BowdSt":
        return "TLLC"
    elif fund == "Selene":
        return "INC"
    else:
        return ""


def read_BAMSNY(fund, cob):
    REPORTS_DIR = DAILY_DIR / fund / "BoA_reports"
    fname = next(
        REPORTS_DIR.glob(f"301__LMCG_INVESTMEN{get_tag(fund)}_CSA_{cob:%m%d%Y}_*")
    )
    df = load_excel(fname)
    df = df[df["ProductID"] == "FX_Fwd"]
    df = df[
        [
            "Back Office Number",
            "Trade Date",
            "Maturity Date",
            "Ccy1",
            "Notional 1",
            "Ccy2",
            "Notional 2",
        ]
    ]
    df.columns = FX_REPORT_COLUMNS
    return df


def read_MSCSNY(fund, cob):
    df = pd.read_excel(
        DAILY_DIR / fund / "MS_reports" / f"Trade_Detail_FX_{cob:%Y%m%d}.xls"
    )
    df = df[
        [
            "trade_id",
            "trade_date",
            "settlement_date",
            "buy_ccy",
            "amt_buy_ccy",
            "sell_ccy",
            "amt_sell_ccy",
        ]
    ]
    df.columns = FX_REPORT_COLUMNS
    return df


def get_forwards(cob):
    return pd.read_sql_query("SELECT * FROM forwards", con=dawn_engine)


def main(cob):
    for fund in ("Serenitas", "BowdSt", "Selene"):
        for counterparty in ("MSCSNY", "BAMSNY"):
            read_fun = globals()[f"read_{counterparty}"]
            print(read_fun(fund, cob))


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "cob",
        type=datetime.date,
        default=prev_business_day(datetime.date.today()),
        help="Date to process (YYYY-MM-DD)",
    )
    args = parser.parse_args()
    main(args.cob)