Exemplo n.º 1
0
    def _rebuild_object(self):
        if self._is_modified_property(
                '_calendar_') and not self._is_modified_property('_spot_'):
            self._spot_ = BusinessPeriod(businessdays=self._spot_.businessdays,
                                         holiday=self._calendar_)

        x_list = list()
        # carefully cast x_list/curve dates
        for x in self._curve_.row_keys():
            if BusinessDate.is_businessdate(x):
                x = BusinessDate(x)
            elif BusinessPeriod.is_businessperiod(x):
                x = BusinessPeriod(x).to_businessdate(self.origin)
            else:
                s = repr(x), type(
                    x), BusinessDate.__name__, self.__class__.__name__
                raise ValueError(
                    'Cannot cast value %s of type %s to %s in %s construction.'
                    % s)
            x_list.append(x)

        y_list = list(map(float, self._curve_.col('Rate')))
        y_inter = Constant(), self._interpolation_, self._extrapolation_
        if self._rate_type_ == "Zero":
            self._inner_curve = ZeroRateCurve(x_list,
                                              y_list,
                                              y_inter,
                                              self.origin,
                                              day_count=self._day_count_)
        else:
            msg = "_curve_ " + self.object_name + ": RateType " + self._rate_type_ + " not implemented, yet."
            raise NotImplementedError(msg)

        self._curve_df_dict = dict()
        return self
Exemplo n.º 2
0
 def test_validations(self):
     self.assertTrue(BusinessPeriod.is_businessperiod('1y'))
     self.assertTrue(BusinessPeriod.is_businessperiod('-1y'))
     self.assertFalse(BusinessPeriod.is_businessperiod('1y-6m'))
Exemplo n.º 3
0
 def test_validations(self):
     self.assertTrue(BusinessPeriod.is_businessperiod('1y'))
     self.assertTrue(BusinessPeriod.is_businessperiod('-1y'))
     self.assertFalse(BusinessPeriod.is_businessperiod('1y-6m'))
Exemplo n.º 4
0
    def test_validations(self):
        for p in ('', '0D', 'ON', 'TN', 'DD'):
            self.assertTrue(BusinessPeriod.is_businessperiod(p))
        self.assertTrue(BusinessPeriod.is_businessperiod(timedelta(1)))
        self.assertTrue(BusinessPeriod.is_businessperiod(BusinessPeriod('1D')))
        self.assertTrue(BusinessPeriod.is_businessperiod('1y'))
        self.assertTrue(BusinessPeriod.is_businessperiod('1y'))
        self.assertTrue(BusinessPeriod.is_businessperiod('1y'))
        self.assertTrue(BusinessPeriod.is_businessperiod('1y'))
        self.assertTrue(BusinessPeriod.is_businessperiod('-1y'))
        self.assertTrue(BusinessPeriod.is_businessperiod('1y-6m'))
        self.assertTrue(BusinessPeriod.is_businessperiod('-2b1y6m'))
        self.assertTrue(BusinessPeriod.is_businessperiod('-2b-1y6m'))
        self.assertTrue(BusinessPeriod.is_businessperiod('-2b-1y6m-2b'))

        self.assertFalse(BusinessPeriod.is_businessperiod(None))
        self.assertFalse(BusinessPeriod.is_businessperiod('123'))
        self.assertFalse(BusinessPeriod.is_businessperiod(123))
        self.assertFalse(BusinessPeriod.is_businessperiod(True))
        self.assertFalse(BusinessPeriod.is_businessperiod('2D3D'))
        self.assertRaises(TypeError, BusinessPeriod().__cmp__, BusinessDate())
        self.assertRaises(TypeError, BusinessPeriod().__cmp__, 123)
        self.assertFalse(BusinessPeriod('1B') == '2D3D')
        self.assertFalse(BusinessPeriod() == '2D3D')