aboutsummaryrefslogtreecommitdiffstats
path: root/python/gfs_monitor.py
blob: 6e5ea735af89f8d666743122170c27b01f4077af (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
from serenitas.analytics.dates import prev_business_day
from serenitas.utils.db import dbconn
from serenitas.utils.exchange import ExchangeMessage
import datetime
import logging

_recipients = {
    "BOWDST": (
        "shkumar@sscinc.com",
        "hedgemark.lmcg.ops@sscinc.com",
        "hm-operations@bnymellon.com",
    ),
    "SERCGMAST": (
        "SERENITAS.FA@sscinc.com",
        "SERENITAS.ops@sscinc.com",
    ),
}


def _formatting(gfs_values):
    if not gfs_values:
        return None
    else:
        return "\n".join(
            f"\t* {amount:,.2f} {currency}" for currency, amount in gfs_values.items()
        )


def gfs_values(ped, conn, fund):
    sql_str = "SELECT endqty, invccy FROM valuation_reports vr WHERE fund=%s AND port ='GFS_HELPER_BUSINESS_UNIT' AND periodenddate =%s AND abs(endqty) > 50000;"
    with conn.cursor() as c:
        c.execute(sql_str, (fund, ped))
        return _formatting({row.invccy: row.endqty for row in c})


if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "workdate",
        nargs="?",
        type=datetime.date.fromisoformat,
        default=prev_business_day(datetime.date.today()),
        help="working date",
    )
    args = parser.parse_args()
    logger = logging.getLogger(__name__)
    conn = dbconn("dawndb")
    em = ExchangeMessage()
    for fund in ("BOWDST", "SERCGMAST"):
        if vals := gfs_values(args.workdate, conn, fund):
            em.send_email(
                f"GFS Helper Strategy Issue: {fund}",
                "Good morning, \n\nWe noticed some cash in the GFS helper strategy that shouldn't be there:\n\n"
                + vals,
                to_recipients=_recipients[fund],
                cc_recipients=(
                    "Bowdoin-Ops@LMCG.com" if fund == "BOWDST" else "NYOps@lmcg.com",
                ),
            )