Exemplo n.º 1
0
    def test_lookup_symbol(self):

        # Incrementing by two so that start and end dates for each
        # generated Asset don't overlap (each Asset's end_date is the
        # day after its start date.)
        dates = pd.date_range('2013-01-01', freq='2D', periods=5, tz='UTC')
        df = pd.DataFrame.from_records(
            [
                {
                    'sid': i,
                    'symbol':  'existing',
                    'start_date': date.value,
                    'end_date': (date + timedelta(days=1)).value,
                    'exchange': 'NYSE',
                }
                for i, date in enumerate(dates)
            ]
        )
        self.env.write_data(equities_df=df)
        finder = AssetFinder(self.env.engine)
        for _ in range(2):  # Run checks twice to test for caching bugs.
            with self.assertRaises(SymbolNotFound):
                finder.lookup_symbol('NON_EXISTING', dates[0])

            with self.assertRaises(MultipleSymbolsFound):
                finder.lookup_symbol('EXISTING', None)

            for i, date in enumerate(dates):
                # Verify that we correctly resolve multiple symbols using
                # the supplied date
                result = finder.lookup_symbol('EXISTING', date)
                self.assertEqual(result.symbol, 'EXISTING')
                self.assertEqual(result.sid, i)
Exemplo n.º 2
0
    def test_lookup_symbol(self):

        # Incrementing by two so that start and end dates for each
        # generated Asset don't overlap (each Asset's end_date is the
        # day after its start date.)
        dates = pd.date_range("2013-01-01", freq="2D", periods=5, tz="UTC")
        df = pd.DataFrame.from_records(
            [
                {
                    "sid": i,
                    "symbol": "existing",
                    "start_date": date.value,
                    "end_date": (date + timedelta(days=1)).value,
                    "exchange": "NYSE",
                }
                for i, date in enumerate(dates)
            ]
        )
        self.env.write_data(equities_df=df)
        finder = AssetFinder(self.env.engine)
        for _ in range(2):  # Run checks twice to test for caching bugs.
            with self.assertRaises(SymbolNotFound):
                finder.lookup_symbol("NON_EXISTING", dates[0])

            with self.assertRaises(MultipleSymbolsFound):
                finder.lookup_symbol("EXISTING", None)

            for i, date in enumerate(dates):
                # Verify that we correctly resolve multiple symbols using
                # the supplied date
                result = finder.lookup_symbol("EXISTING", date)
                self.assertEqual(result.symbol, "EXISTING")
                self.assertEqual(result.sid, i)
Exemplo n.º 3
0
    def test_lookup_symbol_delimited(self):
        as_of = pd.Timestamp("2013-01-01", tz="UTC")
        frame = pd.DataFrame.from_records(
            [
                {
                    "sid": i,
                    "symbol": "TEST.%d" % i,
                    "company_name": "company%d" % i,
                    "start_date": as_of.value,
                    "end_date": as_of.value,
                    "exchange": uuid.uuid4().hex,
                }
                for i in range(3)
            ]
        )
        self.env.write_data(equities_df=frame)
        finder = AssetFinder(self.env.engine)
        asset_0, asset_1, asset_2 = (finder.retrieve_asset(i) for i in range(3))

        # we do it twice to catch caching bugs
        for i in range(2):
            with self.assertRaises(SymbolNotFound):
                finder.lookup_symbol("TEST", as_of)
            with self.assertRaises(SymbolNotFound):
                finder.lookup_symbol("TEST1", as_of)
            # '@' is not a supported delimiter
            with self.assertRaises(SymbolNotFound):
                finder.lookup_symbol("TEST@1", as_of)

            # Adding an unnecessary fuzzy shouldn't matter.
            for fuzzy_char in ["-", "/", "_", "."]:
                self.assertEqual(asset_1, finder.lookup_symbol("TEST%s1" % fuzzy_char, as_of))
Exemplo n.º 4
0
    def test_lookup_symbol_delimited(self):
        as_of = pd.Timestamp('2013-01-01', tz='UTC')
        frame = pd.DataFrame.from_records([{
            'sid': i,
            'symbol': 'TEST.%d' % i,
            'company_name': "company%d" % i,
            'start_date': as_of.value,
            'end_date': as_of.value,
            'exchange': uuid.uuid4().hex
        } for i in range(3)])
        self.env.write_data(equities_df=frame)
        finder = AssetFinder(self.env.engine)
        asset_0, asset_1, asset_2 = (finder.retrieve_asset(i)
                                     for i in range(3))

        # we do it twice to catch caching bugs
        for i in range(2):
            with self.assertRaises(SymbolNotFound):
                finder.lookup_symbol('TEST', as_of)
            with self.assertRaises(SymbolNotFound):
                finder.lookup_symbol('TEST1', as_of)
            # '@' is not a supported delimiter
            with self.assertRaises(SymbolNotFound):
                finder.lookup_symbol('TEST@1', as_of)

            # Adding an unnecessary fuzzy shouldn't matter.
            for fuzzy_char in ['-', '/', '_', '.']:
                self.assertEqual(
                    asset_1, finder.lookup_symbol('TEST%s1' % fuzzy_char,
                                                  as_of))
Exemplo n.º 5
0
    def test_lookup_symbol_fuzzy(self):
        as_of = pd.Timestamp('2013-01-01', tz='UTC')
        frame = pd.DataFrame.from_records(
            [
                {
                    'sid': i,
                    'symbol':  'TEST@%d' % i,
                    'company_name': "company%d" % i,
                    'start_date': as_of.value,
                    'end_date': as_of.value,
                    'exchange': uuid.uuid4().hex,
                    'fuzzy': 'TEST%d' % i
                }
                for i in range(3)
            ]
        )
        self.env.write_data(equities_df=frame)
        finder = AssetFinder(self.env.engine, fuzzy_char='@')
        asset_0, asset_1, asset_2 = (
            finder.retrieve_asset(i) for i in range(3)
        )

        for i in range(2):  # we do it twice to test for caching bugs
            self.assertIsNone(finder.lookup_symbol('test', as_of))
            self.assertEqual(
                asset_1,
                finder.lookup_symbol('test@1', as_of)
            )

            # Adding an unnecessary fuzzy shouldn't matter.
            self.assertEqual(
                asset_1,
                finder.lookup_symbol('test@1', as_of, fuzzy=True)
            )

            # Shouldn't find this with no fuzzy_str passed.
            self.assertIsNone(finder.lookup_symbol('test1', as_of))
            # Should find exact match.
            self.assertEqual(
                asset_1,
                finder.lookup_symbol('test1', as_of, fuzzy=True),
            )
Exemplo n.º 6
0
    def test_lookup_symbol_fuzzy(self):
        as_of = pd.Timestamp('2013-01-01', tz='UTC')
        frame = pd.DataFrame.from_records([{
            'sid': i,
            'file_name': 'TEST@%d' % i,
            'company_name': "company%d" % i,
            'start_date_nano': as_of.value,
            'end_date_nano': as_of.value,
            'exchange': uuid.uuid4().hex,
        } for i in range(3)])
        finder = AssetFinder(frame)
        asset_0, asset_1, asset_2 = (finder.retrieve_asset(i)
                                     for i in range(3))

        for i in range(2):  # we do it twice to test for caching bugs
            self.assertIsNone(finder.lookup_symbol('test', as_of))
            self.assertEqual(asset_1, finder.lookup_symbol('test@1', as_of))

            # Adding an unnecessary fuzzy shouldn't matter.
            self.assertEqual(asset_1,
                             finder.lookup_symbol('test@1', as_of, fuzzy='@'))

            # Shouldn't find this with no fuzzy_str passed.
            self.assertIsNone(finder.lookup_symbol('test1', as_of))
            # Shouldn't find this with an incorrect fuzzy_str.
            self.assertIsNone(finder.lookup_symbol('test1', as_of, fuzzy='*'))
            # Should find it with the correct fuzzy_str.
            self.assertEqual(
                asset_1,
                finder.lookup_symbol('test1', as_of, fuzzy='@'),
            )
Exemplo n.º 7
0
    def test_sid_assignment(self):

        # This metadata does not contain SIDs
        metadata = {'PLAY': {'symbol': 'PLAY'}, 'MSFT': {'symbol': 'MSFT'}}

        # Build a finder that is allowed to assign sids
        finder = AssetFinder(metadata=metadata, allow_sid_assignment=True)

        # Verify that Assets were built and different sids were assigned
        play = finder.lookup_symbol('PLAY', datetime.now())
        msft = finder.lookup_symbol('MSFT', datetime.now())
        self.assertEqual('PLAY', play.symbol)
        self.assertIsNotNone(play.sid)
        self.assertNotEqual(play.sid, msft.sid)
Exemplo n.º 8
0
    def test_sid_assignment(self):

        # This metadata does not contain SIDs
        metadata = {'PLAY': {'symbol': 'PLAY'},
                    'MSFT': {'symbol': 'MSFT'}}

        # Build a finder that is allowed to assign sids
        finder = AssetFinder(metadata=metadata, allow_sid_assignment=True)

        # Verify that Assets were built and different sids were assigned
        play = finder.lookup_symbol('PLAY', datetime.now())
        msft = finder.lookup_symbol('MSFT', datetime.now())
        self.assertEqual('PLAY', play.symbol)
        self.assertIsNotNone(play.sid)
        self.assertNotEqual(play.sid, msft.sid)
Exemplo n.º 9
0
    def test_sid_assignment(self):

        # This metadata does not contain SIDs
        metadata = {'PLAY': {'symbol': 'PLAY'}, 'MSFT': {'symbol': 'MSFT'}}

        today = normalize_date(pd.Timestamp('2015-07-09', tz='UTC'))

        # Build a finder that is allowed to assign sids
        finder = AssetFinder(metadata=metadata, allow_sid_assignment=True)

        # Verify that Assets were built and different sids were assigned
        play = finder.lookup_symbol('PLAY', today)
        msft = finder.lookup_symbol('MSFT', today)
        self.assertEqual('PLAY', play.symbol)
        self.assertIsNotNone(play.sid)
        self.assertNotEqual(play.sid, msft.sid)
Exemplo n.º 10
0
    def test_sid_assignment(self):

        # This metadata does not contain SIDs
        metadata = ["PLAY", "MSFT"]

        today = normalize_date(pd.Timestamp("2015-07-09", tz="UTC"))

        # Write data with sid assignment
        self.env.write_data(equities_identifiers=metadata, allow_sid_assignment=True)

        # Verify that Assets were built and different sids were assigned
        finder = AssetFinder(self.env.engine)
        play = finder.lookup_symbol("PLAY", today)
        msft = finder.lookup_symbol("MSFT", today)
        self.assertEqual("PLAY", play.symbol)
        self.assertIsNotNone(play.sid)
        self.assertNotEqual(play.sid, msft.sid)
Exemplo n.º 11
0
    def test_sid_assignment(self):

        # This metadata does not contain SIDs
        metadata = ['PLAY', 'MSFT']

        today = normalize_date(pd.Timestamp('2015-07-09', tz='UTC'))

        # Write data with sid assignment
        self.env.write_data(equities_identifiers=metadata,
                            allow_sid_assignment=True)

        # Verify that Assets were built and different sids were assigned
        finder = AssetFinder(self.env.engine)
        play = finder.lookup_symbol('PLAY', today)
        msft = finder.lookup_symbol('MSFT', today)
        self.assertEqual('PLAY', play.symbol)
        self.assertIsNotNone(play.sid)
        self.assertNotEqual(play.sid, msft.sid)
Exemplo n.º 12
0
    def test_sid_assignment(self):

        # This metadata does not contain SIDs
        metadata = {'PLAY': {'symbol': 'PLAY'},
                    'MSFT': {'symbol': 'MSFT'}}

        today = normalize_date(pd.Timestamp('2015-07-09', tz='UTC'))

        # Build a finder that is allowed to assign sids
        finder = AssetFinder(metadata=metadata,
                             allow_sid_assignment=True)

        # Verify that Assets were built and different sids were assigned
        play = finder.lookup_symbol('PLAY', today)
        msft = finder.lookup_symbol('MSFT', today)
        self.assertEqual('PLAY', play.symbol)
        self.assertIsNotNone(play.sid)
        self.assertNotEqual(play.sid, msft.sid)
Exemplo n.º 13
0
    def test_lookup_symbol_delimited(self):
        as_of = pd.Timestamp('2013-01-01', tz='UTC')
        frame = pd.DataFrame.from_records(
            [
                {
                    'sid': i,
                    'symbol':  'TEST.%d' % i,
                    'company_name': "company%d" % i,
                    'start_date': as_of.value,
                    'end_date': as_of.value,
                    'exchange': uuid.uuid4().hex
                }
                for i in range(3)
            ]
        )
        self.env.write_data(equities_df=frame)
        finder = AssetFinder(self.env.engine)
        asset_0, asset_1, asset_2 = (
            finder.retrieve_asset(i) for i in range(3)
        )

        # we do it twice to catch caching bugs
        for i in range(2):
            with self.assertRaises(SymbolNotFound):
                finder.lookup_symbol('TEST', as_of)
            with self.assertRaises(SymbolNotFound):
                finder.lookup_symbol('TEST1', as_of)
            # '@' is not a supported delimiter
            with self.assertRaises(SymbolNotFound):
                finder.lookup_symbol('TEST@1', as_of)

            # Adding an unnecessary fuzzy shouldn't matter.
            for fuzzy_char in ['-', '/', '_', '.']:
                self.assertEqual(
                    asset_1,
                    finder.lookup_symbol('TEST%s1' % fuzzy_char, as_of)
                )
Exemplo n.º 14
0
    def test_lookup_symbol_fuzzy(self):
        as_of = pd.Timestamp('2013-01-01', tz='UTC')
        frame = pd.DataFrame.from_records(
            [
                {
                    'sid': i,
                    'file_name':  'TEST@%d' % i,
                    'company_name': "company%d" % i,
                    'start_date_nano': as_of.value,
                    'end_date_nano': as_of.value,
                    'exchange': uuid.uuid4().hex,
                }
                for i in range(3)
            ]
        )
        finder = AssetFinder(frame)
        asset_0, asset_1, asset_2 = (
            finder.retrieve_asset(i) for i in range(3)
        )

        for i in range(2):  # we do it twice to test for caching bugs
            self.assertIsNone(finder.lookup_symbol('test', as_of))
            self.assertEqual(
                asset_1,
                finder.lookup_symbol('test@1', as_of)
            )

            # Adding an unnecessary fuzzy shouldn't matter.
            self.assertEqual(
                asset_1,
                finder.lookup_symbol('test@1', as_of, fuzzy='@')
            )

            # Shouldn't find this with no fuzzy_str passed.
            self.assertIsNone(finder.lookup_symbol('test1', as_of))
            # Shouldn't find this with an incorrect fuzzy_str.
            self.assertIsNone(finder.lookup_symbol('test1', as_of, fuzzy='*'))
            # Should find it with the correct fuzzy_str.
            self.assertEqual(
                asset_1,
                finder.lookup_symbol('test1', as_of, fuzzy='@'),
            )