예제 #1
0
    def test_read_financial_metric_with_api_exception(self):
        with patch.object(intrinio_data.COMPANY_API, 'get_company_historical_data',
                          side_effect=ApiException("Server Error")), \
                patch('support.financial_cache.cache', new=nop.Nop()):

            (start_date) = intrinio_util.get_year_date_range(2018, 0)[0]

            with self.assertRaises(DataError):
                intrinio_data._get_company_historical_data(
                    'NON-EXISTENT-TICKER', start_date, start_date, 'tag')
    def test_read_financial_metric_with_api_exception(self):
        with patch.object(intrinio_data.COMPANY_API, 'get_company_historical_data',
                          side_effect=ApiException("Server Error")), \
                patch.object(FinancialCache, 'read', return_value=None), \
                patch.object(FinancialCache, 'write', return_value=None):

            (start_date) = intrinio_util.get_year_date_range(2018, 0)[0]

            with self.assertRaises(DataError):
                intrinio_data._get_company_historical_data(
                    'NON-EXISTENT-TICKER', start_date, start_date, 'tag')
예제 #3
0
def get_historical_revenue(ticker: str, year_from: int, year_to: int):
    '''
      Returns a dictionary of year->"total revenue" for the supplied ticker and
      range of years.

      Returns
      -----------
      a dictionary of year->"fcff value" like this
      {
        2010: 123,
        2012: 234,
        2013: 345,
        2014: 456,
      }
    '''

    start_date = intrinio_util.get_year_date_range(year_from, 0)[0]
    end_date = intrinio_util.get_year_date_range(year_to, 0)[1]

    return _aggregate_by_year(
        _get_company_historical_data(ticker, start_date, end_date,
                                     'totalrevenue'))
예제 #4
0
def get_historical_fcff(ticker: str, year_from: int, year_to: int):
    '''
      Returns a dictionary of year->"fcff value" for the supplied ticker and
      range of years.

        This is the description from Intrinio documentation:

        Definition
        Free cash flow for the firm (FCFF) is a measure of financial performance that
        expresses the net amount of cash that is generated for a firm after expenses,
        taxes and changes in net working capital and investments are deducted.
        FCFF is essentially a measurement of a company's profitability after all expenses
        and reinvestments. It's one of the many benchmarks used to compare and analyze
        financial health.

        Formula
        freecashflow = nopat - investedcapitalincreasedecrease


      Returns
      -----------
      a dictionary of year->"fcff value" like this
      {
        2010: 123,
        2012: 234,
        2013: 345,
        2014: 456,
      }
    '''

    start_date = intrinio_util.get_year_date_range(year_from, 0)[0]
    end_date = intrinio_util.get_year_date_range(year_to, 0)[1]

    return _aggregate_by_year(
        _get_company_historical_data(ticker, start_date, end_date,
                                     'freecashflow'))
    def test_year_range_invalid_extendedby(self):
        with self.assertRaises(ValidationError):
            intrinio_util.get_year_date_range(2018, -1)

        with self.assertRaises(ValidationError):
            intrinio_util.get_year_date_range(2018, 360)
 def test_year_range_invaid_date(self):
     with self.assertRaises(ValidationError):
         intrinio_util.get_year_date_range(0, 0)
    def test_year_range_valid_date_extended(self):
        (date_from, date_to) = intrinio_util.get_year_date_range(2018, 10)

        self.assertEqual(date_from, "2018-01-01")
        self.assertEqual(date_to, "2019-01-10")
    def test_year_range_valid_date(self):
        (date_from, date_to) = intrinio_util.get_year_date_range(2018, 0)

        self.assertEqual(date_from, "2018-01-01")
        self.assertEqual(date_to, "2018-12-31")