Coupon paying a YoY-inflation type index
Inheritance: QLNet.InflationCoupon
Exemple #1
0
 public CappedFlooredYoYInflationCoupon(YoYInflationCoupon underlying, double?cap, double?floor)
     : this(underlying.Date, underlying.nominal(), underlying.accrualStartDate(), underlying.accrualEndDate(), underlying.fixingDays(), underlying.yoyIndex(), underlying.observationLag(), underlying.dayCounter(), underlying.gearing(), underlying.spread(), null, null, underlying.refPeriodStart, underlying.refPeriodEnd)
 {
     underlying_ = underlying;
     setCommon(cap, floor);
     underlying.registerWith(update);
 }
Exemple #2
0
        public override void setupArguments(IPricingEngineArguments args)
        {
            YoYInflationCapFloor.Arguments arguments = args as YoYInflationCapFloor.Arguments;
            Utils.QL_REQUIRE(arguments != null, () => "wrong argument type");

            int n = yoyLeg_.Count;

            arguments.startDates   = new List <Date>(n);
            arguments.fixingDates  = new List <Date>(n);
            arguments.payDates     = new List <Date>(n);
            arguments.accrualTimes = new List <double>(n);
            arguments.nominals     = new List <double>(n);
            arguments.gearings     = new List <double>(n);
            arguments.capRates     = new List <double?>(n);
            arguments.floorRates   = new List <double?>(n);
            arguments.spreads      = new List <double>(n);

            arguments.type = type_;

            for (int i = 0; i < n; ++i)
            {
                YoYInflationCoupon coupon = yoyLeg_[i] as YoYInflationCoupon;
                Utils.QL_REQUIRE(coupon != null, () => "non-YoYInflationCoupon given");
                arguments.startDates.Add(coupon.accrualStartDate());
                arguments.fixingDates.Add(coupon.fixingDate());
                arguments.payDates.Add(coupon.date());

                // this is passed explicitly for precision
                arguments.accrualTimes.Add(coupon.accrualPeriod());

                arguments.nominals.Add(coupon.nominal());
                double spread  = coupon.spread();
                double gearing = coupon.gearing();
                arguments.gearings.Add(gearing);
                arguments.spreads.Add(spread);

                if (type_ == CapFloorType.Cap || type_ == CapFloorType.Collar)
                {
                    arguments.capRates.Add((capRates_[i] - spread) / gearing);
                }
                else
                {
                    arguments.capRates.Add(null);
                }

                if (type_ == CapFloorType.Floor || type_ == CapFloorType.Collar)
                {
                    arguments.floorRates.Add((floorRates_[i] - spread) / gearing);
                }
                else
                {
                    arguments.floorRates.Add(null);
                }
            }
        }
Exemple #3
0
        // other
        public override void setupArguments(IPricingEngineArguments args)
        {
            base.setupArguments(args);

            YearOnYearInflationSwap.Arguments arguments = args as YearOnYearInflationSwap.Arguments;

            if (arguments == null) // it's a swap engine...
            {
                return;
            }

            arguments.type    = type_;
            arguments.nominal = nominal_;

            List <CashFlow> fixedCoupons = fixedLeg();

            arguments.fixedResetDates = arguments.fixedPayDates = new List <Date>(fixedCoupons.Count);
            arguments.fixedCoupons    = new List <double>(fixedCoupons.Count);

            for (int i = 0; i < fixedCoupons.Count; ++i)
            {
                FixedRateCoupon coupon = fixedCoupons[i] as FixedRateCoupon;

                arguments.fixedPayDates.Add(coupon.date());
                arguments.fixedResetDates.Add(coupon.accrualStartDate());
                arguments.fixedCoupons.Add(coupon.amount());
            }

            List <CashFlow> yoyCoupons = yoyLeg();

            arguments.yoyResetDates   = arguments.yoyPayDates = arguments.yoyFixingDates = new List <Date>(yoyCoupons.Count);
            arguments.yoyAccrualTimes = new List <double>(yoyCoupons.Count);
            arguments.yoySpreads      = new List <double>(yoyCoupons.Count);
            arguments.yoyCoupons      = new List <double?>(yoyCoupons.Count);
            for (int i = 0; i < yoyCoupons.Count; ++i)
            {
                YoYInflationCoupon coupon = yoyCoupons[i] as YoYInflationCoupon;

                arguments.yoyResetDates.Add(coupon.accrualStartDate());
                arguments.yoyPayDates.Add(coupon.date());

                arguments.yoyFixingDates.Add(coupon.fixingDate());
                arguments.yoyAccrualTimes.Add(coupon.accrualPeriod());
                arguments.yoySpreads.Add(coupon.spread());
                try
                {
                    arguments.yoyCoupons.Add(coupon.amount());
                }
                catch (Exception)
                {
                    arguments.yoyCoupons.Add(null);
                }
            }
        }
        public override void initialize(InflationCoupon coupon)
        {
            coupon_ = coupon as YoYInflationCoupon;
            gearing_ = coupon_.gearing();
            spread_ = coupon_.spread();
            PaymentDate = coupon_.Date;
            YoYInflationIndex y = (YoYInflationIndex)(coupon.index());
            RateCurve = y.yoyInflationTermStructure().link.nominalTermStructure();

            // past or future fixing is managed in YoYInflationIndex::fixing()
            // use yield curve from index (which sets discount)

            discount_ = 1.0;
            if (PaymentDate > RateCurve.link.referenceDate())
                discount_ = RateCurve.link.discount(PaymentDate);

            spreadLegValue_ = spread_ * coupon_.accrualPeriod() * discount_;
        }
 // we may watch an underlying coupon ...
 public CappedFlooredYoYInflationCoupon(YoYInflationCoupon underlying,
                                      double? cap = null,
                                      double? floor = null)
     : base(underlying.date(),
        underlying.nominal(),
        underlying.accrualStartDate(),
        underlying.accrualEndDate(),
        underlying.fixingDays(),
        underlying.yoyIndex(),
        underlying.observationLag(),
        underlying.dayCounter(),
        underlying.gearing(),
        underlying.spread(),
        underlying.refPeriodStart,
        underlying.refPeriodEnd)
 {
     underlying_ = underlying;
      isFloored_ = false;
      isCapped_ = false;
      setCommon(cap, floor);
      underlying.registerWith(update);
 }
Exemple #6
0
        // we may watch an underlying coupon ...
        public CappedFlooredYoYInflationCoupon(YoYInflationCoupon underlying,
                                               double?cap   = null,
                                               double?floor = null)
            : base(underlying.date(),
                   underlying.nominal(),
                   underlying.accrualStartDate(),
                   underlying.accrualEndDate(),
                   underlying.fixingDays(),
                   underlying.yoyIndex(),
                   underlying.observationLag(),
                   underlying.dayCounter(),
                   underlying.gearing(),
                   underlying.spread(),
                   underlying.referencePeriodStart,
                   underlying.referencePeriodEnd)

        {
            underlying_ = underlying;
            isFloored_  = false;
            isCapped_   = false;
            setCommon(cap, floor);
            underlying.registerWith(update);
        }
Exemple #7
0
        public static List <CashFlow> yoyInflationLeg(List <double> notionals_,
                                                      Schedule schedule_,
                                                      BusinessDayConvention paymentAdjustment_,
                                                      YoYInflationIndex index_,
                                                      List <double> gearings_,
                                                      List <double> spreads_,
                                                      DayCounter paymentDayCounter_,
                                                      List <double> caps_,
                                                      List <double> floors_,
                                                      Calendar paymentCalendar_,
                                                      List <int> fixingDays_,
                                                      Period observationLag_)
        {
            int n = schedule_.Count - 1;

            Utils.QL_REQUIRE(!notionals_.empty(), () => "no notional given");
            Utils.QL_REQUIRE(notionals_.Count <= n, () => "too many nominals (" + notionals_.Count + "), only " + n + " required");
            if (gearings_ != null)
            {
                Utils.QL_REQUIRE(gearings_.Count <= n, () => "too many gearings (" + gearings_.Count + "), only " + n + " required");
            }
            if (spreads_ != null)
            {
                Utils.QL_REQUIRE(spreads_.Count <= n, () => "too many spreads (" + spreads_.Count + "), only " + n + " required");
            }
            if (caps_ != null)
            {
                Utils.QL_REQUIRE(caps_.Count <= n, () => "too many caps (" + caps_.Count + "), only " + n + " required");
            }
            if (floors_ != null)
            {
                Utils.QL_REQUIRE(floors_.Count <= n, () => "too many floors (" + floors_.Count + "), only " + n + " required");
            }


            List <CashFlow> leg = new List <CashFlow>(n);

            Calendar calendar = paymentCalendar_;

            Date refStart, start, refEnd, end;

            for (int i = 0; i < n; ++i)
            {
                refStart = start = schedule_.date(i);
                refEnd   = end = schedule_.date(i + 1);
                Date paymentDate = calendar.adjust(end, paymentAdjustment_);
                if (i == 0 && !schedule_.isRegular(i + 1))
                {
                    BusinessDayConvention bdc = schedule_.businessDayConvention();
                    refStart = schedule_.calendar().adjust(end - schedule_.tenor(), bdc);
                }
                if (i == n - 1 && !schedule_.isRegular(i + 1))
                {
                    BusinessDayConvention bdc = schedule_.businessDayConvention();
                    refEnd = schedule_.calendar().adjust(start + schedule_.tenor(), bdc);
                }
                if (Utils.Get(gearings_, i, 1.0).IsEqual(0.0))
                {
                    // fixed coupon
                    leg.Add(new FixedRateCoupon(paymentDate, Utils.Get(notionals_, i, 1.0),
                                                Utils.effectiveFixedRate(spreads_, caps_, floors_, i),
                                                paymentDayCounter_,
                                                start, end, refStart, refEnd));
                }
                else
                {
                    // yoy inflation coupon
                    if (Utils.noOption(caps_, floors_, i))
                    {
                        // just swaplet
                        YoYInflationCoupon coup = new YoYInflationCoupon(paymentDate,
                                                                         Utils.Get(notionals_, i, 1.0),
                                                                         start, end,
                                                                         Utils.Get(fixingDays_, i, 0),
                                                                         index_,
                                                                         observationLag_,
                                                                         paymentDayCounter_,
                                                                         Utils.Get(gearings_, i, 1.0),
                                                                         Utils.Get(spreads_, i, 0.0),
                                                                         refStart, refEnd);

                        // in this case you can set a pricer
                        // straight away because it only provides computation - not data
                        YoYInflationCouponPricer pricer = new YoYInflationCouponPricer();
                        coup.setPricer(pricer);
                        leg.Add(coup);
                    }
                    else
                    {
                        // cap/floorlet
                        leg.Add(new CappedFlooredYoYInflationCoupon(
                                    paymentDate,
                                    Utils.Get(notionals_, i, 1.0),
                                    start, end,
                                    Utils.Get(fixingDays_, i, 0),
                                    index_,
                                    observationLag_,
                                    paymentDayCounter_,
                                    Utils.Get(gearings_, i, 1.0),
                                    Utils.Get(spreads_, i, 0.0),
                                    Utils.toNullable(Utils.Get(caps_, i, Double.MinValue)),
                                    Utils.toNullable(Utils.Get(floors_, i, Double.MinValue)),
                                    refStart, refEnd));
                    }
                }
            }

            return(leg);
        }
Exemple #8
0
        public YoYInflationCoupon lastYoYInflationCoupon()
        {
            YoYInflationCoupon lastYoYInflationCoupon = yoyLeg_.Last() as YoYInflationCoupon;

            return(lastYoYInflationCoupon);
        }
Exemple #9
0
 public CappedFlooredYoYInflationCoupon(YoYInflationCoupon underlying)
     : this(underlying, null, null)
 {
 }
 public CappedFlooredYoYInflationCoupon(YoYInflationCoupon underlying)
     : this(underlying, null, null)
 {
 }