def test_nth_imm_of_year(self):
        from ppf.date_time import nth_imm_of_year, date, months_of_year

        imm = nth_imm_of_year
        Mar, Jun, Sep, Dec = months_of_year.Mar, months_of_year.Jun, months_of_year.Sep, months_of_year.Dec
        imm_dates = [imm(x).get_date(2005) for x in [imm.first, imm.second, imm.third, imm.fourth]]
        assert imm_dates == [date(2005, Mar, 16), date(2005, Jun, 15), date(2005, Sep, 21), date(2005, Dec, 21)]
Exemple #2
0
def _create_fixed_leg(coupon = None):
  from ppf.date_time \
       import date, shift_convention, modified_following, basis_act_360, months
  cpn = 0.06
  if coupon <> None:
    cpn = coupon
  coupon_observables = ppf.core.generate_fixed_coupon_observables(\
     start  = date(2007, 06, 29)\
    , end  = date(2010, 06, 29)\
    , roll_period = 6\
    , reset_currency = "USD"\
    , coupon_shift_method = shift_convention.modified_following\
    , coupon_rate = cpn)  

  flows = ppf.core.generate_flows(\
      start  = date(2007, 06, 29)\
    , end  = date(2010, 06, 29)\
    , duration = ppf.date_time.months\
    , period = 6\
    , pay_shift_method = shift_convention.modified_following\
    , pay_currency = "USD"\
    , accrual_basis = basis_act_360
    , observables = coupon_observables)

  leg = ppf.core.leg(flows, ppf.core.PAY, None\
    , ppf.pricer.payoffs.fixed_leg_payoff())
  return leg 
Exemple #3
0
  def test_explanatory_variables(self):
    from ppf.math.interpolation import loglinear
    times = [0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
    factors = [math.exp(-0.05*t) for t in times]
    c = ppf.market.curve(times, factors, loglinear)
    expiries = [0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0]
    tenors = [0, 90]
    values = numpy.zeros((8, 2))
    surf = ppf.market.surface(expiries, tenors, values)
    from ppf.date_time \
         import date, shift_convention, modified_following, basis_act_360, months
    pd = date(2008, 01, 01)
    env = ppf.market.environment(pd)
    key = "zc.disc.eur"
    env.add_curve(key, c)
    key = "ve.term.eur.hw"
    env.add_surface(key, surf)
    key = "cv.mr.eur.hw"
    env.add_constant(key, 0.0)
    r = ppf.model.hull_white.requestor()
    s = ppf.model.hull_white.monte_carlo.state(10)
    sx = s.fill(0.25, r, env)
    f = ppf.model.hull_white.fill(3.0)
    flows = ppf.core.generate_flows(
             start  = date(2008, 01, 01)
            , end  = date(2010, 01, 01)
            , duration = months
            , period = 6
            , shift_method = shift_convention.modified_following
            , basis = "ACT/360"
            , pay_currency = "EUR")
    lg = ppf.core.leg(flows, ppf.core.PAY)
    ex = ppf.model.hull_white.monte_carlo.cle_exercise(lg)
    t = env.relative_date(flows[1].accrual_start_date())/365.0
    T = env.relative_date(flows[1].accrual_end_date())/365.0
    ret = ex(t, f, sx, r, env)
    dft = c(t)
    dfT = c(T)
    expected_libor = (dft/dfT-1.0)/flows[1].year_fraction()
    pv01 = 0.0
    for fl in flows[1:]:
      T = env.relative_date(fl.pay_date())/365.0
      dfT = c(T)
      pv01 += fl.year_fraction()*dfT
    T = env.relative_date(flows[-1].accrual_end_date())/365.0
    dfT = c(T)
    expected_swap = (dft-dfT)/pv01
    expected_libors = numpy.zeros(10)
    expected_libors.fill(expected_libor)
    expected_swaps = numpy.zeros(10)
    expected_swaps.fill(expected_swap)
    actual_libors = ret[:, 0]
    actual_swaps = ret[:, 1]

    _assert_seq_close(actual_libors, expected_libors)
    _assert_seq_close(actual_swaps, expected_swaps)
Exemple #4
0
def _create_exercise_schedule():
  from ppf.date_time \
       import date, shift_convention, modified_following, basis_act_360, months
  sched = ppf.core.generate_exercise_table(
    start  = date(2007, 06, 29)
    , end  = date(2009, 06, 29)
    , period = 1
    , duration = ppf.date_time.years
    , shift_method = shift_convention.modified_following)
  return sched
Exemple #5
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)
Exemple #6
0
 def test_nth_imm_of_year(self):
     from ppf.date_time import nth_imm_of_year, date, months_of_year
     imm = nth_imm_of_year
     Mar, Jun, Sep, Dec = \
          months_of_year.Mar, months_of_year.Jun, \
          months_of_year.Sep, months_of_year.Dec
     imm_dates = [
         imm(x).get_date(2005)
         for x in [imm.first, imm.second, imm.third, imm.fourth]
     ]
     assert imm_dates == [ \
           date(2005, Mar, 16)
         , date(2005, Jun, 15)
         , date(2005, Sep, 21)
         , date(2005, Dec, 21)]
Exemple #7
0
 def test_bond(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.monte_carlo.state(10000)
   e = ppf.model.hull_white.monte_carlo.evolve("eur")
   e.evolve(0.0,3.0,s,r,env)
   f = ppf.model.hull_white.fill(5.0)
   t = 3.0
   T = 4.0
   sx = s.fill(t, r, env)
   ptT = f.numeraire_rebased_bond(t, T, "eur", env, r, sx)
   actual = ptT.mean()
   expected = r.discount_factor(T, "eur", env)
   assert(math.fabs(actual-expected) < 1.0e-3)
Exemple #8
0
 def test_mean_and_variance(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.monte_carlo.state(10000)
   e = ppf.model.hull_white.monte_carlo.evolve("eur")
   e.evolve(0.0,0.5,s,r,env)
   e.evolve(0.5,1.0,s,r,env)
   variates = s.get_variates()
   mean = variates.sum()/10000
   assert(math.fabs(mean) < 1.0e-4)
   tmp = variates*variates
   variance = tmp.sum()/10000
   vol = r.term_vol(1.0,"eur",env)
   assert(math.fabs(variance-vol*vol) < 1.0e-4)
Exemple #9
0
 def test_constant(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, 5.5)
   f = ppf.model.hull_white.fill(5.0)
   t = 3.0
   T = 4.0
   terminal_T = 5.0
   sx = s.fill(t, r, env)
   yT = numpy.zeros(41)
   yT.fill(1)
   roll = ppf.model.hull_white.lattice.rollback("eur")    
   yt = roll.rollback(t, T, s, r, env, yT)
   _assert_seq_close(yt, yT, 1.0e-5)
Exemple #10
0
 def test_bond_option(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)
   t = 3.0
   T = 4.0
   terminal_T = 5.0
   sx = s.fill(t, r, env)
   ptT = f.numeraire_rebased_bond(t, T, "eur", env, r, sx)
   k = 0.9
   pv = ptT-k
   roll = ppf.model.hull_white.lattice.rollback("eur")    
   actual = roll.rollback_max(0.0, t, s, r, env, pv).mean()
   volt = r.term_vol(t, "eur", env)*r.local_vol(T, terminal_T, "eur", env)
   F = r.discount_factor(T, "eur", env)
   d1 = math.log(F/k)/volt+0.5*volt
   d2 = d1-volt
   expected = F*ppf.math.N(d1)-k*ppf.math.N(d2)
   _assert_seq_close([expected],[actual],1.0e-5)
Exemple #11
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)
Exemple #12
0
def _create_funding_leg():
  from ppf.date_time \
       import date, shift_convention, modified_following, basis_act_360, months
  libor_observables = ppf.core.generate_libor_observables(\
    start  = date(2007, 06, 29)\
    , end  = date(2010, 06, 29)\
    , roll_period = 6\
    , roll_duration = ppf.date_time.months\
    , reset_period = 6\
    , reset_duration = ppf.date_time.months\
    , reset_currency = "USD"\
    , reset_basis = basis_act_360\
    , reset_shift_method = shift_convention.modified_following)  

  adjuvant_table = ppf.core.generate_adjuvant_table(\
    keys = ["spread0"]\
    , tenors = [48]\
    , values = numpy.array([[0.0]])\
    , shift_method = shift_convention.modified_following\
    , start_date = date(2007, 06, 29)) 
Exemple #13
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)
Exemple #14
0
 def test(self):
   from ppf.date_time import date
   Jun = ppf.date_time.Jun
   periods = ppf.core.generate_date_tuples(
        start = date(2007, Jun, 29)
      , end   = date(2027, Jun, 29)
      , duration = ppf.date_time.months
      , period = 3
      , shift_method = ppf.date_time.shift_convention.modified_following
      , basis = "ACT/360")
   attributes={}
   t = date(2007, Jun, 29) #valuation date
   import math
   from ppf.math.interpolation import loglinear
   times = range(0, 22)
   P = loglinear(times, [math.exp(-0.05*T) for T in times])
   libor_table= []
   for i in range(len(periods)):
     reset = periods[i]
     reset_date = reset[0]
     projection_start, projection_until = reset
     libor_table.append(
       ppf.core.libor_rate(attributes
                         , i #flow id
                         , i #reset id
                         , reset_date
                         , "JPY"
                         , projection_start
                         , projection_until
                         , ppf.date_time.basis_act_360
                         , ppf.core.fixing(False)))
   forwards = [l.forward(t, P) for l in libor_table]
   for l in libor_table:
     Ts, Te = (int(l.proj_start_date() - t)/365.0
             , int(l.proj_end_date()   - t)/365.0)
     Ps, Pe = (P(Ts), P(Te))
     alpha = ppf.date_time.year_fraction(
       l.proj_start_date(), l.proj_end_date(), l.proj_basis())
     fwd = (Ps/Pe - 1)/alpha
     assert(fwd == l.forward(t, P))
def _create_tarn_coupon_leg(floor, fixed_rate, leverage, target, redemption_floor\
   , redemption_cap):
  from ppf.date_time \
       import date, shift_convention, modified_following, basis_act_360, months
  libor_observables = ppf.core.generate_libor_observables(\
    start  = date(2007, 06, 29)\
    , end  = date(2010, 06, 29)\
    , roll_period = 6\
    , roll_duration = ppf.date_time.months\
    , reset_period = 6\
    , reset_duration = ppf.date_time.months\
    , reset_currency = "USD"\
    , reset_basis = basis_act_360\
    , reset_shift_method = shift_convention.modified_following)  

  adjuvant_table = ppf.core.generate_adjuvant_table(\
    keys = ["floor0", "fixed_rate0", "leverage0", "target0", "redemption_floor0"\
      , "redemption_cap0"]\
    , tenors = [48]\
    , values = numpy.array([[floor], [fixed_rate], [leverage], [target]\
      , [redemption_floor], [redemption_cap]])\
    , shift_method = shift_convention.modified_following\
    , start_date = date(2007, 06, 29)) 
Exemple #16
0
def _create_environment():
  from ppf.date_time import date
  pd = date(2006, 12, 29)
  env = ppf.market.environment(pd)
  times = [0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0]
  factors = [math.exp(-0.05*t) for t in times]
  env.add_curve("zc.disc.usd"
     , ppf.market.curve(times, factors, ppf.math.interpolation.loglinear))
  expiries = [0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0]
  tenors = [0, 90]
  values = numpy.zeros((14, 2))  
  values.fill(0.001)#(0.00001)
  env.add_surface("ve.term.usd.hw"
                 , ppf.market.surface(expiries, tenors, values))
  env.add_constant("cv.mr.usd.hw", 0.01)
  return env
Exemple #17
0
def _create_environment():
  from ppf.date_time import date
  pd = date(2006, 12, 29)
  env = ppf.market.environment(pd)
  times = [0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0]
  factors = [math.exp(-0.05*t) for t in times]
  env.add_curve("zc.disc.usd"
     , ppf.market.curve(times, factors, ppf.math.interpolation.loglinear))
  expiries = [0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0]
  tenors = [0, 90]
  values = numpy.zeros((14, 2))  
  values.fill(0.001)#(0.00001)
  env.add_surface("ve.term.usd.hw"
                 , ppf.market.surface(expiries, tenors, values))
  env.add_constant("cv.mr.usd.hw", 0.01)
  return env
Exemple #18
0
 def test_first_imm_before(self):
     from ppf.date_time import first_imm_before, date, months_of_year
     Jun = months_of_year.Jun
     assert first_imm_before(date(2007, Jun, 27)) == date(2007, Jun, 20)
Exemple #19
0
    def test(self):
        from ppf.date_time import date, months_of_year, is_business_day

        Jun = months_of_year.Jun
        assert is_business_day(date(2007, Jun, 27))
        assert not is_business_day(date(2007, Jun, 30))
Exemple #20
0
    def test_first_imm_after(self):
        from ppf.date_time import first_imm_after, date, months_of_year

        Jun, Sep = months_of_year.Jun, months_of_year.Sep
        assert first_imm_after(date(2007, Jun, 27)) == date(2007, Sep, 19)
Exemple #21
0
    def test_first_imm_before(self):
        from ppf.date_time import first_imm_before, date, months_of_year

        Jun = months_of_year.Jun
        assert first_imm_before(date(2007, Jun, 27)) == date(2007, Jun, 20)
Exemple #22
0
 def test(self):
     from ppf.date_time import date, months_of_year, is_business_day
     Jun = months_of_year.Jun
     assert is_business_day(date(2007, Jun, 27))
     assert not is_business_day(date(2007, Jun, 30))
Exemple #23
0
  def test(self):
    from ppf.date_time import date
    from ppf.date_time import months
    from ppf.date_time import Feb, Apr, Jul, Oct, Jan
    from numpy import zeros

    expiries = [
       date(2006, Feb, 11)
     , date(2006, Apr, 11)
     , date(2006, Jul, 11)
     , date(2006, Oct, 11)
     , date(2007, Jan, 11)
     , date(2008, Jan, 11)
     , date(2009, Jan, 11)
     , date(2010, Jan, 11)
     , date(2011, Jan, 11)
     , date(2012, Jan, 11)
     , date(2013, Jan, 11) ]

    tenors = [ months(12), months(24), months(36) ]

    vols = zeros((len(expiries), len(tenors)))
    # expiry, tenor surface                    1y    2y     3y                                
    vols[ 0, 0], vols[ 0, 1], vols[ 0, 2] = 200.00, 76.25, 64.00 # 1m
    vols[ 1, 0], vols[ 1, 1], vols[ 1, 2] =  98.50, 84.75, 69.00 # 3m
    vols[ 2, 0], vols[ 2, 1], vols[ 2, 2] =  98.00, 81.75, 68.00 # 6m
    vols[ 3, 0], vols[ 3, 1], vols[ 3, 2] = 101.25, 82.25, 69.25 # 9m
    vols[ 4, 0], vols[ 4, 1], vols[ 4, 2] = 106.00, 82.00, 69.25 # 1y
    vols[ 5, 0], vols[ 5, 1], vols[ 5, 2] =  78.75, 73.25, 61.25 # 2y
    vols[ 6, 0], vols[ 6, 1], vols[ 6, 2] =  66.25, 59.00, 50.00 # 3y
    vols[ 7, 0], vols[ 7, 1], vols[ 7, 2] =  55.25, 47.75, 41.75 # 4y
    vols[ 8, 0], vols[ 8, 1], vols[ 8, 2] =  44.75, 40.25, 35.50 # 5y
    vols[ 9, 0], vols[ 9, 1], vols[ 9, 2] =  32.00, 30.50, 28.25 # 6y
    vols[10, 0], vols[10, 1], vols[10, 2] =  26.50, 24.25, 24.25 # 7y

    base = date(2006, Jan, 11);
    sig = ppf.market.surface(
         [int(t - base)/365.0 for t in expiries]
       , [m.number_of_months().as_number() for m in tenors]
       , vols)

    tol=1.0e-8
    for i in range(len(expiries)):
      expiry = expiries[i]
      t = int(expiry - base)/365.0
      for j in range(len(tenors)):
        tenor = tenors[j]
        T = tenor.number_of_months().as_number()
        assert math.fabs(sig(t, T) - vols[i, j]) <= tol 
Exemple #24
0
    def test(self):
        from ppf.date_time import date
        from ppf.date_time import months
        from ppf.date_time import Feb, Apr, Jul, Oct, Jan
        from numpy import zeros

        expiries = [
            date(2006, Feb, 11),
            date(2006, Apr, 11),
            date(2006, Jul, 11),
            date(2006, Oct, 11),
            date(2007, Jan, 11),
            date(2008, Jan, 11),
            date(2009, Jan, 11),
            date(2010, Jan, 11),
            date(2011, Jan, 11),
            date(2012, Jan, 11),
            date(2013, Jan, 11)
        ]

        tenors = [months(12), months(24), months(36)]

        vols = zeros((len(expiries), len(tenors)))
        # expiry, tenor surface                    1y    2y     3y
        vols[0, 0], vols[0, 1], vols[0, 2] = 200.00, 76.25, 64.00  # 1m
        vols[1, 0], vols[1, 1], vols[1, 2] = 98.50, 84.75, 69.00  # 3m
        vols[2, 0], vols[2, 1], vols[2, 2] = 98.00, 81.75, 68.00  # 6m
        vols[3, 0], vols[3, 1], vols[3, 2] = 101.25, 82.25, 69.25  # 9m
        vols[4, 0], vols[4, 1], vols[4, 2] = 106.00, 82.00, 69.25  # 1y
        vols[5, 0], vols[5, 1], vols[5, 2] = 78.75, 73.25, 61.25  # 2y
        vols[6, 0], vols[6, 1], vols[6, 2] = 66.25, 59.00, 50.00  # 3y
        vols[7, 0], vols[7, 1], vols[7, 2] = 55.25, 47.75, 41.75  # 4y
        vols[8, 0], vols[8, 1], vols[8, 2] = 44.75, 40.25, 35.50  # 5y
        vols[9, 0], vols[9, 1], vols[9, 2] = 32.00, 30.50, 28.25  # 6y
        vols[10, 0], vols[10, 1], vols[10, 2] = 26.50, 24.25, 24.25  # 7y

        base = date(2006, Jan, 11)
        sig = ppf.market.surface(
            [int(t - base) / 365.0 for t in expiries],
            [m.number_of_months().as_number() for m in tenors], vols)

        tol = 1.0e-8
        for i in range(len(expiries)):
            expiry = expiries[i]
            t = int(expiry - base) / 365.0
            for j in range(len(tenors)):
                tenor = tenors[j]
                T = tenor.number_of_months().as_number()
                assert math.fabs(sig(t, T) - vols[i, j]) <= tol
Exemple #25
0
 def test_first_imm_after(self):
     from ppf.date_time import first_imm_after, date, months_of_year
     Jun, Sep = months_of_year.Jun, months_of_year.Sep
     assert first_imm_after(date(2007, Jun, 27)) == date(2007, Sep, 19)
Exemple #26
0
    , roll_duration = ppf.date_time.months\
    , reset_period = 6\
    , reset_duration = ppf.date_time.months\
    , reset_currency = "USD"\
    , reset_basis = basis_act_360\
    , reset_shift_method = shift_convention.modified_following)  

  adjuvant_table = ppf.core.generate_adjuvant_table(\
    keys = ["spread0"]\
    , tenors = [48]\
    , values = numpy.array([[0.0]])\
    , shift_method = shift_convention.modified_following\
    , start_date = date(2007, 06, 29)) 

  flows = ppf.core.generate_flows(\
    start  = date(2007, 06, 29)\
    , end  = date(2010, 06, 29)\
    , duration = ppf.date_time.months\
    , period = 6\
    , pay_shift_method = shift_convention.modified_following\
    , pay_currency = "USD"\
    , accrual_basis = basis_act_360\
    , observables = libor_observables)

  leg = ppf.core.leg(flows, ppf.core.RECEIVE, adjuvant_table\
    , ppf.pricer.payoffs.float_leg_payoff())
  return leg

def _create_fixed_leg(coupon = None):
  from ppf.date_time \
       import date, shift_convention, modified_following, basis_act_360, months