示例#1
0
    def test_historic_UK_ETF(self):

        directory = os.path.join(str(pathlib.Path.home()),
                                 '.financials-extension')
        verx = os.path.join(directory, 'yahoo-VERX.L.csv')
        try:
            os.unlink(verx)
        except:
            pass  # ignore if file doesn't exists

        financials.yahoo.historicdata = {}

        #  Inception Date 2014-09-30
        s = financials.getHistoric('VERX.L', Datacode.CLOSE.value,
                                   '2018-04-02', 'YAHOO')  # Easter Monday
        self.assertEqual(s, 'Not a trading day \'2018-04-02\'',
                         'test_historic_UK_ETF CLOSE {}'.format(s))

        #  Inception Date 2014-09-30
        s = financials.getHistoric('VERX.L', Datacode.CLOSE.value,
                                   '2015-01-01', 'YAHOO')
        self.assertEqual(s, 'Not a trading day \'2015-01-01\'',
                         'test_historic_UK_ETF CLOSE {}'.format(s))

        s = financials.getHistoric('VERX.L', Datacode.LAST_PRICE.value,
                                   '2017-01-01', 'YAHOO')
        self.assertEqual(s, 'Not a trading day \'2017-01-01\'',
                         'test_historic_UK_ETF LAST_PRICE {}'.format(s))

        s = financials.getHistoric('VERX.L', Datacode.CLOSE.value,
                                   '2017-01-03', 'YAHOO')
        self.assertEqual(s, 23.24, 'test_historic_UK_ETF CLOSE {}'.format(s))

        s = financials.getHistoric('VERX.L', Datacode.CLOSE.value,
                                   '2016-10-03', 'YAHOO')
        self.assertEqual(s, 22.26, 'test_historic_UK_ETF CLOSE {}'.format(s))

        #  Inception Date 2014-09-30
        s = financials.getHistoric('VERX.L', Datacode.CLOSE.value,
                                   '2018-04-02', 'YAHOO')
        self.assertEqual(s, 'Not a trading day \'2018-04-02\'',
                         'test_historic_UK_ETF CLOSE {}'.format(s))

        #  Inception Date 2014-09-30
        s = financials.getHistoric('VERX.L', Datacode.CLOSE.value,
                                   '2015-01-01', 'YAHOO')
        self.assertEqual(s, 'Not a trading day \'2015-01-01\'',
                         'test_historic_UK_ETF CLOSE {}'.format(s))

        s = financials.getHistoric('VERX.L', Datacode.CLOSE.value, 42738,
                                   'YAHOO')  # 2017-01-03
        self.assertEqual(s, 23.24, 'test_historic_UK_ETF CLOSE {}'.format(s))

        s = financials.getHistoric('VERX.L', Datacode.CLOSE.value, 42738.0,
                                   'YAHOO')  # 2017-01-03
        self.assertEqual(s, 23.24, 'test_historic_UK_ETF CLOSE {}'.format(s))

        s = financials.getHistoric('VERX.L', Datacode.CLOSE.value, 42646.0,
                                   'YAHOO')  # 2016-10-03
        self.assertEqual(s, 22.26, 'test_historic_UK_ETF CLOSE {}'.format(s))
示例#2
0
    def test_historic_DE_equity(self):

        s = financials.getHistoric('SAP.DE', Datacode.LAST_PRICE.value,
                                   '2017-01-01', 'YAHOO')
        self.assertEqual(s, 'Not a trading day \'2017-01-01\'',
                         'test_historic_DE_equity LAST_PRICE {}'.format(s))

        s = financials.getHistoric('SAP.DE', Datacode.CLOSE.value,
                                   '2017-01-03', 'YAHOO')
        self.assertEqual(s, 82.889999,
                         'test_historic_DE_equity CLOSE {}'.format(s))

        s = financials.getHistoric('C060.DE', Datacode.CLOSE.value,
                                   '2017-01-03', 'YAHOO')
        self.assertEqual(s, 68.209999,
                         'test_historic_DE_equity CLOSE {}'.format(s))
示例#3
0
    def test_errors_cell_range_passed(self):
        cell_range = ((1, 2), ('3', '4'), (5.0, 6.0))

        s = financials.getHistoric(cell_range, Datacode.CLOSE.value,
                                   '2017-01-03', 'YAHOO')
        self.assertEqual(s, 'Cell range not allowed for ticker', 'test_errors')

        s = financials.getHistoric('IBM', cell_range, '2017-01-03', 'YAHOO')
        self.assertEqual(s, 'Cell range not allowed for datacode',
                         'test_errors')

        s = financials.getHistoric('IBM', Datacode.CLOSE.value, cell_range,
                                   'YAHOO')
        self.assertEqual(s, 'Cell range not allowed for date', 'test_errors')

        s = financials.getHistoric('IBM', Datacode.CLOSE.value, '2017-01-03',
                                   cell_range)
        self.assertEqual(s, 'Cell range not allowed for source', 'test_errors')
示例#4
0
    def test_historic_US_equity(self):

        s = financials.getHistoric('IBM', Datacode.LAST_PRICE.value,
                                   '2017-01-01', 'YAHOO')
        self.assertEqual('Not a trading day \'2017-01-01\'', s,
                         'test_historic_US_equity LAST_PRICE {}'.format(s))

        s = financials.getHistoric('IBM', Datacode.CLOSE.value, '2017-01-01',
                                   'YAHOO')
        self.assertEqual('Not a trading day \'2017-01-01\'', s,
                         'test_historic_US_equity CLOSE {}'.format(s))

        s = financials.getHistoric('IBM', Datacode.LAST_PRICE.value,
                                   '2017-01-03', 'YAHOO')
        self.assertEqual('Data doesn\'t exist - 21', s,
                         'test_historic_US_equity LAST_PRICE {}'.format(s))

        s = financials.getHistoric('IBM', Datacode.CLOSE.value, '2017-01-03',
                                   'YAHOO')
        self.assertEqual(167.190002, s,
                         'test_historic_US_equity CLOSE {}'.format(s))

        financials.yahoo.historicdata = {}

        s = financials.getHistoric('IBM', Datacode.CLOSE.value, '2017-01-03',
                                   'YAHOO')
        self.assertEqual(167.190002, s,
                         'test_historic_US_equity CLOSE {}'.format(s))

        directory = os.path.join(str(pathlib.Path.home()),
                                 '.financials-extension')
        ibm = os.path.join(directory, 'yahoo-IBM.csv')
        try:
            os.unlink(ibm)
        except:
            pass  # ignore if file doesn't exists

        financials.yahoo.historicdata = {}

        s = financials.getHistoric('IBM', Datacode.CLOSE.value, '2017-01-03',
                                   'YAHOO')
        self.assertEqual(167.190002, s,
                         'test_historic_US_equity CLOSE {}'.format(s))

        # Note: quarterly dividend and splits will change past adjusted prices - will fail after the next dividend
        s = financials.getHistoric('IBM', Datacode.ADJ_CLOSE.value,
                                   '2017-01-03', 'YAHOO')
        self.assertEqual(139.61322, s,
                         'test_historic_US_equity ADJ_CLOSE {}'.format(s))
示例#5
0
    def test_errors(self):
        s = financials.getRealtime(None, Datacode.LAST_PRICE.value, 'GOOGLE')
        self.assertEqual(s, 'Ticker is empty', 'test_errors')

        s = financials.getRealtime('NYS:IBM', None, 'GOOGLE')
        self.assertEqual(s, 'Datacode is empty', 'test_errors')

        s = financials.getRealtime('DOES_NOT_EXISTS', Datacode.LAST_PRICE.value, 'GOOGLE')
        self.assertIsNone(s, 'test_errors')

        s = financials.getRealtime('NYS:IBM', 'Foo', 'GOOGLE')
        self.assertEqual(s, 'Datacode is invalid', 'test_errors')

        # Historic data not supported on GOOGLE

        s = financials.getHistoric('NYS:IBM', Datacode.LAST_PRICE.value, '2017-01-01', 'GOOGLE')
        self.assertEqual(s, 'Source \'GOOGLE\' not supported', 'test_errors')
示例#6
0
    def test_historic_errors(self):

        s = financials.getHistoric('NO_NAME', Datacode.LAST_PRICE.value,
                                   '2018-01-08', 'YAHOO')
        self.assertIsNone(s, 'test_historic_errors LAST_PRICE {}'.format(s))

        s = financials.getHistoric('IBM', Datacode.CLOSE.value, '2030-01-01',
                                   'YAHOO')
        self.assertEqual(s, 'Future date \'2030-01-01\'',
                         'test_historic_errors CLOSE {}'.format(s))

        s = financials.getRealtime('IBM', 9999, 'YAHOO')
        self.assertEqual(s, 'Datacode 9999 not supported',
                         'test_historic_errors 9999')

        s = financials.getRealtime('IBM', Datacode.ADJ_CLOSE.value, 'YAHOO')
        self.assertEqual(s, 'Data doesn\'t exist - 91',
                         'test_historic_errors ADJ_CLOSE {}'.format(s))

        s = financials.getHistoric('IBM', Datacode.CLOSE.value, '2030-01-01',
                                   'YAHOO')
        self.assertEqual(s, 'Future date \'2030-01-01\'',
                         'test_historic_errors CLOSE {}'.format(s))

        s = financials.getHistoric('IBM', Datacode.CLOSE.value, '1990-01-01',
                                   'YAHOO')
        self.assertEqual(s, 'Date before 2000 \'1990-01-01\'',
                         'test_historic_errors CLOSE {}'.format(s))

        s = financials.getHistoric('IBM', Datacode.CLOSE.value, 'abcdef',
                                   'YAHOO')
        self.assertEqual(s, 'Date format not supported: \'abcdef\'',
                         'test_historic_errors CLOSE {}'.format(s))

        s = financials.getHistoric('IBM', Datacode.CLOSE.value, True, 'YAHOO')
        self.assertEqual(s,
                         'Date type not supported: <class \'bool\'> \'True\'',
                         'test_historic_errors CLOSE {}'.format(s))

        s = financials.getHistoric('IBM', Datacode.CLOSE.value, -1000000,
                                   'YAHOO')
        self.assertEqual(s, 'Date format not supported: -1000000',
                         'test_historic_errors CLOSE {}'.format(s))