예제 #1
0
        private static Trade trade(string counterparty, double notional)
        {
            TradeInfo tradeInfo = TradeInfo.builder().counterparty(StandardId.of("cpty", counterparty)).build();
            Fra       fra       = Fra.builder().buySell(BUY).notional(notional).startDate(date(2015, 8, 5)).endDate(date(2015, 11, 5)).paymentDate(AdjustableDate.of(date(2015, 8, 7))).fixedRate(0.25d).index(GBP_LIBOR_3M).build();

            return(FraTrade.builder().info(tradeInfo).product(fra).build());
        }
        //-------------------------------------------------------------------------
        public virtual void test_createTrade_periods()
        {
            FraConvention @base     = ImmutableFraConvention.builder().index(GBP_LIBOR_3M).spotDateOffset(NEXT_SAME_BUS_DAY).build();
            LocalDate     tradeDate = LocalDate.of(2015, 5, 5);
            FraTrade      test      = @base.createTrade(tradeDate, Period.ofMonths(3), Period.ofMonths(6), BUY, NOTIONAL_2M, 0.25d, REF_DATA);
            Fra           expected  = Fra.builder().buySell(BUY).notional(NOTIONAL_2M).startDate(date(2015, 8, 5)).endDate(date(2015, 11, 5)).fixedRate(0.25d).index(GBP_LIBOR_3M).build();

            assertEquals(test.Info.TradeDate, tradeDate);
            assertEquals(test.Product, expected);
        }
        //-------------------------------------------------------------------------
        public virtual void test_createTrade()
        {
            FraTemplate @base     = FraTemplate.of(Period.ofMonths(3), Period.ofMonths(6), FRA_GBP_LIBOR_3M);
            LocalDate   tradeDate = LocalDate.of(2015, 5, 4);   // trade date is a holiday!
            FraTrade    test      = @base.createTrade(tradeDate, BUY, NOTIONAL_2M, 0.25d, REF_DATA);
            Fra         expected  = Fra.builder().buySell(BUY).notional(NOTIONAL_2M).startDate(date(2015, 8, 5)).endDate(date(2015, 11, 5)).fixedRate(0.25d).index(GBP_LIBOR_3M).build();

            assertEquals(test.Info.TradeDate, tradeDate);
            assertEquals(test.Product, expected);
        }
        public virtual void test_createTrade_periods_adjust_payOffset()
        {
            FraConvention @base     = ImmutableFraConvention.builder().index(GBP_LIBOR_3M).spotDateOffset(NEXT_SAME_BUS_DAY).paymentDateOffset(PLUS_TWO_DAYS).build();
            LocalDate     tradeDate = LocalDate.of(2016, 8, 11);
            FraTrade      test      = @base.createTrade(tradeDate, Period.ofMonths(1), Period.ofMonths(4), BUY, NOTIONAL_2M, 0.25d, REF_DATA);
            Fra           expected  = Fra.builder().buySell(BUY).notional(NOTIONAL_2M).startDate(date(2016, 9, 12)).endDate(date(2016, 12, 12)).paymentDate(AdjustableDate.of(date(2016, 9, 14), PLUS_TWO_DAYS.Adjustment)).fixedRate(0.25d).index(GBP_LIBOR_3M).build();

            assertEquals(test.Info.TradeDate, tradeDate);
            assertEquals(test.Product, expected);
        }
        public virtual void test_createTrade_paymentOffset()
        {
            FraConvention convention = ((ImmutableFraConvention)FRA_GBP_LIBOR_3M).toBuilder().paymentDateOffset(PLUS_TWO_DAYS).build();
            FraTemplate   @base      = FraTemplate.of(Period.ofMonths(3), Period.ofMonths(6), convention);
            LocalDate     tradeDate  = LocalDate.of(2015, 5, 4); // trade date is a holiday!
            FraTrade      test       = @base.createTrade(tradeDate, BUY, NOTIONAL_2M, 0.25d, REF_DATA);
            Fra           expected   = Fra.builder().buySell(BUY).notional(NOTIONAL_2M).startDate(date(2015, 8, 5)).endDate(date(2015, 11, 5)).paymentDate(AdjustableDate.of(date(2015, 8, 7), PLUS_TWO_DAYS.Adjustment)).fixedRate(0.25d).index(GBP_LIBOR_3M).build();

            assertEquals(test.Info.TradeDate, tradeDate);
            assertEquals(test.Product, expected);
        }
        public virtual void test_toTrade_dates_paymentOffset()
        {
            FraConvention @base       = ImmutableFraConvention.builder().index(GBP_LIBOR_3M).spotDateOffset(NEXT_SAME_BUS_DAY).paymentDateOffset(PLUS_TWO_DAYS).build();
            LocalDate     tradeDate   = LocalDate.of(2015, 5, 5);
            LocalDate     startDate   = date(2015, 8, 5);
            LocalDate     endDate     = date(2015, 11, 5);
            LocalDate     paymentDate = date(2015, 8, 7);
            FraTrade      test        = @base.toTrade(tradeDate, startDate, endDate, paymentDate, BUY, NOTIONAL_2M, 0.25d);
            Fra           expected    = Fra.builder().buySell(BUY).notional(NOTIONAL_2M).startDate(date(2015, 8, 5)).endDate(date(2015, 11, 5)).paymentDate(AdjustableDate.of(paymentDate, PLUS_TWO_DAYS.Adjustment)).fixedRate(0.25d).index(GBP_LIBOR_3M).build();

            assertEquals(test.Info.TradeDate, tradeDate);
            assertEquals(test.Product, expected);
        }
예제 #7
0
        //-------------------------------------------------------------------------
        public virtual void test_resolve_Ibor()
        {
            Fra         fra  = Fra.builder().buySell(BUY).notional(NOTIONAL_1M).startDate(date(2015, 6, 15)).endDate(date(2015, 9, 15)).paymentDate(AdjustableDate.of(date(2015, 6, 20), BDA_MOD_FOLLOW)).fixedRate(FIXED_RATE).index(GBP_LIBOR_3M).fixingDateOffset(MINUS_TWO_DAYS).build();
            ResolvedFra test = fra.resolve(REF_DATA);

            assertEquals(test.Currency, GBP);
            assertEquals(test.Notional, NOTIONAL_1M, 0d);
            assertEquals(test.StartDate, date(2015, 6, 15));
            assertEquals(test.EndDate, date(2015, 9, 15));
            assertEquals(test.PaymentDate, date(2015, 6, 22));
            assertEquals(test.FixedRate, FIXED_RATE, 0d);
            assertEquals(test.FloatingRate, IborRateComputation.of(GBP_LIBOR_3M, date(2015, 6, 11), REF_DATA));
            assertEquals(test.YearFraction, ACT_365F.yearFraction(date(2015, 6, 15), date(2015, 9, 15)), 0d);
            assertEquals(test.Discounting, ISDA);
        }
        public virtual void test_trade()
        {
            FraCurveNode        node              = FraCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD);
            LocalDate           valuationDate     = LocalDate.of(2015, 1, 22);
            double              rate              = 0.035;
            ImmutableMarketData marketData        = ImmutableMarketData.builder(valuationDate).addValue(QUOTE_ID, rate).build();
            FraTrade            trade             = node.trade(1d, marketData, REF_DATA);
            LocalDate           startDateExpected = BDA_MOD_FOLLOW.adjust(OFFSET.adjust(valuationDate, REF_DATA).plus(PERIOD_TO_START), REF_DATA);
            LocalDate           endDateExpected   = BDA_MOD_FOLLOW.adjust(OFFSET.adjust(valuationDate, REF_DATA).plus(PERIOD_TO_END), REF_DATA);
            Fra       productExpected             = Fra.builder().buySell(BuySell.SELL).currency(GBP).dayCount(ACT_365F).startDate(startDateExpected).endDate(endDateExpected).paymentDate(AdjustableDate.of(startDateExpected)).notional(1.0d).index(GBP_LIBOR_3M).fixedRate(rate + SPREAD).build();
            TradeInfo tradeInfoExpected           = TradeInfo.builder().tradeDate(valuationDate).build();

            assertEquals(trade.Product, productExpected);
            assertEquals(trade.Info, tradeInfoExpected);
        }
예제 #9
0
        public virtual void test_resolve_IborInterpolated()
        {
            Fra         fra  = Fra.builder().buySell(SELL).notional(NOTIONAL_1M).startDate(date(2015, 6, 12)).endDate(date(2015, 9, 5)).businessDayAdjustment(BDA_MOD_FOLLOW).fixedRate(FIXED_RATE).index(GBP_LIBOR_3M).indexInterpolated(GBP_LIBOR_2M).fixingDateOffset(MINUS_TWO_DAYS).build();
            ResolvedFra test = fra.resolve(REF_DATA);

            assertEquals(test.Currency, GBP);
            assertEquals(test.Notional, -NOTIONAL_1M, 0d);     // sell
            assertEquals(test.StartDate, date(2015, 6, 12));
            assertEquals(test.EndDate, date(2015, 9, 7));
            assertEquals(test.PaymentDate, date(2015, 6, 12));
            assertEquals(test.FixedRate, FIXED_RATE, 0d);
            assertEquals(test.FloatingRate, IborInterpolatedRateComputation.of(GBP_LIBOR_2M, GBP_LIBOR_3M, date(2015, 6, 10), REF_DATA));
            assertEquals(test.YearFraction, ACT_365F.yearFraction(date(2015, 6, 12), date(2015, 9, 7)), 0d);
            assertEquals(test.Discounting, ISDA);
        }
예제 #10
0
        public virtual void test_builder_NZD()
        {
            ImmutableIborIndex dummyIndex = ImmutableIborIndex.builder().name("NZD-INDEX-3M").currency(NZD).dayCount(ACT_360).fixingDateOffset(MINUS_TWO_DAYS).effectiveDateOffset(PLUS_TWO_DAYS).maturityDateOffset(TenorAdjustment.ofLastDay(TENOR_3M, BDA_MOD_FOLLOW)).fixingCalendar(SAT_SUN).fixingTime(LocalTime.NOON).fixingZone(ZoneId.of("NZ")).build();
            Fra test = Fra.builder().buySell(BUY).notional(NOTIONAL_1M).startDate(date(2015, 6, 15)).endDate(date(2015, 9, 15)).paymentDate(AdjustableDate.of(date(2015, 6, 16))).fixedRate(FIXED_RATE).index(dummyIndex).fixingDateOffset(MINUS_TWO_DAYS).build();

            assertEquals(test.BuySell, BUY);
            assertEquals(test.Currency, NZD);     // defaulted
            assertEquals(test.Notional, NOTIONAL_1M, 0d);
            assertEquals(test.StartDate, date(2015, 6, 15));
            assertEquals(test.EndDate, date(2015, 9, 15));
            assertEquals(test.BusinessDayAdjustment, null);
            assertEquals(test.PaymentDate, AdjustableDate.of(date(2015, 6, 16)));
            assertEquals(test.FixedRate, FIXED_RATE, 0d);
            assertEquals(test.Index, dummyIndex);
            assertEquals(test.IndexInterpolated, null);
            assertEquals(test.FixingDateOffset, MINUS_TWO_DAYS);
            assertEquals(test.DayCount, ACT_360);     // defaulted
            assertEquals(test.Discounting, AFMA);     // defaulted
        }
예제 #11
0
        //-----------------------------------------------------------------------
        // create a FRA trade
        private static Trade createTrade1()
        {
            Fra fra = Fra.builder().buySell(BuySell.SELL).index(IborIndices.USD_LIBOR_3M).startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2014, 12, 12)).fixedRate(0.0125).notional(10_000_000).build();

            return(FraTrade.builder().product(fra).info(TradeInfo.builder().id(StandardId.of("example", "1")).addAttribute(AttributeType.DESCRIPTION, "0x3 FRA").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 9, 14)).build()).build());
        }
        //-------------------------------------------------------------------------
        public Trade parseTrade(FpmlDocument document, XmlElement tradeEl)
        {
            // supported elements:
            //  'buyerPartyReference'
            //  'sellerPartyReference'
            //  'adjustedTerminationDate'
            //  'paymentDate'
            //  'fixingDateOffset'
            //  'dayCountFraction'
            //  'notional'
            //  'fixedRate'
            //  'floatingRateIndex'
            //  'indexTenor+'
            //  'fraDiscounting'
            // ignored elements:
            //  'Product.model?'
            //  'buyerAccountReference?'
            //  'sellerAccountReference?'
            //  'calculationPeriodNumberOfDays'
            //  'additionalPayment*'
            TradeInfoBuilder tradeInfoBuilder = document.parseTradeInfo(tradeEl);
            XmlElement       fraEl            = tradeEl.getChild("fra");

            Fra.Builder fraBuilder = Fra.builder();
            // buy/sell and counterparty
            fraBuilder.buySell(document.parseBuyerSeller(fraEl, tradeInfoBuilder));
            // start date
            fraBuilder.startDate(document.parseDate(fraEl.getChild("adjustedEffectiveDate")));
            // end date
            fraBuilder.endDate(document.parseDate(fraEl.getChild("adjustedTerminationDate")));
            // payment date
            fraBuilder.paymentDate(document.parseAdjustableDate(fraEl.getChild("paymentDate")));
            // fixing offset
            fraBuilder.fixingDateOffset(document.parseRelativeDateOffsetDays(fraEl.getChild("fixingDateOffset")));
            // dateRelativeTo required to refer to adjustedEffectiveDate, so ignored here
            // day count
            fraBuilder.dayCount(document.parseDayCountFraction(fraEl.getChild("dayCountFraction")));
            // notional
            CurrencyAmount notional = document.parseCurrencyAmount(fraEl.getChild("notional"));

            fraBuilder.currency(notional.Currency);
            fraBuilder.notional(notional.Amount);
            // fixed rate
            fraBuilder.fixedRate(document.parseDecimal(fraEl.getChild("fixedRate")));
            // index
            IList <Index> indexes = document.parseIndexes(fraEl);

            switch (indexes.Count)
            {
            case 1:
                fraBuilder.index((IborIndex)indexes[0]);
                break;

            case 2:
                fraBuilder.index((IborIndex)indexes[0]);
                fraBuilder.indexInterpolated((IborIndex)indexes[1]);
                break;

            default:
                throw new FpmlParseException("Expected one or two indexes, but found " + indexes.Count);
            }
            // discounting
            fraBuilder.discounting(FraDiscountingMethod.of(fraEl.getChild("fraDiscounting").Content));

            return(FraTrade.builder().info(tradeInfoBuilder.build()).product(fraBuilder.build()).build());
        }
	  private ResolvedFra createNewFra(Fra product, double newFixedRate)
	  {
		return Fra.builder().buySell(product.BuySell).notional(product.Notional).startDate(product.StartDate).endDate(product.EndDate).index(product.Index).fixedRate(newFixedRate).currency(product.Currency).build().resolve(REF_DATA);
	  }
 private static Bean bean()
 {
     return(Fra.builder().buySell(BUY).notional(1_000_000).startDate(date(2015, 8, 5)).endDate(date(2015, 11, 5)).paymentDate(AdjustableDate.of(date(2015, 8, 7))).fixedRate(0.25d).index(GBP_LIBOR_3M).build());
 }
예제 #15
0
 internal static Fra sut2()
 {
     return(Fra.builder().buySell(SELL).currency(USD).notional(NOTIONAL_2M).startDate(date(2015, 6, 16)).endDate(date(2015, 8, 17)).businessDayAdjustment(BDA_MOD_FOLLOW).paymentDate(AdjustableDate.of(date(2015, 6, 17))).dayCount(ACT_360).fixedRate(0.30d).index(GBP_LIBOR_2M).indexInterpolated(GBP_LIBOR_3M).fixingDateOffset(MINUS_FIVE_DAYS).discounting(FraDiscountingMethod.NONE).build());
 }
예제 #16
0
 //-------------------------------------------------------------------------
 internal static Fra sut()
 {
     return(Fra.builder().buySell(BUY).notional(NOTIONAL_1M).startDate(date(2015, 6, 15)).endDate(date(2015, 9, 15)).fixedRate(FIXED_RATE).index(GBP_LIBOR_3M).build());
 }
예제 #17
0
 public virtual void test_builder_noDates()
 {
     assertThrowsIllegalArg(() => Fra.builder().buySell(BUY).notional(NOTIONAL_1M).endDate(date(2015, 9, 15)).fixedRate(FIXED_RATE).index(GBP_LIBOR_3M).build());
 }