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); }
public ZeroCouponInflationSwapHelper( Handle <Quote> quote, Period swapObsLag, // lag on swap observation of index Date maturity, Calendar calendar, // index may have null calendar as valid on every day BusinessDayConvention paymentConvention, DayCounter dayCounter, ZeroInflationIndex zii) : base(quote) { swapObsLag_ = swapObsLag; maturity_ = maturity; calendar_ = calendar; paymentConvention_ = paymentConvention; dayCounter_ = dayCounter; zii_ = zii; if (zii_.interpolated()) { // if interpolated then simple earliestDate_ = maturity_ - swapObsLag_; latestDate_ = maturity_ - swapObsLag_; } else { // but if NOT interpolated then the value is valid // for every day in an inflation period so you actually // get an extended validity, however for curve building // just put the first date because using that convention // for the base date throughout KeyValuePair <Date, Date> limStart = Utils.inflationPeriod(maturity_ - swapObsLag_, zii_.frequency()); earliestDate_ = limStart.Key; latestDate_ = limStart.Key; } // check that the observation lag of the swap // is compatible with the availability lag of the index AND // it's interpolation (assuming the start day is spot) if (zii_.interpolated()) { Period pShift = new Period(zii_.frequency()); Utils.QL_REQUIRE((swapObsLag_ - pShift) > zii_.availabilityLag(), () => "inconsistency between swap observation of index " + swapObsLag_ + " index availability " + zii_.availabilityLag() + " index period " + pShift + " and index availability " + zii_.availabilityLag() + " need (obsLag-index period) > availLag"); } Settings.registerWith(update); }
public CPIBondHelper(Handle <Quote> price, int settlementDays, double faceAmount, bool growthOnly, double baseCPI, Period observationLag, ZeroInflationIndex cpiIndex, InterpolationType observationInterpolation, Schedule schedule, List <double> fixedRate, DayCounter dayCounter, BusinessDayConvention paymentConvention, double redemption, Date issueDate, Calendar paymentCalendar = null, Period exCouponPeriod = null, Calendar exCouponCalendar = null, BusinessDayConvention exCouponConvention = BusinessDayConvention.Unadjusted, bool exCouponEndOfMonth = false, bool useCleanPrice = true) : base(price, new CPIBond(settlementDays, faceAmount, growthOnly, baseCPI, observationLag, cpiIndex, observationInterpolation, schedule, fixedRate, dayCounter, paymentConvention, issueDate, paymentCalendar, exCouponPeriod, exCouponCalendar, exCouponConvention, exCouponEndOfMonth), useCleanPrice) { cpiBond_ = bond_ as CPIBond; }
public ZeroCouponInflationSwap(Type type, double nominal, Date startDate, // start date of contract (only) Date maturity, // this is pre-adjustment! Calendar fixCalendar, BusinessDayConvention fixConvention, DayCounter dayCounter, double fixedRate, ZeroInflationIndex infIndex, Period observationLag) : this(type, nominal, startDate, maturity, fixCalendar, fixConvention, dayCounter, fixedRate, infIndex, observationLag, false, new Calendar(), new BusinessDayConvention()) { }
private List<BootstrapHelper<ZeroInflationTermStructure>> makeHelpers(Datum[] iiData, int N, ZeroInflationIndex ii, Period observationLag, Calendar calendar, BusinessDayConvention bdc, DayCounter dc) { List <BootstrapHelper<ZeroInflationTermStructure>> instruments = new List<BootstrapHelper<ZeroInflationTermStructure>>(); for (int i = 0; i < N; i++) { Date maturity = iiData[i].date; Handle<Quote> quote = new Handle<Quote>(new SimpleQuote(iiData[i].rate / 100.0)); BootstrapHelper<ZeroInflationTermStructure> anInstrument = new ZeroCouponInflationSwapHelper(quote, observationLag, maturity, calendar, bdc, dc, ii); instruments.Add(anInstrument); } return instruments; }
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) : base(settlementDays, 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) .withNotionals(faceAmount) .withPaymentAdjustment(paymentConvention); cpiIndex_.registerWith(update); foreach (CashFlow i in cashflows_) { i.registerWith(update); } }
public CPILeg(Schedule schedule, ZeroInflationIndex index, double baseCPI, Period observationLag) { schedule_ = schedule; index_ = index; baseCPI_ = baseCPI; observationLag_ = observationLag; paymentDayCounter_ = new Thirty360(); paymentAdjustment_ = BusinessDayConvention.ModifiedFollowing; fixingDays_ = new List <int>() { 0 }; observationInterpolation_ = InterpolationType.AsIndex; subtractInflationNominal_ = true; spreads_ = new List <double>() { 0 }; }
public CPICoupon(double baseCPI, // user provided, could be arbitrary Date paymentDate, double nominal, Date startDate, Date endDate, int fixingDays, ZeroInflationIndex index, Period observationLag, InterpolationType observationInterpolation, DayCounter dayCounter, double fixedRate, // aka gearing double spread = 0.0, Date refPeriodStart = null, Date refPeriodEnd = null) : base(paymentDate, nominal, startDate, endDate, fixingDays, index, observationLag, dayCounter, refPeriodStart, refPeriodEnd) { baseCPI_ = baseCPI; fixedRate_ = fixedRate; spread_ = spread; observationInterpolation_ = observationInterpolation; Utils.QL_REQUIRE(Math.Abs(baseCPI_) > 1e-16, "|baseCPI_| < 1e-16, future divide-by-zero problem"); }
public CPICashFlow(double notional, ZeroInflationIndex index, Date baseDate, double baseFixing, Date fixingDate, Date paymentDate, bool growthOnly = false, InterpolationType interpolation = InterpolationType.AsIndex, Frequency frequency = Frequency.NoFrequency) : base(notional, index, baseDate, fixingDate, paymentDate, growthOnly) { baseFixing_ = baseFixing; interpolation_ = interpolation; frequency_ = frequency; Utils.QL_REQUIRE(Math.Abs(baseFixing_) > 1e-16, () => "|baseFixing|<1e-16, future divide-by-zero error"); if (interpolation_ != InterpolationType.AsIndex) { Utils.QL_REQUIRE(frequency_ != Frequency.NoFrequency, () => "non-index interpolation w/o frequency"); } }
public CPICashFlow(double notional, ZeroInflationIndex index, Date baseDate, double baseFixing, Date fixingDate, Date paymentDate, bool growthOnly = false, InterpolationType interpolation = InterpolationType.AsIndex, Frequency frequency = Frequency.NoFrequency) : base(notional, index, baseDate, fixingDate,paymentDate, growthOnly) { baseFixing_= baseFixing; interpolation_= interpolation; frequency_=frequency; if(Math.Abs(baseFixing_) <= 1e-16) throw new ApplicationException("|baseFixing|<1e-16, future divide-by-zero error"); if (interpolation_ != InterpolationType.AsIndex) { if ( frequency_ == Frequency.NoFrequency) throw new ApplicationException ("non-index interpolation w/o frequency"); } }
public CPILeg(Schedule schedule, ZeroInflationIndex index, double baseCPI, Period observationLag) { schedule_ = schedule; index_ = index; baseCPI_ = baseCPI; observationLag_ = observationLag; paymentDayCounter_ = new Thirty360(); paymentAdjustment_ = BusinessDayConvention.ModifiedFollowing; paymentCalendar_ = schedule.calendar(); fixingDays_ = new List<int>() { 0 }; observationInterpolation_ = InterpolationType.AsIndex; subtractInflationNominal_ = true; spreads_ = new List<double>() { 0 }; }
public CPICoupon(double baseCPI, // user provided, could be arbitrary Date paymentDate, double nominal, Date startDate, Date endDate, int fixingDays, ZeroInflationIndex index, Period observationLag, InterpolationType observationInterpolation, DayCounter dayCounter, double fixedRate, // aka gearing double spread = 0.0, Date refPeriodStart = null, Date refPeriodEnd = null, Date exCouponDate = null) : base(paymentDate, nominal, startDate, endDate, fixingDays, index, observationLag, dayCounter, refPeriodStart, refPeriodEnd, exCouponDate) { baseCPI_ = baseCPI; fixedRate_ = fixedRate; spread_ = spread; observationInterpolation_ = observationInterpolation; Utils.QL_REQUIRE( Math.Abs( baseCPI_ ) > 1e-16, () => "|baseCPI_| < 1e-16, future divide-by-zero problem" ); }
public ZeroCouponInflationSwap(Type type, double nominal, Date startDate, // start date of contract (only) Date maturity, // this is pre-adjustment! Calendar fixCalendar, BusinessDayConvention fixConvention, DayCounter dayCounter, double fixedRate, ZeroInflationIndex infIndex, Period observationLag, bool adjustInfObsDates, Calendar infCalendar, BusinessDayConvention infConvention) : base(2) { type_ = type; nominal_ = nominal; fixedRate_ = fixedRate; infIndex_ = infIndex; observationLag_ = observationLag; dayCounter_ = dayCounter; // first check compatibility of index and swap definitions if (infIndex_.interpolated()) { Period pShift = new Period(infIndex_.frequency()); if ((observationLag_ - pShift) <= infIndex_.availabilityLag()) { throw new ApplicationException( "inconsistency between swap observation of index " + observationLag_ + " index availability " + infIndex_.availabilityLag() + " interpolated index period " + pShift + " and index availability " + infIndex_.availabilityLag() + " need (obsLag-index period) > availLag"); } } else { if (infIndex_.availabilityLag() >= observationLag_) { throw new ApplicationException( "index tries to observe inflation fixings that do not yet exist: " + " availability lag " + infIndex_.availabilityLag() + " versus obs lag = " + observationLag_); } } if (infCalendar == null) { infCalendar = fixCalendar; } if (infConvention == new BusinessDayConvention()) { infConvention = fixConvention; } if (adjustInfObsDates) { baseDate_ = infCalendar.adjust(startDate - observationLag_, infConvention); obsDate_ = infCalendar.adjust(maturity - observationLag_, infConvention); } else { baseDate_ = startDate - observationLag_; obsDate_ = maturity - observationLag_; } Date infPayDate = infCalendar.adjust(maturity, infConvention); Date fixedPayDate = fixCalendar.adjust(maturity, fixConvention); // At this point the index may not be able to forecast // i.e. do not want to force the existence of an inflation // term structure before allowing users to create instruments. double T = Utils.inflationYearFraction(infIndex_.frequency(), infIndex_.interpolated(), dayCounter_, baseDate_, obsDate_); // N.B. the -1.0 is because swaps only exchange growth, not notionals as well double fixedAmount = nominal * (Math.Pow(1.0 + fixedRate, T) - 1.0); legs_[0].Add(new SimpleCashFlow(fixedAmount, fixedPayDate)); bool growthOnly = true; legs_[1].Add(new IndexedCashFlow(nominal, infIndex, baseDate_, obsDate_, infPayDate, growthOnly)); for (int j = 0; j < 2; ++j) { for (int i = 0; i < legs_[j].Count; i++) { legs_[j][i].registerWith(update); } } switch (type_) { case Type.Payer: payer_[0] = +1.0; payer_[1] = -1.0; break; case Type.Receiver: payer_[0] = -1.0; payer_[1] = +1.0; break; default: throw new ApplicationException("Unknown zero-inflation-swap type"); } }
public CPIBondHelper(Handle<Quote> price, int settlementDays, double faceAmount, bool growthOnly, double baseCPI, Period observationLag, ZeroInflationIndex cpiIndex, InterpolationType observationInterpolation, Schedule schedule, List<double> fixedRate, DayCounter dayCounter, BusinessDayConvention paymentConvention, double redemption, Date issueDate, Calendar paymentCalendar = null, Period exCouponPeriod = null, Calendar exCouponCalendar = null, BusinessDayConvention exCouponConvention = BusinessDayConvention.Unadjusted, bool exCouponEndOfMonth = false, bool useCleanPrice = true) : base(price, new CPIBond(settlementDays, faceAmount, growthOnly, baseCPI, observationLag, cpiIndex, observationInterpolation, schedule, fixedRate, dayCounter, paymentConvention, issueDate, paymentCalendar, exCouponPeriod, exCouponCalendar, exCouponConvention, exCouponEndOfMonth), useCleanPrice) { cpiBond_ = bond_ as CPIBond; }
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; } }