def test_simple(self): t0 = datetime(2014,4,1) cash = [ fixed_income.cash(t0,t0+dates.relativedelta(days=t),1.0,r,'A/360') for t,r in ((30,0.005),(90,0.007),(180,0.010)) ] swaps = [ fixed_income.simple_swap(dates.schedule(t0,t0+dates.relativedelta(years=t),6,False,'A/360'),1.0,r) for t,r in ((1,0.012),(3,0.02),(5,0.020)) ] inst = cash + swaps func = __fmin__(t0,inst,'linear',True) func( ones(len(inst)) ) yc = bootstrap(t0,inst) print '>>> Discounts:',[yc(i.maturity_date) for i in inst] for i in inst: self.assertAlmostEqual(i.par_rate(yc),i.rate,3) self.assertAlmostEqual(i.value(yc),0.0,3)
def test_simple(self): t0 = datetime(2014, 4, 1) cash = [ fixed_income.cash(t0, t0 + dates.relativedelta(days=t), 1.0, r, 'A/360') for t, r in ((30, 0.005), (90, 0.007), (180, 0.010)) ] swaps = [ fixed_income.simple_swap( dates.schedule(t0, t0 + dates.relativedelta(years=t), 6, False, 'A/360'), 1.0, r) for t, r in ((1, 0.012), (3, 0.02), (5, 0.020)) ] inst = cash + swaps func = __fmin__(t0, inst, 'linear', True) func(ones(len(inst))) yc = bootstrap(t0, inst) print '>>> Discounts:', [yc(i.maturity_date) for i in inst] for i in inst: self.assertAlmostEqual(i.par_rate(yc), i.rate, 3) self.assertAlmostEqual(i.value(yc), 0.0, 3)
def test_swap(self): yc = testyc() t0 = datetime(2014,4,1) s = simple_swap(dates.schedule(t0,t0+dates.relativedelta(years=3),6,False,'A/360'),1.0,0.1) r = s.par_rate(yc) s.rate = r v = s.value(yc) self.assertAlmostEqual(v,0.0,3)
def test_cash(self): yc = testyc() t0 = yc.date c = cash(t0,t0+dates.relativedelta(days=30),1.0,0.01,'A/360') r = c.par_rate(yc) c.rate = r v = c.value(yc) self.assertAlmostEqual(v,0.0,3)
def test_cash(self): yc = testyc() t0 = yc.date c = cash(t0, t0 + dates.relativedelta(days=30), 1.0, 0.01, 'A/360') r = c.par_rate(yc) c.rate = r v = c.value(yc) self.assertAlmostEqual(v, 0.0, 3)
def test_swap(self): yc = testyc() t0 = datetime(2014, 4, 1) s = simple_swap( dates.schedule(t0, t0 + dates.relativedelta(years=3), 6, False, 'A/360'), 1.0, 0.1) r = s.par_rate(yc) s.rate = r v = s.value(yc) self.assertAlmostEqual(v, 0.0, 3)