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
|
import logging
import argparse
import datetime
from serenitas.analytics.dates import prev_business_day
from serenitas.utils.db import dbconn
from serenitas.utils.exchange import ExchangeMessage
from .sma import SMA
from .cash import CashReport
from .admin import CitcoReport
from .wires import WireReport
from .custodians import upload_to_custodian, get_custodian_download_fun
from .utils import notify_payment_settlements, notify_fx_hedge
from .misc import _fund_custodians
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
logger = logging.getLogger(__name__)
logging.getLogger("exchangelib.fields").setLevel(logging.WARNING)
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(
"-fh",
"--fx_hedge",
action="store_true",
help="return fx trades",
)
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 = 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 or args.wire_reports:
em = ExchangeMessage()
for fund, custodians in _fund_custodians.items():
for custodian in custodians:
get_custodian_download_fun(custodian)(args.date, fund, em=em)
if args.cash_reports:
cash_report = CashReport[custodian]
cash_report.to_db(args.date, fund)
if args.wire_reports:
wire_report = WireReport[custodian]
wire_report.to_db(args.date, fund)
if args.isosel_reports:
for fund in ("ISOSEL",):
for report in ("isosel_accrued", "citco_reports"):
try:
report = CitcoReport[report](cob, fund)
report.to_db()
except ValueError as e:
logger.warning(e)
if args.send_to_custodians:
for account in (
"BBH",
"UMB",
):
upload_to_custodian(account, args.date, not args.no_upload)
if args.payment_settlements:
conn = dbconn("dawndb")
for fund in ("SERCGMAST", "BRINKER", "BOWDST", "ISOSEL"):
notify_payment_settlements(args.date, fund, conn)
if args.fx_hedge:
conn = dbconn("dawndb")
for fund in ("SERCGMAST", "BOWDST", "ISOSEL"):
notify_fx_hedge(cob, fund, conn)
|