aboutsummaryrefslogtreecommitdiffstats
path: root/python/report_ops/__main__.py
blob: 9ff1a3d9530480518d4fd4abcaeb5391df73a438 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from serenitas.analytics.dates import prev_business_day
from serenitas.utils.exchange import ExchangeMessage
from serenitas.utils.db import dbconn
import logging
import argparse
import datetime
from .sma import (
    SMA,
    PositionReport,
    BondPosition,
    FuturePosition,
    TranchePosition,
    CDXPosition,
    IRSwaptionPosition,
    CDXSwaptionPosition,
)
from .cash import CashReport
from .admin import CitcoReport
from .wires import Wire
from .custodians import upload_to_custodian
from .utils import notify_payment_settlements, PaymentMonitor
from .misc import _fund_custodians

logger = logging.getLogger(__name__)

parser = argparse.ArgumentParser()

parser.add_argument(
    "-s",
    "--sma_positions",
    action="store_true",
    help="upload sma positions to hedgemark",
)
parser.add_argument(
    "-c", "--cash_reports", action="store_true", help="process cash reports to database"
)
parser.add_argument(
    "-i",
    "--isosel_reports",
    action="store_true",
    help="download isosel reports to database",
)
parser.add_argument(
    "-w", "--wire_reports", action="store_true", help="download wires to db"
)
parser.add_argument(
    "-sc",
    "--send_to_custodians",
    action="store_true",
    help="upload trade files to notify custodians",
)
parser.add_argument(
    "-ps",
    "--payment_settlements",
    action="store_true",
    help="notify payment settlements by email",
)
parser.add_argument(
    "-n", "--no-upload", action="store_true", help="do not upload, just create files"
)
parser.add_argument(
    "date",
    nargs="?",
    type=datetime.date.fromisoformat,
    default=datetime.date.today(),
)

args = parser.parse_args()

cob = date = prev_business_day(args.date)

if args.sma_positions:
    for fund in ("BOWDST", "ISOSEL", "BRINKER"):
        sma = SMA[fund](cob)
        try:
            sma.email_positions()
        except ValueError as e:
            logger.warning(e)

if args.cash_reports:
    for fund, custodians in _fund_custodians.items():
        for custodian in custodians:
            report = CashReport[
                (
                    fund,
                    custodian,
                )
            ](args.date)
            try:
                report.to_db()
            except ValueError as e:
                logger.warning(e)

if args.isosel_reports:
    for report in ("isosel_accrued", "citco_reports"):
        report = CitcoReport[report]
        try:
            report.to_db(cob)
        except ValueError as e:
            logger.info(e)

if args.wire_reports:
    for fund in ("BOWDST", "ISOSEL"):
        try:
            Wire[fund].to_db(args.date)
        except ValueError as e:
            logger.info(e)

if args.send_to_custodians:
    em = ExchangeMessage()
    for account in (
        "BBH",
        "UMB",
    ):
        try:
            upload_to_custodian(account, args.date, not args.no_upload, em)
        except ValueError as e:
            logger.info(e)

if args.payment_settlements:
    conn = dbconn("dawndb")
    for fund in ("SERCGMAST", "BRINKER", "BOWDST", "ISOSEL"):
        notify_payment_settlements(date, fund, conn)
        PaymentMonitor._insert_queue.clear()