def test_equality_method(self): day_counter = Thirty360(EUROBONDBASIS) self.assertNotEquals(day_counter.name(), Thirty360().name()) self.assertNotEqual(day_counter, Thirty360()) self.assertEquals(day_counter, Thirty360(EUROBONDBASIS))
def test_equality_method(self): day_counter = Thirty360(EurobondBasis) a = Thirty360() self.assertNotEqual(day_counter, a) self.assertNotEqual(day_counter, Thirty360()) self.assertEqual(day_counter, Thirty360(EurobondBasis))
def test_thirty360_from_name(self): for c in Convention: dc = Thirty360(c) try: dc2 = DayCounter.from_name(dc.name) except ValueError: pass else: self.assertEqual(dc, dc2)
def test_thirty360(self): day_counter = Thirty360(EUROBONDBASIS) from_date = Date(1, July, 1999) to_date = Date(1, July, 2000) expected_result = 1.000000000000 self.assertAlmostEquals(expected_result, day_counter.year_fraction(from_date, to_date))
class DayCounters(dict): from quantlib.time.daycounters.thirty360 import Thirty360 from quantlib.time.daycounter import ( Actual360, Actual365Fixed ) from quantlib.time.daycounters.actual_actual import ( ActualActual, ISMA, ISDA, Bond ) _lookup = dict([(dc.name(), dc) for dc in [Thirty360(), Actual360(), Actual365Fixed(), ActualActual(), ActualActual(ISMA), ActualActual(ISDA), ActualActual(Bond) ]] ) def __init__(self, *args): dict.__init__(self, self._lookup) self.update(*args) @classmethod def year_fraction(cls, date1, date2, daycounter=None): ''' Calculate the fraction of a year between two date1 and date2, based on the daycount specified. dates may be ccyymmdd or python datetime.dates ''' pydate1, pydate2 = map(pydate, (date1, date2)) if not daycounter: daycounter = cls.ActualActual() qldate1 = qldate_from_pydate(pydate1) qldate2 = qldate_from_pydate(pydate2) return daycounter.year_fraction(qldate1, qldate2) @classmethod def daycount(cls, date1, date2, daycounter=None): pydate1, pydate2 = map(pydate, (date1, date2)) if not daycounter: daycounter = cls.ActualActual() qldate1 = qldate_from_pydate(pydate1) qldate2 = qldate_from_pydate(pydate2) return daycounter.day_count(qldate1, qldate2)