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()