// calculate the last fixing date
        private LocalDate calculateLastFixingDate(LocalDate valuationDate, ReferenceData refData)
        {
            SwapTrade                 trade                = template.createTrade(valuationDate, BuySell.BUY, 1, 1, refData);
            SwapLeg                   inflationLeg         = trade.Product.getLegs(SwapLegType.INFLATION).get(0);
            ResolvedSwapLeg           inflationLegExpanded = inflationLeg.resolve(refData);
            IList <SwapPaymentPeriod> periods              = inflationLegExpanded.PaymentPeriods;
            int nbPeriods = periods.Count;
            RatePaymentPeriod         lastPeriod = (RatePaymentPeriod)periods[nbPeriods - 1];
            IList <RateAccrualPeriod> accruals   = lastPeriod.AccrualPeriods;
            int nbAccruals = accruals.Count;
            RateAccrualPeriod lastAccrual = accruals[nbAccruals - 1];

            if (lastAccrual.RateComputation is InflationMonthlyRateComputation)
            {
                return(((InflationMonthlyRateComputation)lastAccrual.RateComputation).EndObservation.FixingMonth.atEndOfMonth());
            }
            if (lastAccrual.RateComputation is InflationInterpolatedRateComputation)
            {
                return(((InflationInterpolatedRateComputation)lastAccrual.RateComputation).EndSecondObservation.FixingMonth.atEndOfMonth());
            }
            if (lastAccrual.RateComputation is InflationEndMonthRateComputation)
            {
                return(((InflationEndMonthRateComputation)lastAccrual.RateComputation).EndObservation.FixingMonth.atEndOfMonth());
            }
            if (lastAccrual.RateComputation is InflationEndInterpolatedRateComputation)
            {
                return(((InflationEndInterpolatedRateComputation)lastAccrual.RateComputation).EndSecondObservation.FixingMonth.atEndOfMonth());
            }
            throw new System.ArgumentException("Rate computation type not supported for last fixing date of an inflation swap.");
        }
Example #2
0
        // calculate the last fixing date
        private LocalDate calculateLastFixingDate(LocalDate valuationDate, ReferenceData refData)
        {
            SwapTrade                 trade           = template.createTrade(valuationDate, BuySell.BUY, 1, 1, refData);
            SwapLeg                   iborLeg         = trade.Product.getLegs(SwapLegType.IBOR).get(0);
            ResolvedSwapLeg           iborLegExpanded = iborLeg.resolve(refData);
            IList <SwapPaymentPeriod> periods         = iborLegExpanded.PaymentPeriods;
            int nbPeriods = periods.Count;
            RatePaymentPeriod         lastPeriod = (RatePaymentPeriod)periods[nbPeriods - 1];
            IList <RateAccrualPeriod> accruals   = lastPeriod.AccrualPeriods;
            int nbAccruals           = accruals.Count;
            IborRateComputation ibor = (IborRateComputation)accruals[nbAccruals - 1].RateComputation;

            return(ibor.FixingDate);
        }