//-------------------------------------------------------------------------
        public virtual void test_getters()
        {
            ResolvedFixedCouponBond test = sut();
            ImmutableList <FixedCouponBondPaymentPeriod> payments = test.PeriodicPayments;

            assertEquals(test.StartDate, payments.get(0).StartDate);
            assertEquals(test.EndDate, payments.get(payments.size() - 1).EndDate);
            assertEquals(test.UnadjustedStartDate, payments.get(0).UnadjustedStartDate);
            assertEquals(test.UnadjustedEndDate, payments.get(payments.size() - 1).UnadjustedEndDate);
            assertEquals(test.hasExCouponPeriod(), true);
        }
示例#2
0
 static BlackFxOptionSmileVolatilitiesSpecificationTest()
 {
     ImmutableList.Builder <FxOptionVolatilitiesNode> builder = ImmutableList.builder();
     ImmutableList.Builder <QuoteId> quoteBuilder             = ImmutableList.builder();
     for (int i = 0; i < TENORS.size(); ++i)
     {
         QuoteId id = QuoteId.of(StandardId.of("OG", TENORS.get(i).ToString() + "_" + DELTAS.get(i).ToString() + "_" + QUOTE_TYPE.get(i).ToString()));
         builder.add(FxOptionVolatilitiesNode.of(EUR_GBP, SPOT_OFFSET, BUS_ADJ, QUOTE_TYPE.get(i), id, TENORS.get(i), DeltaStrike.of(DELTAS.get(i))));
         quoteBuilder.add(id);
     }
     NODES     = builder.build();
     QUOTE_IDS = quoteBuilder.build();
 }
        //-------------------------------------------------------------------------
        public virtual void test_cashFlowEquivalentAndSensitivity()
        {
            ResolvedSwap swap = ResolvedSwap.of(IBOR_LEG, FIXED_LEG);
            ImmutableMap <Payment, PointSensitivityBuilder> computedFull = CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivitySwap(swap, PROVIDER);
            ImmutableList <Payment> keyComputedFull = computedFull.Keys.asList();
            ImmutableList <PointSensitivityBuilder>         valueComputedFull = computedFull.values().asList();
            ImmutableMap <Payment, PointSensitivityBuilder> computedIborLeg   = CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivityIborLeg(IBOR_LEG, PROVIDER);
            ImmutableMap <Payment, PointSensitivityBuilder> computedFixedLeg  = CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivityFixedLeg(FIXED_LEG, PROVIDER);

            assertEquals(computedFixedLeg.Keys.asList(), keyComputedFull.subList(0, 2));
            assertEquals(computedIborLeg.Keys.asList(), keyComputedFull.subList(2, 6));
            assertEquals(computedFixedLeg.values().asList(), valueComputedFull.subList(0, 2));
            assertEquals(computedIborLeg.values().asList(), valueComputedFull.subList(2, 6));

            double eps = 1.0e-7;
            RatesFiniteDifferenceSensitivityCalculator calc = new RatesFiniteDifferenceSensitivityCalculator(eps);
            int size = keyComputedFull.size();

            for (int i = 0; i < size; ++i)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int index = i;
                int index = i;
                CurrencyParameterSensitivities expected = calc.sensitivity(PROVIDER, p => ((NotionalExchange)CashFlowEquivalentCalculator.cashFlowEquivalentSwap(swap, p).PaymentEvents.get(index)).PaymentAmount);
                SwapPaymentEvent               @event   = CashFlowEquivalentCalculator.cashFlowEquivalentSwap(swap, PROVIDER).PaymentEvents.get(index);
                PointSensitivityBuilder        point    = computedFull.get(((NotionalExchange)@event).Payment);
                CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point.build());
                assertTrue(computed.equalWithTolerance(expected, eps * NOTIONAL));
            }
        }
示例#4
0
        public virtual void test_resolve()
        {
            FixedCouponBond         @base    = sut();
            ResolvedFixedCouponBond resolved = @base.resolve(REF_DATA);

            assertEquals(resolved.LegalEntityId, LEGAL_ENTITY);
            assertEquals(resolved.SettlementDateOffset, DATE_OFFSET);
            assertEquals(resolved.YieldConvention, YIELD_CONVENTION);
            ImmutableList <FixedCouponBondPaymentPeriod> periodicPayments = resolved.PeriodicPayments;
            int expNum = 20;

            assertEquals(periodicPayments.size(), expNum);
            LocalDate unadjustedEnd = END_DATE;
            Schedule  unadjusted    = PERIOD_SCHEDULE.createSchedule(REF_DATA).toUnadjusted();

            for (int i = 0; i < expNum; ++i)
            {
                FixedCouponBondPaymentPeriod payment = periodicPayments.get(expNum - 1 - i);
                assertEquals(payment.Currency, EUR);
                assertEquals(payment.Notional, NOTIONAL);
                assertEquals(payment.FixedRate, FIXED_RATE);
                assertEquals(payment.UnadjustedEndDate, unadjustedEnd);
                assertEquals(payment.EndDate, BUSINESS_ADJUST.adjust(unadjustedEnd, REF_DATA));
                assertEquals(payment.PaymentDate, payment.EndDate);
                LocalDate unadjustedStart = unadjustedEnd.minusMonths(6);
                assertEquals(payment.UnadjustedStartDate, unadjustedStart);
                assertEquals(payment.StartDate, BUSINESS_ADJUST.adjust(unadjustedStart, REF_DATA));
                assertEquals(payment.YearFraction, unadjusted.getPeriod(expNum - 1 - i).yearFraction(DAY_COUNT, unadjusted));
                assertEquals(payment.DetachmentDate, EX_COUPON.adjust(payment.PaymentDate, REF_DATA));
                unadjustedEnd = unadjustedStart;
            }
            Payment expectedPayment = Payment.of(CurrencyAmount.of(EUR, NOTIONAL), BUSINESS_ADJUST.adjust(END_DATE, REF_DATA));

            assertEquals(resolved.NominalPayment, expectedPayment);
        }
        /// <summary>
        /// Calculates the price sensitivity of the bond future product with z-spread.
        /// <para>
        /// The price sensitivity of the product is the sensitivity of the price to the underlying curves.
        /// </para>
        /// <para>
        /// The z-spread is a parallel shift applied to continuously compounded rates or periodic compounded rates
        /// of the issuer discounting curve.
        /// </para>
        /// <para>
        /// Note that the price sensitivity should be no currency.
        ///
        /// </para>
        /// </summary>
        /// <param name="future">  the future </param>
        /// <param name="discountingProvider">  the discounting provider </param>
        /// <param name="zSpread">  the z-spread </param>
        /// <param name="compoundedRateType">  the compounded rate type </param>
        /// <param name="periodPerYear">  the number of periods per year </param>
        /// <returns> the price curve sensitivity of the product </returns>
        public PointSensitivities priceSensitivityWithZSpread(ResolvedBondFuture future, LegalEntityDiscountingProvider discountingProvider, double zSpread, CompoundedRateType compoundedRateType, int periodPerYear)
        {
            ImmutableList <ResolvedFixedCouponBond> basket = future.DeliveryBasket;
            int size = basket.size();

            double[] priceBonds = new double[size];
            int      indexCTD   = 0;
            double   priceMin   = 2d;

            for (int i = 0; i < size; i++)
            {
                ResolvedFixedCouponBond bond = basket.get(i);
                double dirtyPrice            = bondPricer.dirtyPriceFromCurvesWithZSpread(bond, discountingProvider, zSpread, compoundedRateType, periodPerYear, future.LastDeliveryDate);
                priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice(bond, future.LastDeliveryDate, dirtyPrice) / future.ConversionFactors.get(i);
                if (priceBonds[i] < priceMin)
                {
                    priceMin = priceBonds[i];
                    indexCTD = i;
                }
            }
            ResolvedFixedCouponBond bond       = basket.get(indexCTD);
            PointSensitivityBuilder pointSensi = bondPricer.dirtyPriceSensitivityWithZspread(bond, discountingProvider, zSpread, compoundedRateType, periodPerYear, future.LastDeliveryDate);

            return(pointSensi.multipliedBy(1d / future.ConversionFactors.get(indexCTD)).build());
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the price of the bond future product.
        /// <para>
        /// The price of the product is the price on the valuation date.
        /// </para>
        /// <para>
        /// Strata uses <i>decimal prices</i> for bond futures. This is coherent with the pricing of <seealso cref="FixedCouponBond"/>.
        /// For example, a price of 99.32% is represented in Strata by 0.9932.
        ///
        /// </para>
        /// </summary>
        /// <param name="future">  the future </param>
        /// <param name="discountingProvider">  the discounting provider </param>
        /// <returns> the price of the product, in decimal form </returns>
        public double price(ResolvedBondFuture future, LegalEntityDiscountingProvider discountingProvider)
        {
            ImmutableList <ResolvedFixedCouponBond> basket = future.DeliveryBasket;
            int size = basket.size();

            double[] priceBonds = new double[size];
            for (int i = 0; i < size; ++i)
            {
                ResolvedFixedCouponBond bond = basket.get(i);
                double dirtyPrice            = bondPricer.dirtyPriceFromCurves(bond, discountingProvider, future.LastDeliveryDate);
                priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice(bond, future.LastDeliveryDate, dirtyPrice) / future.ConversionFactors.get(i);
            }
            return(Doubles.min(priceBonds));
        }
        //-------------------------------------------------------------------------
        public virtual void test_findPeriod()
        {
            ResolvedFixedCouponBond test = sut();
            ImmutableList <FixedCouponBondPaymentPeriod> payments = test.PeriodicPayments;

            assertEquals(test.findPeriod(test.UnadjustedStartDate), payments.get(0));
            assertEquals(test.findPeriod(test.UnadjustedEndDate.minusDays(1)), payments.get(payments.size() - 1));
            assertEquals(test.findPeriod(LocalDate.MIN), null);
            assertEquals(test.findPeriod(LocalDate.MAX), null);
        }
	  //-------------------------------------------------------------------------
	  public virtual void test_toCurveParameterSize()
	  {
		InflationNodalCurveDefinition test = new InflationNodalCurveDefinition(UNDERLYING_DEF, LAST_FIX_MONTH, LAST_FIX_VALUE, SEASONALITY_DEF);
		assertEquals(test.toCurveParameterSize(), CurveParameterSize.of(CURVE_NAME, NODES.size()));
	  }
        //-------------------------------------------------------------------------
        public virtual void test_toCurveParameterSize()
        {
            InterpolatedNodalCurveDefinition test = InterpolatedNodalCurveDefinition.builder().name(CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(ACT_365F).nodes(NODES).interpolator(CurveInterpolators.LINEAR).extrapolatorLeft(CurveExtrapolators.FLAT).extrapolatorRight(CurveExtrapolators.FLAT).build();

            assertEquals(test.toCurveParameterSize(), CurveParameterSize.of(CURVE_NAME, NODES.size()));
        }