Package org.threeten.bp

Examples of org.threeten.bp.Period


      _period = period;
    }

    @Override
    public DateConstraint plus(final Period period) {
      final Period newPeriod;
      if (_plus) {
        newPeriod = _period.plus(period);
      } else {
        newPeriod = _period.minus(period);
      }
      if (newPeriod.isZero()) {
        if (_underlying != null) {
          return _underlying;
        } else {
          return VALUATION_TIME;
        }
View Full Code Here


      }
    }

    @Override
    public DateConstraint minus(final Period period) {
      final Period newPeriod;
      if (_plus) {
        newPeriod = _period.minus(period);
      } else {
        newPeriod = _period.plus(period);
      }
      if (newPeriod.isZero()) {
        if (_underlying != null) {
          return _underlying;
        } else {
          return VALUATION_TIME;
        }
View Full Code Here

    @Override
    public Period periodUntil(final DateConstraint o) {
      if (o instanceof PlusMinusPeriodDateConstraint) {
        final PlusMinusPeriodDateConstraint other = (PlusMinusPeriodDateConstraint) o;
        if (ObjectUtils.equals(_underlying, other._underlying)) {
          final Period a = _plus ? _period : _period.negated();
          final Period b = other._plus ? other._period : other._period.negated();
          return b.minus(a);
        }
      } else if (o.equals((_underlying == null) ? DateConstraint.VALUATION_TIME : _underlying)) {
        if (_plus) {
          return _period.negated();
        } else {
View Full Code Here

      final Currency currency = Currency.of(message.getString(CURRENCY_FIELD));
      final int spotLag = message.getInt(SPOT_LAG_FIELD);
      final DayCount dayCount = DayCountFactory.INSTANCE.getDayCount(message.getString(DAY_COUNT_FIELD));
      final BusinessDayConvention businessDayConvention = BusinessDayConventionFactory.INSTANCE.getBusinessDayConvention(message.getString(BUSINESS_DAY_CONVENTION_FIELD));
      final boolean isEOM = message.getBoolean(EOM_FIELD);
      final Period tenor = Period.parse(message.getString(TENOR_FIELD));
      final String name = message.getString(NAME_FIELD);
      return new IborIndex(currency, tenor, spotLag, dayCount, businessDayConvention, isEOM, name);
    }
View Full Code Here

  public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
    final HistoricalTimeSeriesSource timeSeriesSource = OpenGammaExecutionContext.getHistoricalTimeSeriesSource(executionContext);
    final ValueRequirement desiredValue = desiredValues.iterator().next();
    final Pair<LocalDate, Double> latestDataPoint = timeSeriesSource.getLatestDataPoint(target.getUniqueId());
    final String ageLimitValue = desiredValue.getConstraint(HistoricalTimeSeriesFunctionUtils.AGE_LIMIT_PROPERTY);
    final Period ageLimit = HistoricalTimeSeriesFunctionUtils.UNLIMITED_AGE_LIMIT_VALUE.equals(ageLimitValue) ? null : Period.parse(ageLimitValue);
    final Object value;
    if (checkMissing(executionContext, latestDataPoint, ageLimit)) {
      value = MissingInput.MISSING_MARKET_DATA;
    } else {
      final String adjusterString = desiredValue.getConstraint(HistoricalTimeSeriesFunctionUtils.ADJUST_PROPERTY);
View Full Code Here

    if (latestDataPoint == null) {
      return true;
    }
    if (ageLimit != null) {
      LocalDate now = LocalDate.now(executionContext.getValuationClock());
      Period difference = ageLimit.minus(Period.between(latestDataPoint.getFirst(), now));
      if (difference.isNegative()) {
        return true;
      }
    }
    return false;
  }
View Full Code Here

    final ZonedDateTime endDate = capFloorCMSSpreadSecurity.getMaturityDate();
    final double notional = capFloorCMSSpreadSecurity.getNotional();
    final Currency currency = capFloorCMSSpreadSecurity.getCurrency();
    final Frequency payFreq = capFloorCMSSpreadSecurity.getFrequency();
    // FIXME: convert frequency to period in a better way
    final Period tenorPayment = getTenor(payFreq);
    final ExternalId[] swapIndexId = new ExternalId[2];
    swapIndexId[0] = capFloorCMSSpreadSecurity.getLongId();
    swapIndexId[1] = capFloorCMSSpreadSecurity.getShortId();
    final ConventionBundle[] swapIndexConvention = new ConventionBundle[2];
    final ConventionBundle[] iborIndexConvention = new ConventionBundle[2];
    for (int loopindex = 0; loopindex < 2; loopindex++) {
      swapIndexConvention[loopindex] = _conventionSource.getConventionBundle(swapIndexId[loopindex]);
      if (swapIndexConvention[loopindex] == null) {
        throw new OpenGammaRuntimeException("Could not get swap index convention for " + swapIndexId[loopindex].toString());
      }
      iborIndexConvention[loopindex] = _conventionSource.getConventionBundle(swapIndexConvention[loopindex].getSwapFloatingLegInitialRate());
      if (iborIndexConvention[loopindex] == null) {
        throw new OpenGammaRuntimeException("Could not get ibor index convention for " + swapIndexConvention[loopindex].getSwapFloatingLegInitialRate());
      }
    }
    final ExternalId regionId = swapIndexConvention[0].getSwapFloatingLegRegion();
    final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, regionId);
    final IborIndex[] iborIndex = new IborIndex[2];
    final IndexSwap[] swapIndex = new IndexSwap[2];
    for (int loopindex = 0; loopindex < 2; loopindex++) {
      iborIndex[loopindex] = new IborIndex(currency, tenorPayment, iborIndexConvention[loopindex].getSettlementDays(), iborIndexConvention[loopindex].getDayCount(),
          iborIndexConvention[loopindex].getBusinessDayConvention(), iborIndexConvention[loopindex].isEOMConvention());
      final Period fixedLegPaymentPeriod = getTenor(swapIndexConvention[loopindex].getSwapFixedLegFrequency());
      swapIndex[loopindex] = new IndexSwap(fixedLegPaymentPeriod, swapIndexConvention[loopindex].getSwapFixedLegDayCount(), iborIndex[loopindex], swapIndexConvention[loopindex].getPeriod(), calendar);
    }
    return AnnuityCapFloorCMSSpreadDefinition.from(startDate, endDate, notional, swapIndex[0], swapIndex[1], tenorPayment, capFloorCMSSpreadSecurity.getDayCount(),
        capFloorCMSSpreadSecurity.isPayer(), capFloorCMSSpreadSecurity.getStrike(), capFloorCMSSpreadSecurity.isCap(), calendar, calendar);
  }
View Full Code Here

        capFloorCMSSpreadSecurity.isPayer(), capFloorCMSSpreadSecurity.getStrike(), capFloorCMSSpreadSecurity.isCap(), calendar, calendar);
  }

  // FIXME: convert frequency to period in a better way
  private Period getTenor(final Frequency freq) {
    Period tenor;
    if (Frequency.ANNUAL_NAME.equals(freq.getConventionName())) {
      tenor = Period.ofMonths(12);
    } else if (Frequency.SEMI_ANNUAL_NAME.equals(freq.getConventionName())) {
      tenor = Period.ofMonths(6);
    } else if (Frequency.QUARTERLY_NAME.equals(freq.getConventionName())) {
View Full Code Here

    final boolean isEOM = fixedLegConvention.isIsEOM();
    final DayCount fixedLegDayCount = fixedLeg.getDayCount();
    final BusinessDayConvention businessDayConvention = fixedLeg.getBusinessDayConvention();
    final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, indexConvention.getRegion());
    final ZoneOffset zone = ZoneOffset.UTC; //TODO
    final Period paymentPeriod = getTenor(indexLeg.getFrequency());
    final Period maturityTenor = security.getMaturityTenor().getPeriod();
    boolean isMonthly;
    switch (indexLeg.getInterpolationMethod()) {
      case MONTH_START_LINEAR:
        isMonthly = true;
        break;
      case NONE:
        isMonthly = false;
        break;
      default:
        throw new OpenGammaRuntimeException("Cannot handle interpolation method of type " + indexLeg.getInterpolationMethod());
    }
    final ZonedDateTime settlementDate = ScheduleCalculator.getAdjustedDate(security.getEffectiveDate(), settlementDays, calendar).toLocalDate().atStartOfDay(zone);
    final double fixedRate = fixedLeg.getRate();
    final int conventionalMonthLag = indexLeg.getConventionalIndexationLag();
    final int quotationMonthLag = indexLeg.getQuotationIndexationLag();
    final boolean exchangeNotional = security.isExchangeInitialNotional() && security.isExchangeFinalNotional();
    final double notional = ((InterestRateNotional) fixedLeg.getNotional()).getAmount();
    if (isMonthly) {
      return SwapFixedInflationYearOnYearDefinition.fromMonthly(priceIndex, settlementDate, paymentPeriod, (int) (maturityTenor.toTotalMonths() / 12), fixedRate,
          notional, isPayer, businessDayConvention, calendar, isEOM, fixedLegDayCount, conventionalMonthLag, quotationMonthLag, exchangeNotional);
    }
    return SwapFixedInflationYearOnYearDefinition.fromInterpolation(priceIndex, settlementDate, paymentPeriod, maturityTenor, fixedRate,
        notional, isPayer, businessDayConvention, calendar, isEOM, fixedLegDayCount, conventionalMonthLag, quotationMonthLag, exchangeNotional);
  }
View Full Code Here

      return null;
    }
    final HistoricalViewEvaluationTarget historicalTarget = (HistoricalViewEvaluationTarget) tempTargetObject;
    final DateConstraint startDate = DateConstraint.parse(historicalTarget.getStartDate());
    final DateConstraint endDate = DateConstraint.parse(historicalTarget.getEndDate());
    final Period samplingPeriod = startDate.periodUntil(endDate);
    return Collections
        .singleton(new ValueSpecification(ValueRequirementNames.COVARIANCE_MATRIX, target.toSpecification(), createValueProperties()
            .with(ValuePropertyNames.SAMPLING_PERIOD, samplingPeriod.toString()).get()));
  }
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.