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; }
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); }