Ejemplo n.º 1
0
  def test(self):
    from ppf.core import swap_rate
    from ppf.market import curve
    from ppf.math import loglinear
    from ppf.date_time            \
         import date              \
              , shift             \
              , shift_convention  \
              , months            \
              , years             \
              , basis_act_360     \
              , basis_act_365

    May = ppf.date_time.May
    modified_following = shift_convention.modified_following

    t = date(2005, May, 01)
    spot = date(2005, May, 03)
    maturity = shift(spot + years(10), modified_following)

    attributes = {}

    attributes["fixed-pay-period"] = 1
    attributes["fixed-pay-period-duration"] = years
    attributes["fixed-pay-basis"] = basis_act_360
    attributes["fixed-pay-holiday-centers"] = None
    attributes["fixed-shift-convention"] = modified_following

    attributes["float-pay-period"] = 6
    attributes["float-pay-period-duration"] = months
    attributes["float-pay-basis"] = basis_act_365
    attributes["float-pay-holiday-centers"] = None
    attributes["float-shift-convention"] = modified_following

    attributes["index-basis"] = basis_act_365
    attributes["index-holiday-centers"] = None
    attributes["index-shift-convention"] = modified_following

    #10y swap rate
    rate = swap_rate(
        attributes
      , 0 #flow id
      , 0 #reset id
      , spot #reset date
      , "GBP" #reset ccy
      , spot #proj start
      , maturity #proj end
      , None #fixing
      )

    times = range(0, 13)#12 years on the curve
    P = curve(times, [math.exp(-0.05*T) for T in times], loglinear)
    assert(math.fabs(0.0495099316847 - rate.forward(t, P)) < 1.0E-4)
Ejemplo n.º 2
0
  def test_libor(self):
    from ppf.date_time \
         import date, shift, modified_following, basis_act_360, months
    pd = date(2008, 01, 01)
    env = ppf.market.environment(pd)
    times = numpy.linspace(0, 2, 5)
    factors = numpy.array([math.exp(-0.05*t) for t in times])
    env.add_curve("zc.disc.eur"
        , ppf.market.curve(times, factors, ppf.math.interpolation.loglinear))
    expiries, tenors =      [0.1, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0], [0, 90]
    env.add_surface("ve.term.eur.hw"
                 , ppf.market.surface(expiries, tenors, numpy.zeros((8, 2))))
    env.add_constant("cv.mr.eur.hw", 0.0)
    rd = date(2008, 07, 01)
    libor_obs = \
      ppf.core.libor_rate( \
           None #attributes
         , 0    #flow-id
         , 0    #reset-id
         , rd   #reset-date
         , "eur"#reset-currency
         , rd   #projection-start-date
         , shift(rd + months(6), modified_following)#projection-end-date
         , basis_act_360#projection-basis
         , ppf.core.fixing(False))# fixing (and no spread)
    r = ppf.model.hull_white.requestor()
    s = ppf.model.hull_white.lattice.state("eur", 11, 3.5)
    sx = s.fill(0.25, r, env)
    f = ppf.model.hull_white.fill(2.0)
    libortT = f.libor(0.25, libor_obs, env, r, sx)
    exp = \
        [0.0499418283138
        ,0.0499418283138
        ,0.0499418283138
        ,0.0499418283138
        ,0.0499418283138
        ,0.0499418283138
        ,0.0499418283138
        ,0.0499418283138
        ,0.0499418283138
        ,0.0499418283138
        ,0.0499418283138
         ]

    _assert_seq_close(exp, libortT)
Ejemplo n.º 3
0
 def test_discounted_libor_rollback(self):
   from ppf.date_time \
        import date, shift, modified_following, basis_act_360, months
   pd = date(2008, 01, 01)
   env = ppf.market.environment(pd)
   times = numpy.linspace(0, 6, 10)
   factors = numpy.array([math.exp(-0.05*t) for t in times])
   env.add_curve("zc.disc.eur"
       , ppf.market.curve(times, factors, ppf.math.interpolation.loglinear))
   expiries, tenors = [0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0], [0, 90]
   values = numpy.zeros((9, 2))
   values.fill(0.001)
   env.add_surface("ve.term.eur.hw"
                , ppf.market.surface(expiries, tenors, values))
   env.add_constant("cv.mr.eur.hw", 0.01)
   r = ppf.model.hull_white.requestor()
   s = ppf.model.hull_white.lattice.state("eur", 41, 4.5)
   f = ppf.model.hull_white.fill(5.0)
   rd = date(2011, 01, 01)
   libor_obs = \
     ppf.core.libor_rate( \
          None #attributes
        , 0    #flow-id
        , 0    #reset-id
        , rd   #reset-date
        , "eur"#reset-currency
        , rd   #projection-start-date
        , shift(rd + months(6), modified_following)#projection-end-date
        , basis_act_360#projection-basis
        , ppf.core.fixing(False))# fixing (and no spread)
   t = env.relative_date(libor_obs.proj_start_date())/365.0
   T = env.relative_date(libor_obs.proj_end_date())/365.0
   sx = s.fill(t, r, env)
   libort = f.libor(t, libor_obs, env, r, sx)
   ptT = f.numeraire_rebased_bond(t, T, "eur", env, r, sx)
   pv = libort*ptT*libor_obs.year_fraction()
   roll = ppf.model.hull_white.lattice.rollback("eur")
   intermediate_pv = roll.rollback(0.5*t, t, s, r, env, pv)
   actual = roll.rollback(0.0, 0.5*t, s, r, env, intermediate_pv).mean() 
   expected = r.discount_factor(t, "eur", env)-r.discount_factor(T, "eur", env)
   _assert_seq_close([expected],[actual],1.0e-6)