当前位置: 首页>>代码示例>>Java>>正文


Java ZonedDateTime.minusDays方法代码示例

本文整理汇总了Java中org.threeten.bp.ZonedDateTime.minusDays方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.minusDays方法的具体用法?Java ZonedDateTime.minusDays怎么用?Java ZonedDateTime.minusDays使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.threeten.bp.ZonedDateTime的用法示例。


在下文中一共展示了ZonedDateTime.minusDays方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAdjustedDate

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
 * Return a good business date computed from a given date and shifted by a certain number of business days.
 * If the number of shift days is 0, the return date is the next business day.
 * If the number of shift days is non-zero (positive or negative), a 0 shift is first applied and then a one business 
 * day shift is applied as many time as the absolute value of the shift. If the shift is positive, the one business 
 * day is to the future, if the shift is negative, the one business day is to the past.
 * @param date The initial date.
 * @param shiftDays The number of days of the adjustment. Can be negative or positive.
 * @param calendar The calendar representing the good business days.
 * @return The adjusted date.
 */
public static ZonedDateTime getAdjustedDate(final ZonedDateTime date, final int shiftDays, final Calendar calendar) {
  ArgumentChecker.notNull(date, "date");
  ArgumentChecker.notNull(calendar, "calendar");
  ZonedDateTime result = date;
  while (!calendar.isWorkingDay(result.toLocalDate())) {
    result = result.plusDays(1);
  }
  if (shiftDays > 0) {
    for (int loopday = 0; loopday < shiftDays; loopday++) {
      result = result.plusDays(1);
      while (!calendar.isWorkingDay(result.toLocalDate())) {
        result = result.plusDays(1);
      }
    }
  } else {
    for (int loopday = 0; loopday < -shiftDays; loopday++) {
      result = result.minusDays(1);
      while (!calendar.isWorkingDay(result.toLocalDate())) {
        result = result.minusDays(1);
      }
    }
  }
  return result;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:36,代码来源:ScheduleCalculator.java

示例2: getAccruedInterest

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
 * Calculates the accrued interest for a {@code ZonedDateTime}.
 * 
 * @param dayCount  the day count convention, not null
 * @param settlementDate  the settlement date, not null
 * @param nominalDates  the nominalDates, not null, no null elements
 * @param coupon  the coupon value
 * @param paymentsPerYear  the number of payments per year, one, two, three, four, six or twelve
 * @param isEndOfMonthConvention  whether to use end of month rules
 * @param exDividendDays the number of ex-dividend days
 * @param index The index of the previous coupon in the nominalDates array
 * @param calendar The working day calendar to be used in calculating ex-dividend dates, not null
 * @return the accrued interest
 */
public static double getAccruedInterest(final DayCount dayCount, final ZonedDateTime settlementDate, final ZonedDateTime[] nominalDates, final double coupon, final double paymentsPerYear,
    final boolean isEndOfMonthConvention, final int exDividendDays, final int index, final Calendar calendar) {
  Validate.notNull(dayCount, "day-count");
  Validate.notNull(settlementDate, "date");
  Validate.noNullElements(nominalDates, "nominalDates");
  Validate.notNull(calendar, "calendar");
  Validate.isTrue(paymentsPerYear > 0);
  Validate.isTrue(exDividendDays >= 0);
  final int length = nominalDates.length;
  Validate.isTrue(index >= 0 && index < length);
  final double accruedInterest = getAccruedInterest(dayCount, index, length, nominalDates[index], settlementDate, nominalDates[index + 1], coupon, paymentsPerYear, isEndOfMonthConvention);
  ZonedDateTime exDividendDate = nominalDates[index + 1];
  for (int i = 0; i < exDividendDays; i++) {
    while (!calendar.isWorkingDay(exDividendDate.toLocalDate())) {
      exDividendDate = exDividendDate.minusDays(1);
    }
    exDividendDate = exDividendDate.minusDays(1);
  }
  if (exDividendDays != 0 && exDividendDate.isBefore(settlementDate)) {
    return accruedInterest - coupon;
  }
  return accruedInterest;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:38,代码来源:AccruedInterestCalculator.java

示例3: tpcLookingBackwardAndForwardOnDayOfPayment

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void tpcLookingBackwardAndForwardOnDayOfPayment() {
  final ZonedDateTime referenceDate = DateUtils.getUTCDate(2012, 8, 17);
  final SwapFixedCoupon<Coupon> swapToday = SWAP_FIXED_IBOR_DEFINITION.toDerivative(referenceDate, FIXING_TS_3_6);

  final ZonedDateTime forwardHorizonDate = referenceDate.minusDays(1);
  final double forwardHorizon = TimeCalculator.getTimeBetween(referenceDate, forwardHorizonDate); // !!! Negative horizon
  final TodayPaymentCalculator forwardCalculator = TodayPaymentCalculator.getInstance(forwardHorizon);
  final MultipleCurrencyAmount paymentIfLookingForward = swapToday.accept(forwardCalculator);

  final ZonedDateTime backwardHorizonDate = referenceDate.minusDays(1);
  final double backwardHorizon = TimeCalculator.getTimeBetween(referenceDate, backwardHorizonDate); // !!! Negative horizon
  final TodayPaymentCalculator backwardCalculator = TodayPaymentCalculator.getInstance(backwardHorizon);
  final MultipleCurrencyAmount paymentIfLookingBackward = swapToday.accept(backwardCalculator);

  assertEquals("TodayPaymentCalculator: fixed-coupon swap", paymentIfLookingForward.getAmount(USD6MLIBOR3M.getCurrency()), paymentIfLookingBackward.getAmount(USD6MLIBOR3M.getCurrency()),
      TOLERANCE_PV);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:19,代码来源:TodayPaymentCalculatorTest.java

示例4: previousWorkingDay

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
 * Returns the date unchanged if this is a working day, otherwise retreats the date.
 * 
 * @param zdt the date to consider
 * @param currency the currency identifying the holiday zone
 * @return the original or adjusted date
 */
// TODO: replace this with a date adjuster
protected ZonedDateTime previousWorkingDay(ZonedDateTime zdt, final Currency currency) {
  while (!isWorkday(zdt.getDayOfWeek(), currency) || isHoliday(zdt.toLocalDate(), currency)) {
    zdt = zdt.minusDays(1);
  }
  return zdt;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:15,代码来源:SecurityGenerator.java

示例5: testCycle

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void testCycle() {
  ExternalId dummyId = ExternalSchemes.bloombergTickerSecurityId("USDRC Curncy");
  ExternalIdBundle bundle = ExternalIdBundle.of(dummyId);
  final ZonedDateTime start = DateUtils.getUTCDate(2011, 9, 30);
  final ZonedDateTime maturity = DateUtils.getUTCDate(2011, 10, 1);
  final DayCount dayCount = DayCounts.ACT_365;
  final CashSecurity cash = new CashSecurity(Currency.USD, ExternalSchemes.financialRegionId("US"), start, maturity, dayCount, 0.05, 1);
  cash.setUniqueId(UniqueId.of("TEST", "TEST"));
  cash.setName("1m deposit rate");
  cash.setExternalIdBundle(bundle);
  final FixedIncomeStripWithSecurity cashStrip = new FixedIncomeStripWithSecurity(new FixedIncomeStrip(StripInstrumentType.CASH, Tenor.ONE_MONTH, "DEFAULT"), Tenor.ONE_MONTH, maturity, dummyId, cash);

  dummyId = ExternalSchemes.bloombergTickerSecurityId("EDZ2 Comdty");
  bundle = ExternalIdBundle.of(dummyId);
  final FutureSecurity future = new InterestRateFutureSecurity(new Expiry(ZonedDateTime.now()), "XCSE", "XCSE", Currency.USD, 0, dummyId, "Interest Rate");
  future.setExternalIdBundle(bundle);
  final FixedIncomeStripWithSecurity futureStrip = new FixedIncomeStripWithSecurity(new FixedIncomeStrip(StripInstrumentType.FUTURE, Tenor.THREE_MONTHS, 2, "DEFAULT"), Tenor.THREE_MONTHS, DateUtils.getUTCDate(2011, 12, 1), dummyId, future);

  dummyId = ExternalSchemes.bloombergTickerSecurityId("USFR0BE Curncy");
  bundle = ExternalIdBundle.of(dummyId);
  final ZonedDateTime startDate = DateUtils.getUTCDate(2011, 11, 1);
  final ZonedDateTime endDate = DateUtils.getUTCDate(2012, 2, 1);
  final ExternalId underlyingIdentifier = ExternalSchemes.bloombergTickerSecurityId("US0003M Index");
  final ZonedDateTime fixingDate = startDate.minusDays(2);
  final FRASecurity fra = new FRASecurity(Currency.USD, ExternalSchemes.financialRegionId("US"), startDate, endDate, 0.05, 1, underlyingIdentifier, fixingDate);
  fra.setExternalIdBundle(bundle);
  final FixedIncomeStripWithSecurity fraStrip = new FixedIncomeStripWithSecurity(new FixedIncomeStrip(StripInstrumentType.FRA_3M, Tenor.FIVE_MONTHS, "DEFAULT"), Tenor.FIVE_MONTHS, endDate, dummyId, fra);

  final Collection<FixedIncomeStripWithSecurity> strips = new ArrayList<FixedIncomeStripWithSecurity>();
  strips.add(cashStrip);
  strips.add(futureStrip);
  strips.add(fraStrip);

  final InterpolatedYieldCurveSpecificationWithSecurities spec = new InterpolatedYieldCurveSpecificationWithSecurities(
      LocalDate.now(), "FUNDING", Currency.USD, Interpolator1DFactory.LINEAR_INSTANCE, true, strips);
  assertEquals(spec, cycleObject(InterpolatedYieldCurveSpecificationWithSecurities.class, spec));
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:39,代码来源:InterpolatedYieldCurveSpecificationWithSecuritiesFudgeEncodingTest.java

示例6: testCycle

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void testCycle() {
  ExternalId dummyId = ExternalSchemes.bloombergTickerSecurityId("USDRC Curncy");
  ExternalIdBundle bundle = ExternalIdBundle.of(dummyId);
  ZonedDateTime maturity = DateUtils.getUTCDate(2011, 10, 1);
  ZonedDateTime start = DateUtils.getUTCDate(2011, 9, 30);
  DayCount dayCount = DayCounts.ACT_365; 
  final CashSecurity cash = new CashSecurity(Currency.USD, ExternalSchemes.financialRegionId("US"), start, maturity, dayCount, 0.05, 1);
  cash.setUniqueId(UniqueId.of("TEST", "TEST"));
  cash.setName("1m deposit rate");
  cash.setExternalIdBundle(bundle);
  FixedIncomeStripWithSecurity strip = new FixedIncomeStripWithSecurity(new FixedIncomeStrip(StripInstrumentType.CASH, Tenor.ONE_MONTH, "DEFAULT"), Tenor.ONE_MONTH, maturity, dummyId, cash);
  assertEquals(strip, cycleObject(FixedIncomeStripWithSecurity.class, strip));

  dummyId = ExternalSchemes.bloombergTickerSecurityId("EDZ2 Comdty");
  bundle = ExternalIdBundle.of(dummyId);
  final FutureSecurity future = new InterestRateFutureSecurity(new Expiry(ZonedDateTime.now()), "XCSE", "XCSE", Currency.USD, 0, dummyId, "Interest Rate");
  future.setExternalIdBundle(bundle);
  strip = new FixedIncomeStripWithSecurity(new FixedIncomeStrip(StripInstrumentType.FUTURE, Tenor.THREE_MONTHS, 2, "DEFAULT"), Tenor.THREE_MONTHS, DateUtils.getUTCDate(2011, 12, 1), dummyId, future);
  assertEquals(strip, cycleObject(FixedIncomeStripWithSecurity.class, strip));
  
  dummyId = ExternalSchemes.bloombergTickerSecurityId("USFR0BE Curncy");
  bundle = ExternalIdBundle.of(dummyId);
  ZonedDateTime startDate = DateUtils.getUTCDate(2011, 11, 1);
  ZonedDateTime endDate = DateUtils.getUTCDate(2012, 2, 1);
  ExternalId underlyingIdentifier = ExternalSchemes.bloombergTickerSecurityId("US0003M Index");
  ZonedDateTime fixingDate = startDate.minusDays(2);
  FRASecurity fra = new FRASecurity(Currency.USD, ExternalSchemes.financialRegionId("US"), startDate, endDate, 0.05, 1, underlyingIdentifier, fixingDate);
  fra.setExternalIdBundle(bundle);
  strip = new FixedIncomeStripWithSecurity(new FixedIncomeStrip(StripInstrumentType.FRA_3M, Tenor.FIVE_MONTHS, "DEFAULT"), Tenor.FIVE_MONTHS, endDate, dummyId, fra);
  assertEquals(strip, cycleObject(FixedIncomeStripWithSecurity.class, strip));
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:33,代码来源:FixedIncomeStripWithSecurityFudgeEncodingTest.java

示例7: createFRASecurity

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
private FRASecurity createFRASecurity() {
  final Currency currency = currency();
  final ExternalId region = region();
  final ZonedDateTime startDate = ZonedDateTime.now().minusMonths(3);
  final ZonedDateTime endDate = ZonedDateTime.now().plusMonths(3);
  final double rate = 0.01;
  final double amount = 15e6;
  final ExternalId underlyingIdentifier = ExternalId.of(ExternalSchemes.BLOOMBERG_TICKER, "US0003M Index");
  final ZonedDateTime fixingDate = endDate.minusDays(7);
  final FRASecurity security = new FRASecurity(currency, region, startDate, endDate, rate, amount, underlyingIdentifier, fixingDate);
  store(security);
  return security;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:14,代码来源:BloombergReferencePortfolioMaker.java

示例8: getAdjustedDateSchedule

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
 * Return the dates adjusted by a certain number of business days.
 * @param dates The initial dates.
 * @param convention The business day convention.
 * @param calendar The calendar.
 * @param settlementDays The number of days of the adjustment. Can be negative or positive.
 * @return The adjusted dates.
 */
public static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime[] dates, final BusinessDayConvention convention, final Calendar calendar,
    final int settlementDays) {
  ArgumentChecker.notEmpty(dates, "dates");
  ArgumentChecker.notNull(convention, "convention");
  ArgumentChecker.notNull(calendar, "calendar");
  final int n = dates.length;
  final ZonedDateTime[] result = new ZonedDateTime[n];
  for (int i = 0; i < n; i++) {
    ZonedDateTime date = convention.adjustDate(calendar, dates[i]);
    if (settlementDays > 0) {
      for (int loopday = 0; loopday < settlementDays; loopday++) {
        date = date.plusDays(1);
        while (!calendar.isWorkingDay(date.toLocalDate())) {
          date = date.plusDays(1);
        }
      }
    } else {
      for (int loopday = 0; loopday < -settlementDays; loopday++) {
        date = date.minusDays(1);
        while (!calendar.isWorkingDay(date.toLocalDate())) {
          date = date.minusDays(1);
        }
      }
    }
    result[i] = date;
  }
  return result;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:37,代码来源:ScheduleCalculator.java

示例9: getOnHts

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
private static Map<IndexON,ZonedDateTimeDoubleTimeSeries> getOnHts(ZonedDateTime calibrationDate, boolean withToday) {
  ZonedDateTime referenceDate = withToday ? calibrationDate : calibrationDate.minusDays(1);
  ZonedDateTimeDoubleTimeSeries htsOn = StandardTimeSeriesOnIborDataSets.timeSeriesUsdOn2014Jan(referenceDate);
  Map<IndexON,ZonedDateTimeDoubleTimeSeries> htsOnMap = new HashMap<>();
  htsOnMap.put(USDFEDFUND, htsOn);    
  return htsOnMap;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:8,代码来源:StandardDataSetsInflationUSD.java

示例10: tpcLookingBackwardOnDayOfPayment

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void tpcLookingBackwardOnDayOfPayment() {
  final ZonedDateTime referenceDate = DateUtils.getUTCDate(2012, 8, 17);
  final SwapFixedCoupon<Coupon> swapToday = SWAP_FIXED_IBOR_DEFINITION.toDerivative(referenceDate, FIXING_TS_3_6);
  final double todayCash = ((CouponFixed) swapToday.getSecondLeg().getNthPayment(0)).getAmount();

  final ZonedDateTime horizonDate = referenceDate.minusDays(1);
  final double horizon = TimeCalculator.getTimeBetween(referenceDate, horizonDate); // !!! Negative horizon
  final TodayPaymentCalculator paymentCalculator = TodayPaymentCalculator.getInstance(horizon);
  final MultipleCurrencyAmount paymentToday = swapToday.accept(paymentCalculator);

  assertEquals("TodayPaymentCalculator: fixed-coupon swap", todayCash, paymentToday.getAmount(USD6MLIBOR3M.getCurrency()), TOLERANCE_PV);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:14,代码来源:TodayPaymentCalculatorTest.java

示例11: tpcLookingBackwardOneDayOneDayAfterPayment

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void tpcLookingBackwardOneDayOneDayAfterPayment() {
  final ZonedDateTime referenceDate = DateUtils.getUTCDate(2012, 8, 18);
  final SwapFixedCoupon<Coupon> swapToday = SWAP_FIXED_IBOR_DEFINITION.toDerivative(referenceDate, FIXING_TS_3_6);
  final double todayCash = 0.0; // ((CouponFixed) swapToday.getSecondLeg().getNthPayment(0)).getAmount();

  final ZonedDateTime horizonDate = referenceDate.minusDays(1);
  final double horizon = TimeCalculator.getTimeBetween(referenceDate, horizonDate); // !!! Negative horizon
  final TodayPaymentCalculator paymentCalculator = TodayPaymentCalculator.getInstance(horizon);
  final MultipleCurrencyAmount paymentToday = swapToday.accept(paymentCalculator);

  assertEquals("TodayPaymentCalculator: fixed-coupon swap", todayCash, paymentToday.getAmount(USD6MLIBOR3M.getCurrency()), TOLERANCE_PV);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:14,代码来源:TodayPaymentCalculatorTest.java

示例12: tpcWontProvidePaymentFromOneWeekBack

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
// The following test fails because the payment on 2012/08/17 is dropped when toDerivative is called.
// TodayPaymentCalculator does what it says on the tin. It provides the cashflows that occur today.
// The horizon is there only to give flexibility in financial-time as to the range in which one considers something as having occurred today.
public void tpcWontProvidePaymentFromOneWeekBack() {
  final ZonedDateTime referenceDate = DateUtils.getUTCDate(2012, 8, 21);
  final SwapFixedCoupon<Coupon> swapToday = SWAP_FIXED_IBOR_DEFINITION.toDerivative(referenceDate, FIXING_TS_3_6);
  final ZonedDateTime horizonDate = referenceDate.minusDays(7);
  final double horizon = TimeCalculator.getTimeBetween(referenceDate, horizonDate); // !!! Negative horizon
  final TodayPaymentCalculator paymentCalculator = TodayPaymentCalculator.getInstance(horizon);
  final MultipleCurrencyAmount paymentToday = swapToday.accept(paymentCalculator);
  assertEquals("TodayPaymentCalculator: fixed-coupon swap", 0.0, paymentToday.getAmount(USD6MLIBOR3M.getCurrency()), TOLERANCE_PV);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:14,代码来源:TodayPaymentCalculatorTest.java


注:本文中的org.threeten.bp.ZonedDateTime.minusDays方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。