Esempio n. 1
0
    def test_get_ticker_1st_contract_6_days_before_exp_date(self):
        exp_dates_to_ticker_str = {
            str_to_date("2016-12-16"): BloombergTicker('ESZ16 Index'),
            str_to_date("2017-03-17"): BloombergTicker('ESH17 Index')
        }

        future_ticker = BloombergFutureTicker("Euroswiss", "ES{} Index", 1, 6,
                                              100, "HMUZ")
        future_ticker.initialize_data_provider(self.timer, self.data_provider)

        # Check dates before 2016-12-16
        self.timer.set_current_time(str_to_date('2016-11-11'))
        self.assertEqual(future_ticker.get_current_specific_ticker(),
                         exp_dates_to_ticker_str[str_to_date("2016-12-16")])

        self.timer.set_current_time(str_to_date('2016-12-10'))
        self.assertEqual(future_ticker.get_current_specific_ticker(),
                         exp_dates_to_ticker_str[str_to_date("2016-12-16")])

        self.timer.set_current_time(
            str_to_date('2016-12-10 23:55:00.0', DateFormat.FULL_ISO))
        self.assertEqual(future_ticker.get_current_specific_ticker(),
                         exp_dates_to_ticker_str[str_to_date("2016-12-16")])

        self.timer.set_current_time(str_to_date('2016-12-16'))
        self.assertEqual(future_ticker.get_current_specific_ticker(),
                         exp_dates_to_ticker_str[str_to_date("2017-03-17")])
Esempio n. 2
0
    def test_get_ticker_2nd_contract_1_day_before_exp_date(self):
        exp_dates_to_ticker_str = {
            str_to_date("2016-06-30"): BloombergTicker('C N16 Comdty'),
            str_to_date("2016-08-31"): BloombergTicker('C U16 Comdty'),
            str_to_date("2016-11-30"): BloombergTicker('C Z16 Comdty')
        }

        future_ticker = BloombergFutureTicker("Corn", "C {} Comdty", 2, 1, 100,
                                              "HKNUZ")
        future_ticker.initialize_data_provider(self.timer, self.data_provider)

        self.timer.set_current_time(str_to_date('2016-06-03'))
        self.assertEqual(future_ticker.get_current_specific_ticker(),
                         exp_dates_to_ticker_str[str_to_date("2016-08-31")])

        self.timer.set_current_time(str_to_date('2016-06-29'))
        self.assertEqual(future_ticker.get_current_specific_ticker(),
                         exp_dates_to_ticker_str[str_to_date("2016-08-31")])

        self.timer.set_current_time(
            str_to_date('2016-06-29 23:59:59.0', DateFormat.FULL_ISO))
        self.assertEqual(future_ticker.get_current_specific_ticker(),
                         exp_dates_to_ticker_str[str_to_date("2016-08-31")])

        self.timer.set_current_time(str_to_date('2016-06-30'))
        self.assertEqual(future_ticker.get_current_specific_ticker(),
                         exp_dates_to_ticker_str[str_to_date("2016-11-30")])