Пример #1
0
        public override void initialize( InflationCoupon coupon)
        {
            coupon_ = coupon as CPICoupon;
             gearing_ = coupon_.fixedRate();
             spread_ = coupon_.spread();
             paymentDate_ = coupon_.date();
             rateCurve_ = ((ZeroInflationIndex)coupon.index())
            .zeroInflationTermStructure().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_;
        }
Пример #2
0
        public override List<CashFlow> value()
        {
            if (notionals_.empty())
            throw new ApplicationException("no notional given");

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

             if (n > 0)
             {
            if (fixedRates_.empty() && spreads_.empty())
               throw new ApplicationException("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) == 0.0)
               {
                  // fixed coupon
                  leg.Add(new FixedRateCoupon(Utils.Get(notionals_, i, 0.0),
                                              paymentDate,
                                              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
                     throw new ApplicationException("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;
        }
Пример #3
0
        public override List <CashFlow> value()
        {
            if (notionals_.empty())
            {
                throw new ApplicationException("no notional given");
            }

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

            if (n > 0)
            {
                if (fixedRates_.empty() && spreads_.empty())
                {
                    throw new ApplicationException("no fixedRates or spreads given");
                }

                Date refStart, start, refEnd, end;
                Date lastPaymentDate = calendar.adjust(schedule_.date(n), paymentAdjustment_);

                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(fixedRates_, i, 1.0) == 0.0)
                    {
                        // fixed coupon
                        leg.Add(new FixedRateCoupon(Utils.Get(notionals_, i, 0.0),
                                                    paymentDate,
                                                    Utils.effectiveFixedRate(spreads_, caps_, floors_, i),
                                                    paymentDayCounter_, start, end, refStart, refEnd));
                    }
                    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);

                            // 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
                            throw new ApplicationException("caps/floors on CPI coupons not implemented.");
                        }
                    }
                }
            }

            // in CPI legs you always have a notional flow of some sort
            Date     pDate      = calendar.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);
        }