Пример #1
0
 @Test
 public void getter() {
   assertEquals("Price Index: getter: name", NAME, PRICE_INDEX.getName());
   assertEquals("Price Index: getter: currency", CUR, PRICE_INDEX.getCurrency());
   assertEquals("Price Index: getter: region", REGION, PRICE_INDEX.getRegion());
   assertEquals("Price Index: getter: lag", LAG, PRICE_INDEX.getPublicationLag());
 }
 @Test(enabled = false)
 /** Tests the clean, dirty and yield vs external hard-coded values. */
 public void priceYieldExternalValues1() {
   final double m1 = 1000000; // Notional of the external figures.
   final ZonedDateTime pricingDate20110817 = DateUtils.getUTCDate(2011, 8, 16); // Spot 18-Aug-2011
   final InflationIssuerProviderDiscount market =
       MulticurveProviderDiscountDataSets.createMarket1(pricingDate20110817);
   final double cleanRealPrice = 1.00;
   final BondCapitalIndexedSecurity<Coupon> bond_110817 =
       BOND_SECURITY_TIPS_1_DEFINITION.toDerivative(pricingDate20110817, US_CPI);
   final double referenceIndexExpected = 225.83129;
   final MultiCurrencyAmount netAmountSettle =
       bond_110817.getSettlement().accept(NADIC, market.getInflationProvider());
   final double referenceIndexComputed =
       netAmountSettle.getAmount(bond_110817.getCurrency()).getAmount()
           * BOND_SECURITY_TIPS_1_DEFINITION.getIndexStartValue()
           / bond_110817.getSettlement().getNotional();
   assertEquals(
       "Inflation Capital Indexed bond: index",
       referenceIndexExpected,
       referenceIndexComputed,
       1.0E-5);
   final double indexRatioExpected = 1.13782;
   final MultiCurrencyAmount indexRatioCalculated =
       bond_110817.getSettlement().accept(NADIC, market.getInflationProvider());
   assertEquals(
       "Inflation Capital Indexed bond: indexRatio",
       indexRatioExpected,
       indexRatioCalculated.getAmount(PRICE_INDEX_USCPI.getCurrency()).getAmount()
           / NOTIONAL_TIPS_1,
       1.0E-5);
   final double yieldExpected = 1.999644 / 100.0;
   final double dirtyRealPriceComputed =
       METHOD_BOND_INFLATION.dirtyRealPriceFromCleanRealPrice(bond_110817, cleanRealPrice);
   final double yieldComputed =
       METHOD_BOND_INFLATION.yieldRealFromDirtyRealPrice(bond_110817, dirtyRealPriceComputed);
   assertEquals("Inflation Capital Indexed bond: yield ", yieldExpected, yieldComputed, 1.0E-8);
   final double accruedExpected = 2102.49;
   final double accruedRealExpected = accruedExpected / m1 / indexRatioExpected;
   final double accruedReal = bond_110817.getAccruedInterest();
   assertEquals(
       "Inflation Capital Indexed bond: accrued",
       accruedRealExpected,
       accruedReal / NOTIONAL_TIPS_1,
       1.0E-8);
   final double netAmountExpected = 1139922.49; // For 1m; uses the rounding rules.
   final double netAmount2 = indexRatioExpected * m1 * cleanRealPrice + accruedExpected;
   assertEquals(
       "Inflation Capital Indexed bond: net amount", netAmountExpected, netAmount2, 1.0E-2);
   final MultiCurrencyAmount netAmount =
       METHOD_BOND_INFLATION.netAmount(bond_110817, market, cleanRealPrice);
   assertEquals(
       "Inflation Capital Indexed bond: net amount",
       netAmountExpected,
       netAmount.getAmount(PRICE_INDEX_USCPI.getCurrency()).getAmount() * m1 / NOTIONAL_TIPS_1,
       2.0E+0); // The difference is due to rounding.
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = super.hashCode();
   result = prime * result + _indexPrice.hashCode();
   return result;
 }
 /**
  * Builder from all the cap/floor details except weight which are calculated using the payment
  * date.
  *
  * @param accrualStartDate Start date of the accrual period.
  * @param paymentDate Coupon payment date.
  * @param notional Coupon notional.
  * @param priceIndex The price index associated to the coupon.
  * @param conventionalMonthLag The lag in month between the index validity and the coupon dates
  *     for the standard product.
  * @param monthlag The lag in month between the index validity and the coupon dates for the actual
  *     product.
  * @param maturity The cap/floor maturity in years.
  * @param lastKnownFixingDate The fixing date (always the first of a month) of the last known
  *     fixing.
  * @param indexStartValue The index value at the start of the coupon.
  * @param referenceEndDate The reference date for the index at the coupon end.
  * @param strike The strike
  * @param isCap The cap/floor flag.
  * @return The cap/floor.
  */
 public static CapFloorInflationZeroCouponInterpolationDefinition from(
     final ZonedDateTime accrualStartDate,
     final ZonedDateTime paymentDate,
     final double notional,
     final IndexPrice priceIndex,
     final int conventionalMonthLag,
     final int monthlag,
     final int maturity,
     final ZonedDateTime lastKnownFixingDate,
     final double indexStartValue,
     final ZonedDateTime[] referenceEndDate,
     final double strike,
     final boolean isCap) {
   Validate.notNull(priceIndex, "Price index");
   final double weight;
   weight = 1.0 - (paymentDate.getDayOfMonth() - 1.0) / paymentDate.toLocalDate().lengthOfMonth();
   return new CapFloorInflationZeroCouponInterpolationDefinition(
       priceIndex.getCurrency(),
       paymentDate,
       accrualStartDate,
       paymentDate,
       1.0,
       notional,
       priceIndex,
       lastKnownFixingDate,
       conventionalMonthLag,
       monthlag,
       maturity,
       indexStartValue,
       referenceEndDate,
       weight,
       strike,
       isCap);
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = super.hashCode();
   result = prime * result + _couponPerYear;
   result = prime * result + ((_dayCount == null) ? 0 : _dayCount.hashCode());
   result = prime * result + (_isEOM ? 1231 : 1237);
   result = prime * result + _monthLag;
   result = prime * result + ((_priceIndex == null) ? 0 : _priceIndex.hashCode());
   result = prime * result + ((_yieldConvention == null) ? 0 : _yieldConvention.hashCode());
   return result;
 }
 @Override
 public boolean equals(final Object obj) {
   if (this == obj) {
     return true;
   }
   if (!super.equals(obj)) {
     return false;
   }
   if (getClass() != obj.getClass()) {
     return false;
   }
   final BondInterestIndexedSecurityDefinition<?, ?> other =
       (BondInterestIndexedSecurityDefinition<?, ?>) obj;
   if (_couponPerYear != other._couponPerYear) {
     return false;
   }
   if (_dayCount == null) {
     if (other._dayCount != null) {
       return false;
     }
   } else if (!_dayCount.equals(other._dayCount)) {
     return false;
   }
   if (_isEOM != other._isEOM) {
     return false;
   }
   if (_monthLag != other._monthLag) {
     return false;
   }
   if (_priceIndex == null) {
     if (other._priceIndex != null) {
       return false;
     }
   } else if (!_priceIndex.equals(other._priceIndex)) {
     return false;
   }
   if (_yieldConvention == null) {
     if (other._yieldConvention != null) {
       return false;
     }
   } else if (!_yieldConvention.equals(other._yieldConvention)) {
     return false;
   }
   return true;
 }
Пример #7
0
 @Test
 public void testEqualHash() {
   assertEquals(PRICE_INDEX, PRICE_INDEX);
   IndexPrice indexDuplicate = new IndexPrice("Euro HICP x", CUR, REGION, LAG);
   assertEquals(PRICE_INDEX, indexDuplicate);
   assertEquals(PRICE_INDEX.hashCode(), indexDuplicate.hashCode());
   IndexPrice modified;
   modified = new IndexPrice("xxx", CUR, REGION, LAG);
   assertFalse(PRICE_INDEX.equals(modified));
   modified = new IndexPrice(NAME, Currency.AUD, REGION, LAG);
   assertFalse(PRICE_INDEX.equals(modified));
   modified = new IndexPrice(NAME, CUR, Currency.AUD, LAG);
   assertFalse(PRICE_INDEX.equals(modified));
 }
  /**
   * Builder of Inflation capital index bond from financial details. The notional and the coupon
   * reference index are interpolated index. The coupon dates are computed from the maturity and
   * have a short first coupon if required.
   *
   * @param priceIndex The price index associated to the bond.
   * @param monthLag The lag in month between the index validity and the coupon dates.
   * @param startDate The bond start date.
   * @param indexStartValue The index value at the start of the bond.
   * @param maturityDate The bond maturity date.
   * @param couponPeriod The period between coupon payments.
   * @param notional The bond notional.
   * @param realRate The bond nominal rate.
   * @param businessDay The business day convention to compute the payment days.
   * @param settlementDays Standard number of days between trade date and trade settlement. Used for
   *     clean price and yield computation.
   * @param calendar The payment calendar.
   * @param dayCount The coupon day count convention.
   * @param yieldConvention The yield (to maturity) computation convention.
   * @param isEOM The end-of-month flag.
   * @param issuer The bond issuer name.
   * @return The bond.
   */
  public static BondInterestIndexedSecurityDefinition<
          PaymentFixedDefinition, CouponInflationYearOnYearInterpolationWithMarginDefinition>
      fromInterpolation(
          final IndexPrice priceIndex,
          final int monthLag,
          final ZonedDateTime startDate,
          final double indexStartValue,
          final ZonedDateTime maturityDate,
          final Period couponPeriod,
          final double notional,
          final double realRate,
          final BusinessDayConvention businessDay,
          final int settlementDays,
          final Calendar calendar,
          final DayCount dayCount,
          final YieldConvention yieldConvention,
          final boolean isEOM,
          final LegalEntity issuer) {
    // Nominal construction
    final PaymentFixedDefinition[] nominalPayment =
        new PaymentFixedDefinition[] {
          new PaymentFixedDefinition(
              priceIndex.getCurrency(), businessDay.adjustDate(calendar, maturityDate), notional)
        };

    final AnnuityDefinition<PaymentFixedDefinition> nominalAnnuity =
        new AnnuityDefinition<>(nominalPayment, calendar);
    // Coupon construction
    final ZonedDateTime[] paymentDatesUnadjusted =
        ScheduleCalculator.getUnadjustedDateSchedule(
            startDate, maturityDate, couponPeriod, true, true);
    final ZonedDateTime[] paymentDates =
        ScheduleCalculator.getAdjustedDateSchedule(
            paymentDatesUnadjusted, businessDay, calendar, false);
    final CouponInflationYearOnYearInterpolationWithMarginDefinition[] coupons =
        new CouponInflationYearOnYearInterpolationWithMarginDefinition[paymentDates.length];
    coupons[0] =
        CouponInflationYearOnYearInterpolationWithMarginDefinition.from(
            realRate, startDate, paymentDates[0], notional, priceIndex, monthLag, monthLag, true);
    for (int loopcpn = 1; loopcpn < paymentDates.length; loopcpn++) {
      coupons[loopcpn] =
          CouponInflationYearOnYearInterpolationWithMarginDefinition.from(
              realRate,
              paymentDatesUnadjusted[loopcpn - 1],
              paymentDates[loopcpn],
              notional,
              priceIndex,
              monthLag,
              monthLag,
              true);
    }
    final AnnuityDefinition<CouponInflationYearOnYearInterpolationWithMarginDefinition>
        couponAnnuity = new AnnuityDefinition<>(coupons, calendar);
    return new BondInterestIndexedSecurityDefinition<>(
        nominalAnnuity,
        couponAnnuity,
        DEFAULT_EX_COUPON_DAYS,
        settlementDays,
        calendar,
        dayCount,
        yieldConvention,
        isEOM,
        monthLag,
        issuer);
  }
 @Override
 public String toString() {
   return super.toString() + ", price index=" + _indexPrice.toString();
 }
 @Override
 protected void buildMessage(
     final FudgeSerializer serializer, final MutableFudgeMsg message, final IndexPrice object) {
   message.add(NAME_FIELD, object.getName());
   message.add(CURRENCY_FIELD, object.getCurrency().getCode());
 }