Example #1
0
        public SubPeriodsCoupon(Date paymentDate, double nominal, Date startDate, Date endDate,
                                InterestRateIndex index, Type type, BusinessDayConvention convention,
                                double spread = 0.0, DayCounter dayCounter = null, bool includeSpread = false, double gearing = 1.0)
            : base(paymentDate, nominal, startDate, endDate, index.fixingDays(), index, gearing, spread, new Date(), new Date(), dayCounter, false)
        {
            _type          = type;
            _includeSpread = includeSpread;

            // Populate the value dates.
            Schedule sch = new MakeSchedule()
                           .from(startDate)
                           .to(endDate)
                           .withTenor(index.tenor())
                           .withCalendar(index.fixingCalendar())
                           .withConvention(convention)
                           .withTerminationDateConvention(convention)
                           .backwards().value();

            _valueDates = sch.dates();
            Utils.QL_REQUIRE(_valueDates.Count >= 2, () => "Degenerate schedule.");

            // Populate the fixing dates.
            _numPeriods = _valueDates.Count - 1;
            if (index.fixingDays() == 0)
            {
                _fixingDates = new List <Date> {
                    _valueDates.First(), _valueDates.Last() - 1
                };
            }
            else
            {
                _fixingDates.Resize(_numPeriods);
                for (int i = 0; i < _numPeriods; ++i)
                {
                    _fixingDates[i] = index.fixingDate(_valueDates[i]);
                }
            }

            // Populate the accrual periods.
            _accrualFractions.Resize(_numPeriods);
            for (int i = 0; i < _numPeriods; ++i)
            {
                _accrualFractions[i] = dayCounter.yearFraction(_valueDates[i], _valueDates[i + 1]);
            }
        }