public DatedOISRateHelper(Date startDate,
                                  Date endDate,
                                  Handle <Quote> fixedRate,
                                  OvernightIndex overnightIndex)

            : base(fixedRate)
        {
            overnightIndex.registerWith(update);

            // dummy OvernightIndex with curve/swap arguments
            // review here
            IborIndex      clonedIborIndex      = overnightIndex.clone(termStructureHandle_);
            OvernightIndex clonedOvernightIndex = clonedIborIndex as OvernightIndex;

            swap_ = new MakeOIS(new Period(), clonedOvernightIndex, 0.0)
                    .withEffectiveDate(startDate)
                    .withTerminationDate(endDate)
                    .withDiscountingTermStructure(termStructureHandle_);

            earliestDate_ = swap_.startDate();
            latestDate_   = swap_.maturityDate();
        }
        public override double swapletRate()
        {
            OvernightIndex index = coupon_.index() as OvernightIndex;

            List <Date>   fixingDates = coupon_.fixingDates();
            List <double> dt          = coupon_.dt();

            int n = dt.Count;
            int i = 0;

            double compoundFactor = 1.0;

            // already fixed part
            Date today = Settings.Instance.evaluationDate();

            while (fixingDates[i] < today && i < n)
            {
                // rate must have been fixed
                double?pastFixing = IndexManager.Instance.getHistory(index.name())[fixingDates[i]];

                Utils.QL_REQUIRE(pastFixing != null, () => "Missing " + index.name() + " fixing for " + fixingDates[i].ToString());

                compoundFactor *= (1.0 + pastFixing.GetValueOrDefault() * dt[i]);
                ++i;
            }

            // today is a border case
            if (fixingDates[i] == today && i < n)
            {
                // might have been fixed
                try
                {
                    double?pastFixing = IndexManager.Instance.getHistory(index.name())[fixingDates[i]];

                    if (pastFixing != null)
                    {
                        compoundFactor *= (1.0 + pastFixing.GetValueOrDefault() * dt[i]);
                        ++i;
                    }
                    else
                    {
                        // fall through and forecast
                    }
                }
                catch (Exception)
                {
                    // fall through and forecast
                }
            }

            // forward part using telescopic property in order
            // to avoid the evaluation of multiple forward fixings
            if (i < n)
            {
                Handle <YieldTermStructure> curve = index.forwardingTermStructure();
                Utils.QL_REQUIRE(!curve.empty(), () => "null term structure set to this instance of" + index.name());

                List <Date> dates         = coupon_.valueDates();
                double      startDiscount = curve.link.discount(dates[i]);
                double      endDiscount   = curve.link.discount(dates[n]);

                compoundFactor *= startDiscount / endDiscount;
            }

            double rate = (compoundFactor - 1.0) / coupon_.accrualPeriod();

            return(coupon_.gearing() * rate + coupon_.spread());
        }
 public OvernightLeg(Schedule schedule, OvernightIndex overnightIndex)
 {
     schedule_          = schedule;
     overnightIndex_    = overnightIndex;
     paymentAdjustment_ = BusinessDayConvention.Following;
 }