ppf/core/generate_observables.py
def generate_libor_observables(
   start
 , end
 , roll_period = 6
 , roll_duration = ppf.date_time.months
 , reset_period = 6
 , reset_duration = ppf.date_time.months
 , tenor_period = 6
 , tenor_duration = ppf.date_time.months
 , reset_currency = "USD"
 , reset_basis = ppf.date_time.basis_act_360
 , reset_holiday_centres = None
 , reset_shift_method = ppf.date_time.shift_convention.modified_following
 , reset_lag = 0
 , *arguments
 , **keywords):
  '''Generate a sequence of libor rates.
  
  >>> from ppf.date_time import *
  >>> observables = generate_libor_observables(
  ...     start  = date(2007, Jun, 29)
  ...   , end  = date(2012, Jun, 29)
  ...   , roll_period = 6
  ...   , roll_duration = ppf.date_time.months
  ...   , reset_period = 3
  ...   , reset_duration = ppf.date_time.months
  ...   , tenor_period = 3
  ...   , tenor_duration = ppf.date_time.months
  ...   , reset_currency = "JPY"
  ...   , reset_basis = basis_act_360
  ...   , reset_shift_method = shift_convention.modified_following)
  >>> for obs_per_flow in observables:
  ...  for obs in obs_per_flow:
  ...   print obs
  0, 0, JPY, [2007-Jun-29, 2007-Sep-28], basis_act_360, 
  0, 1, JPY, [2007-Sep-28, 2007-Dec-31], basis_act_360, 
  1, 0, JPY, [2007-Dec-31, 2008-Mar-31], basis_act_360, 
  1, 1, JPY, [2008-Mar-31, 2008-Jun-30], basis_act_360, 
  2, 0, JPY, [2008-Jun-30, 2008-Sep-29], basis_act_360, 
  2, 1, JPY, [2008-Sep-29, 2008-Dec-29], basis_act_360, 
  3, 0, JPY, [2008-Dec-29, 2009-Mar-30], basis_act_360, 
  3, 1, JPY, [2009-Mar-30, 2009-Jun-29], basis_act_360, 
  4, 0, JPY, [2009-Jun-29, 2009-Sep-29], basis_act_360, 
  4, 1, JPY, [2009-Sep-29, 2009-Dec-29], basis_act_360, 
  5, 0, JPY, [2009-Dec-29, 2010-Mar-29], basis_act_360, 
  5, 1, JPY, [2010-Mar-29, 2010-Jun-29], basis_act_360, 
  6, 0, JPY, [2010-Jun-29, 2010-Sep-29], basis_act_360, 
  6, 1, JPY, [2010-Sep-29, 2010-Dec-29], basis_act_360, 
  7, 0, JPY, [2010-Dec-29, 2011-Mar-29], basis_act_360, 
  7, 1, JPY, [2011-Mar-29, 2011-Jun-29], basis_act_360, 
  8, 0, JPY, [2011-Jun-29, 2011-Sep-29], basis_act_360, 
  8, 1, JPY, [2011-Sep-29, 2011-Dec-29], basis_act_360, 
  9, 0, JPY, [2011-Dec-29, 2012-Mar-29], basis_act_360, 
  9, 1, JPY, [2012-Mar-29, 2012-Jun-29], basis_act_360, 
 '''
  from ppf.date_time import days
  shift = ppf.date_time.shift

  if reset_lag > 0:
    raise RuntimeError, "index lag expected less or equal to zero"

  day, flow_id, all_observables = 0, 0, []
  while day < end:
      roll_start = start + roll_duration(flow_id*roll_period)
      roll_end = start + roll_duration((flow_id+1)*roll_period)
      reset_id = 0
      proj_roll = roll_start
      observables = []
      while proj_roll < roll_end:
           proj_start = shift(
                    proj_roll
                  , reset_shift_method, reset_holiday_centres)
           proj_end = shift(
                    proj_roll+tenor_duration(tenor_period)
                  , reset_shift_method, reset_holiday_centres)
           reset_date = shift(
                    proj_start+days(reset_lag)
                  , reset_shift_method, reset_holiday_centres)
           observables.append( 
                     libor_rate(None, flow_id,  reset_id, reset_date
                              , reset_currency, proj_start, proj_end
                              , reset_basis, fixing(False)))
           reset_id += 1
           proj_roll = roll_start+reset_duration(reset_id*reset_period) 
      day = roll_end
      all_observables.append(observables)
      flow_id += 1

  return all_observables
Generate a sequence of libor rates.
  
  >>> from ppf.date_time import *
  >>> observables = generate_libor_observables(
  ...     start  = date(2007, Jun, 29)
  ...   , end  = date(2012, Jun, 29)
  ...   , roll_period = 6
  ...   , roll_duration = ppf.date_time.months
  ...   , reset_period = 3
  ...   , reset_duration = ppf.date_time.months
  ...   , tenor_period = 3
  ...   , tenor_duration = ppf.date_time.months
  ...   , reset_currency = "JPY"
  ...   , reset_basis = basis_act_360
  ...   , reset_shift_method = shift_convention.modified_following)
  >>> for obs_per_flow in observables:
  ...  for obs in obs_per_flow:
  ...   print obs
  0, 0, JPY, [2007-Jun-29, 2007-Sep-28], basis_act_360, 
  0, 1, JPY, [2007-Sep-28, 2007-Dec-31], basis_act_360, 
  1, 0, JPY, [2007-Dec-31, 2008-Mar-31], basis_act_360, 
  1, 1, JPY, [2008-Mar-31, 2008-Jun-30], basis_act_360, 
  2, 0, JPY, [2008-Jun-30, 2008-Sep-29], basis_act_360, 
  2, 1, JPY, [2008-Sep-29, 2008-Dec-29], basis_act_360, 
  3, 0, JPY, [2008-Dec-29, 2009-Mar-30], basis_act_360, 
  3, 1, JPY, [2009-Mar-30, 2009-Jun-29], basis_act_360, 
  4, 0, JPY, [2009-Jun-29, 2009-Sep-29], basis_act_360, 
  4, 1, JPY, [2009-Sep-29, 2009-Dec-29], basis_act_360, 
  5, 0, JPY, [2009-Dec-29, 2010-Mar-29], basis_act_360, 
  5, 1, JPY, [2010-Mar-29, 2010-Jun-29], basis_act_360, 
  6, 0, JPY, [2010-Jun-29, 2010-Sep-29], basis_act_360, 
  6, 1, JPY, [2010-Sep-29, 2010-Dec-29], basis_act_360, 
  7, 0, JPY, [2010-Dec-29, 2011-Mar-29], basis_act_360, 
  7, 1, JPY, [2011-Mar-29, 2011-Jun-29], basis_act_360, 
  8, 0, JPY, [2011-Jun-29, 2011-Sep-29], basis_act_360, 
  8, 1, JPY, [2011-Sep-29, 2011-Dec-29], basis_act_360, 
  9, 0, JPY, [2011-Dec-29, 2012-Mar-29], basis_act_360, 
  9, 1, JPY, [2012-Mar-29, 2012-Jun-29], basis_act_360, 
 
Generate a sequence of libor rates.
Generate a sequence of libor rates .
def generate_libor_observables(
   start
 , end
 , roll_period = 6
 , roll_duration = ppf.date_time.months
 , reset_period = 6
 , reset_duration = ppf.date_time.months
 , tenor_period = 6
 , tenor_duration = ppf.date_time.months
 , reset_currency = "USD"
 , reset_basis = ppf.date_time.basis_act_360
 , reset_holiday_centres = None
 , reset_shift_method = ppf.date_time.shift_convention.modified_following
 , reset_lag = 0
 , *arguments
 , **keywords):
  from ppf.date_time import days
  shift = ppf.date_time.shift
  if reset_lag > 0:
    raise RuntimeError, "index lag expected less or equal to zero"
  day, flow_id, all_observables = 0, 0, []
  while day < end:
      roll_start = start + roll_duration(flow_id*roll_period)
      roll_end = start + roll_duration((flow_id+1)*roll_period)
      reset_id = 0
      proj_roll = roll_start
      observables = []
      while proj_roll < roll_end:
           proj_start = shift(
                    proj_roll
                  , reset_shift_method, reset_holiday_centres)
           proj_end = shift(
                    proj_roll+tenor_duration(tenor_period)
                  , reset_shift_method, reset_holiday_centres)
           reset_date = shift(
                    proj_start+days(reset_lag)
                  , reset_shift_method, reset_holiday_centres)
           observables.append( 
                     libor_rate(None, flow_id,  reset_id, reset_date
                              , reset_currency, proj_start, proj_end
                              , reset_basis, fixing(False)))
           reset_id += 1
           proj_roll = roll_start+reset_duration(reset_id*reset_period) 
      day = roll_end
      all_observables.append(observables)
      flow_id += 1
  return all_observables
def generate_libor_observables ( start , end , roll_period = 6 , roll_duration = ppf . date_time . months , reset_period = 6 , reset_duration = ppf . date_time . months , tenor_period = 6 , tenor_duration = ppf . date_time . months , reset_currency = "USD" , reset_basis = ppf . date_time . basis_act_360 , reset_holiday_centres = None , reset_shift_method = ppf . date_time . shift_convention . modified_following , reset_lag = 0 , * arguments , ** keywords ) : from ppf . date_time import days shift = ppf . date_time . shift if reset_lag > 0 : raise RuntimeError , "index lag expected less or equal to zero" day , flow_id , all_observables = 0 , 0 , [ ] while day < end : roll_start = start + roll_duration ( flow_id * roll_period ) roll_end = start + roll_duration ( ( flow_id + 1 ) * roll_period ) reset_id = 0 proj_roll = roll_start observables = [ ] while proj_roll < roll_end : proj_start = shift ( proj_roll , reset_shift_method , reset_holiday_centres ) proj_end = shift ( proj_roll + tenor_duration ( tenor_period ) , reset_shift_method , reset_holiday_centres ) reset_date = shift ( proj_start + days ( reset_lag ) , reset_shift_method , reset_holiday_centres ) observables . append ( libor_rate ( None , flow_id , reset_id , reset_date , reset_currency , proj_start , proj_end , reset_basis , fixing ( False ) ) ) reset_id += 1 proj_roll = roll_start + reset_duration ( reset_id * reset_period ) day = roll_end all_observables . append ( observables ) flow_id += 1 return all_observables
Generate a sequence of libor rates.
Generate a sequence of libor rates .
'''Generate a sequence of libor rates.
  
  >>> from ppf.date_time import *
  >>> observables = generate_libor_observables(
  ...     start  = date(2007, Jun, 29)
  ...   , end  = date(2012, Jun, 29)
  ...   , roll_period = 6
  ...   , roll_duration = ppf.date_time.months
  ...   , reset_period = 3
  ...   , reset_duration = ppf.date_time.months
  ...   , tenor_period = 3
  ...   , tenor_duration = ppf.date_time.months
  ...   , reset_currency = "JPY"
  ...   , reset_basis = basis_act_360
  ...   , reset_shift_method = shift_convention.modified_following)
  >>> for obs_per_flow in observables:
  ...  for obs in obs_per_flow:
  ...   print obs
  0, 0, JPY, [2007-Jun-29, 2007-Sep-28], basis_act_360, 
  0, 1, JPY, [2007-Sep-28, 2007-Dec-31], basis_act_360, 
  1, 0, JPY, [2007-Dec-31, 2008-Mar-31], basis_act_360, 
  1, 1, JPY, [2008-Mar-31, 2008-Jun-30], basis_act_360, 
  2, 0, JPY, [2008-Jun-30, 2008-Sep-29], basis_act_360, 
  2, 1, JPY, [2008-Sep-29, 2008-Dec-29], basis_act_360, 
  3, 0, JPY, [2008-Dec-29, 2009-Mar-30], basis_act_360, 
  3, 1, JPY, [2009-Mar-30, 2009-Jun-29], basis_act_360, 
  4, 0, JPY, [2009-Jun-29, 2009-Sep-29], basis_act_360, 
  4, 1, JPY, [2009-Sep-29, 2009-Dec-29], basis_act_360, 
  5, 0, JPY, [2009-Dec-29, 2010-Mar-29], basis_act_360, 
  5, 1, JPY, [2010-Mar-29, 2010-Jun-29], basis_act_360, 
  6, 0, JPY, [2010-Jun-29, 2010-Sep-29], basis_act_360, 
  6, 1, JPY, [2010-Sep-29, 2010-Dec-29], basis_act_360, 
  7, 0, JPY, [2010-Dec-29, 2011-Mar-29], basis_act_360, 
  7, 1, JPY, [2011-Mar-29, 2011-Jun-29], basis_act_360, 
  8, 0, JPY, [2011-Jun-29, 2011-Sep-29], basis_act_360, 
  8, 1, JPY, [2011-Sep-29, 2011-Dec-29], basis_act_360, 
  9, 0, JPY, [2011-Dec-29, 2012-Mar-29], basis_act_360, 
  9, 1, JPY, [2012-Mar-29, 2012-Jun-29], basis_act_360, 
 '''
start
end
roll_period
roll_duration
reset_period
reset_duration
tenor_period
tenor_duration
reset_currency
reset_basis
reset_holiday_centres
reset_shift_method
reset_lag