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
|
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 _monthend_nav_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 build_file(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.capitalize()}Deal.PositionsAsOf{cob}.csv"
yield buf, dest
def send_position_file(cob, fund, upload):
client = Client.from_creds("hm_globeop", folder="incoming")
attachments = []
for buf, dest in build_file(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=_monthend_nav_recipients[fund],
cc_recipients=_cc_recipients[fund],
reply_to=_cc_recipients[fund],
attach=attachments,
)
def parse_args():
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",
)
parser.add_argument(
"--manual",
"-m",
action="store_true",
default=False,
help="indicates that the script is being run manually",
)
return parser.parse_args()
def main():
args = parse_args()
if (
not prev_business_day(datetime.date.today()) == args.date and not args.no_upload
) and not args.manual: # We only want to upload if the previous business day was monthend
pass
else:
send_position_file(args.date, "BOWDST", not args.no_upload)
if __name__ == "__main__":
main()
|