Package org.threeten.bp

Examples of org.threeten.bp.ZonedDateTime


    final int numItems = _zCurveDates.size();

    for (int i = iLo; i <= iHi; i++) {
      final double amt = cflAmount[i];
      final ZonedDateTime date = cflDate[i];

      double pv = 0.0;

      //ZonedDateTime zcDate = _zCurveDates.get(j);
View Full Code Here


    final int lowNumIntervals = Math.max(0, (int) Math.floor(Math.abs(fromToYears / intervalYears)) - 2);

    int index = lowNumIntervals;

    ZonedDateTime currDate = fromDate.plusMonths(k * index * _fixedInterval);

    ZonedDateTime lastDate = currDate;

    while (!currDate.isBefore(fromDate) && !currDate.isAfter(toDate)) {
      ++index;
      lastDate = currDate;
      currDate = fromDate.plusMonths(k * index * _fixedInterval);
    }

    // TODO : Check if this is < lowNumIntervals
    result[0] = index - 1;

    final long t = toDate.toEpochSecond() - lastDate.toEpochSecond();

    result[1] = (int) (t / (60 * 60));

    return result;
  }
View Full Code Here

  // ----------------------------------------------------------------------------------------------------------------------------------------

  private ZonedDateTime previousDate(final boolean onCycle, final ZonedDateTime valueDate, final ZonedDateTime origDate) {

    ZonedDateTime prevDate = origDate;

    if (onCycle) {
      // TODO : Add this code
    } else {
      prevDate = origDate.minusMonths(_fixedInterval);
View Full Code Here

    boolean onCycle = false;

    if (valueDate.getDayOfMonth() <= 28 && unadjustedSwapDate.getDayOfMonth() <= 28) {

      final ZonedDateTime fromDate = valueDate;
      final ZonedDateTime toDate = unadjustedSwapDate;

      double intervalYears = 0.0;
      final double fromToYears = TimeCalculator.getTimeBetween(fromDate, toDate, ACT_365);

      // Need to fix this - bit of a hack
      if (swapFixedLegCouponFrequency == PeriodFrequency.SEMI_ANNUAL) {
        intervalYears = 0.5;
      }

      if (swapFixedLegCouponFrequency == PeriodFrequency.QUARTERLY) {
        intervalYears = 0.25;
      }

      final int lowNumIntervals = Math.max(0, (int) Math.floor(Math.abs(fromToYears / intervalYears)) - 2);
      int index = lowNumIntervals;

      int compoundInterval = 0;
      int multiplier = 0;

      // Need to fix this - bit of a hack
      if (swapFixedLegCouponFrequency == PeriodFrequency.SEMI_ANNUAL) {
        multiplier = 6;
        compoundInterval = index * multiplier;
      }

      if (swapFixedLegCouponFrequency == PeriodFrequency.QUARTERLY) {
        multiplier = 3;
        compoundInterval = index * multiplier;
      }

      ZonedDateTime currDate = valueDate.plusMonths(compoundInterval);
      ZonedDateTime lastDate = currDate;

      while (currDate.isAfter(fromDate) && !currDate.isAfter(toDate)) {
        ++index;
        lastDate = currDate;
        currDate = valueDate.plusMonths(index * multiplier);
 
View Full Code Here

      return;
    }

    final GenerateCreditDefaultSwapPremiumLegSchedule swapMaturities = new GenerateCreditDefaultSwapPremiumLegSchedule();

    final ZonedDateTime lastStubDate = cashDates[cashDates.length - 1];

    // Need to implement this if want to have swaps with maturities less than MM instruments
    // numSwaps = getNumberOfActiveSwaps(lastStubDate, swapDates, numSwaps);

    final ZonedDateTime[] unadjustedSwapDates = new ZonedDateTime[swapDates.length];
    final ZonedDateTime[] adjustedSwapDates = new ZonedDateTime[swapDates.length];

    final boolean[] onCycleSwapDates = new boolean[swapDates.length];
    final ZonedDateTime[] previousSwapDates = new ZonedDateTime[swapDates.length];

    for (int i = 0; i < numSwaps; i++) {
      unadjustedSwapDates[i] = swapDates[i];
      adjustedSwapDates[i] = swapMaturities.businessDayAdjustDate(swapDates[i], calendar, businessdayAdjustmentConvention);
    }

    int numIntervals = 0;
    int extraDays = 0;

    int compoundInterval = 0;
    int multiplier = 0;

    double intervalYears = 0.0;

    // Need to fix this - bit of a hack
    /*if (swapFixedLegCouponFrequency == PeriodFrequency.SEMI_ANNUAL)*/
    {
      intervalYears = 0.5;
      multiplier = 6;
    }

    /*if (swapFixedLegCouponFrequency == PeriodFrequency.QUARTERLY)*/
    {
      intervalYears = 0.25;
      multiplier = 3;
    }

    // -------------------------------------------

    for (int i = 0; i < numSwaps; i++) {

      boolean onCycle = false;

      if (valueDate.getDayOfMonth() <= 28 && unadjustedSwapDates[i].getDayOfMonth() <= 28) {

        final ZonedDateTime fromDate = valueDate;
        final ZonedDateTime toDate = unadjustedSwapDates[i];

        final double fromToYears = TimeCalculator.getTimeBetween(fromDate, toDate, ACT_365);

        final int lowNumIntervals = Math.max(0, (int) Math.floor(Math.abs(fromToYears / intervalYears)) - 2);
        int index = lowNumIntervals;

        compoundInterval = index * multiplier;

        ZonedDateTime currDate = fromDate.plusMonths(compoundInterval);
        ZonedDateTime lastDate = currDate;

        while (currDate.isAfter(fromDate) && !currDate.isAfter(toDate)) {
          ++index;
          lastDate = currDate;
          currDate = valueDate.plusMonths(index * multiplier);
        }

        numIntervals = index - 1;
        extraDays = (int) Math.abs(TimeCalculator.getTimeBetween(toDate, lastDate));

        if (extraDays == 0) {
          onCycle = true;
        } // end if extraDays

      } // end if dom <= 28

      onCycleSwapDates[i] = onCycle;

      ZonedDateTime prevDate;

      if (onCycleSwapDates[i]) {
        prevDate = valueDate.plusMonths(multiplier * (numIntervals - 1));
      } else {
        prevDate = unadjustedSwapDates[i].plusMonths(6 * (-1));
      }

      previousSwapDates[i] = prevDate;

    } // end loop over i

    // -------------------------------------------

    final boolean oneAlreadyAdded = false;

    boolean isEndStub = false;

    int numDates;

    for (int i = 0; i < numSwaps; i++) {

      if (adjustedSwapDates[i].isAfter(cashDates[cashDates.length - 1])) {

        if (onCycleSwapDates[i]) {
          isEndStub = true;
        } else {
          // Need to fill this in - jpmcdsisendstub
        } // end if

        // need to add rate = 0 case

        if (isEndStub) {

          final ZonedDateTime fromDate = valueDate;
          final ZonedDateTime toDate = unadjustedSwapDates[i];

          final double fromToYears = TimeCalculator.getTimeBetween(fromDate, toDate, ACT_365);

          final int lowNumIntervals = Math.max(0, (int) Math.floor(Math.abs(fromToYears / intervalYears)) - 2);
          int index = lowNumIntervals;

          compoundInterval = index * multiplier;

          ZonedDateTime currDate = fromDate.plusMonths(compoundInterval);
          ZonedDateTime lastDate = currDate;

          while (currDate.isAfter(fromDate) && !currDate.isAfter(toDate)) {
            ++index;
            lastDate = currDate;
            currDate = valueDate.plusMonths(index * multiplier);
          }

          numIntervals = index - 1;
          extraDays = (int) Math.abs(TimeCalculator.getTimeBetween(toDate, lastDate));
        } else {
          // Need to add this
        }

        if (extraDays > 0) {
          numDates = numIntervals + 2;
        } else {
          numDates = numIntervals + 1;
        }

        final ZonedDateTime[] dateList = new ZonedDateTime[numDates];

        if (isEndStub) {

          for (int j = 0; j < numDates - 1; j++) {
            dateList[j] = valueDate.plusMonths(j * multiplier);
          }

          dateList[numDates - 1] = unadjustedSwapDates[i];
        } else {
          // Need to add this
        }

        for (int j = 0; j < numDates - 1; j++) {
          dateList[j] = dateList[j + 1];
        }
        numDates--;

        //

        final ZonedDateTime[] adjustedDateList = new ZonedDateTime[numDates];

        for (int idx = 0; idx < numDates; idx++) {
          adjustedDateList[idx] = swapMaturities.businessDayAdjustDate(dateList[idx], calendar, businessdayAdjustmentConvention);
        }

        final double[] cashflowList = new double[numDates];

        ZonedDateTime prevDate = valueDate;

        for (int idx = 0; idx < numDates; idx++) {

          final ZonedDateTime cDate = adjustedDateList[idx];

          final double dcf = ACT_360.getDayCountFraction(prevDate, cDate);

          cashflowList[idx] = dcf * swapRates[i];

          prevDate = cDate;
        }

        cashflowList[numDates - 1] += 1.0;

        final ZonedDateTime adjMatDate = adjustedSwapDates[i];

        final double price = 1.0;

        //ZCAddCashFlowList(adjustedDateList, cashflowList, price, adjMatDate);

View Full Code Here

    for (int i = 0; i < boxedTimePoints.length; ++i) {
      timePoints[i] = boxedTimePoints[i];
      ccRates[i] = boxedCCRates[i];
    }

    ZonedDateTime loDate;
    ZonedDateTime hiDate;

    double loRate = 0.0;
    double hiRate = 0.0;

    double z1 = 0.0;
    double z2 = 0.0;

    double t1 = 0.0;
    double t2 = 0.0;
    double t = 0.0;
    double Z = 0.0;
    double rate = 0.0;

    // ---------------------------------------------

    // Extrapolation below the first date
    if (date.isBefore(timePoints[0])) {
      //loRate = _zCurveCCRates[0];
      loRate = ccRates[0];
      z1 = Math.log(1.0 + loRate);
      t = TimeCalculator.getTimeBetween(valueDate, date, ACT_365);
      rate = z1;
      Z = Math.exp(-rate * t);
    }

    // ---------------------------------------------

    // Extrapolation beyond the last date
    if (!date.isBefore(timePoints[_numberOfInstruments - 1])) {

      final int lo = _numberOfInstruments - 2;
      final int hi = _numberOfInstruments - 1;

      t1 = TimeCalculator.getTimeBetween(valueDate, timePoints[lo], ACT_360);
      t2 = TimeCalculator.getTimeBetween(valueDate, timePoints[hi], ACT_360);
      t = TimeCalculator.getTimeBetween(valueDate, date, ACT_360);

      //loRate = _zCurveCCRates[lo];
      //hiRate = _zCurveCCRates[hi];

      loRate = ccRates[lo];
      hiRate = ccRates[hi];

      z1 = Math.log(1.0 + loRate);
      z2 = Math.log(1.0 + hiRate);

      // TODO : DoubleToBits this
      if (t == 0.0) {
        // TODO : Check for t2 == 0 as well
        t = 1.0 / 365.0;
      }

      final double zt = getInterpolatedRate(t, t1, t2, z1, z2);
      rate = zt / t;

      t = TimeCalculator.getTimeBetween(valueDate, date, ACT_365);

      Z = Math.exp(-rate * t);
    }

    // ---------------------------------------------

    // Interpolation
    if (!date.isBefore(timePoints[0]) && date.isBefore(timePoints[_numberOfInstruments - 1]))
    {
      // ... date is within the window spanned by the input dates

      int lo = 0;

      // Start at the first date
      ZonedDateTime rollingDate = timePoints[0];

      while (!rollingDate.isAfter(date)) {
        lo++;
        rollingDate = timePoints[lo];
      }

      final int hi = lo + 1;
View Full Code Here

  public void presentValueDomestic() {
    final double strike = 1.45;
    final boolean isCall = true;
    final boolean isLong = true;
    final double notional = 100000000;
    final ZonedDateTime payDate = ScheduleCalculator.getAdjustedDate(REFERENCE_DATE, Period.ofMonths(9), BUSINESS_DAY, CALENDAR);
    final ZonedDateTime expDate = ScheduleCalculator.getAdjustedDate(payDate, -SETTLEMENT_DAYS, CALENDAR);
    final double timeToExpiry = TimeCalculator.getTimeBetween(REFERENCE_DATE, expDate);
    final ForexDefinition forexUnderlyingDefinition = new ForexDefinition(EUR, USD, payDate, notional, strike);
    final ForexOptionDigitalDefinition forexOptionDefinition = new ForexOptionDigitalDefinition(forexUnderlyingDefinition, expDate, isCall, isLong);
    final ForexOptionDigital forexOption = forexOptionDefinition.toDerivative(REFERENCE_DATE, CURVES_NAME);
    final double dfDomestic = CURVES.getCurve(CURVES_NAME[1]).getDiscountFactor(forexOption.getUnderlyingForex().getPaymentTime());
View Full Code Here

    } else if (maturityPeriod.getMonths() != 0) {
      swapString = maturityPeriod.getMonths() + "M";
    } else {
      throw new OpenGammaRuntimeException("Could not handle swap maturity " + maturity);
    }
    final ZonedDateTime swaptionExpiry = tradeDate.plus(expiryPeriod).atStartOfDay().atZone(ZoneOffset.UTC);
    final ZonedDateTime swapMaturity = swaptionExpiry.plus(maturity.getPeriod());
    final double amount = 100000 * (1 + random.nextInt(30));
    final InterestRateNotional notional = new InterestRateNotional(ccy, amount);
    final double rate = getSwapRate(ccy, tradeDate, maturity) * (1 + ((random.nextDouble() - 0.5) / 30.));
    final Frequency frequency = ccy.equals(Currency.USD) ? PeriodFrequency.QUARTERLY : PeriodFrequency.SEMI_ANNUAL;
    final SwapLeg fixedLeg = new FixedInterestRateLeg(DAY_COUNT, PeriodFrequency.SEMI_ANNUAL, region, BDC, notional, false, rate);
View Full Code Here

  }

  //-------------------------------------------------------------------------
  @Test(enabled = false)
  public void test_bond() throws Exception {
    ZonedDateTime zdt = ZonedDateTime.parse("2011-01-31T12:00Z[Europe/London]");
    GovernmentBondSecurity sec = new GovernmentBondSecurity("US TREASURY N/B", "issuerType", "issuerDomicile", "market",
        Currency.GBP, SimpleYieldConvention.US_TREASURY_EQUIVALANT, new Expiry(zdt),
        "couponType", 23.5d, SimpleFrequency.ANNUAL, DayCountFactory.INSTANCE.getDayCount("Act/Act"),
        zdt, zdt, zdt, 129d, 1324d, 12d, 1d, 2d, 3d);
    sec.addExternalId(ExternalId.of("abc", "def"));
View Full Code Here

  @Override
  public CashSecurity createSecurity() {
    final Currency currency = getRandomCurrency();
    final ExternalId region = ExternalSchemes.currencyRegionId(currency);
    final ZonedDateTime start = previousWorkingDay(ZonedDateTime.now().minusDays(getRandom(60) + 7), currency);
    final int length = getRandom(6) + 3;
    final ZonedDateTime maturity = nextWorkingDay(start.plusMonths(length), currency);
    final ConventionBundle convention = getConventionBundleSource().getConventionBundle(ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, currency.getCode() + "_GENERIC_CASH"));
    if (convention == null) {
      return null;
    }
    final DayCount dayCount = convention.getDayCount();
View Full Code Here

TOP

Related Classes of org.threeten.bp.ZonedDateTime

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.