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
|
from report_ops.sma import build_position_file
import argparse
from serenitas.utils.remote import Client
from serenitas.utils.exchange import ExchangeMessage, FileAttachment
from report_ops.misc import _recipients, _cc_recipients
import datetime
from serenitas.analytics.dates import prev_business_day
asset_splits = {
"OTC": [
"future",
"tranche",
"ir_swaption",
"cdx_swaption",
"irs",
"cdx",
],
"BOND": ["bond"],
}
def gen_positions_and_fnames(cob, fund):
for split, asset_classes in asset_splits.items():
buf, _ = build_position_file(cob, fund, asset_classes)
timestamp = datetime.datetime.now()
dest = f"HEDGEMARK.POSITION.BOS_PAT_BOWDOIN.{timestamp:%Y%m%d.%H%M%S}.{split}Deal.{cob}.csv"
yield buf, dest
def main(cob, fund, upload):
client = Client.from_creds("hm_globeop", folder="incoming")
attachments = []
for buf, dest in gen_positions_and_fnames(cob, fund):
if upload:
client.put(buf, dest)
attachments.append(FileAttachment(name=dest, content=buf))
if attachments:
em = ExchangeMessage()
em.send_email(
subject=f"Position_files for Bowdoin Street as of {cob}",
body=f"Please see monthend positions for Bowdoin Street as of {cob}. They have been uploaded to the SFTP as well.",
to_recipients=_recipients[fund],
cc_recipients=_cc_recipients[fund],
reply_to=_cc_recipients[fund],
attach=attachments,
)
parser = argparse.ArgumentParser(
description="Generate position files for Bowdoin Street"
)
parser.add_argument(
"date",
nargs="?",
type=datetime.date.fromisoformat,
default=prev_business_day((datetime.date.today().replace(day=1))),
)
parser.add_argument(
"--no-upload",
"-n",
action="store_true",
default=False,
help="uploads to globeop",
)
args = parser.parse_args()
if (
not prev_business_day(datetime.date.today()) == args.date and not args.no_upload
): # We only want to upload if the previous business day was monthend
pass
else:
main(args.date, "BOWDST", not args.no_upload)
|