本文整理汇总了Java中org.threeten.bp.ZonedDateTime.plus方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.plus方法的具体用法?Java ZonedDateTime.plus怎么用?Java ZonedDateTime.plus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.threeten.bp.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.plus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: presentValueCurveSensitivityAnnuity
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
/**
* Tests the present value of an annuity vs the sum of pv of each caplet.
*/
public void presentValueCurveSensitivityAnnuity() {
final Period START_CMSCAP = Period.ofYears(5);
final Period LENGTH_CMSCAP = Period.ofYears(10);
final ZonedDateTime START_DATE = ScheduleCalculator.getAdjustedDate(SPOT_DATE, START_CMSCAP, EUR1YEURIBOR6M.getIborIndex().getBusinessDayConvention(), CALENDAR, EUR1YEURIBOR6M.getIborIndex()
.isEndOfMonth());
final ZonedDateTime END_DATE = START_DATE.plus(LENGTH_CMSCAP);
final Period capPeriod = Period.ofMonths(6);
final DayCount capDayCount = DayCounts.ACT_360;
final AnnuityCapFloorCMSDefinition capDefinition = AnnuityCapFloorCMSDefinition.from(START_DATE, END_DATE, NOTIONAL, INDEX_SWAP_5Y, capPeriod, capDayCount, false, STRIKE, IS_CAP, CALENDAR);
final Annuity<? extends Payment> cap = capDefinition.toDerivative(REFERENCE_DATE);
MultipleCurrencyMulticurveSensitivity pvcsCalculator = PVCSSSC.visit(cap, SABR_MULTICURVES);
pvcsCalculator = pvcsCalculator.cleaned();
MultipleCurrencyMulticurveSensitivity pvcsExpected = new MultipleCurrencyMulticurveSensitivity();
for (int loopcpn = 0; loopcpn < cap.getNumberOfPayments(); loopcpn++) {
pvcsExpected = pvcsExpected.plus(PVCSSSC.visit(cap.getNthPayment(loopcpn), SABR_MULTICURVES));
}
pvcsExpected = pvcsExpected.cleaned();
AssertSensitivityObjects.assertEquals("Cap annuity - SABR pv", pvcsExpected, pvcsCalculator, 1.0E-2);
}
示例2: presentValueAnnuity
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
/**
* Tests the present value of an annuity vs the sum of pv of each caplet.
*/
public void presentValueAnnuity() {
final Period START_CMSCAP = Period.ofYears(5);
final Period LENGTH_CMSCAP = Period.ofYears(10);
final ZonedDateTime START_DATE = ScheduleCalculator.getAdjustedDate(SPOT_DATE, START_CMSCAP, EUR1YEURIBOR6M.getIborIndex().getBusinessDayConvention(), CALENDAR, EUR1YEURIBOR6M.getIborIndex()
.isEndOfMonth());
final ZonedDateTime END_DATE = START_DATE.plus(LENGTH_CMSCAP);
final Period capPeriod = Period.ofMonths(6);
final DayCount capDayCount = DayCounts.ACT_360;
final AnnuityCapFloorCMSDefinition capDefinition = AnnuityCapFloorCMSDefinition.from(START_DATE, END_DATE, NOTIONAL, INDEX_SWAP_5Y, capPeriod, capDayCount, false, STRIKE, IS_CAP, CALENDAR);
final Annuity<? extends Payment> cap = capDefinition.toDerivative(REFERENCE_DATE);
final double pvCalculator = PVSSC.visit(cap, SABR_MULTICURVES).getAmount(EUR);
double pvExpected = 0.0;
for (int loopcpn = 0; loopcpn < cap.getNumberOfPayments(); loopcpn++) {
pvExpected += PVSSC.visit(cap.getNthPayment(loopcpn), SABR_MULTICURVES).getAmount(EUR);
}
assertEquals("Cap annuity - SABR pv", pvExpected, pvCalculator, 1.0E-2);
}
示例3: getSpreadCurveNew
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
* Get spread curve for the given tenors
*
* @param spreadCurve the spread curve
* @param bucketDates the bucket dates
* @param quoteConvention the convention, spread or puf
* @return the spread curve
*/
public static double[] getSpreadCurveNew(final NodalTenorDoubleCurve spreadCurve, final ZonedDateTime[] bucketDates,
final ZonedDateTime startDate, final StandardCDSQuotingConvention quoteConvention) {
ArgumentChecker.notNull(spreadCurve, "spread curve");
ArgumentChecker.notNull(bucketDates, "bucket dates");
ArgumentChecker.isTrue(spreadCurve.size() > 0, "spread curve had no values");
final double[] spreads = new double[bucketDates.length];
// PUF normalised to 1%, spreads to 1 BP
final double multiplier = StandardCDSQuotingConvention.POINTS_UPFRONT.equals(quoteConvention) ? s_tenminus2 : s_tenminus4;
// take spreads from subset of dates that we want
int i = 0;
for (final Tenor tenor : spreadCurve.getXData()) {
final ZonedDateTime bucketDate = startDate.plus(tenor.getPeriod());
final int index = Arrays.binarySearch(bucketDates, bucketDate);
if (index >= 0) {
spreads[i++] = spreadCurve.getYValue(tenor) * multiplier;
}
}
// if spread curve ends before required buckets take last spread entry
for (int j = spreads.length - 1; j >= 0; j--) {
final double lastspread = spreadCurve.getYData()[spreadCurve.getYData().length - 1] * multiplier;
if (spreads[j] == 0) {
spreads[j] = lastspread;
} else {
break;
}
}
return spreads;
}
示例4: getAdjustedMaturityDateSchedule
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public static ZonedDateTime[] getAdjustedMaturityDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime[] dates, final BusinessDayConvention convention,
final Calendar calendar, final Frequency frequency) {
ArgumentChecker.notEmpty(dates, "dates");
ArgumentChecker.notNull(convention, "convention");
ArgumentChecker.notNull(calendar, "calendar");
ArgumentChecker.notNull(frequency, "frequency");
PeriodFrequency periodFrequency;
if (frequency instanceof PeriodFrequency) {
periodFrequency = (PeriodFrequency) frequency;
} else if (frequency instanceof SimpleFrequency) {
periodFrequency = ((SimpleFrequency) frequency).toPeriodFrequency();
} else {
throw new IllegalArgumentException("For the moment can only deal with PeriodFrequency and SimpleFrequency");
}
final Period period = periodFrequency.getPeriod();
final int n = dates.length;
final ZonedDateTime[] results = new ZonedDateTime[n];
results[0] = effectiveDate.plus(period);
for (int i = 1; i < n; i++) {
results[i] = convention.adjustDate(calendar, dates[i - 1].plus(period)); // TODO need to further shift these dates by a convention
}
return results;
}
示例5: getBasisSwap
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
private SwapSecurity getBasisSwap(final InterpolatedYieldCurveSpecification spec, final FixedIncomeStripWithIdentifier strip, final SnapshotDataBundle marketValues) {
final ExternalId swapIdentifier = strip.getSecurity();
final ZonedDateTime curveDate = spec.getCurveDate().atStartOfDay(ZoneOffset.UTC);
final FixedIncomeStrip fixedIncomeStrip = strip.getStrip();
final IndexType payIndexType = fixedIncomeStrip.getPayIndexType();
final Tenor payTenor = fixedIncomeStrip.getPayTenor();
final IndexType receiveIndexType = fixedIncomeStrip.getReceiveIndexType();
final Tenor receiveTenor = fixedIncomeStrip.getReceiveTenor();
final String ccy = spec.getCurrency().getCode();
final ExternalId payFloatingReferenceRateId = ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, payIndexType + "_" + ccy + "_" + payTenor.getPeriod().toString());
final ExternalId receiveFloatingReferenceRateId = ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, receiveIndexType + "_" + ccy + "_" + receiveTenor.getPeriod().toString());
final ConventionBundle payConvention = _conventionBundleSource.getConventionBundle(payFloatingReferenceRateId);
final ConventionBundle receiveConvention = _conventionBundleSource.getConventionBundle(receiveFloatingReferenceRateId);
final Calendar payCalendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, payConvention.getRegion());
final ZonedDateTime paySpotDate = ScheduleCalculator.getAdjustedDate(curveDate, payConvention.getSettlementDays(), payCalendar);
final ZonedDateTime payMaturityDate = paySpotDate.plus(strip.getMaturity().getPeriod());
final String counterparty = "";
final InterestRateNotional notional = new InterestRateNotional(spec.getCurrency(), 1);
final ExternalId payRegionIdentifier = payConvention.getRegion();
final DayCount payDayCount = payConvention.getDayCount();
final Frequency payFrequency = PeriodFrequency.of(fixedIncomeStrip.getPayTenor().getPeriod());
final BusinessDayConvention payBusinessDayConvention = payConvention.getBusinessDayConvention();
final FloatingRateType payFloatingRateType = getFloatingTypeFromIndexType(fixedIncomeStrip.getPayIndexType());
final ExternalId receiveRegionIdentifier = receiveConvention.getRegion();
final DayCount receiveDayCount = receiveConvention.getDayCount();
final Frequency receiveFrequency = PeriodFrequency.of(fixedIncomeStrip.getReceiveTenor().getPeriod());
final BusinessDayConvention receiveBusinessDayConvention = receiveConvention.getBusinessDayConvention();
final FloatingRateType receiveFloatingRateType = getFloatingTypeFromIndexType(fixedIncomeStrip.getReceiveIndexType());
final double spread = marketValues.getDataPoint(swapIdentifier);
// Implementation note: By convention the spread is on the first leg (shorter tenor)
final FloatingSpreadIRLeg payLeg = new FloatingSpreadIRLeg(payDayCount, payFrequency, payRegionIdentifier, payBusinessDayConvention, notional, false, payFloatingReferenceRateId,
payFloatingRateType, spread);
final FloatingInterestRateLeg receiveLeg = new FloatingInterestRateLeg(receiveDayCount, receiveFrequency, receiveRegionIdentifier, receiveBusinessDayConvention, notional, false,
receiveFloatingReferenceRateId, receiveFloatingRateType);
//TODO don't use pay spot date and maturity date automatically
final SwapSecurity swap = new SwapSecurity(curveDate, paySpotDate, payMaturityDate, counterparty, payLeg, receiveLeg);
swap.setExternalIdBundle(ExternalIdBundle.of(swapIdentifier));
return swap;
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:40,代码来源:FixedIncomeStripIdentifierAndMaturityBuilder.java
示例6: getAdjustedDate
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
* Compute the end date of a period from the start date, the tenor and the conventions without end-of-month convention.
* @param startDate The period start date.
* @param tenor The period tenor.
* @param convention The business day convention.
* @param calendar The calendar.
* @return The end date.
*/
public static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final Period tenor, final BusinessDayConvention convention, final Calendar calendar) {
ArgumentChecker.notNull(startDate, "start date");
ArgumentChecker.notNull(convention, "convention");
ArgumentChecker.notNull(calendar, "calendar");
ArgumentChecker.notNull(tenor, "tenor");
final ZonedDateTime endDate = startDate.plus(tenor); // Unadjusted date.
return convention.adjustDate(calendar, endDate); // Adjusted by Business day convention
}
示例7: 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());
}
示例8: testIborIborSwap
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void testIborIborSwap() {
final ExternalId marketDataId = ExternalId.of(SCHEME, "3Mx6M basis spread");
final SnapshotDataBundle marketValues = new SnapshotDataBundle();
final double spread = 0.001;
marketValues.setDataPoint(marketDataId, spread);
final ZonedDateTime now = DateUtils.getUTCDate(2013, 3, 1);
ZonedDateTime settlementDate = DateUtils.getUTCDate(2013, 3, 5);
final Period swapTenor = Period.ofYears(2);
ZonedDateTime maturityDate = settlementDate.plus(swapTenor);
final CurveNodeVisitor<InstrumentDefinition<?>> converter = new SwapNodeConverter(SECURITY_SOURCE, CONVENTION_SOURCE, HOLIDAY_SOURCE, REGION_SOURCE, marketValues, marketDataId, now, FX_MATRIX);
SwapNode swapNode = new SwapNode(Tenor.of(Period.ZERO), Tenor.of(swapTenor), LEG_USDLIBOR3M_ID, LEG_USDLIBOR6M_ID, "Mapper");
InstrumentDefinition<?> definition = swapNode.accept(converter);
assertTrue(definition instanceof SwapDefinition);
final IborIndex index3m = ConverterUtils.indexIbor(USDLIBOR3M_NAME, USDLIBOR_ACT_360, Tenor.THREE_MONTHS);
final IborIndex index6m = ConverterUtils.indexIbor(USDLIBOR6M_NAME, USDLIBOR_ACT_360, Tenor.SIX_MONTHS);
AnnuityDefinition<CouponIborSpreadDefinition> payLeg = AnnuityDefinitionBuilder.couponIborSpread(settlementDate, maturityDate, LEG_USDLIBOR3M.getResetTenor().getPeriod(),
1.0d, spread, index3m, true, index3m.getDayCount(), index3m.getBusinessDayConvention(), index3m.isEndOfMonth(), CALENDAR, LEG_USDLIBOR3M.getStubType(),
LEG_USDLIBOR3M.getPaymentLag());
final AnnuityCouponIborDefinition receiveLeg = AnnuityDefinitionBuilder.couponIbor(settlementDate, maturityDate, LEG_USDLIBOR6M.getResetTenor().getPeriod(),
1.0d, index6m, false, index6m.getDayCount(), index6m.getBusinessDayConvention(), index6m.isEndOfMonth(), CALENDAR, LEG_USDLIBOR6M.getStubType(),
LEG_USDLIBOR6M.getPaymentLag());
assertEquals(new SwapDefinition(payLeg, receiveLeg), definition);
settlementDate = DateUtils.getUTCDate(2014, 3, 5);
maturityDate = settlementDate.plus(swapTenor);
swapNode = new SwapNode(Tenor.ONE_YEAR, Tenor.of(swapTenor), LEG_USDLIBOR3M_ID, LEG_USDLIBOR6M_ID, "Mapper");
definition = swapNode.accept(converter);
assertTrue(definition instanceof SwapDefinition);
payLeg = AnnuityDefinitionBuilder.couponIborSpread(settlementDate, maturityDate, LEG_USDLIBOR3M.getResetTenor().getPeriod(),
1.0d, spread, index3m, true, index3m.getDayCount(), index3m.getBusinessDayConvention(), index3m.isEndOfMonth(), CALENDAR, LEG_USDLIBOR3M.getStubType(), LEG_USDLIBOR3M.getPaymentLag());
final AnnuityCouponIborDefinition spreadLeg = AnnuityDefinitionBuilder.couponIbor(settlementDate, maturityDate, LEG_USDLIBOR6M.getResetTenor().getPeriod(),
1.0d, index6m, false, index6m.getDayCount(), index6m.getBusinessDayConvention(), index6m.isEndOfMonth(), CALENDAR, LEG_USDLIBOR6M.getStubType(), LEG_USDLIBOR6M.getPaymentLag());
assertEquals(new SwapDefinition(payLeg, spreadLeg), definition);
}
示例9: testXCcyIborIborSwap
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void testXCcyIborIborSwap() {
final ExternalId marketDataId = ExternalId.of(SCHEME, "USD/EUR basis spread");
final SnapshotDataBundle marketValues = new SnapshotDataBundle();
final double spread = 0.001;
marketValues.setDataPoint(marketDataId, spread);
final ZonedDateTime now = DateUtils.getUTCDate(2013, 3, 1);
// First test
ZonedDateTime settlementDate = DateUtils.getUTCDate(2013, 3, 5);
final Period swapTenor = Period.ofYears(1);
ZonedDateTime maturityDate = settlementDate.plus(swapTenor);
final CurveNodeVisitor<InstrumentDefinition<?>> converter = new SwapNodeConverter(SECURITY_SOURCE, CONVENTION_SOURCE, HOLIDAY_SOURCE, REGION_SOURCE, marketValues, marketDataId, now, FX_MATRIX);
SwapNode swapNode = new SwapNode(Tenor.of(Period.ZERO), Tenor.of(swapTenor), LEG_USDLIBOR3M_ID, LEG_EURIBOR3M_ID, "Mapper");
InstrumentDefinition<?> definition = swapNode.accept(converter);
assertTrue(definition instanceof SwapDefinition);
final IborIndex usdLibor3M = ConverterUtils.indexIbor(USDLIBOR3M_NAME, USDLIBOR_ACT_360, Tenor.THREE_MONTHS);
final IborIndex euribor3M = ConverterUtils.indexIbor(EURIBOR3M_NAME, EURIBOR_CONVENTION, Tenor.THREE_MONTHS);
AnnuityDefinition<CouponDefinition> quoteLeg = AnnuityDefinitionBuilder.couponIborSpreadWithNotional(settlementDate, maturityDate, 1.0, spread,
usdLibor3M, true, CALENDAR, LEG_USDLIBOR3M.getStubType(), 2, true, true);
final double notional = FX_MATRIX.getFxRate(Currency.USD, Currency.EUR);
AnnuityDefinition<CouponDefinition> nonQuoteLeg = AnnuityDefinitionBuilder.couponIborWithNotional(settlementDate, maturityDate, notional,
euribor3M, false, CALENDAR, LEG_EURIBOR3M.getStubType(), 0, true, true);
assertEquals(new SwapDefinition(quoteLeg, nonQuoteLeg), definition);
// Second test
settlementDate = DateUtils.getUTCDate(2014, 3, 5);
maturityDate = settlementDate.plus(swapTenor);
swapNode = new SwapNode(Tenor.ONE_YEAR, Tenor.of(swapTenor), LEG_USDLIBOR3M_ID, LEG_EURIBOR3M_ID, "Mapper");
definition = swapNode.accept(converter);
assertTrue(definition instanceof SwapDefinition);
quoteLeg = AnnuityDefinitionBuilder.couponIborSpreadWithNotional(settlementDate, maturityDate, 1.0, spread,
usdLibor3M, true, CALENDAR, LEG_USDLIBOR3M.getStubType(), 2, true, true);
nonQuoteLeg = AnnuityDefinitionBuilder.couponIborWithNotional(settlementDate, maturityDate, notional,
euribor3M, false, CALENDAR, LEG_EURIBOR3M.getStubType(), 0, true, true);
assertEquals(new SwapDefinition(quoteLeg, nonQuoteLeg), definition);
}
示例10: testOIS
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void testOIS() {
final ExternalId marketDataId = ExternalId.of(SCHEME, "3M1M future");
final SnapshotDataBundle marketValues = new SnapshotDataBundle();
final double rate = 0.001;
marketValues.setDataPoint(marketDataId, rate);
final ZonedDateTime now = DateUtils.getUTCDate(2013, 3, 1);
ZonedDateTime settlementDate = DateUtils.getUTCDate(2013, 3, 5);
final Period swapTenor = Period.ofYears(2);
SwapNode swapNode = new SwapNode(Tenor.of(Period.ZERO), Tenor.of(swapTenor), FIXED_LEG_PAY_LAG_ID, LEG_ON_CMP_ID, "Mapper");
final CurveNodeVisitor<InstrumentDefinition<?>> converter = new SwapNodeConverter(SECURITY_SOURCE, CONVENTION_SOURCE, HOLIDAY_SOURCE, REGION_SOURCE, marketValues, marketDataId, now, FX_MATRIX);
InstrumentDefinition<?> definition = swapNode.accept(converter);
assertTrue(definition instanceof SwapDefinition);
final IndexON index = ConverterUtils.indexON(USD_FEDFUND_INDEX_NAME, USD_OVERNIGHT_CONVENTION);
ZonedDateTime maturityDate = settlementDate.plus(swapTenor);
AnnuityCouponFixedDefinition fixedLeg = AnnuityDefinitionBuilder.couponFixed(Currency.USD, settlementDate, maturityDate, FIXED_LEG_PAY_LAG.getPaymentTenor().getPeriod(),
CALENDAR, ACT_360, MODIFIED_FOLLOWING, false, 1, rate, true, StubType.SHORT_START, FIXED_LEG_PAY_LAG.getPaymentLag());
AnnuityDefinition<CouponONSpreadSimplifiedDefinition> floatLeg = AnnuityDefinitionBuilder.couponONSimpleCompoundedSpreadSimplified(settlementDate, maturityDate,
LEG_ON_CMP.getPaymentTenor().getPeriod(), 1.0d, 0.0, index, false, LEG_ON_CMP.getBusinessDayConvention(), LEG_ON_CMP.isIsEOM(), CALENDAR, LEG_ON_CMP.getStubType(), LEG_ON_CMP.getPaymentLag());
assertEquals(new SwapDefinition(fixedLeg, floatLeg), definition);
settlementDate = DateUtils.getUTCDate(2013, 3, 5);
swapNode = new SwapNode(Tenor.of(Period.ZERO), Tenor.of(swapTenor), LEG_ON_CMP_ID, FIXED_LEG_PAY_LAG_ID, "Mapper");
definition = swapNode.accept(converter);
assertTrue(definition instanceof SwapDefinition);
fixedLeg = AnnuityDefinitionBuilder.couponFixed(Currency.USD, settlementDate, maturityDate, FIXED_LEG_PAY_LAG.getPaymentTenor().getPeriod(), CALENDAR, ACT_360,
MODIFIED_FOLLOWING, false, 1, rate, false, StubType.SHORT_START, FIXED_LEG_PAY_LAG.getPaymentLag());
floatLeg = AnnuityDefinitionBuilder.couponONSimpleCompoundedSpreadSimplified(settlementDate, maturityDate,
LEG_ON_CMP.getPaymentTenor().getPeriod(), 1.0d, 0.0, index, true, LEG_ON_CMP.getBusinessDayConvention(), LEG_ON_CMP.isIsEOM(), CALENDAR, LEG_ON_CMP.getStubType(), LEG_ON_CMP.getPaymentLag());
assertEquals(new SwapDefinition(floatLeg, fixedLeg), definition);
settlementDate = DateUtils.getUTCDate(2013, 4, 5);
swapNode = new SwapNode(Tenor.ONE_MONTH, Tenor.of(swapTenor), FIXED_LEG_PAY_LAG_ID, LEG_ON_CMP_ID, "Mapper");
maturityDate = settlementDate.plus(swapTenor);
definition = swapNode.accept(converter);
assertTrue(definition instanceof SwapDefinition);
fixedLeg = AnnuityDefinitionBuilder.couponFixed(Currency.USD, settlementDate, maturityDate, FIXED_LEG_PAY_LAG.getPaymentTenor().getPeriod(), CALENDAR, ACT_360,
MODIFIED_FOLLOWING, false, 1, rate, true, StubType.SHORT_START, FIXED_LEG_PAY_LAG.getPaymentLag());
floatLeg = AnnuityDefinitionBuilder.couponONSimpleCompoundedSpreadSimplified(settlementDate, maturityDate,
LEG_ON_CMP.getPaymentTenor().getPeriod(), 1.0d, 0.0, index, false, LEG_ON_CMP.getBusinessDayConvention(), LEG_ON_CMP.isIsEOM(), CALENDAR, LEG_ON_CMP.getStubType(), LEG_ON_CMP.getPaymentLag());
assertEquals(new SwapDefinition(fixedLeg, floatLeg), definition);
}
示例11: testThreeLegSwapNode
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void testThreeLegSwapNode() {
final ExternalId marketDataId = ExternalId.of(SCHEME, "EUR Basis Three Leg 3Mx6M");
final SnapshotDataBundle marketValues = new SnapshotDataBundle();
final double spread = 0.0010;
marketValues.setDataPoint(marketDataId, spread);
final ZonedDateTime now = DateUtils.getUTCDate(2013, 3, 1);
final Tenor tenorStart = Tenor.ONE_YEAR;
final Tenor tenorSwap = Tenor.ONE_YEAR;
final ThreeLegBasisSwapNode node = new ThreeLegBasisSwapNode(tenorStart, tenorSwap, LEG_EURIBOR3M_ID, LEG_EURIBOR6M_ID, EUR1Y_FIXED_ID, false, "Mapper", "1Yx3Y baiss");
final CurveNodeVisitor<InstrumentDefinition<?>> converter = new ThreeLegBasisSwapNodeConverter(SECURITY_SOURCE, CONVENTION_SOURCE, HOLIDAY_SOURCE, REGION_SOURCE, marketValues, marketDataId, now);
final InstrumentDefinition<?> definition = node.accept(converter);
final SwapMultilegDefinition swap = (SwapMultilegDefinition) definition;
assertTrue("ThreeLegSwapNode: correct type", definition instanceof SwapMultilegDefinition);
final ZonedDateTime spot = ScheduleCalculator.getAdjustedDate(now, EUR1Y_FIXED.getSettlementDays(), CALENDAR);
final ZonedDateTime effectiveDate = ScheduleCalculator.getAdjustedDate(spot, tenorStart.getPeriod(), EUR1Y_FIXED.getBusinessDayConvention(), CALENDAR, EUR1Y_FIXED.isIsEOM());
final ZonedDateTime maturityDate = effectiveDate.plus(tenorSwap.getPeriod());
final AnnuityCouponFixedDefinition spreadLeg = AnnuityDefinitionBuilder.couponFixed(EUR1Y_FIXED.getCurrency(), effectiveDate, maturityDate, EUR1Y_FIXED.getPaymentTenor().getPeriod(),
CALENDAR, EUR1Y_FIXED.getDayCount(), EUR1Y_FIXED.getBusinessDayConvention(), EUR1Y_FIXED.isIsEOM(), 1.0d, spread, true, EUR1Y_FIXED.getStubType(), 0);
assertEquals("ThreeLegSwapNode: spread leg", spreadLeg, swap.getLegs()[0]);
final IborIndex euribor3M = ConverterUtils.indexIbor(EURIBOR3M_NAME, EURIBOR_CONVENTION, Tenor.THREE_MONTHS);
final AnnuityDefinition<CouponIborDefinition> associatedLeg = AnnuityDefinitionBuilder.couponIbor(effectiveDate, maturityDate, LEG_EURIBOR3M.getResetTenor().getPeriod(), 1.0d, euribor3M, true,
euribor3M.getDayCount(), euribor3M.getBusinessDayConvention(), euribor3M.isEndOfMonth(), CALENDAR, LEG_EURIBOR3M.getStubType(), 0);
assertEquals("ThreeLegSwapNode: associated leg", associatedLeg, swap.getLegs()[1]);
final IborIndex euribor6M = ConverterUtils.indexIbor(EURIBOR6M_NAME, EURIBOR_CONVENTION, Tenor.SIX_MONTHS);
final AnnuityDefinition<CouponIborDefinition> otherLeg = AnnuityDefinitionBuilder.couponIbor(effectiveDate, maturityDate, LEG_EURIBOR6M.getResetTenor().getPeriod(), 1.0d, euribor6M, false,
euribor6M.getDayCount(), euribor6M.getBusinessDayConvention(), euribor6M.isEndOfMonth(), CALENDAR, LEG_EURIBOR3M.getStubType(), 0);
assertEquals("ThreeLegSwapNode: associated leg", otherLeg, swap.getLegs()[2]);
}
示例12: getUnadjustedDateSchedule
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
* Calculates the unadjusted date schedule.
*
* @param effectiveDate the effective date, not null
* @param accrualDate the accrual date, not null
* @param maturityDate the maturity date, not null
* @param frequency how many times a year dates occur, not null
* @return the schedule, not null
*/
public static ZonedDateTime[] getUnadjustedDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime accrualDate, final ZonedDateTime maturityDate,
final Frequency frequency) {
ArgumentChecker.notNull(effectiveDate, "effective date");
ArgumentChecker.notNull(accrualDate, "accrual date");
ArgumentChecker.notNull(maturityDate, "maturity date");
ArgumentChecker.notNull(frequency, "frequency");
if (effectiveDate.isAfter(maturityDate)) {
throw new IllegalArgumentException("Effective date was after maturity");
}
if (accrualDate.isAfter(maturityDate)) {
throw new IllegalArgumentException("Accrual date was after maturity");
}
// TODO what if there's no valid date between accrual date and maturity date?
PeriodFrequency periodFrequency;
if (frequency instanceof PeriodFrequency) {
periodFrequency = (PeriodFrequency) frequency;
} else if (frequency instanceof SimpleFrequency) {
periodFrequency = ((SimpleFrequency) frequency).toPeriodFrequency();
} else {
throw new IllegalArgumentException("For the moment can only deal with PeriodFrequency and SimpleFrequency");
}
final Period period = periodFrequency.getPeriod();
final List<ZonedDateTime> dates = new ArrayList<>();
ZonedDateTime date = effectiveDate; // TODO this is only correct if effective date = accrual date
date = date.plus(period);
while (isWithinSwapLifetime(date, maturityDate)) { // REVIEW: could speed this up by working out how many periods between start and end date?
dates.add(date);
date = date.plus(period);
}
return dates.toArray(EMPTY_ARRAY);
}
示例13: getAdjustedDateSchedule
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
* Construct an array of dates according the a start date, an end date, the period between dates and the conventions.
* The start date is not included in the array. The date are constructed forward and the stub period, if any, is last.
* The end date is always included in the schedule.
* @param startDate The reference initial date for the construction.
* @param endDate The end date. Usually unadjusted.
* @param period The period between payments.
* @param businessDayConvention The business day convention.
* @param calendar The applicable calendar.
* @param isEOM The end-of-month rule flag.
* @param stubShort Flag indicating if the stub, if any, is short (true) or long (false).
* @return The array of dates.
*/
public static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period period,
final BusinessDayConvention businessDayConvention, final Calendar calendar, final boolean isEOM, final boolean stubShort) {
boolean eomApply = false;
if (isEOM) {
final BusinessDayConvention following = new FollowingBusinessDayConvention();
eomApply = (following.adjustDate(calendar, startDate.plusDays(1)).getMonth() != startDate.getMonth());
}
// When the end-of-month rule applies and the start date is on month-end, the dates are the last business day of the month.
BusinessDayConvention actualBDC;
final List<ZonedDateTime> adjustedDates = new ArrayList<>();
ZonedDateTime date = startDate;
if (eomApply) {
actualBDC = new PrecedingBusinessDayConvention(); //To ensure that the date stays in the current month.
date = date.plus(period).with(TemporalAdjusters.lastDayOfMonth());
while (date.isBefore(endDate)) { // date is strictly before endDate
adjustedDates.add(actualBDC.adjustDate(calendar, date));
date = date.plus(period).with(TemporalAdjusters.lastDayOfMonth());
}
} else {
actualBDC = businessDayConvention;
date = date.plus(period);
while (date.isBefore(endDate)) { // date is strictly before endDate
adjustedDates.add(businessDayConvention.adjustDate(calendar, date));
date = date.plus(period);
}
}
// For long stub the last date before end date, if any, is removed.
if (!stubShort && adjustedDates.size() >= 1) {
adjustedDates.remove(adjustedDates.size() - 1);
}
adjustedDates.add(actualBDC.adjustDate(calendar, endDate)); // the end date
return adjustedDates.toArray(EMPTY_ARRAY);
}
示例14: generateInstrument
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public SwapDefinition generateInstrument(final ZonedDateTime date, final double spread, final double notional, final GeneratorAttributeIR attribute) {
ArgumentChecker.notNull(date, "Reference date");
ArgumentChecker.notNull(attribute, "Attributes");
final ZonedDateTime spot = ScheduleCalculator.getAdjustedDate(date, _spotLag, _calendar1);
final ZonedDateTime startDate = ScheduleCalculator.getAdjustedDate(spot, attribute.getStartPeriod(), _iborIndex1, _calendar1);
final ZonedDateTime maturityDate = startDate.plus(attribute.getEndPeriod());
final AnnuityDefinition<CouponIborCompoundingFlatSpreadDefinition> leg1 = AnnuityDefinitionBuilder.couponIborCompoundingFlatSpread(startDate, maturityDate,
_compoundingPeriod1, notional, spread, _iborIndex1, StubType.SHORT_START, true, _businessDayConvention, _endOfMonth, _calendar1, StubType.SHORT_START);
final AnnuityDefinition<CouponIborDefinition> leg2 = AnnuityDefinitionBuilder.couponIbor(startDate, maturityDate, _iborIndex2.getTenor(), notional, _iborIndex2, false,
_iborIndex2.getDayCount(), _businessDayConvention, _endOfMonth, _calendar2, StubType.SHORT_START, 0);
return new SwapDefinition(leg1, leg2);
}
示例15: getOISSwap
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
private SwapSecurity getOISSwap(final InterpolatedYieldCurveSpecification spec, final FixedIncomeStripWithIdentifier strip, final SnapshotDataBundle marketValues) {
final FixedIncomeStrip underlyingStrip = strip.getStrip();
final ExternalId swapIdentifier = strip.getSecurity();
final ConventionBundle swapConvention = _conventionBundleSource.getConventionBundle(ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, spec.getCurrency().getCode() + "_OIS_SWAP"));
if (swapConvention == null) {
throw new OpenGammaRuntimeException("Could not get convention for id " + ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, spec.getCurrency().getCode() + "_OIS_SWAP"));
}
if (!swapConvention.getSwapFloatingLegFrequency().equals(swapConvention.getSwapFixedLegFrequency())) {
throw new OpenGammaRuntimeException("Payment frequencies for the fixed and floating legs did not match");
}
final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, swapConvention.getSwapFloatingLegRegion());
final ZonedDateTime curveDate = spec.getCurveDate().atStartOfDay(ZoneOffset.UTC);
final ZonedDateTime spotDate = ScheduleCalculator.getAdjustedDate(curveDate, swapConvention.getSwapFixedLegSettlementDays(), calendar);
final ZonedDateTime maturityDate = spotDate.plus(strip.getMaturity().getPeriod());
final String counterparty = "";
final Double rate = marketValues.getDataPoint(swapIdentifier);
if (rate == null) {
throw new OpenGammaRuntimeException("rate was null on " + strip + " from " + spec);
}
Frequency floatingFrequency;
final ExternalId floatingReferenceRateId;
if (underlyingStrip.getResetTenor() != null) {
final Period resetTenor = underlyingStrip.getResetTenor().getPeriod();
floatingFrequency = PeriodFrequency.of(resetTenor);
final IndexType indexType = underlyingStrip.getIndexType();
floatingReferenceRateId = ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, indexType + "_" + resetTenor.toString());
} else {
floatingFrequency = swapConvention.getSwapFloatingLegFrequency();
if (floatingFrequency == null) {
throw new OpenGammaRuntimeException("Could not get floating leg frequency from convention");
}
floatingReferenceRateId = swapConvention.getSwapFloatingLegInitialRate();
if (floatingReferenceRateId == null) {
throw new OpenGammaRuntimeException("Could not get floating reference rate from convention");
}
}
final FloatingInterestRateLeg oisLeg = new FloatingInterestRateLeg(swapConvention.getSwapFloatingLegDayCount(), floatingFrequency,
swapConvention.getSwapFloatingLegRegion(), swapConvention.getSwapFloatingLegBusinessDayConvention(), new InterestRateNotional(spec.getCurrency(), 1), false, floatingReferenceRateId,
FloatingRateType.OIS);
final FixedInterestRateLeg fixedLeg = new FixedInterestRateLeg(swapConvention.getSwapFixedLegDayCount(), swapConvention.getSwapFixedLegFrequency(), swapConvention.getSwapFixedLegRegion(),
swapConvention.getSwapFixedLegBusinessDayConvention(), new InterestRateNotional(spec.getCurrency(), 1), false, rate);
final SwapSecurity swap = new SwapSecurity(curveDate, spotDate, maturityDate, counterparty, oisLeg, fixedLeg);
swap.setExternalIdBundle(ExternalIdBundle.of(swapIdentifier));
return swap;
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:46,代码来源:FixedIncomeStripIdentifierAndMaturityBuilder.java