Package org.threeten.bp

Examples of org.threeten.bp.Period


   * Tests of performance. "enabled = false" for the standard testing.
   */
  public void performance() {
    long startTime, endTime;
    final int nbTest = 1000;
    final Period swapTenor = Period.ofYears(10);
    final Period expTenor = Period.ofYears(10);
    final ZonedDateTime expiryDate = ScheduleCalculator.getAdjustedDate(REFERENCE_DATE, expTenor, EURIBOR6M, TARGET);
    final ZonedDateTime settleDate = ScheduleCalculator.getAdjustedDate(expiryDate, EURIBOR6M.getSpotLag(), TARGET);
    final LiborMarketModelDisplacedDiffusionParameters parametersLMM = TestsDataSetLiborMarketModelDisplacedDiffusion.createLMMParameters(REFERENCE_DATE,
        SwapFixedIborDefinition.from(settleDate, swapTenor, EUR1YEURIBOR3M, NOTIONAL, 0.0, FIXED_IS_PAYER).getIborLeg());
    final LiborMarketModelDisplacedDiffusionProviderDiscount lmmMulticurves = new LiborMarketModelDisplacedDiffusionProviderDiscount(MULTICURVES, parametersLMM, EUR);
View Full Code Here


  */
  public void calibrationWithAllInstrruments() {

    for (int loop1 = 0; loop1 < strikes.length; loop1++) {
      for (int loop2 = 0; loop2 < availabelTenor.length; loop2++) {
        final Period tenor = Period.ofYears(availabelTenor[loop2]);

        CAP_DEFINITIONS[loop1][loop2] = AnnuityCapFloorInflationYearOnYearInterpolationDefinition.from(PRICE_INDEX_EUR, SETTLEMENT_DATE, NOTIONAL,
            tenor, COUPON_PAYMENT_TENOR, BUSINESS_DAY, CALENDAR, IS_EOM, MONTH_LAG, MONTH_LAG, LAST_KNOWN_FIXING_DATE, strikes[loop1], IS_CAP);
        CAPS[loop1][loop2] = CAP_DEFINITIONS[loop1][loop2].toDerivative(REFERENCE_DATE);
      }
View Full Code Here

   */
  public void calibrationWithOnlyAvailableMarketData() {

    for (int loop1 = 0; loop1 < strikes_AVAILABLE.length; loop1++) {
      for (int loop2 = 0; loop2 < availabelTenor.length; loop2++) {
        final Period tenor = Period.ofYears(availabelTenor[loop2]);

        CAP_DEFINITIONS_AVAILABLE[loop1][loop2] = AnnuityCapFloorInflationYearOnYearInterpolationDefinition.from(PRICE_INDEX_EUR, SETTLEMENT_DATE, NOTIONAL,
            tenor, COUPON_PAYMENT_TENOR, BUSINESS_DAY, CALENDAR, IS_EOM, MONTH_LAG, MONTH_LAG, LAST_KNOWN_FIXING_DATE, strikes_AVAILABLE[loop1], IS_CAP);
        CAPS_AVAILABLE[loop1][loop2] = CAP_DEFINITIONS_AVAILABLE[loop1][loop2].toDerivative(REFERENCE_DATE);
      }
View Full Code Here

   */
  public void calibrationWithOnlyAvailableMarketDataCapAndFloor() {

    for (int loop1 = 0; loop1 < strikes_AVAILABLE.length; loop1++) {
      for (int loop2 = 0; loop2 < availabelTenor.length; loop2++) {
        final Period tenor = Period.ofYears(availabelTenor[loop2]);
        boolean isCap = true;
        if (loop1 == 0 || loop1 == 1 || loop1 == 2) {
          isCap = false;
        }
        CAP_DEFINITIONS_AVAILABLE[loop1][loop2] = AnnuityCapFloorInflationYearOnYearInterpolationDefinition.from(PRICE_INDEX_EUR, SETTLEMENT_DATE, NOTIONAL,
View Full Code Here

  @Test(enabled = false)
  public void performance() {
    for (int loop1 = 0; loop1 < strikes_AVAILABLE.length; loop1++) {
      for (int loop2 = 0; loop2 < availabelTenor.length; loop2++) {
        final Period tenor = Period.ofYears(availabelTenor[loop2]);
        boolean isCap = true;
        if (loop1 == 0 || loop1 == 1 || loop1 == 2) {
          isCap = false;
        }
        CAP_DEFINITIONS_AVAILABLE[loop1][loop2] = AnnuityCapFloorInflationYearOnYearInterpolationDefinition.from(PRICE_INDEX_EUR, SETTLEMENT_DATE, NOTIONAL,
View Full Code Here

  private FRASecurity getFRA(final InterpolatedYieldCurveSpecification spec, final FixedIncomeStripWithIdentifier strip, final SnapshotDataBundle marketValues, final Tenor tenor) {
    final ExternalId fraIdentifier = strip.getSecurity();
    final int months = tenor.getPeriod().getMonths();
    final ExternalId underlyingId = getUnderlyingId(spec, strip);
    Period fraPeriod;
    final Currency ccy = spec.getCurrency();
    BusinessDayConvention businessDayConvention;
    boolean eom;
    Calendar calendar;
    ExternalId underlyingIdentifier;
    int settlementDays;
    if (underlyingId == null) {
      s_logger.info("Could not get convention for underlying from {}; trying tenor-based convention", strip);
      final ConventionBundle fraConvention = _conventionBundleSource.getConventionBundle(ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, spec.getCurrency().getCode() + "_" + months
          + "M_FRA"));
      if (fraConvention == null) {
        throw new OpenGammaRuntimeException("Could not get convention for " + fraIdentifier + ": tried "
            + ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, spec.getCurrency().getCode() + "_" + months + "M_FRA"));
      }
      underlyingIdentifier = fraConvention.getSwapFloatingLegInitialRate();
      final ConventionBundle iborConvention = _conventionBundleSource.getConventionBundle(underlyingIdentifier);
      underlyingIdentifier = fraConvention.getSwapFloatingLegInitialRate();
      fraPeriod = iborConvention.getPeriod();
      businessDayConvention = iborConvention.getBusinessDayConvention();
      eom = iborConvention.isEOMConvention();
      calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, fraConvention.getSwapFloatingLegRegion());
      settlementDays = iborConvention.getSettlementDays();
    } else {
      ConventionBundle fraConvention = _conventionBundleSource.getConventionBundle(underlyingId);
      if (fraConvention == null || fraConvention.getIdentifiers().size() != 1) {
        s_logger.info("Could not get unique convention for underlying from {}; trying tenor-based convention", strip);
        fraConvention = _conventionBundleSource.getConventionBundle(ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, spec.getCurrency().getCode() + "_" + months
            + "M_FRA"));
        if (fraConvention == null) {
          throw new OpenGammaRuntimeException("Could not get convention for " + fraIdentifier + ": tried "
              + ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, spec.getCurrency().getCode() + "_" + months + "M_FRA"));
        }
        final ConventionBundle iborConvention = _conventionBundleSource.getConventionBundle(fraConvention.getSwapFloatingLegInitialRate());
        fraPeriod = iborConvention.getPeriod();
        businessDayConvention = fraConvention.getSwapFloatingLegBusinessDayConvention();
        eom = fraConvention.isEOMConvention();
        calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, fraConvention.getSwapFloatingLegRegion());
        underlyingIdentifier = underlyingId;
        settlementDays = fraConvention.getSwapFloatingLegSettlementDays();
      } else {
        fraPeriod = fraConvention.getPeriod();
        businessDayConvention = fraConvention.getBusinessDayConvention();
        eom = fraConvention.isEOMConvention();
        calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, fraConvention.getRegion());
        underlyingIdentifier = Iterables.getOnlyElement(fraConvention.getIdentifiers());
        settlementDays = fraConvention.getSettlementDays();
      }
    }
    final ZonedDateTime curveDate = spec.getCurveDate().atStartOfDay(ZoneOffset.UTC); // TODO: review?
    final ZonedDateTime spotDate = ScheduleCalculator.getAdjustedDate(curveDate, settlementDays, calendar);
    final Period endPeriod = strip.getMaturity().getPeriod();
    final ZonedDateTime endDate = ScheduleCalculator.getAdjustedDate(spotDate, endPeriod, businessDayConvention, calendar, eom);
    final Period startPeriod = endPeriod.minus(fraPeriod).normalized(); // TODO: check period >0?
    final ZonedDateTime startDate = ScheduleCalculator.getAdjustedDate(spotDate, startPeriod, businessDayConvention, calendar, eom);
    final ZonedDateTime fixingDate = ScheduleCalculator.getAdjustedDate(startDate, -settlementDays, calendar);
    if (marketValues.getDataPoint(strip.getSecurity()) == null) {
      throw new OpenGammaRuntimeException("Could not get market data for " + strip);
    }
View Full Code Here

      throw new OpenGammaRuntimeException("rate was null on " + strip + " from " + spec);
    }
    Frequency floatingFrequency;
    final ExternalId floatingReferenceRateId;
    if (underlyingStrip.getResetTenor() != null) {
      final Period resetTenor = underlyingStrip.getResetTenor().getPeriod();
      floatingFrequency = PeriodFrequency.of(resetTenor);
      final IndexType indexType = underlyingStrip.getIndexType();
      floatingReferenceRateId = ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, indexType + "_" + resetTenor.toString());
    } else {
      floatingFrequency = swapConvention.getSwapFloatingLegFrequency();
      if (floatingFrequency == null) {
        throw new OpenGammaRuntimeException("Could not get floating leg frequency from convention");
      }
View Full Code Here

    final PriceIndexConvention priceIndexConvention = _conventionSource.getConvention(PriceIndexConvention.class, inflationLegConvention.getPriceIndexConvention());
    if (priceIndexConvention == null) {
      throw new OpenGammaRuntimeException("Convention with id " + inflationLegConvention.getPriceIndexConvention() + " was null");
    }
    final int settlementDays = fixedLegConvention.getSettlementDays();
    final Period tenor = inflationNode.getTenor().getPeriod();
    final double notional = 1;
    //TODO business day convention and currency are in both conventions - should we enforce that they're the same or use
    // different ones for each leg?
    final BusinessDayConvention businessDayConvention = fixedLegConvention.getBusinessDayConvention();
    final boolean endOfMonth = fixedLegConvention.isIsEOM();
    final Currency currency = priceIndexConvention.getCurrency();
    final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, priceIndexConvention.getRegion());
    final ZoneId zone = _valuationTime.getZone(); //TODO time zone set to midnight UTC
    final ZonedDateTime settlementDate = ScheduleCalculator.getAdjustedDate(_valuationTime, settlementDays, calendar).toLocalDate().atStartOfDay(zone);
    final ZonedDateTime paymentDate = ScheduleCalculator.getAdjustedDate(settlementDate, tenor, businessDayConvention, calendar, endOfMonth).toLocalDate().atStartOfDay(zone);
    final CouponFixedCompoundingDefinition fixedCoupon = CouponFixedCompoundingDefinition.from(currency, settlementDate, paymentDate, notional, tenor.getYears(),
        rate);
    final HistoricalTimeSeries ts = _timeSeries.get(MarketDataRequirementNames.MARKET_VALUE, priceIndexConvention.getPriceIndexId());
    if (ts == null) {
      throw new OpenGammaRuntimeException("Could not get price index time series with id " + priceIndexConvention.getPriceIndexId());
    }
View Full Code Here

  @Override
  public ExternalId getInstrument(final LocalDate curveDate, final Tenor tenor) {
    final StringBuffer ticker = new StringBuffer();
    ticker.append(_prefix);
    final Period period = tenor.getPeriod();
    if (period.getYears() != 0) {
      ticker.append(period.getYears() + "Y");
    } else if (period.getMonths() != 0) {
      ticker.append(period.getMonths() + "M");
    } else {
      final int days = period.getDays();
      if (days != 0) {
        if (days % 7 == 0) {
          ticker.append(days / 7 + "W");
        } else if (days == 1) {
          ticker.append("ON");
View Full Code Here

      derivative_FD[loopshift] = pvpsFD.totalSensitivity(MULTICURVES.getFxRates(), EUR);
      diff[loopshift] = derivative_FD[loopshift] - derivativeExact;
      eps[loopshift + 1] = eps[loopshift] / ratio;
    }
    // 1Mx5Y
    final Period expirationPeriod = Period.ofDays(1); // Period.ofDays(1); Period.ofDays(7); Period.ofMonths(1); Period.ofYears(1); Period.ofYears(10);
    final ZonedDateTime expiryDateExp = ScheduleCalculator.getAdjustedDate(REFERENCE_DATE, expirationPeriod, EURIBOR6M, CALENDAR);
    final ZonedDateTime settlementDateExp = ScheduleCalculator.getAdjustedDate(expiryDateExp, SPOT_LAG, CALENDAR);
    final double ATM = 0.0151; //  1W: 1.52% - 1M: 1.52% - 1Y: 1.51% - 10Y: 1.51%
    final SwapFixedIborDefinition swapExpx5YDefinition = SwapFixedIborDefinition.from(settlementDateExp, SWAP_TENOR, EUR1YEURIBOR6M, NOTIONAL, ATM, !FIXED_IS_PAYER);
    final SwaptionPhysicalFixedIborDefinition swaptionExpx5YDefinition = SwaptionPhysicalFixedIborDefinition.from(EXPIRY_DATE, swapExpx5YDefinition, !IS_LONG);
View Full Code Here

TOP

Related Classes of org.threeten.bp.Period

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.