示例#1
0
        public override CreditDefaultSwap GenerateInstrument()
        {
            var calendar     = TradeInfo.Calendar.ToCalendarImpl();
            var startDate    = TradeInfo.StartDate.ToDate();
            var maturityDate = TradeInfo.MaturityDate.ToDate();

            var premiumLegNotiaonalFactor = TradeInfo.SwapDirection.ToSwapDirection() == SwapDirection.Payer ? -1 : 1;
            var premiumLeg = new SwapLeg(startDate,
                                         maturityDate,
                                         premiumLegNotiaonalFactor * TradeInfo.Notional,
                                         false,
                                         TradeInfo.Currency.ToCurrencyCode(),
                                         new FixedCoupon(TradeInfo.Coupon),
                                         calendar,
                                         TradeInfo.Frequency.ToFrequency(),
                                         TradeInfo.Stub.ToStub(),
                                         TradeInfo.DayCount.ToDayCountImpl(),
                                         TradeInfo.BusinessDayConvention.ToBda());
            var protectionLeg = new CdsProtectionLeg(
                startDate,
                maturityDate,
                null,
                TradeInfo.Currency.ToCurrencyCode(),
                -premiumLegNotiaonalFactor * TradeInfo.Notional,
                TradeInfo.RecoveryRate);

            return(new CreditDefaultSwap(premiumLeg, protectionLeg, TradeInfo.SwapDirection.ToSwapDirection()));
        }
        // 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.");
        }
示例#3
0
        protected ICalibrationSupportedInstrument CreateCreditDefaultSwap(RateMktData rateMktData)
        {
            var indexType = rateMktData.IndexType.ToIndexType();
            var cdsJson   = MktInstrumentCdsRule.MktCdsRule[indexType];
            var cdsInfo   = cdsJson.CreditDefaultSwapInfo;

            var calendar = cdsInfo.Calendar.ToCalendarImpl();

            var startDate    = Market.ReferenceDate;
            var isTernor     = rateMktData.IsTerm();
            var tenor        = isTernor ? rateMktData.Tenor : null;
            var maturityDate = isTernor ? new Term(tenor).Next(startDate) : new Date(DateTime.Parse(rateMktData.Tenor));
            var premiumLeg   = new SwapLeg(startDate,
                                           maturityDate,
                                           1.0,
                                           false,
                                           cdsInfo.Currency.ToCurrencyCode(),
                                           new FixedCoupon(rateMktData.Rate),
                                           calendar,
                                           cdsInfo.Frequency.ToFrequency(),
                                           cdsInfo.Stub.ToStub(),
                                           cdsInfo.DayCount.ToDayCountImpl(),
                                           cdsInfo.BusinessDayConvention.ToBda()
                                           );
            var protectionLeg = new CdsProtectionLeg(startDate, maturityDate, null, cdsInfo.Currency.ToCurrencyCode(), 1.0, cdsInfo.RecoveryRate);

            return(new CreditDefaultSwap(premiumLeg, protectionLeg, SwapDirection.Payer, tenor, cdsJson.CreditDefaultSwapInfo.NumIntegrationInterval));
        }
 private IborCapFloor(IborCapFloorLeg capFloorLeg, SwapLeg payLeg)
 {
     JodaBeanUtils.notNull(capFloorLeg, "capFloorLeg");
     this.capFloorLeg = capFloorLeg;
     this.payLeg      = payLeg;
     validate();
 }
示例#5
0
 private Cms(CmsLeg cmsLeg, SwapLeg payLeg)
 {
     JodaBeanUtils.notNull(cmsLeg, "cmsLeg");
     this.cmsLeg = cmsLeg;
     this.payLeg = payLeg;
     validate();
 }
        // create a cross-currency GBP libor 3m vs USD libor 3m swap with spread
        private static Trade createXCcyGbpLibor3mVsUsdLibor3mSwap()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2021, 1, 24)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(Currency.GBP, 61_600_000)).calculation(IborRateCalculation.of(IborIndices.GBP_LIBOR_3M)).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2021, 1, 24)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(Currency.USD, 100_000_000)).calculation(IborRateCalculation.builder().index(IborIndices.USD_LIBOR_3M).spread(ValueSchedule.of(0.0091)).build()).build();

            return(SwapTrade.builder().product(Swap.of(receiveLeg, payLeg)).info(TradeInfo.builder().id(StandardId.of("example", "14")).addAttribute(AttributeType.DESCRIPTION, "GBP Libor 3m vs USD Libor 3m").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 1, 24)).build()).build());
        }
        // create a cross-currency USD fixed vs GBP libor 3m swap with initial and final notional exchange
        private static SwapTrade createNotionalExchangeSwap()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2021, 1, 24)).frequency(Frequency.P6M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(Currency.USD).amount(ValueSchedule.of(100_000_000)).initialExchange(true).finalExchange(true).build()).calculation(FixedRateCalculation.of(0.03, DayCounts.THIRTY_U_360)).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2021, 1, 24)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(Currency.GBP).amount(ValueSchedule.of(61_600_000)).initialExchange(true).finalExchange(true).build()).calculation(IborRateCalculation.of(IborIndices.GBP_LIBOR_3M)).build();

            return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "16")).addAttribute(AttributeType.DESCRIPTION, "USD fixed vs GBP Libor 3m (notional exchange)").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 1, 24)).build()).build());
        }
        private SwapTrade getMtmTrade(bool initialExchange, bool intermediateExchange, bool finalExchange, double?initialNotional)
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(finalExchange).initialExchange(initialExchange).amount(ValueSchedule.of(NOTIONAL_EUR)).currency(EUR).build()).calculation(IborRateCalculation.builder().index(EUR_EURIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).spread(ValueSchedule.of(0.0020)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(finalExchange).initialExchange(initialExchange).intermediateExchange(intermediateExchange).amount(ValueSchedule.of(NOTIONAL_USD)).currency(USD).fxReset(FxResetCalculation.builder().fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).referenceCurrency(EUR).index(EUR_USD_WM).initialNotionalValue(initialNotional).build()).build()).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            return(SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build());
        }
        // Create a fixed vs libor 6m swap
        private static Trade createInterpolatedStub4mFixedVsLibor6mSwap()
        {
            NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 100_000_000);

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 7, 12)).frequency(Frequency.P6M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(IborRateCalculation.builder().index(IborIndices.USD_LIBOR_6M).initialStub(IborRateStubCalculation.ofIborInterpolatedRate(IborIndices.USD_LIBOR_3M, IborIndices.USD_LIBOR_6M)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 7, 12)).stubConvention(StubConvention.SHORT_INITIAL).frequency(Frequency.P6M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(FixedRateCalculation.of(0.01, DayCounts.THIRTY_U_360)).build();

            return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "9")).addAttribute(AttributeType.DESCRIPTION, "Fixed vs Libor 6m (interpolated 4m short initial stub)").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 9, 12)).build()).build());
        }
        // Create an overnight averaged vs libor 3m swap with spread
        private static Trade createOvernightAveragedWithSpreadVsLibor3mSwap()
        {
            NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 100_000_000);

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_3M)).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(OvernightRateCalculation.builder().dayCount(DayCounts.ACT_360).index(OvernightIndices.USD_FED_FUND).accrualMethod(OvernightAccrualMethod.AVERAGED).spread(ValueSchedule.of(0.0025)).build()).build();

            return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "3")).addAttribute(AttributeType.DESCRIPTION, "Fed Funds averaged + spread vs Libor 3m").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 9, 12)).build()).build());
        }
        // Create a compounding fixed vs fed funds swap
        private static Trade createCompoundingFixedVsFedFundsSwap()
        {
            NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 100_000_000);

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 2, 5)).endDate(LocalDate.of(2014, 4, 7)).frequency(Frequency.TERM).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.TERM).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(FixedRateCalculation.of(0.00123, DayCounts.ACT_360)).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 2, 5)).endDate(LocalDate.of(2014, 4, 7)).frequency(Frequency.TERM).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.TERM).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(OvernightRateCalculation.of(OvernightIndices.USD_FED_FUND)).build();

            return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "11")).addAttribute(AttributeType.DESCRIPTION, "Compounding fixed vs fed funds").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 2, 5)).build()).build());
        }
        // Create a compounding libor 6m vs libor 3m swap
        private static Trade createCompoundingLibor6mVsLibor3mSwap()
        {
            NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 100_000_000);

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 27)).endDate(LocalDate.of(2024, 8, 27)).frequency(Frequency.P6M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_6M)).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 27)).endDate(LocalDate.of(2024, 8, 27)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(notional).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_3M)).build();

            return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "13")).addAttribute(AttributeType.DESCRIPTION, "Compounding libor 6m vs libor 3m").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 8, 27)).build()).build());
        }
示例#13
0
        public virtual void test_getEndDate()
        {
            SwapLeg leg1 = MockSwapLeg.of(FIXED, PAY, date(2015, 6, 29), date(2017, 6, 30), Currency.USD);
            SwapLeg leg2 = MockSwapLeg.of(FIXED, RECEIVE, date(2015, 6, 30), date(2017, 6, 29), Currency.USD);

            assertEquals(Swap.of(leg1).EndDate, AdjustableDate.of(date(2017, 6, 30)));
            assertEquals(Swap.of(leg2).EndDate, AdjustableDate.of(date(2017, 6, 29)));
            assertEquals(Swap.of(leg1, leg2).EndDate, AdjustableDate.of(date(2017, 6, 30)));
            assertEquals(Swap.of(leg2, leg1).EndDate, AdjustableDate.of(date(2017, 6, 30)));
        }
示例#14
0
 public CreditDefaultSwap(SwapLeg premiumLeg,
                          CdsProtectionLeg protectionLeg,
                          SwapDirection swapDirection,
                          string tenor = null,
                          int premiumLegIntegrationIntervals = 60)
 {
     PremiumLeg    = premiumLeg;
     ProtectionLeg = protectionLeg;
     SwapDirection = swapDirection;
     Tenor         = tenor ?? new Term(UnderlyingMaturityDate - StartDate, Period.Day).ToString();
     PremiumLegIntegrationIntervals = premiumLegIntegrationIntervals;
 }
        //-------------------------------------------------------------------------
        public virtual void test_BasisLibor3mVsLibor6mSwapWithSpread()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2024, 8, 29)).frequency(P6M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_6M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2024, 8, 29)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).spread(ValueSchedule.of(0.0010)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 8, 27)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, -21875.376339152455, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_CompoundingOisFixed2mVsFedFund12mSwapWithFixing()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 17)).endDate(LocalDate.of(2014, 3, 17)).frequency(TERM).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, CalendarUSD.NYC)).build()).notionalSchedule(NOTIONAL).calculation(FixedRateCalculation.builder().dayCount(ACT_360).rate(ValueSchedule.of(0.00123)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 17)).endDate(LocalDate.of(2014, 3, 17)).frequency(TERM).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, CalendarUSD.NYC)).build()).notionalSchedule(NOTIONAL).calculation(OvernightRateCalculation.builder().dayCount(ACT_360).index(USD_FED_FUND).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 1, 15)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, -7352.973875972721, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_OnAASpreadVsLibor3MSwap()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(OvernightRateCalculation.builder().dayCount(ACT_360).index(USD_FED_FUND).accrualMethod(OvernightAccrualMethod.AVERAGED).rateCutOffDays(0).spread(ValueSchedule.of(0.0025)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 1, 15)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, -160663.8362, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_ZeroCouponFixedVsLibor3mSwap()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P12M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(NOTIONAL).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(0.015)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, 7850279.042216873, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_InterpolatedStub4mFixed6mVsLibor6mSwap()
        {
            SwapLeg receiveLeg = fixedLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2016, 7, 12), P6M, RECEIVE, NOTIONAL, 0.01, StubConvention.SHORT_INITIAL);

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 7, 12)).frequency(P6M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_6M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).initialStub(IborRateStubCalculation.ofIborInterpolatedRate(USD_LIBOR_3M, USD_LIBOR_6M)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, 314215.2347116342, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_VanillaFixedVsLibor3mSwapWithFixing()
        {
            SwapLeg payLeg = fixedLeg(LocalDate.of(2013, 9, 12), LocalDate.of(2020, 9, 12), P6M, PAY, NOTIONAL, 0.015, null);

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2013, 9, 12)).endDate(LocalDate.of(2020, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2013, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, 3588376.471608199, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_BasisCompoundedLibor1mVsLibor3mSwap()
        {
            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2019, 8, 29)).frequency(P1M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.FLAT).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_1M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 29)).endDate(LocalDate.of(2019, 8, 29)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 8, 27)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, -342874.98367929866, TOLERANCE_PV);
        }
示例#22
0
        //-------------------------------------------------------------------------
        public SwapTrade toTrade(TradeInfo tradeInfo, LocalDate startDate, LocalDate endDate, BuySell buySell, double notional, double spread)
        {
            Optional <LocalDate> tradeDate = tradeInfo.TradeDate;

            if (tradeDate.Present)
            {
                ArgChecker.inOrderOrEqual(tradeDate.get(), startDate, "tradeDate", "startDate");
            }
            SwapLeg leg1 = spreadLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.Buy), notional, spread);
            SwapLeg leg2 = flatLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.Sell), notional);

            return(SwapTrade.builder().info(tradeInfo).product(Swap.of(leg1, leg2)).build());
        }
示例#23
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);
        }
        private static Trade createTrade1()
        {
            NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 12_000_000);

            PeriodicSchedule accrual = PeriodicSchedule.builder().startDate(LocalDate.of(2006, 2, 24)).endDate(LocalDate.of(2011, 2, 24)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build();

            PaymentSchedule payment = PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, HolidayCalendarIds.USNY)).build();

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(FixedRateCalculation.of(0.05004, DayCounts.ACT_360)).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_3M)).build();

            return(SwapTrade.builder().product(Swap.builder().legs(payLeg, receiveLeg).build()).info(TradeInfo.builder().id(StandardId.of("mn", "14248")).counterparty(StandardId.of("mn", "Dealer A")).settlementDate(LocalDate.of(2006, 2, 24)).build()).build());
        }
        //-----------------------------------------------------------------------
        // XCcy swap with exchange of notional
        public virtual void test_XCcyEur3MSpreadVsUSD3M()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(true).initialExchange(true).amount(ValueSchedule.of(NOTIONAL_EUR)).currency(EUR).build()).calculation(IborRateCalculation.builder().index(EUR_EURIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).spread(ValueSchedule.of(0.0020)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2016, 1, 24)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().finalExchange(true).initialExchange(true).amount(ValueSchedule.of(NOTIONAL_USD)).currency(USD).build()).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build().resolve(REF_DATA);

            double pvUsdExpected = 431944.6868;
            double pvEurExpected = -731021.1778;

            DiscountingSwapTradePricer pricer = swapPricer();
            MultiCurrencyAmount        pv     = pricer.presentValue(trade, provider());

            assertEquals(pv.getAmount(USD).Amount, pvUsdExpected, TOLERANCE_PV);
            assertEquals(pv.getAmount(EUR).Amount, pvEurExpected, TOLERANCE_PV);
        }
示例#26
0
            public override Builder set(string propertyName, object newValue)
            {
                switch (propertyName.GetHashCode())
                {
                case -1356515323:         // cmsLeg
                    this.cmsLeg = (CmsLeg)newValue;
                    break;

                case -995239866:         // payLeg
                    this.payLeg = (SwapLeg)newValue;
                    break;

                default:
                    throw new NoSuchElementException("Unknown property: " + propertyName);
                }
                return(this);
            }
示例#27
0
        // a summary of the leg
        private string legSummary(SwapLeg leg)
        {
            if (leg is RateCalculationSwapLeg)
            {
                RateCalculationSwapLeg rcLeg       = (RateCalculationSwapLeg)leg;
                RateCalculation        calculation = rcLeg.Calculation;
                if (calculation is FixedRateCalculation)
                {
                    FixedRateCalculation calc = (FixedRateCalculation)calculation;
                    string vary = calc.Rate.Steps.Count > 0 || calc.Rate.StepSequence.Present ? " variable" : "";
                    return(SummarizerUtils.percent(calc.Rate.InitialValue) + vary);
                }
                if (calculation is IborRateCalculation)
                {
                    IborRateCalculation calc = (IborRateCalculation)calculation;
                    string gearing           = calc.Gearing.map(g => " * " + SummarizerUtils.value(g.InitialValue)).orElse("");
                    string spread            = calc.Spread.map(s => " + " + SummarizerUtils.percent(s.InitialValue)).orElse("");
                    return(calc.Index.Name + gearing + spread);
                }
                if (calculation is OvernightRateCalculation)
                {
                    OvernightRateCalculation calc = (OvernightRateCalculation)calculation;
                    string avg     = calc.AccrualMethod == OvernightAccrualMethod.AVERAGED ? " avg" : "";
                    string gearing = calc.Gearing.map(g => " * " + SummarizerUtils.value(g.InitialValue)).orElse("");
                    string spread  = calc.Spread.map(s => " + " + SummarizerUtils.percent(s.InitialValue)).orElse("");
                    return(calc.Index.Name + avg + gearing + spread);
                }
                if (calculation is InflationRateCalculation)
                {
                    InflationRateCalculation calc = (InflationRateCalculation)calculation;
                    string gearing = calc.Gearing.map(g => " * " + SummarizerUtils.value(g.InitialValue)).orElse("");
                    return(calc.Index.Name + gearing);
                }
            }
            if (leg is KnownAmountSwapLeg)
            {
                KnownAmountSwapLeg kaLeg = (KnownAmountSwapLeg)leg;
                string             vary  = kaLeg.Amount.Steps.Count > 0 || kaLeg.Amount.StepSequence.Present ? " variable" : "";
                return(SummarizerUtils.amount(kaLeg.Currency, kaLeg.Amount.InitialValue) + vary);
            }
            ImmutableSet <Index> allIndices = leg.allIndices();

            return(allIndices.Empty ? "Fixed" : allIndices.ToString());
        }
示例#28
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Summarizes this swap into string form.
        /// </summary>
        /// <returns> the summary description </returns>
        public string summaryDescription()
        {
            // 5Y USD 2mm Rec USD-LIBOR-6M / Pay 1% : 21Jan17-21Jan22
            StringBuilder buf = new StringBuilder(64);

            buf.Append(SummarizerUtils.datePeriod(StartDate.Unadjusted, EndDate.Unadjusted));
            buf.Append(' ');
            if (Legs.size() == 2 && PayLeg.Present && ReceiveLeg.Present && Legs.All(leg => leg is RateCalculationSwapLeg))
            {
                // normal swap
                SwapLeg payLeg      = PayLeg.get();
                SwapLeg recLeg      = ReceiveLeg.get();
                string  payNotional = notional(payLeg);
                string  recNotional = notional(recLeg);
                if (payNotional.Equals(recNotional))
                {
                    buf.Append(recNotional);
                    buf.Append(" Rec ");
                    buf.Append(legSummary(recLeg));
                    buf.Append(" / Pay ");
                    buf.Append(legSummary(payLeg));
                }
                else
                {
                    buf.Append("Rec ");
                    buf.Append(legSummary(recLeg));
                    buf.Append(' ');
                    buf.Append(recNotional);
                    buf.Append(" / Pay ");
                    buf.Append(legSummary(payLeg));
                    buf.Append(' ');
                    buf.Append(payNotional);
                }
            }
            else
            {
                // abnormal swap
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
                buf.Append(Legs.Select(leg => (SummarizerUtils.payReceive(leg.PayReceive) + " " + legSummary(leg) + " " + notional(leg)).Trim()).collect(joining(" / ")));
            }
            buf.Append(" : ");
            buf.Append(SummarizerUtils.dateRange(StartDate.Unadjusted, EndDate.Unadjusted));
            return(buf.ToString());
        }
示例#29
0
 // the notional, with trailing space if present
 private string notional(SwapLeg leg)
 {
     if (leg is RateCalculationSwapLeg)
     {
         RateCalculationSwapLeg rcLeg            = (RateCalculationSwapLeg)leg;
         NotionalSchedule       notionalSchedule = rcLeg.NotionalSchedule;
         ValueSchedule          amount           = notionalSchedule.Amount;
         double   notional = amount.InitialValue;
         string   vary     = amount.Steps.Count > 0 || amount.StepSequence.Present ? " variable" : "";
         Currency currency = notionalSchedule.FxReset.map(fxr => fxr.ReferenceCurrency).orElse(rcLeg.Currency);
         return(SummarizerUtils.amount(currency, notional) + vary);
     }
     if (leg is RatePeriodSwapLeg)
     {
         RatePeriodSwapLeg rpLeg = (RatePeriodSwapLeg)leg;
         return(SummarizerUtils.amount(rpLeg.PaymentPeriods.get(0).NotionalAmount));
     }
     return("");
 }
示例#30
0
        public InterestRateSwap(
            SwapLeg fixedLeg,
            SwapLeg floatingLeg,
            SwapDirection swapDirection,
            string tenor = null)
        {
            FixedLeg    = fixedLeg;
            FloatingLeg = floatingLeg;

            if (FixedLeg.StartDate != FloatingLeg.StartDate || FixedLeg.UnderlyingMaturityDate != FloatingLeg.UnderlyingMaturityDate ||
                !FixedLeg.Notional.AlmostEqual(-FloatingLeg.Notional) || FixedLeg.NotionalExchange != FloatingLeg.NotionalExchange)
            {
                throw new PricingBaseException("Interest rate swap fixed leg and floating leg mismatches");
            }

            SwapDirection = swapDirection;

            Tenor = tenor ?? string.Format("{0}{1}", (int)(UnderlyingMaturityDate - StartDate), "D");
        }