Exemplo n.º 1
0
        public CPIBond(int settlementDays,
                       double faceAmount,
                       bool growthOnly,
                       double baseCPI,
                       Period observationLag,
                       ZeroInflationIndex cpiIndex,
                       InterpolationType observationInterpolation,
                       Schedule schedule,
                       List <double> fixedRate,
                       DayCounter accrualDayCounter,
                       BusinessDayConvention paymentConvention = BusinessDayConvention.ModifiedFollowing,
                       Date issueDate            = null,
                       Calendar paymentCalendar  = null,
                       Period exCouponPeriod     = null,
                       Calendar exCouponCalendar = null,
                       BusinessDayConvention exCouponConvention = BusinessDayConvention.Unadjusted,
                       bool exCouponEndOfMonth = false)
            : base(settlementDays, paymentCalendar ?? schedule.calendar(), issueDate)
        {
            frequency_                = schedule.tenor().frequency();
            dayCounter_               = accrualDayCounter;
            growthOnly_               = growthOnly;
            baseCPI_                  = baseCPI;
            observationLag_           = observationLag;
            cpiIndex_                 = cpiIndex;
            observationInterpolation_ = observationInterpolation;

            maturityDate_ = schedule.endDate();

            // a CPIleg know about zero legs and inclusion of base inflation notional
            cashflows_ = new CPILeg(schedule, cpiIndex_,
                                    baseCPI_, observationLag_)
                         .withSubtractInflationNominal(growthOnly_)
                         .withObservationInterpolation(observationInterpolation_)
                         .withPaymentDayCounter(accrualDayCounter)
                         .withFixedRates(fixedRate)
                         .withPaymentCalendar(calendar_)
                         .withExCouponPeriod(exCouponPeriod,
                                             exCouponCalendar,
                                             exCouponConvention,
                                             exCouponEndOfMonth)
                         .withNotionals(faceAmount)
                         .withPaymentAdjustment(paymentConvention);


            calculateNotionalsFromCashflows();

            cpiIndex_.registerWith(update);

            foreach (CashFlow i in cashflows_)
            {
                i.registerWith(update);
            }
        }
Exemplo n.º 2
0
        public CPIBond(int settlementDays,
                double faceAmount,
                bool growthOnly,
                double baseCPI,
                Period observationLag,
                ZeroInflationIndex cpiIndex,
                InterpolationType observationInterpolation,
                Schedule schedule,
                List<double> fixedRate,
                DayCounter accrualDayCounter,
                BusinessDayConvention paymentConvention = BusinessDayConvention.ModifiedFollowing,
                Date issueDate = null,
                Calendar paymentCalendar = null,
                Period exCouponPeriod = null,
                Calendar exCouponCalendar = null,
					 BusinessDayConvention exCouponConvention = BusinessDayConvention.Unadjusted,
                bool exCouponEndOfMonth = false)                
            :base(settlementDays, paymentCalendar == null ? schedule.calendar() : paymentCalendar, issueDate)
        {
            frequency_ = schedule.tenor().frequency();
            dayCounter_ = accrualDayCounter;
            growthOnly_ = growthOnly;
            baseCPI_=baseCPI;
            observationLag_ = observationLag;
            cpiIndex_= cpiIndex;
            observationInterpolation_ = observationInterpolation;

            maturityDate_ = schedule.endDate();

            // a CPIleg know about zero legs and inclusion of base inflation notional
            cashflows_ = new CPILeg(schedule, cpiIndex_,
                                    baseCPI_, observationLag_)
             .withSubtractInflationNominal(growthOnly_)
             .withObservationInterpolation(observationInterpolation_)
             .withPaymentDayCounter(accrualDayCounter)
             .withFixedRates(fixedRate)
             .withPaymentCalendar(calendar_)
             .withExCouponPeriod(exCouponPeriod,
                                exCouponCalendar,
                                exCouponConvention,
                                exCouponEndOfMonth)
             .withNotionals(faceAmount)
             .withPaymentAdjustment(paymentConvention);
            

            calculateNotionalsFromCashflows();

            cpiIndex_.registerWith(update);

            foreach ( CashFlow i in cashflows_) 
                i.registerWith(update);
        }
Exemplo n.º 3
0
        public CPISwap(Type type,
                       double nominal,
                       bool subtractInflationNominal,
                       // float+spread leg
                       double spread,
                       DayCounter floatDayCount,
                       Schedule floatSchedule,
                       BusinessDayConvention floatPaymentRoll,
                       int fixingDays,
                       IborIndex floatIndex,
                       // fixed x inflation leg
                       double fixedRate,
                       double baseCPI,
                       DayCounter fixedDayCount,
                       Schedule fixedSchedule,
                       BusinessDayConvention fixedPaymentRoll,
                       Period observationLag,
                       ZeroInflationIndex fixedIndex,
                       InterpolationType observationInterpolation = InterpolationType.AsIndex,
                       double?inflationNominal = null)
            : base(2)
        {
            type_    = type;
            nominal_ = nominal;
            subtractInflationNominal_ = subtractInflationNominal;
            spread_                   = spread;
            floatDayCount_            = floatDayCount;
            floatSchedule_            = floatSchedule;
            floatPaymentRoll_         = floatPaymentRoll;
            fixingDays_               = fixingDays;
            floatIndex_               = floatIndex;
            fixedRate_                = fixedRate;
            baseCPI_                  = baseCPI;
            fixedDayCount_            = fixedDayCount;
            fixedSchedule_            = fixedSchedule;
            fixedPaymentRoll_         = fixedPaymentRoll;
            fixedIndex_               = fixedIndex;
            observationLag_           = observationLag;
            observationInterpolation_ = observationInterpolation;

            Utils.QL_REQUIRE(floatSchedule_.Count > 0, () => "empty float schedule");
            Utils.QL_REQUIRE(fixedSchedule_.Count > 0, () => "empty fixed schedule");
            // todo if roll!=unadjusted then need calendars ...

            inflationNominal_ = inflationNominal ?? nominal_;

            List <CashFlow> floatingLeg;

            if (floatSchedule_.Count > 1)
            {
                floatingLeg = new IborLeg(floatSchedule_, floatIndex_)
                              .withFixingDays(fixingDays_)
                              .withPaymentDayCounter(floatDayCount_)
                              .withSpreads(spread_)
                              .withNotionals(nominal_)
                              .withPaymentAdjustment(floatPaymentRoll_);
            }
            else
            {
                floatingLeg = new List <CashFlow>();
            }

            if (floatSchedule_.Count == 1 ||
                !subtractInflationNominal_ ||
                (subtractInflationNominal && Math.Abs(nominal_ - inflationNominal_) > 0.00001)
                )
            {
                Date payNotional;
                if (floatSchedule_.Count == 1)
                {
                    // no coupons
                    payNotional = floatSchedule_[0];
                    payNotional = floatSchedule_.calendar().adjust(payNotional, floatPaymentRoll_);
                }
                else
                {
                    // use the pay date of the last coupon
                    payNotional = floatingLeg.Last().date();
                }

                double   floatAmount = subtractInflationNominal_ ? nominal_ - inflationNominal_ : nominal_;
                CashFlow nf          = new SimpleCashFlow(floatAmount, payNotional);
                floatingLeg.Add(nf);
            }

            // a CPIleg know about zero legs and inclusion of base inflation notional
            List <CashFlow> cpiLeg = new CPILeg(fixedSchedule_, fixedIndex_, baseCPI_, observationLag_)
                                     .withFixedRates(fixedRate_)
                                     .withPaymentDayCounter(fixedDayCount_)
                                     .withObservationInterpolation(observationInterpolation_)
                                     .withSubtractInflationNominal(subtractInflationNominal_)
                                     .withNotionals(inflationNominal_)
                                     .withPaymentAdjustment(fixedPaymentRoll_);

            foreach (CashFlow cashFlow in cpiLeg)
            {
                cashFlow.registerWith(update);
            }

            if (floatingLeg.Count > 0)
            {
                foreach (CashFlow cashFlow in floatingLeg)
                {
                    cashFlow.registerWith(update);
                }
            }

            legs_[0] = cpiLeg;
            legs_[1] = floatingLeg;


            if (type_ == Type.Payer)
            {
                payer_[0] = 1.0;
                payer_[1] = -1.0;
            }
            else
            {
                payer_[0] = -1.0;
                payer_[1] = 1.0;
            }
        }