Пример #1
0
    def test_earningsTodayDF(self):
        from pyEX import earningsTodayDF
        with patch('requests.get') as mock:
            mock.return_value = MagicMock()
            mock.return_value.status_code = 200
            mock.return_value.json = MagicMock(return_value=[])

            earningsTodayDF()
Пример #2
0
    def test_earningsTodayDF(self):
        from pyEX import earningsTodayDF

        with patch("requests.get") as mock, patch("pickle.dump"):
            mock.return_value = MagicMock()
            mock.return_value.status_code = 200
            mock.return_value.json = MagicMock(return_value=[])

            earningsTodayDF()
Пример #3
0
    def co_earnings_today(self, today_ymd=None):

        from datetime import datetime
        try_local_pull = False
        if today_ymd is None or today_ymd == datetime.now().strftime("%Y%m%d"):
            today_ymd = datetime.now().strftime("%Y%m%d")
            df = pyex.earningsTodayDF()
            if df.empty is True and os.path.isfile(self.co_earnings_path +
                                                   today_ymd + ".csv") is True:
                try_local_pull = True
            elif df.empty is True:
                self.logger.info(
                    "IEXTradingApi:co_earnings_today().: no earnings for date %s!",
                    today_ymd)
                return
        elif os.path.isfile(self.co_earnings_path + today_ymd +
                            ".csv") is False:
            self.logger.info(
                "IEXTradingApi:co_earnings_today(): no historical file available for date %s",
                today_ymd)
            return
        else:
            self.logger.warning(
                "IEXTradingApi:co_earnings_today(): try_local_pull is True, nothing at IEX!!!"
            )
            try_local_pull = True
        if try_local_pull is True:
            # check for an existing flat csv file, maybe we did a pull already
            df = pd.read_csv(self.co_earnings_path + today_ymd + ".csv",
                             sep=',',
                             header=0)
            df.set_index('symbol', inplace=True)
            df.reset_index(inplace=True)
        else:
            df.to_csv(self.co_earnings_path + today_ymd + ".csv", sep=',')
            df.reset_index(inplace=True)
        market_cap_billions = df['quote.marketCap'].astype(
            'float64') / 1000000000.0
        market_cap_billions = market_cap_billions.round(3)
        df['quote.marketCap'] = market_cap_billions.apply(
            lambda x: self.format_market_cap(x))
        df.EPSReportDate = df.EPSReportDate.astype('str')
        df.announceTime = df.announceTime.apply(
            lambda x: self.format_announce_time(x))
        df.estimatedChangePercent = df.estimatedChangePercent.mul(100).round(
            2).astype('str') + '%'
        df.estimatedEPS = '$' + df.estimatedEPS.astype('str')
        df.fiscalEndDate = df.fiscalEndDate.astype('str')
        df.headline = df.headline.apply(lambda x: self.format_headline(x))
        df[['headline', 'headline_color']] = df.headline.apply(pd.Series)
        df["quote.week52High"] = '$' + df['quote.week52High'].astype('str')
        df["quote.week52Low"] = '$' + df['quote.week52Low'].astype('str')
        df['quote.ytdChange'] = df['quote.ytdChange'].mul(100).round(2).astype(
            'str') + '%'
        df.rename(index=str,
                  columns={
                      "symbol": "Symbol",
                      "quote.peRatio": "P/E Ratio",
                      "fiscalPeriod": "Quarter",
                      "numberOfEstimates": "# of Estimates",
                      "consensusEPS": "Consensus EPS",
                      "headline": "Headline",
                      "fiscalEndDate": "Quarter End",
                      "estimatedEPS": "EPS Estimate",
                      "estimatedChangePercent": "Estimated 1-Yr Change, EPS",
                      "announceTime": "Announce Time",
                      "EPSReportDate": "Report Date",
                      "quote.marketCap": "Market Cap",
                      "quote.peRatio": "P/E Ratio",
                      "quote.sector": "Sector",
                      "quote.week52High": "52-Week High",
                      "quote.week52Low": "52-Week Low",
                      "quote.ytdChange": "YTD Change",
                      "yearAgo": "Year Ago EPS"
                  },
                  inplace=True)
        list_of_columns = [
            'Symbol', 'Report Date', 'Announce Time', 'Consensus EPS',
            'Estimated 1-Yr Change, EPS', 'EPS Estimate', 'Quarter End',
            'Quarter', 'Headline', 'headline_color', '# of Estimates',
            'Market Cap', 'P/E Ratio', 'Sector', '52-Week High', '52-Week Low',
            'YTD Change', 'Year Ago EPS'
        ]
        df = df[list_of_columns]
        output_html_filename = self.iex_html_path + 'co_earnings_' + today_ymd + '.html'
        data_table = ExtendBokeh.bokeh_co_earnings_today_datatable(
            dataframe=df)
        ExtendBokeh.save_co_earnings_today_data_table(
            data_table,
            html_output_file=output_html_filename,
            html_output_file_title='CoEarningsToday')