Ejemplo n.º 1
0
    def test_as_of(self):
        """ Test the as_of method of FutureChain.
        """
        cl = FutureChain(self.asset_finder, lambda: "2005-12-01", "CL")

        # Test that the as_of_date is set correctly to the future
        feb = pd.Timestamp("2006-02-01", tz="UTC")
        cl_feb = cl.as_of(feb)
        self.assertEqual(cl_feb.as_of_date, pd.Timestamp(feb, tz="UTC"))

        # Test that the as_of_date is set correctly to the past, with
        # args of str, datetime.datetime, and pd.Timestamp.
        feb_prev = pd.Timestamp("2005-02-01", tz="UTC")
        cl_feb_prev = cl.as_of(feb_prev)
        self.assertEqual(cl_feb_prev.as_of_date, pd.Timestamp(feb_prev, tz="UTC"))

        feb_prev = pd.Timestamp(datetime(year=2005, month=2, day=1), tz="UTC")
        cl_feb_prev = cl.as_of(feb_prev)
        self.assertEqual(cl_feb_prev.as_of_date, pd.Timestamp(feb_prev, tz="UTC"))

        feb_prev = pd.Timestamp("2005-02-01", tz="UTC")
        cl_feb_prev = cl.as_of(feb_prev)
        self.assertEqual(cl_feb_prev.as_of_date, pd.Timestamp(feb_prev, tz="UTC"))

        # The chain as of the current dt should always be the same as
        # the defualt chain.
        self.assertEqual(cl[0], cl.as_of(pd.Timestamp("2005-12-01"))[0])
Ejemplo n.º 2
0
    def test_as_of(self):
        """ Test the as_of method of FutureChain.
        """
        cl = FutureChain(self.asset_finder, lambda: '2005-12-01', 'CL')

        # Test that the as_of_date is set correctly to the future
        feb = pd.Timestamp('2006-02-01', tz='UTC')
        cl_feb = cl.as_of(feb)
        self.assertEqual(cl_feb.as_of_date, pd.Timestamp(feb, tz='UTC'))

        # Test that the as_of_date is set correctly to the past, with
        # args of str, datetime.datetime, and pd.Timestamp.
        feb_prev = pd.Timestamp('2005-02-01', tz='UTC')
        cl_feb_prev = cl.as_of(feb_prev)
        self.assertEqual(cl_feb_prev.as_of_date,
                         pd.Timestamp(feb_prev, tz='UTC'))

        feb_prev = pd.Timestamp(datetime(year=2005, month=2, day=1), tz='UTC')
        cl_feb_prev = cl.as_of(feb_prev)
        self.assertEqual(cl_feb_prev.as_of_date,
                         pd.Timestamp(feb_prev, tz='UTC'))

        feb_prev = pd.Timestamp('2005-02-01', tz='UTC')
        cl_feb_prev = cl.as_of(feb_prev)
        self.assertEqual(cl_feb_prev.as_of_date,
                         pd.Timestamp(feb_prev, tz='UTC'))

        # The chain as of the current dt should always be the same as
        # the defualt chain.
        self.assertEqual(cl[0], cl.as_of(pd.Timestamp('2005-12-01'))[0])
Ejemplo n.º 3
0
    def test_as_of(self):
        """ Test the as_of method of FutureChain.
        """
        cl = FutureChain(self.asset_finder, lambda: '2005-12-01', 'CL')

        # Test that the as_of_date is set correctly to the future
        feb = '2006-02-01'
        cl_feb = cl.as_of(feb)
        self.assertEqual(
            cl_feb.as_of_date,
            pd.Timestamp(feb, tz='UTC')
        )

        # Test that the as_of_date is set correctly to the past, with
        # args of str, datetime.datetime, and pd.Timestamp.
        feb_prev = '2005-02-01'
        cl_feb_prev = cl.as_of(feb_prev)
        self.assertEqual(
            cl_feb_prev.as_of_date,
            pd.Timestamp(feb_prev, tz='UTC')
        )

        feb_prev = datetime(year=2005, month=2, day=1)
        cl_feb_prev = cl.as_of(feb_prev)
        self.assertEqual(
            cl_feb_prev.as_of_date,
            pd.Timestamp(feb_prev, tz='UTC')
        )

        feb_prev = pd.Timestamp('2005-02-01')
        cl_feb_prev = cl.as_of(feb_prev)
        self.assertEqual(
            cl_feb_prev.as_of_date,
            pd.Timestamp(feb_prev, tz='UTC')
        )

        # The chain as of the current dt should always be the same as
        # the defualt chain. Tests date as str, pd.Timestamp, and
        # datetime.datetime.
        self.assertEqual(cl[0], cl.as_of('2005-12-01')[0])
        self.assertEqual(cl[0], cl.as_of(pd.Timestamp('2005-12-01'))[0])
        self.assertEqual(
            cl[0],
            cl.as_of(datetime(year=2005, month=12, day=1))[0]
        )