Beispiel #1
0
        //-------------------------------------------------------------------------
        // build conventions
        private static OvernightIborSwapConvention makeConvention(string name, OvernightIndex onIndex, IborIndex iborIndex, DayCount dayCount, Frequency frequency, int paymentLag, int cutOffDays, OvernightAccrualMethod accrual)
        {
            HolidayCalendarId calendarOn        = onIndex.FixingCalendar;
            DaysAdjustment    paymentDateOffset = DaysAdjustment.ofBusinessDays(paymentLag, calendarOn);

            return(ImmutableOvernightIborSwapConvention.of(name, OvernightRateSwapLegConvention.builder().index(onIndex).accrualMethod(accrual).accrualFrequency(frequency).paymentFrequency(frequency).paymentDateOffset(paymentDateOffset).stubConvention(StubConvention.SMART_INITIAL).rateCutOffDays(cutOffDays).build(), IborRateSwapLegConvention.of(iborIndex)));
        }
Beispiel #2
0
        //-------------------------------------------------------------------------
        // build conventions
        private static FixedOvernightSwapConvention makeConvention(string name, OvernightIndex index, DayCount dayCount, Frequency frequency, int paymentLag, int spotLag)
        {
            HolidayCalendarId calendar          = index.FixingCalendar;
            DaysAdjustment    paymentDateOffset = DaysAdjustment.ofBusinessDays(paymentLag, calendar);
            DaysAdjustment    spotDateOffset    = DaysAdjustment.ofBusinessDays(spotLag, calendar);

            return(ImmutableFixedOvernightSwapConvention.of(name, FixedRateSwapLegConvention.builder().currency(index.Currency).dayCount(dayCount).accrualFrequency(frequency).accrualBusinessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, calendar)).paymentFrequency(frequency).paymentDateOffset(paymentDateOffset).stubConvention(StubConvention.SMART_INITIAL).build(), OvernightRateSwapLegConvention.builder().index(index).accrualMethod(COMPOUNDED).accrualFrequency(frequency).paymentFrequency(frequency).paymentDateOffset(paymentDateOffset).stubConvention(StubConvention.SMART_INITIAL).build(), spotDateOffset));
        }
        public virtual PointSensitivityBuilder rateSensitivity(OvernightAveragedDailyRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider)
        {
            OvernightIndex          index                   = computation.Index;
            OvernightIndexRates     rates                   = provider.overnightIndexRates(index);
            LocalDate               lastFixingDate          = computation.EndDate;
            PointSensitivityBuilder pointSensitivityBuilder = PointSensitivityBuilder.none();
            int       numberOfDays      = 0;
            LocalDate currentFixingDate = computation.StartDate;

            while (!currentFixingDate.isAfter(lastFixingDate))
            {
                LocalDate referenceFixingDate      = computation.FixingCalendar.previousOrSame(currentFixingDate);
                OvernightIndexObservation indexObs = computation.observeOn(referenceFixingDate);
                PointSensitivityBuilder   forwardRateSensitivity = rates.ratePointSensitivity(indexObs);
                pointSensitivityBuilder = pointSensitivityBuilder.combinedWith(forwardRateSensitivity);
                numberOfDays++;
                currentFixingDate = currentFixingDate.plusDays(1);
            }

            return(pointSensitivityBuilder.multipliedBy(1d / numberOfDays));
        }
        //-------------------------------------------------------------------------
        public virtual double rate(OvernightAveragedDailyRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider)
        {
            OvernightIndex      index          = computation.Index;
            OvernightIndexRates rates          = provider.overnightIndexRates(index);
            LocalDate           lastFixingDate = computation.EndDate;
            double    interestSum       = 0d;
            int       numberOfDays      = 0;
            LocalDate currentFixingDate = computation.StartDate;

            while (!currentFixingDate.isAfter(lastFixingDate))
            {
                LocalDate referenceFixingDate      = computation.FixingCalendar.previousOrSame(currentFixingDate);
                OvernightIndexObservation indexObs = computation.observeOn(referenceFixingDate);
                double forwardRate = rates.rate(indexObs);
                interestSum += forwardRate;
                numberOfDays++;
                currentFixingDate = currentFixingDate.plusDays(1);
            }

            return(interestSum / numberOfDays);
        }
Beispiel #5
0
        //-------------------------------------------------------------------------
        public virtual double rate(OvernightAveragedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider)
        {
            OvernightIndex      index = computation.Index;
            OvernightIndexRates rates = provider.overnightIndexRates(index);
            LocalDate           lastNonCutoffFixing = computation.EndDate;
            int    cutoffOffset        = computation.RateCutOffDays > 1 ? computation.RateCutOffDays : 1;
            double accumulatedInterest = 0.0d;
            double accrualFactorTotal  = 0.0d;
            // Cut-off period. Starting from the end as the cutoff period is defined as a lag from the end.
            // When the fixing period end-date is not a good business day in the index calendar,
            // the last fixing end date will be after the fixing end-date.
            double cutoffAccrualFactor             = 0.0;
            OvernightIndexObservation lastIndexObs = null;

            // cutoffOffset >= 1, so loop always runs at least once
            for (int i = 0; i < cutoffOffset; i++)
            {
                lastNonCutoffFixing  = computation.FixingCalendar.previous(lastNonCutoffFixing);
                lastIndexObs         = computation.observeOn(lastNonCutoffFixing);
                accrualFactorTotal  += lastIndexObs.YearFraction;
                cutoffAccrualFactor += lastIndexObs.YearFraction;
            }
            double forwardRateCutOff = rates.rate(lastIndexObs);

            accumulatedInterest += cutoffAccrualFactor * forwardRateCutOff;
            LocalDate currentFixingNonCutoff = computation.StartDate;

            while (currentFixingNonCutoff.isBefore(lastNonCutoffFixing))
            {
                // All dates involved in the period are computed. Potentially slow.
                // The fixing periods are added as long as their start date is (strictly) before the no cutoff period end-date.
                OvernightIndexObservation indexObs = computation.observeOn(currentFixingNonCutoff);
                double forwardRate = rates.rate(indexObs);
                accrualFactorTotal    += indexObs.YearFraction;
                accumulatedInterest   += indexObs.YearFraction * forwardRate;
                currentFixingNonCutoff = computation.FixingCalendar.next(currentFixingNonCutoff);
            }
            // final rate
            return(accumulatedInterest / accrualFactorTotal);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "onLeg") public void test_float_leg(OvernightIborSwapConvention convention, com.opengamma.strata.basics.index.OvernightIndex floatLeg)
        public virtual void test_float_leg(OvernightIborSwapConvention convention, OvernightIndex floatLeg)
        {
            assertEquals(convention.OvernightLeg.Index, floatLeg);
        }
 //-------------------------------------------------------------------------
 public virtual OvernightIndexRates overnightIndexRates(OvernightIndex index)
 {
     throw new System.NotSupportedException();
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "floatLeg") public void test_float_leg(FixedOvernightSwapConvention convention, com.opengamma.strata.basics.index.OvernightIndex floatLeg)
        public virtual void test_float_leg(FixedOvernightSwapConvention convention, OvernightIndex floatLeg)
        {
            assertEquals(convention.FloatingLeg.Index, floatLeg);
        }