def make_rate_helper(market, quote, reference_date=None): """ Wrapper for deposit and swaps rate helpers makers TODO: class method of RateHelper? """ rate_type, tenor, quote_value = quote if rate_type == 'SWAP': libor_index = market._floating_rate_index spread = SimpleQuote(0) fwdStart = Period(0, Days) helper = SwapRateHelper.from_tenor( quote_value, Period(tenor), market._floating_rate_index.fixing_calendar, Period(market._params.fixed_leg_period).frequency, BusinessDayConvention.from_name( market._params.fixed_leg_convention), DayCounter.from_name(market._params.fixed_leg_daycount), libor_index, spread, fwdStart) elif rate_type == 'DEP': end_of_month = True helper = DepositRateHelper( quote_value, Period(tenor), market._params.settlement_days, market._floating_rate_index.fixing_calendar, market._floating_rate_index.business_day_convention, end_of_month, DayCounter.from_name(market._deposit_daycount)) elif rate_type == 'ED': if reference_date is None: raise Exception("Reference date needed with ED Futures data") forward_date = next_imm_date(reference_date, tenor) helper = FuturesRateHelper( price=SimpleQuote(quote_value), imm_date=qldate_from_pydate(forward_date), length_in_months=3, calendar=market._floating_rate_index.fixing_calendar, convention=market._floating_rate_index.business_day_convention, end_of_month=True, day_counter=DayCounter.from_name( market._params.floating_leg_daycount)) elif rate_type.startswith('ER'): # TODO For Euribor futures, we found it useful to supply the `imm_date` # parameter directly, instead of as a number of periods from the # evaluation date, as for ED futures. To achieve this, we pass the # `imm_date` in the `tenor` field of the quote. helper = FuturesRateHelper( price=SimpleQuote(quote_value), imm_date=tenor, length_in_months=3, calendar=market._floating_rate_index.fixing_calendar, convention=market._floating_rate_index.business_day_convention, end_of_month=True, day_counter=DayCounter.from_name( market._params.floating_leg_daycount)) else: raise Exception("Rate type %s not supported" % rate_type) return helper
def next_imm_date(reference_date, tenor): """ Third Wednesday of contract month """ dt = qldate_from_pydate(reference_date) for k in range(tenor): tmp = imm.next_date(dt) dt = pydate_to_qldate(tmp) return pydate_from_qldate(dt)
def make_rate_helper(market, quote, reference_date=None): """ Wrapper for deposit and swaps rate helpers makers TODO: class method of RateHelper? """ rate_type, tenor, quote_value = quote if rate_type == 'SWAP': libor_index = market._floating_rate_index spread = SimpleQuote(0) fwdStart = Period(0, Days) helper = SwapRateHelper.from_tenor( quote_value, Period(tenor), market._floating_rate_index.fixing_calendar, code_to_frequency(market._params.fixed_leg_period), BusinessDayConvention.from_name( market._params.fixed_leg_convention), DayCounter.from_name(market._params.fixed_leg_daycount), libor_index, spread, fwdStart) elif rate_type == 'DEP': end_of_month = True helper = DepositRateHelper( quote_value, Period(tenor), market._params.settlement_days, market._floating_rate_index.fixing_calendar, market._floating_rate_index.business_day_convention, end_of_month, DayCounter.from_name(market._deposit_daycount)) elif rate_type == 'ED': if reference_date is None: raise Exception("Reference date needed with ED Futures data") forward_date = next_imm_date(reference_date, tenor) helper = FuturesRateHelper( rate =SimpleQuote(quote_value), imm_date = qldate_from_pydate(forward_date), length_in_months = 3, calendar = market._floating_rate_index.fixing_calendar, convention = market._floating_rate_index.business_day_convention, end_of_month = True, day_counter = DayCounter.from_name( market._params.floating_leg_daycount)) elif rate_type.startswith('ER'): # TODO For Euribor futures, we found it useful to supply the `imm_date` # parameter directly, instead of as a number of periods from the # evaluation date, as for ED futures. To achieve this, we pass the # `imm_date` in the `tenor` field of the quote. helper = FuturesRateHelper( rate=SimpleQuote(quote_value), imm_date=tenor, length_in_months=3, calendar=market._floating_rate_index.fixing_calendar, convention=market._floating_rate_index.business_day_convention, end_of_month=True, day_counter=DayCounter.from_name( market._params.floating_leg_daycount)) else: raise Exception("Rate type %s not supported" % rate_type) return helper