Exemplo n.º 1
0
    def calculate_next_coupon(self, coupon_date, freq, biz_day_conv, iso,
                              lastDate):
        next_coupon_date = None
        if freq[-1:] == "M":
            months = int(freq[:-2])
            next_coupon_date = coupon_date + relativedelta(months=months)
        elif freq[-1:] == "D":
            days = int(freq[:-2])
            next_coupon_date = coupon_date + relativedelta(days=days)
        elif freq[-1:] == "W":
            weeks = int(freq[:-2])
            next_coupon_date = coupon_date + relativedelta(weeks=weeks)
        else:
            raise RuntimeError('Invalid coupon frequency: %s' % freq)

        cal = CalendarFactory().get(iso)

        biz_day = next_coupon_date
        if not cal.is_working_day(next_coupon_date):
            if biz_day_conv == "ADJMBC" or biz_day_conv == "MBC":
                biz_day = self.get_next_business_day(next_coupon_date, iso)
                if (biz_day.month != next_coupon_date.month):
                    biz_day = self.get_prev_business_day(next_coupon_date, iso)
            elif biz_day_conv == "ADJFWD" or biz_day_conv == "FWD":
                biz_day = self.get_next_business_day(next_coupon_date, iso)
            elif biz_day_conv == "ADJBACK":
                biz_day = self.get_prev_business_day(next_coupon_date, iso)
            elif biz_day_conv == "ADJROLL" or biz_day_conv == "ROLL":
                biz_day = self.get_next_business_day(next_coupon_date, iso)
            else:
                #TODO: raise RuntimeError('Invalid business day convention: %s' % biz_day_conv)
                biz_day = next_coupon_date

        if lastDate == True:
            next_coupon_date = self.last_day_of_month(next_coupon_date)

        return {
            'next_coupon_date': next_coupon_date,
            'act_coupon_date': biz_day
        }
Exemplo n.º 2
0
	def calculate_next_coupon(self, coupon_date, freq, biz_day_conv,iso,lastDate):
		next_coupon_date = None 
		if freq[-1:] == "M":
			months = int(freq[:-2])
			next_coupon_date = coupon_date + relativedelta(months=months)
		elif freq[-1:] == "D":
			days = int(freq[:-2])
			next_coupon_date = coupon_date + relativedelta(days=days)
		elif freq[-1:] == "W":
			weeks = int(freq[:-2])
			next_coupon_date = coupon_date + relativedelta(weeks=weeks)
		else:
			raise RuntimeError('Invalid coupon frequency: %s' % freq)

		cal = CalendarFactory().get(iso)

		biz_day = next_coupon_date
		if not cal.is_working_day(next_coupon_date):
			if biz_day_conv == "ADJMBC" or biz_day_conv == "MBC":
				biz_day = self.get_next_business_day(next_coupon_date,iso)
				if(biz_day.month != next_coupon_date.month):
					biz_day = self.get_prev_business_day(next_coupon_date,iso)
			elif biz_day_conv == "ADJFWD" or biz_day_conv == "FWD":
				biz_day = self.get_next_business_day(next_coupon_date,iso)
			elif biz_day_conv == "ADJBACK":
				biz_day = self.get_prev_business_day(next_coupon_date,iso)
			elif biz_day_conv == "ADJROLL" or biz_day_conv == "ROLL":
				biz_day =self.get_next_business_day(next_coupon_date,iso)
			else:
				#TODO: raise RuntimeError('Invalid business day convention: %s' % biz_day_conv)
				biz_day = next_coupon_date
		
		if lastDate == True:
			next_coupon_date = self.last_day_of_month(next_coupon_date)

		return {'next_coupon_date': next_coupon_date, 'act_coupon_date': biz_day}
Exemplo n.º 3
0
 def get_prev_business_day(self, coupon_date, iso):
     cal = CalendarFactory().get(iso)
     prev_day = coupon_date - relativedelta(days=1)
     while (not cal.is_working_day(prev_day)):
         prev_day = prev_day - relativedelta(days=1)
     return prev_day
Exemplo n.º 4
0
 def get_next_business_day(self, coupon_date, iso):
     cal = CalendarFactory().get(iso)
     next_day = coupon_date + relativedelta(days=1)
     while (not cal.is_working_day(next_day)):
         next_day = next_day + relativedelta(days=1)
     return next_day
Exemplo n.º 5
0
	def get_prev_business_day(self, coupon_date,iso):
		cal = CalendarFactory().get(iso)
		prev_day = coupon_date - relativedelta(days=1)
		while(not cal.is_working_day(prev_day)):
			prev_day = prev_day - relativedelta(days=1)
		return prev_day
Exemplo n.º 6
0
	def get_next_business_day(self, coupon_date,iso):
		cal = CalendarFactory().get(iso)
		next_day = coupon_date + relativedelta(days=1)
		while(not cal.is_working_day(next_day)):
			next_day = next_day + relativedelta(days=1)
		return next_day