Package org.threeten.bp

Examples of org.threeten.bp.Period


        default:
          throw new OpenGammaRuntimeException("Did not recognise quote type " + quoteType);
      }
    }
    ticker.append("_");
    final Period period = xAxis.getPeriod();
    if (period.getYears() != 0) {
      ticker.append(period.getYears());
      ticker.append(YR_STRING);
    } else if (period.getMonths() != 0) {
      ticker.append(period.getMonths());
      ticker.append(M_STRING);
    } else if (period.getDays() != 0) {
      if (period.getDays() % 7 != 0) {
        throw new OpenGammaRuntimeException("Can only handle tenors with periods in weeks; have " + period.getDays());
      }
      ticker.append(period.getDays() / 7);
      ticker.append(WK_STRING);
    }
    return ExternalId.of(SCHEME, ticker.toString());
  }
View Full Code Here


  }

  @Test
  public void fromTrade() {
    final ZonedDateTime tradeDate = DateUtils.getUTCDate(2011, 1, 3);
    final Period startPeriod = Period.ofMonths(6);
    final ForwardRateAgreementDefinition fraFromTrade = ForwardRateAgreementDefinition.fromTrade(tradeDate, startPeriod, NOTIONAL, INDEX, FRA_RATE, CALENDAR);
    final Period endPeriod = Period.ofMonths(9);
    final ZonedDateTime spotDate = ScheduleCalculator.getAdjustedDate(tradeDate, SETTLEMENT_DAYS, CALENDAR);
    final ZonedDateTime accrualStartDate = ScheduleCalculator.getAdjustedDate(spotDate, startPeriod, INDEX, CALENDAR);
    final ZonedDateTime accrualEndDate = ScheduleCalculator.getAdjustedDate(spotDate, endPeriod, INDEX, CALENDAR);
    final ZonedDateTime fixingDate = ScheduleCalculator.getAdjustedDate(accrualStartDate, -SETTLEMENT_DAYS, CALENDAR);
    final double accrualFactor = DAY_COUNT_INDEX.getDayCountFraction(accrualStartDate, accrualEndDate);
View Full Code Here

    final ZonedDateTime settlementDate = testCase.getCashSettle() != null
      ? testCase.getCashSettle().atStartOfDay(ZoneOffset.UTC)
      : pricingDate.plusDays(1).with(adjuster).plusDays(1).with(adjuster).plusDays(1).with(adjuster);

    // If start date is not supplied, construct one that is before the pricing date
    final Period yearsToMaturity = Period.ZERO.plusYears(YEARS.between(pricingDate, maturity));
    final ZonedDateTime startDate = testCase.getStartDate() != null
      ? testCase.getStartDate().atStartOfDay(ZoneOffset.UTC)
      : maturity.minusYears(yearsToMaturity.getYears() + 1).with(adjuster);

    // Spread and recovery are always given
    final double spread = testCase.getCoupon() / 10000.0;
    final double recoveryRate = testCase.getRecoveryRate();
View Full Code Here

        xList.toArray(new Double[0]), yList.toArray(new Double[0]), volatilityValues);
  }

  //TODO not the best way to do this
  private static double getTime(final Tenor tenor) {
    final Period period = tenor.getPeriod();
    if (period.getYears() != 0) {
      return period.getYears();
    } else if (period.getMonths() != 0) {
      return period.getMonths() / 12.;
    } else if (period.getDays() != 0) {
      return period.getDays() / 365.;
    }
    throw new OpenGammaRuntimeException("Cannot handle tenor " + period);
  }
View Full Code Here

    if (convention == null) {
      throw new OpenGammaRuntimeException("Could not get interest rate future convention with id " + ExternalId.of(SCHEME_NAME, conventionName));
    }
    final IborIndexConvention iborIndexConvention = _conventionSource.getConvention(IborIndexConvention.class, convention.getIndexConvention());
    final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, convention.getExchangeCalendar());
    final Period period = Period.ofMonths(3); //TODO
    final double paymentAccrualFactor = getAccrualFactor(period);
    final int spotLag = iborIndexConvention.getSettlementDays();
    final IborIndex iborIndex = new IborIndex(currency, period, spotLag, iborIndexConvention.getDayCount(),
        iborIndexConvention.getBusinessDayConvention(), iborIndexConvention.isIsEOM(), iborIndexConvention.getName());
    final double notional = security.getUnitAmount() / paymentAccrualFactor;
View Full Code Here

    final Object fundingCurveSensitivitiesObject = inputs.getValue(new ValueRequirement(ValueRequirementNames.YIELD_CURVE_NODE_SENSITIVITIES, targetSpec, fundingCurveProperties));
    if (fundingCurveSensitivitiesObject == null) {
      throw new OpenGammaRuntimeException("Could not get sensitivities for " + fundingCurveName);
    }
    final DoubleLabelledMatrix1D fundingCurveSensitivities = (DoubleLabelledMatrix1D) fundingCurveSensitivitiesObject;
    final Period samplingPeriod = getSamplingPeriod(constraints.getValues(ValuePropertyNames.SAMPLING_PERIOD));
    final LocalDate startDate = now.minus(samplingPeriod);
    final Schedule scheduleCalculator = getScheduleCalculator(constraints.getValues(ValuePropertyNames.SCHEDULE_CALCULATOR));
    final TimeSeriesSamplingFunction samplingFunction = getSamplingFunction(constraints.getValues(ValuePropertyNames.SAMPLING_FUNCTION));
    final LocalDate[] schedule = HOLIDAY_REMOVER.getStrippedSchedule(scheduleCalculator.getSchedule(startDate, now, true, false), WEEKEND_CALENDAR); //REVIEW emcleod should "fromEnd" be hard-coded?
    final DoubleTimeSeries<?> result = getPnLSeries(forwardCurveSpec, forwardCurveSensitivities, historicalSource, startDate, now, schedule, samplingFunction)
View Full Code Here

    final ValueRequirement desiredValue = desiredValues.iterator().next();
    final Set<String> samplingPeriodName = desiredValue.getConstraints().getValues(ValuePropertyNames.SAMPLING_PERIOD);
    final Set<String> scheduleCalculatorName = desiredValue.getConstraints().getValues(ValuePropertyNames.SCHEDULE_CALCULATOR);
    final Set<String> samplingFunctionName = desiredValue.getConstraints().getValues(ValuePropertyNames.SAMPLING_FUNCTION);
    final ExternalIdBundle underlyingId = getUnderlyingIdentifier((FutureSecurity) position.getSecurity());
    final Period samplingPeriod = getSamplingPeriod(samplingPeriodName);
    final LocalDate startDate = now.minus(samplingPeriod);
    final HistoricalTimeSeries dbTimeSeries = (HistoricalTimeSeries) inputs.getValue(ValueRequirementNames.HISTORICAL_TIME_SERIES);
    final DoubleTimeSeries<?> ts = dbTimeSeries.getTimeSeries();
    if (ts == null) {
      throw new OpenGammaRuntimeException("Could not get price series for id " + underlyingId);
View Full Code Here

    final LocalDate now = MAGIC_DATE; //ZonedDateTime.now(snapshotClock).getDate();
    final Currency currency = FinancialSecurityUtils.getCurrency(position.getSecurity());
    final String currencyString = currency.getCode();
    final ValueRequirement desiredValue = desiredValues.iterator().next();
    final ValueProperties constraints = desiredValue.getConstraints();
    final Period samplingPeriod = getSamplingPeriod(constraints.getValues(ValuePropertyNames.SAMPLING_PERIOD));
    final LocalDate startDate = now.minus(samplingPeriod);
    final Schedule scheduleCalculator = getScheduleCalculator(constraints.getValues(ValuePropertyNames.SCHEDULE_CALCULATOR));
    final TimeSeriesSamplingFunction samplingFunction = getSamplingFunction(constraints.getValues(ValuePropertyNames.SAMPLING_FUNCTION));
    final LocalDate[] schedule = HOLIDAY_REMOVER.getStrippedSchedule(scheduleCalculator.getSchedule(startDate, now, true, false), WEEKEND_CALENDAR); //REVIEW emcleod should "fromEnd" be hard-coded?
    final HistoricalTimeSeriesBundle timeSeries = HistoricalTimeSeriesFunctionUtils.getHistoricalTimeSeriesInputs(executionContext, inputs);
View Full Code Here

    } else {
      desiredCurrency = currencyString;
    }
    final String curveCalculationConfigName = desiredValue.getConstraint(ValuePropertyNames.CURVE_CALCULATION_CONFIG);
    final Set<String> yieldCurveNames = constraints.getValues(ValuePropertyNames.CURVE);
    final Period samplingPeriod = getSamplingPeriod(desiredValue.getConstraint(ValuePropertyNames.SAMPLING_PERIOD));
    final LocalDate startDate = now.minus(samplingPeriod);
    final Schedule scheduleCalculator = getScheduleCalculator(desiredValue.getConstraint(ValuePropertyNames.SCHEDULE_CALCULATOR));
    final TimeSeriesSamplingFunction samplingFunction = getSamplingFunction(desiredValue.getConstraint(ValuePropertyNames.SAMPLING_FUNCTION));
    final LocalDate[] schedule = HOLIDAY_REMOVER.getStrippedSchedule(scheduleCalculator.getSchedule(startDate, now, true, false), WEEKEND_CALENDAR); //REVIEW emcleod should "fromEnd" be hard-coded?
    DoubleTimeSeries<?> result = null;
    final ConfigDBCurveCalculationConfigSource curveCalculationConfigSource = new ConfigDBCurveCalculationConfigSource(configSource);
    final MultiCurveCalculationConfig curveCalculationConfig = curveCalculationConfigSource.getConfig(curveCalculationConfigName);
    DoubleTimeSeries<?> fxSeries = null;
    boolean isInverse = true;
    if (!desiredCurrency.equals(currencyString)) {
      if (inputs.getValue(ValueRequirementNames.HISTORICAL_FX_TIME_SERIES) != null) {
        final Map<UnorderedCurrencyPair, DoubleTimeSeries<?>> allFXSeries = (Map<UnorderedCurrencyPair, DoubleTimeSeries<?>>) inputs.getValue(ValueRequirementNames.HISTORICAL_FX_TIME_SERIES);
        final CurrencyPairs currencyPairs = OpenGammaExecutionContext.getCurrencyPairsSource(executionContext).getCurrencyPairs(CurrencyPairs.DEFAULT_CURRENCY_PAIRS);
        if (desiredCurrency.equals(currencyPairs.getCurrencyPair(Currency.of(desiredCurrency), currency).getCounter().getCode())) {
          isInverse = false;
        }
        if (allFXSeries.size() != 1) {
          throw new OpenGammaRuntimeException("Have more than one FX series; should not happen");
        }
        final Map.Entry<UnorderedCurrencyPair, DoubleTimeSeries<?>> entry = Iterables.getOnlyElement(allFXSeries.entrySet());
        if (!UnorderedCurrencyPair.of(Currency.of(desiredCurrency), currency).equals(entry.getKey())) {
          throw new OpenGammaRuntimeException("Could not get FX series for currency pair " + desiredCurrency + ", " + currencyString);
        }
        fxSeries = entry.getValue();
      } else {
        throw new OpenGammaRuntimeException("Could not get FX series for currency pair " + desiredCurrency + ", " + currencyString);
      }
    }
    for (final String yieldCurveName : yieldCurveNames) {
      final ValueRequirement ycnsRequirement = getYCNSRequirement(currencyString, curveCalculationConfigName, yieldCurveName, target, constraints);
      final Object ycnsObject = inputs.getValue(ycnsRequirement);
      if (ycnsObject == null) {
        throw new OpenGammaRuntimeException("Could not get yield curve node sensitivities; " + ycnsRequirement);
      }
      final DoubleLabelledMatrix1D ycns = (DoubleLabelledMatrix1D) ycnsObject;
      final ValueRequirement ychtsRequirement = getYCHTSRequirement(currency, yieldCurveName, samplingPeriod.toString());
      final Object ychtsObject = inputs.getValue(ychtsRequirement);
      if (ychtsObject == null) {
        throw new OpenGammaRuntimeException("Could not get yield curve historical time series; " + ychtsRequirement);
      }
      final HistoricalTimeSeriesBundle ychts = (HistoricalTimeSeriesBundle) ychtsObject;
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

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.