Esempio n. 1
0
        protected override bool checkPricerImpl(InflationCouponPricer pricer)
        {
            CPICouponPricer p = pricer as CPICouponPricer;

            return(p != null);
        }
Esempio n. 2
0
        public override List <CashFlow> value()
        {
            Utils.QL_REQUIRE(!notionals_.empty(), () => "no notional given");

            int             n   = schedule_.Count - 1;
            List <CashFlow> leg = new List <CashFlow>(n + 1);

            if (n > 0)
            {
                Utils.QL_REQUIRE(!fixedRates_.empty() || !spreads_.empty(), () => "no fixedRates or spreads given");

                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 = paymentCalendar_.adjust(end, paymentAdjustment_);

                    Date exCouponDate = null;
                    if (exCouponPeriod_ != null)
                    {
                        exCouponDate = exCouponCalendar_.advance(paymentDate,
                                                                 -exCouponPeriod_,
                                                                 exCouponAdjustment_,
                                                                 exCouponEndOfMonth_);
                    }

                    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(fixedRates_, i, 1.0).IsEqual(0.0))
                    {
                        // fixed coupon
                        leg.Add(new FixedRateCoupon(paymentDate, Utils.Get(notionals_, i, 0.0),
                                                    Utils.effectiveFixedRate(spreads_, caps_, floors_, i),
                                                    paymentDayCounter_, start, end, refStart, refEnd, exCouponDate));
                    }
                    else
                    {
                        // zero inflation coupon
                        if (Utils.noOption(caps_, floors_, i))
                        {
                            // just swaplet
                            CPICoupon coup;

                            coup = new CPICoupon(baseCPI_, // all have same base for ratio
                                                 paymentDate,
                                                 Utils.Get(notionals_, i, 0.0),
                                                 start, end,
                                                 Utils.Get(fixingDays_, i, 0),
                                                 index_, observationLag_,
                                                 observationInterpolation_,
                                                 paymentDayCounter_,
                                                 Utils.Get(fixedRates_, i, 0.0),
                                                 Utils.Get(spreads_, i, 0.0),
                                                 refStart, refEnd, exCouponDate);

                            // in this case you can set a pricer
                            // straight away because it only provides computation - not data
                            CPICouponPricer pricer = new CPICouponPricer();
                            coup.setPricer(pricer);
                            leg.Add(coup);
                        }
                        else
                        {
                            // cap/floorlet
                            Utils.QL_FAIL("caps/floors on CPI coupons not implemented.");
                        }
                    }
                }
            }

            // in CPI legs you always have a notional flow of some sort
            Date     pDate      = paymentCalendar_.adjust(schedule_.date(n), paymentAdjustment_);
            Date     fixingDate = pDate - observationLag_;
            CashFlow xnl        = new CPICashFlow
                                      (Utils.Get(notionals_, n, 0.0), index_,
                                      new Date(), // is fake, i.e. you do not have one
                                      baseCPI_, fixingDate, pDate,
                                      subtractInflationNominal_, observationInterpolation_,
                                      index_.frequency());

            leg.Add(xnl);

            return(leg);
        }