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


Java ZonedDateTime.plusDays方法代码示例

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


在下文中一共展示了ZonedDateTime.plusDays方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getTheta

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public MultipleCurrencyAmount getTheta(final BondTotalReturnSwapDefinition definition, final ZonedDateTime date, 
                                       final IssuerProviderInterface data, final int daysForward, final Calendar calendar, 
                                       final ZonedDateTimeDoubleTimeSeries fixingSeries) {
  ArgumentChecker.notNull(definition, "definition");
  ArgumentChecker.notNull(date, "date");
  ArgumentChecker.notNull(data, "data");
  ArgumentChecker.isTrue(daysForward == 1 || daysForward == -1, "daysForward must be either 1 or -1");
  final BondTotalReturnSwap instrumentToday = definition.toDerivative(date, fixingSeries);
  final ZonedDateTime horizonDate = date.plusDays(daysForward);
  final double shiftTime = TimeCalculator.getTimeBetween(date, horizonDate);
  final BondTotalReturnSwap instrumentTomorrow = definition.toDerivative(horizonDate, fixingSeries);
  final IssuerProviderInterface dataTomorrow = (IssuerProviderInterface) CURVE_ROLLDOWN.rollDown(data, shiftTime);
  final MultipleCurrencyAmount fundingLegPvTomorrow = instrumentTomorrow.getFundingLeg().accept(PV_CALCULATOR, dataTomorrow);
  final MultipleCurrencyAmount fundingLegPvToday = instrumentToday.getFundingLeg().accept(PV_CALCULATOR, data);
  final MultipleCurrencyAmount bondLegPvTomorrow = instrumentTomorrow.getAsset().accept(PV_CALCULATOR, dataTomorrow).multipliedBy(instrumentTomorrow.getQuantity());
  final MultipleCurrencyAmount bondLegPvToday = instrumentToday.getAsset().accept(PV_CALCULATOR, data).multipliedBy(instrumentToday.getQuantity());
  final Currency assetCurrency = instrumentToday.getAsset().getCurrency();
  final Currency fundingCurrency = instrumentToday.getFundingLeg().getCurrency();
  final double fxRate = data.getMulticurveProvider().getFxRate(fundingCurrency, assetCurrency);
  final MultipleCurrencyAmount pvToday = bondLegPvToday.plus(CurrencyAmount.of(assetCurrency, fundingLegPvToday.getAmount(fundingCurrency) * fxRate));
  final MultipleCurrencyAmount pvTomorrow = bondLegPvTomorrow.plus(CurrencyAmount.of(assetCurrency, fundingLegPvTomorrow.getAmount(fundingCurrency) * fxRate));
  return subtract(pvTomorrow, pvToday);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:25,代码来源:BondTrsConstantSpreadHorizonCalculator.java

示例3: getTheta

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public MultipleCurrencyAmount getTheta(final EquityTotalReturnSwapDefinition definition, final ZonedDateTime date, final MulticurveProviderInterface data,
    final int daysForward, final Calendar calendar, final ZonedDateTimeDoubleTimeSeries fixingSeries) {
  ArgumentChecker.notNull(definition, "definition");
  ArgumentChecker.notNull(date, "date");
  ArgumentChecker.notNull(data, "data");
  ArgumentChecker.isTrue(daysForward == 1 || daysForward == -1, "daysForward must be either 1 or -1");
  final EquityTotalReturnSwap instrumentToday = definition.toDerivative(date, fixingSeries);
  final ZonedDateTime horizonDate = date.plusDays(daysForward);
  final double shiftTime = TimeCalculator.getTimeBetween(date, horizonDate);
  final EquityTotalReturnSwap instrumentTomorrow = definition.toDerivative(horizonDate, fixingSeries);
  final MulticurveProviderInterface dataTomorrow = (MulticurveProviderInterface) CURVE_ROLLDOWN.rollDown(data, shiftTime);
  final MultipleCurrencyAmount pvTomorrow = instrumentTomorrow.getFundingLeg().accept(PV_CALCULATOR, dataTomorrow);
  final MultipleCurrencyAmount pvToday = instrumentToday.getFundingLeg().accept(PV_CALCULATOR, data);
  return subtract(pvTomorrow, pvToday);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:EqyTrsConstantSpreadHorizonCalculator.java

示例4: getTheta

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public MultipleCurrencyAmount getTheta(BillTotalReturnSwapDefinition definition, ZonedDateTime date, 
                                       IssuerProviderInterface data, int daysForward, Calendar calendar, 
                                       ZonedDateTimeDoubleTimeSeries fixingSeries) {
  ArgumentChecker.notNull(definition, "definition");
  ArgumentChecker.notNull(date, "date");
  ArgumentChecker.notNull(data, "data");
  ArgumentChecker.isTrue(daysForward == 1 || daysForward == -1, "daysForward must be either 1 or -1");
  BillTotalReturnSwap instrumentToday = definition.toDerivative(date, fixingSeries);
  ZonedDateTime horizonDate = date.plusDays(daysForward);
  double shiftTime = TimeCalculator.getTimeBetween(date, horizonDate);
  BillTotalReturnSwap instrumentTomorrow = definition.toDerivative(horizonDate, fixingSeries);
  IssuerProviderInterface dataTomorrow = (IssuerProviderInterface) CURVE_ROLLDOWN.rollDown(data, shiftTime);
  MultipleCurrencyAmount fundingLegPvTomorrow = instrumentTomorrow.getFundingLeg().accept(PV_CALCULATOR, dataTomorrow);
  MultipleCurrencyAmount fundingLegPvToday = instrumentToday.getFundingLeg().accept(PV_CALCULATOR, data);
  MultipleCurrencyAmount billLegPvTomorrow = instrumentTomorrow.getAsset().accept(PV_CALCULATOR, dataTomorrow).multipliedBy(instrumentTomorrow.getQuantity());
  MultipleCurrencyAmount billLegPvToday = instrumentToday.getAsset().accept(PV_CALCULATOR, data).multipliedBy(instrumentToday.getQuantity());
  Currency assetCurrency = instrumentToday.getAsset().getCurrency();
  Currency fundingCurrency = instrumentToday.getFundingLeg().getCurrency();
  double fxRate = data.getMulticurveProvider().getFxRate(fundingCurrency, assetCurrency);
  MultipleCurrencyAmount pvToday = billLegPvToday.plus(CurrencyAmount.of(assetCurrency, fundingLegPvToday.getAmount(fundingCurrency) * fxRate));
  MultipleCurrencyAmount pvTomorrow = billLegPvTomorrow.plus(CurrencyAmount.of(assetCurrency, fundingLegPvTomorrow.getAmount(fundingCurrency) * fxRate));
  return subtract(pvTomorrow, pvToday);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:25,代码来源:BillTrsConstantSpreadHorizonCalculator.java

示例5: getTheta

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public MultipleCurrencyAmount getTheta(final BondFuturesTransactionDefinition definition, final ZonedDateTime date, final IssuerProviderInterface data,
    final int daysForward, final Calendar calendar, final Double lastMarginPrice) {
  ArgumentChecker.notNull(definition, "definition");
  ArgumentChecker.notNull(date, "date");
  ArgumentChecker.notNull(data, "data");
  ArgumentChecker.isTrue(daysForward == 1 || daysForward == -1, "daysForward must be either 1 or -1");
  final InstrumentDerivative instrumentToday = definition.toDerivative(date, lastMarginPrice);
  final ZonedDateTime horizonDate = date.plusDays(daysForward);
  final double shiftTime = TimeCalculator.getTimeBetween(date, horizonDate);
  final InstrumentDerivative instrumentTomorrow = definition.toDerivative(horizonDate, lastMarginPrice);
  final ParameterIssuerProviderInterface dataTomorrow = (ParameterIssuerProviderInterface) CURVE_ROLLDOWN.rollDown(data, shiftTime);
  final MultipleCurrencyAmount pvTomorrow = instrumentTomorrow.accept(PV_CALCULATOR, dataTomorrow);
  final MultipleCurrencyAmount pvToday = instrumentToday.accept(PV_CALCULATOR, data);
  return subtract(pvTomorrow, pvToday);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:BondFutureConstantSpreadHorizonCalculator.java

示例6: getTheta

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public MultipleCurrencyAmount getTheta(final BondTransactionDefinition<?, ?> definition, final ZonedDateTime date, final IssuerProviderInterface data,
    final int daysForward, final Calendar calendar) {
  ArgumentChecker.notNull(definition, "definition");
  ArgumentChecker.notNull(date, "date");
  ArgumentChecker.notNull(data, "data");
  ArgumentChecker.isTrue(daysForward == 1 || daysForward == -1, "daysForward must be either 1 or -1");
  final InstrumentDerivative instrumentToday = definition.toDerivative(date);
  final ZonedDateTime horizonDate = date.plusDays(daysForward);
  final double shiftTime = TimeCalculator.getTimeBetween(date, horizonDate);
  final InstrumentDerivative instrumentTomorrow = definition.toDerivative(horizonDate);
  final ParameterIssuerProviderInterface dataTomorrow = (ParameterIssuerProviderInterface) CURVE_ROLLDOWN.rollDown(data, shiftTime);
  final MultipleCurrencyAmount pvTomorrow = instrumentTomorrow.accept(PV_CALCULATOR, dataTomorrow);
  final MultipleCurrencyAmount pvToday = instrumentToday.accept(PV_CALCULATOR, data);
  return subtract(pvTomorrow, pvToday);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:BondConstantSpreadHorizonCalculator.java

示例7: nextWorkingDay

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
 * Returns the date unchanged if this is a working day, otherwise advances 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 nextWorkingDay(ZonedDateTime zdt, final Currency currency) {
  while (!isWorkday(zdt.getDayOfWeek(), currency) || isHoliday(zdt.toLocalDate(), currency)) {
    zdt = zdt.plusDays(1);
  }
  return zdt;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:15,代码来源:SecurityGenerator.java

示例8: createFRASecurity

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
protected Security createFRASecurity(final String name, final Currency currency, final double rate, final ExternalId underlying) {
  final ZonedDateTime startDate = zdt(2010, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC);
  final ZonedDateTime settlementDate = startDate.plusDays(2);
  final FRASecurity security = new FRASecurity(currency, ExternalId.of("Region", "US"), startDate, zdt(2012, 10, 10, 12, 0, 0, 0,
      ZoneOffset.UTC), rate, 0d, underlying, settlementDate);
  security.setExternalIdBundle(createExternalIdBundle());
  security.setName(name);
  security.setUniqueId(createUniqueId("Security"));
  return security;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:11,代码来源:AbstractTest.java

示例9: getSchedule

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate) {
  ArgumentChecker.notNull(startDate, "start date");
  ArgumentChecker.notNull(endDate, "end date");
  ArgumentChecker.isFalse(startDate.isAfter(endDate), "start date must not be after end date");
  if (startDate.equals(endDate)) {
    return new ZonedDateTime[] {startDate};
  }
  final List<ZonedDateTime> dates = new ArrayList<>();
  ZonedDateTime date = startDate;
  while (!date.isAfter(endDate)) {
    dates.add(date);
    date = date.plusDays(1);
  }
  return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:16,代码来源:DailyScheduleCalculator.java

示例10: 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

示例11: adjustDateByTenor

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
 * Adjusts a {@link ZonedDateTime} by a tenor. If the tenor is backed by a {@link BusinessDayTenor}, the calendar and
 * spot days are used when adjusting.
 * @param date The date to adjust, not null
 * @param tenor The tenor, not null
 * @param calendar The calendar, not null
 * @param spotDays The number of days for spot, greater than or equal to zero
 * @return The date adjusted by a tenor
 */
public static ZonedDateTime adjustDateByTenor(final ZonedDateTime date, final Tenor tenor, final Calendar calendar, final int spotDays) {
  ArgumentChecker.notNull(date, "date");
  ArgumentChecker.notNull(tenor, "tenor");
  ArgumentChecker.notNull(calendar, "calendar");
  ArgumentChecker.isTrue(spotDays >= 0, "number of spot days must be greater than zero; have {}", spotDays);
  if (tenor.isBusinessDayTenor()) {
    int offset;
    final BusinessDayTenor bdt = tenor.getBusinessDayTenor();
    switch (bdt) {
      case OVERNIGHT:
        offset = 0;
        break;
      case TOM_NEXT:
        offset = 1;
        break;
      case SPOT_NEXT:
        offset = spotDays;
        break;
      default:
        throw new IllegalArgumentException("Did not recognise tenor " + tenor);
    }
    ZonedDateTime result = date;
    int count = 0;
    while (count < offset) {
      result = result.plusDays(1);
      if (calendar.isWorkingDay(result.toLocalDate())) {
        count++;
      }
    }
    result = result.plusDays(1);
    while (!calendar.isWorkingDay(result.toLocalDate())) {
      result = result.plusDays(1);
    }
    return result;
  }
  return date.plus(tenor.getPeriod());
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:47,代码来源:TenorUtils.java

示例12: createFixingSeries

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
static ZonedDateTimeDoubleTimeSeries createFixingSeries(final ZonedDateTime startDate, final ZonedDateTime endDate) {
  final List<ZonedDateTime> dates = new ArrayList<>();
  final List<Double> data = new ArrayList<>();
  ZonedDateTime dt = startDate;
  while (dt.isBefore(endDate) || dt.equals(endDate)) {
    dates.add(dt);
    data.add(0.05 + Math.sin(dt.getDayOfYear()) / 100);
    dt = dt.plusDays(1);
    if (dt.getDayOfWeek().equals(DayOfWeek.SATURDAY)) {
      dt = dt.plusDays(2);
    }
  }
  return ImmutableZonedDateTimeDoubleTimeSeries.of(dates, data, ZoneOffset.UTC);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:15,代码来源:AnnuityCouponONDefinitionTest.java

示例13: todayPaymentCalculatorOnDayOfPayment

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void todayPaymentCalculatorOnDayOfPayment() {
  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.plusDays(1);
  final double horizon = TimeCalculator.getTimeBetween(referenceDate, horizonDate);
  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

示例14: todayPaymentCalculatorOnDayBeforePayment

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

  final ZonedDateTime horizonDate = referenceDate.plusDays(1);
  final double horizon = TimeCalculator.getTimeBetween(referenceDate, horizonDate);
  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

示例15: todayPaymentCalculatorOnDayAfterPayment

import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void todayPaymentCalculatorOnDayAfterPayment() {
  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;

  final ZonedDateTime horizonDate = referenceDate.plusDays(1);
  final double horizon = TimeCalculator.getTimeBetween(referenceDate, horizonDate);
  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


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