/// <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());
        }
コード例 #2
0
        //-------------------------------------------------------------------------
        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);
        }
コード例 #3
0
        //-------------------------------------------------------------------------
        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);
        }
コード例 #4
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();
 }
コード例 #5
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);
        }
コード例 #6
0
        public virtual void test_createProduct_wrongType()
        {
            BondFutureSecurity test = sut();
            ImmutableList <FixedCouponBond> basket = PRODUCT.DeliveryBasket;
            SecurityId      secId   = basket.get(0).SecurityId;
            GenericSecurity sec     = GenericSecurity.of(INFO);
            ReferenceData   refData = ImmutableReferenceData.of(secId, sec);

            assertThrows(() => test.createProduct(refData), typeof(System.InvalidCastException));
        }
コード例 #7
0
        //-------------------------------------------------------------------------
        public virtual void test_builder()
        {
            BondFutureSecurity test = sut();

            assertEquals(test.Info, INFO);
            assertEquals(test.SecurityId, PRODUCT.SecurityId);
            assertEquals(test.Currency, PRODUCT.Currency);
            assertEquals(test.FirstDeliveryDate, PRODUCT.FirstDeliveryDate);
            assertEquals(test.LastDeliveryDate, PRODUCT.LastDeliveryDate);
            ImmutableList <FixedCouponBond> basket = PRODUCT.DeliveryBasket;

            assertEquals(test.UnderlyingIds, ImmutableSet.of(basket.get(0).SecurityId, basket.get(1).SecurityId));
        }
        //-------------------------------------------------------------------------
        /// <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));
        }
コード例 #9
0
        //-------------------------------------------------------------------------
        public virtual void test_createProduct()
        {
            BondFutureSecurity test = sut();
            ImmutableList <FixedCouponBond> basket   = PRODUCT.DeliveryBasket;
            FixedCouponBondSecurity         bondSec0 = FixedCouponBondSecurityTest.createSecurity(PRODUCT.DeliveryBasket.get(0));
            FixedCouponBondSecurity         bondSec1 = FixedCouponBondSecurityTest.createSecurity(PRODUCT.DeliveryBasket.get(1));
            ReferenceData refData = ImmutableReferenceData.of(ImmutableMap.of(basket.get(0).SecurityId, bondSec0, basket.get(1).SecurityId, bondSec1));
            BondFuture    product = test.createProduct(refData);

            assertEquals(product.DeliveryBasket.get(0), PRODUCT.DeliveryBasket.get(0));
            assertEquals(product.DeliveryBasket.get(1), PRODUCT.DeliveryBasket.get(1));
            TradeInfo       tradeInfo     = TradeInfo.of(date(2016, 6, 30));
            BondFutureTrade expectedTrade = BondFutureTrade.builder().info(tradeInfo).product(product).quantity(100).price(123.50).build();

            assertEquals(test.createTrade(tradeInfo, 100, 123.50, refData), expectedTrade);

            PositionInfo       positionInfo      = PositionInfo.empty();
            BondFuturePosition expectedPosition1 = BondFuturePosition.builder().info(positionInfo).product(product).longQuantity(100).build();

            TestHelper.assertEqualsBean(test.createPosition(positionInfo, 100, refData), expectedPosition1);
            BondFuturePosition expectedPosition2 = BondFuturePosition.builder().info(positionInfo).product(product).longQuantity(100).shortQuantity(50).build();

            assertEquals(test.createPosition(positionInfo, 100, 50, refData), expectedPosition2);
        }
	  //-------------------------------------------------------------------------
	  public virtual void test_metadata()
	  {
		InflationNodalCurveDefinition test = new InflationNodalCurveDefinition(UNDERLYING_DEF, LAST_FIX_MONTH, LAST_FIX_VALUE, SEASONALITY_DEF);
		DefaultCurveMetadata expected = DefaultCurveMetadata.builder().curveName(CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.PRICE_INDEX).dayCount(ACT_365F).parameterMetadata(NODES.get(0).metadata(VAL_DATE, REF_DATA), NODES.get(1).metadata(VAL_DATE, REF_DATA)).build();
		assertEquals(test.metadata(VAL_DATE, REF_DATA), expected);
	  }
        //-------------------------------------------------------------------------
        public virtual void test_metadata()
        {
            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();
            DefaultCurveMetadata             expected = DefaultCurveMetadata.builder().curveName(CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(ACT_365F).parameterMetadata(NODES.get(0).metadata(VAL_DATE, REF_DATA), NODES.get(1).metadata(VAL_DATE, REF_DATA)).build();

            assertEquals(test.metadata(VAL_DATE, REF_DATA), expected);
        }
コード例 #12
0
        internal static BondFutureSecurity sut2()
        {
            ImmutableList <FixedCouponBond> basket = PRODUCT2.DeliveryBasket;

            return(BondFutureSecurity.builder().info(INFO2).currency(PRODUCT2.Currency).deliveryBasketIds(basket.get(0).SecurityId).conversionFactors(3d).firstNoticeDate(PRODUCT2.FirstNoticeDate).lastNoticeDate(PRODUCT2.LastNoticeDate).lastTradeDate(PRODUCT2.LastTradeDate).rounding(PRODUCT2.Rounding).build());
        }