ppf/core/generate_observables.py
def generate_swap_observables(
   start
 , end
 , attributes
 , spread = 0
 , roll_period = 6
 , roll_duration = ppf.date_time.months
 , tenor_period = 10
 , tenor_duration = ppf.date_time.years
 , 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 swap rates.
  
    >>> from ppf.date_time import *
    >>> props = {}
    >>> props["fixed-pay-period"] = 1
    >>> props["fixed-pay-period-duration"] = years
    >>> props["fixed-pay-basis"] = basis_act_360
    >>> props["fixed-pay-holiday-centers"] = None
    >>> props["fixed-shift-convention"] = modified_following
    >>> props["float-pay-period"] = 6
    >>> props["float-pay-period-duration"] = months
    >>> props["float-pay-basis"] = basis_act_365
    >>> props["float-pay-holiday-centers"] = None
    >>> props["float-shift-convention"] = modified_following
    >>> props["index-basis"] = basis_act_365
    >>> props["index-holiday-centers"] = None
    >>> props["index-shift-convention"] = modified_following
    >>> observables = generate_swap_observables(
    ...     start  = date(2007, Jun, 29)
    ...   , end  = date(2017, Jun, 29)
    ...   , attributes = props
    ...   , roll_period = 1
    ...   , roll_duration = years
    ...   , tenor_period = 10
    ...   , tenor_duration = years)
    >>> for o in observables: print o
    0, 0, USD, [2007-Jun-29, 2017-Jun-29], 
    1, 0, USD, [2008-Jun-30, 2018-Jun-29], 
    2, 0, USD, [2009-Jun-29, 2019-Jun-28], 
    3, 0, USD, [2010-Jun-29, 2020-Jun-29], 
    4, 0, USD, [2011-Jun-29, 2021-Jun-29], 
    5, 0, USD, [2012-Jun-29, 2022-Jun-29], 
    6, 0, USD, [2013-Jun-28, 2023-Jun-29], 
    7, 0, USD, [2014-Jun-30, 2024-Jun-28], 
    8, 0, USD, [2015-Jun-29, 2025-Jun-30], 
    9, 0, USD, [2016-Jun-29, 2026-Jun-29], 
  '''
  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
      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
          )
      all_observables.append(
        swap_rate(
            attributes
          , flow_id
          , reset_id
          , reset_date
          , reset_currency
          , proj_start
          , proj_end
          , fixing(False)
          , spread) )
      flow_id += 1; reset_id += 1; day = roll_end

  return all_observables
Generate a sequence of swap rates.
  
    >>> from ppf.date_time import *
    >>> props = {}
    >>> props["fixed-pay-period"] = 1
    >>> props["fixed-pay-period-duration"] = years
    >>> props["fixed-pay-basis"] = basis_act_360
    >>> props["fixed-pay-holiday-centers"] = None
    >>> props["fixed-shift-convention"] = modified_following
    >>> props["float-pay-period"] = 6
    >>> props["float-pay-period-duration"] = months
    >>> props["float-pay-basis"] = basis_act_365
    >>> props["float-pay-holiday-centers"] = None
    >>> props["float-shift-convention"] = modified_following
    >>> props["index-basis"] = basis_act_365
    >>> props["index-holiday-centers"] = None
    >>> props["index-shift-convention"] = modified_following
    >>> observables = generate_swap_observables(
    ...     start  = date(2007, Jun, 29)
    ...   , end  = date(2017, Jun, 29)
    ...   , attributes = props
    ...   , roll_period = 1
    ...   , roll_duration = years
    ...   , tenor_period = 10
    ...   , tenor_duration = years)
    >>> for o in observables: print o
    0, 0, USD, [2007-Jun-29, 2017-Jun-29], 
    1, 0, USD, [2008-Jun-30, 2018-Jun-29], 
    2, 0, USD, [2009-Jun-29, 2019-Jun-28], 
    3, 0, USD, [2010-Jun-29, 2020-Jun-29], 
    4, 0, USD, [2011-Jun-29, 2021-Jun-29], 
    5, 0, USD, [2012-Jun-29, 2022-Jun-29], 
    6, 0, USD, [2013-Jun-28, 2023-Jun-29], 
    7, 0, USD, [2014-Jun-30, 2024-Jun-28], 
    8, 0, USD, [2015-Jun-29, 2025-Jun-30], 
    9, 0, USD, [2016-Jun-29, 2026-Jun-29], 
  
Generate a sequence of swap rates.
Generate a sequence of swap rates .
def generate_swap_observables(
   start
 , end
 , attributes
 , spread = 0
 , roll_period = 6
 , roll_duration = ppf.date_time.months
 , tenor_period = 10
 , tenor_duration = ppf.date_time.years
 , 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
      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
          )
      all_observables.append(
        swap_rate(
            attributes
          , flow_id
          , reset_id
          , reset_date
          , reset_currency
          , proj_start
          , proj_end
          , fixing(False)
          , spread) )
      flow_id += 1; reset_id += 1; day = roll_end
  return all_observables
def generate_swap_observables ( start , end , attributes , spread = 0 , roll_period = 6 , roll_duration = ppf . date_time . months , tenor_period = 10 , tenor_duration = ppf . date_time . years , 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 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 ) all_observables . append ( swap_rate ( attributes , flow_id , reset_id , reset_date , reset_currency , proj_start , proj_end , fixing ( False ) , spread ) ) flow_id += 1 ; reset_id += 1 ; day = roll_end return all_observables
Generate a sequence of swap rates.
Generate a sequence of swap rates .
'''Generate a sequence of swap rates.
  
    >>> from ppf.date_time import *
    >>> props = {}
    >>> props["fixed-pay-period"] = 1
    >>> props["fixed-pay-period-duration"] = years
    >>> props["fixed-pay-basis"] = basis_act_360
    >>> props["fixed-pay-holiday-centers"] = None
    >>> props["fixed-shift-convention"] = modified_following
    >>> props["float-pay-period"] = 6
    >>> props["float-pay-period-duration"] = months
    >>> props["float-pay-basis"] = basis_act_365
    >>> props["float-pay-holiday-centers"] = None
    >>> props["float-shift-convention"] = modified_following
    >>> props["index-basis"] = basis_act_365
    >>> props["index-holiday-centers"] = None
    >>> props["index-shift-convention"] = modified_following
    >>> observables = generate_swap_observables(
    ...     start  = date(2007, Jun, 29)
    ...   , end  = date(2017, Jun, 29)
    ...   , attributes = props
    ...   , roll_period = 1
    ...   , roll_duration = years
    ...   , tenor_period = 10
    ...   , tenor_duration = years)
    >>> for o in observables: print o
    0, 0, USD, [2007-Jun-29, 2017-Jun-29], 
    1, 0, USD, [2008-Jun-30, 2018-Jun-29], 
    2, 0, USD, [2009-Jun-29, 2019-Jun-28], 
    3, 0, USD, [2010-Jun-29, 2020-Jun-29], 
    4, 0, USD, [2011-Jun-29, 2021-Jun-29], 
    5, 0, USD, [2012-Jun-29, 2022-Jun-29], 
    6, 0, USD, [2013-Jun-28, 2023-Jun-29], 
    7, 0, USD, [2014-Jun-30, 2024-Jun-28], 
    8, 0, USD, [2015-Jun-29, 2025-Jun-30], 
    9, 0, USD, [2016-Jun-29, 2026-Jun-29], 
  '''
start
end
attributes
spread
roll_period
roll_duration
tenor_period
tenor_duration
reset_currency
reset_basis
reset_holiday_centres
reset_shift_method
reset_lag