コード例 #1
0
def _setup_leg(start_date, end_date, discount_curve_type, leg, schedule_fn,
               schedule, past_fixing):
    """Setup swap legs."""
    if isinstance(leg, coupon_specs.FixedCouponSpecs):
        return cashflow_streams.FixedCashflowStream(
            start_date=start_date,
            end_date=end_date,
            coupon_spec=leg,
            schedule_fn=schedule_fn,
            schedule=schedule,
            discount_curve_type=discount_curve_type,
            dtype=tf.float64)
    elif isinstance(leg, coupon_specs.FloatCouponSpecs):
        return cashflow_streams.FloatingCashflowStream(
            start_date=start_date,
            end_date=end_date,
            coupon_spec=leg,
            schedule_fn=schedule_fn,
            schedule=schedule,
            discount_curve_type=discount_curve_type,
            past_fixing=past_fixing,
            dtype=tf.float64)
    elif isinstance(leg, dict):
        coupon_spec = leg["coupon_spec"]
        if "fixed_rate" in coupon_spec:
            coupon_spec = coupon_specs.FixedCouponSpecs(**coupon_spec)
            return cashflow_streams.FixedCashflowStream(
                start_date=start_date,
                end_date=end_date,
                schedule_fn=schedule_fn,
                schedule=schedule,
                coupon_spec=coupon_spec,
                discount_curve_type=leg["discount_curve_type"],
                discount_curve_mask=leg["discount_curve_mask"],
                dtype=tf.float64)
        else:
            coupon_spec = coupon_specs.FloatCouponSpecs(**coupon_spec)
            return cashflow_streams.FloatingCashflowStream(
                start_date=start_date,
                end_date=end_date,
                schedule_fn=schedule_fn,
                schedule=schedule,
                coupon_spec=coupon_spec,
                discount_curve_type=leg["discount_curve_type"],
                discount_curve_mask=leg["discount_curve_mask"],
                reference_mask=leg["reference_mask"],
                rate_index_curves=leg["rate_index_curves"],
                past_fixing=past_fixing,
                dtype=tf.float64)
    else:
        raise ValueError(f"Unknown leg type {type(leg)}")
コード例 #2
0
 def _setup_leg(
     self, leg: Union[coupon_specs.FixedCouponSpecs,
                      coupon_specs.FloatCouponSpecs]
 ) -> Union[cashflow_streams.FixedCashflowStream,
            cashflow_streams.FloatingCashflowStream]:
     """Setup swap legs."""
     if isinstance(leg, coupon_specs.FixedCouponSpecs):
         return cashflow_streams.FixedCashflowStream(
             start_date=self._start_date,
             end_date=self._maturity_date,
             coupon_spec=leg,
             discount_curve_type=self._discount_curve_type,
             dtype=self._dtype)
     elif isinstance(leg, coupon_specs.FloatCouponSpecs):
         return cashflow_streams.FloatingCashflowStream(
             start_date=self._start_date,
             end_date=self._maturity_date,
             coupon_spec=leg,
             discount_curve_type=self._discount_curve_type,
             dtype=self._dtype)
     else:
         raise ValueError(f"Unknown leg type {type(leg)}")