コード例 #1
0
ファイル: dailyOpsProcess.py プロジェクト: robertbetts/Kew
    def _buildInputfile(self):

        logging.info("Building input file %s" % self.input_file)

        prev_asofdate = getPrevDay(self.asofdate)

        outstring = cStringIO.StringIO()
        # Replace the date keys in the input file, with the correct date range
        outstring.write(
            """startDate,endDate,startTime,endTime,holdCustomer,r_factor
%s,%s,171000,171000,Whiteclif,6\n"""
            % (prev_asofdate.strftime("%Y%m%d"), self.asofdate.strftime("%Y%m%d"))
        )
        outfile = file(self.input_file, "wb")
        outfile.write(outstring.getvalue())
        outfile.close()
コード例 #2
0
ファイル: dailyOpsProcess.py プロジェクト: robertbetts/Kew
    def _parseOutputFile(self):

        prev_asofdate = getPrevDay(self.asofdate)

        # Collect yesterday's NAV from file in file archive

        output_file_yesterday = self.output_file.replace(
            self.asofdate.strftime("%Y%m%d"), prev_asofdate.strftime("%Y%m%d")
        )
        output_file_yesterday = output_file_yesterday.replace(
            self.asofdate.strftime("%Y-%m-%d"), prev_asofdate.strftime("%Y-%m-%d")
        )

        # If yesterdays output file doesn't exist, assume we had a bank holiday so go back to the last file we had within
        # the last 5 days
        day_limit = 0
        while not os.path.exists(output_file_yesterday) and day_limit < 5:
            logging.warning("Output file for {} not found, trying {}".format(prev_asofdate, getPrevDay(prev_asofdate)))
            prev_asofdate = getPrevDay(prev_asofdate)
            output_file_yesterday = self.output_file.replace(
                self.asofdate.strftime("%Y%m%d"), prev_asofdate.strftime("%Y%m%d")
            )
            output_file_yesterday = output_file_yesterday.replace(
                self.asofdate.strftime("%Y-%m-%d"), prev_asofdate.strftime("%Y-%m-%d")
            )
            day_limit += 1

        logging.info("Using previous asofdate of {}".format(prev_asofdate))

        if os.path.exists(output_file_yesterday):
            with open(output_file_yesterday) as outF:
                headers = outF.readline().replace('"', "").strip().split(",")
                header_data = outF.readline().replace('"', "").strip().split(",")
                data = dict(zip(headers, header_data))
                nav_yesterday = float(data["NAV Today"])
                logging.info("Using previous NAV of {}".format(nav_yesterday))
        else:
            logging.info(
                "Output file for yesterday not found at %s, defaulting to previous nav of 0!" % output_file_yesterday
            )
            nav_yesterday = 0.0

        # Parse today's output file

        top_counter = 5
        bottom_counter = 5
        pnl_limit = 500000

        with open(self.output_file) as outF:
            headers = outF.readline().replace('"', "").strip().split(",")
            header_data = outF.readline().replace('"', "").strip().split(",")
            data = dict(zip(headers, header_data))

            # skip holding header row
            outF.readline()

            top_pnl = {}
            bottom_pnl = {}
            for line in outF:
                [name, pnl] = line.replace('"', "").strip().split(",")
                pnl = float(pnl)
                if name == "~Other":
                    continue
                elif pnl >= pnl_limit and top_counter > 0:
                    top_pnl[name] = pnl
                elif pnl <= -pnl_limit and bottom_counter > 0:
                    bottom_pnl[name] = pnl

        # Calculate values

        data["NAV Yesterday"] = nav_yesterday
        data["NAV Difference"] = (
            float(data["NAV Today"])
            - float(data["Ptf Day P&L"])
            - float(data["Ptf Day Unexplained"])
            - data["NAV Yesterday"]
        )

        # Compose message body

        body = "NAV Difference:\n\n"
        for header in ["NAV Yesterday", "Ptf Day P&L", "Ptf Day Unexplained", "NAV Today", "NAV Difference"]:
            body += "{0:<20}:{1:>16,}\n".format(header, int(round(float(data[header]))))
        body += "\n\n"

        for movers in [top_pnl, bottom_pnl]:
            for name, pnl in movers.iteritems():
                body += "{0}: {1}\n".format(name, fmtIntThou(pnl))

        if len(top_pnl) == 0 and len(bottom_pnl) == 0:
            body += "No major movers today.\n"

        body += "\n\n"

        for header in [
            "# MarginType Errors",
            "# MarginUsym Errors",
            "# Coupons Ex Today",
            "Day Whole Coupon Adj",
            "Day Dividend Adj",
            "# Missing Regions",
            "# Missing Sectors",
            "$$ Quantity Difference",
            "Cap Usage NAV Impact",
        ]:
            body += "{0} : {1:,}\n".format(header, int(round(float(data[header]))))

        return body