Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed accrual period calculation for swap leg #2656

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void collectIndices(ImmutableSet.Builder<Index> builder) {
* Returns an instance based on this leg with the start date replaced.
* <p>
* This uses {@link PeriodicSchedule#replaceStartDate(LocalDate)}.
*
*
* @throws IllegalArgumentException if the start date cannot be replaced with the proposed start date
*/
@Override
Expand All @@ -157,15 +157,15 @@ public RateCalculationSwapLeg replaceStartDate(LocalDate adjustedStartDate) {
* <p>
* An {@link ResolvedSwapLeg} represents the same data as this leg, but with
* a complete schedule of dates defined using {@link RatePaymentPeriod}.
*
*
* @return the equivalent resolved swap leg
* @throws ReferenceDataNotFoundException if an identifier cannot be resolved in the reference data
* @throws RuntimeException if unable to resolve due to an invalid swap schedule or definition
*/
@Override
public ResolvedSwapLeg resolve(ReferenceData refData) {
DayCount dayCount = calculation.getDayCount();
Schedule resolvedAccruals = accrualSchedule.createSchedule(refData);
Schedule resolvedAccruals = accrualSchedule.createSchedule(refData, true);
Schedule resolvedPayments = paymentSchedule.createSchedule(resolvedAccruals, refData);
List<RateAccrualPeriod> accrualPeriods = calculation.createAccrualPeriods(resolvedAccruals, resolvedPayments, refData);
List<NotionalPaymentPeriod> payPeriods = paymentSchedule.createPaymentPeriods(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

import static com.opengamma.strata.basics.currency.Currency.EUR;
import static com.opengamma.strata.basics.currency.Currency.GBP;
import static com.opengamma.strata.basics.currency.Currency.USD;
import static com.opengamma.strata.basics.date.BusinessDayConventions.FOLLOWING;
import static com.opengamma.strata.basics.date.DayCounts.ACT_360;
import static com.opengamma.strata.basics.date.DayCounts.ACT_365F;
import static com.opengamma.strata.basics.date.DayCounts.ONE_ONE;
import static com.opengamma.strata.basics.date.HolidayCalendarIds.GBLO;
import static com.opengamma.strata.basics.date.HolidayCalendarIds.USGS;
import static com.opengamma.strata.basics.index.FxIndices.EUR_GBP_ECB;
import static com.opengamma.strata.basics.index.IborIndices.GBP_LIBOR_1M;
import static com.opengamma.strata.basics.index.IborIndices.GBP_LIBOR_3M;
Expand All @@ -20,13 +22,15 @@
import static com.opengamma.strata.basics.schedule.Frequency.P1M;
import static com.opengamma.strata.basics.schedule.Frequency.P2M;
import static com.opengamma.strata.basics.schedule.Frequency.P3M;
import static com.opengamma.strata.basics.schedule.StubConvention.SHORT_FINAL;
import static com.opengamma.strata.basics.schedule.StubConvention.SMART_INITIAL;
import static com.opengamma.strata.collect.TestHelper.assertSerialization;
import static com.opengamma.strata.collect.TestHelper.coverBeanEquals;
import static com.opengamma.strata.collect.TestHelper.coverImmutableBean;
import static com.opengamma.strata.collect.TestHelper.date;
import static com.opengamma.strata.product.common.PayReceive.PAY;
import static com.opengamma.strata.product.common.PayReceive.RECEIVE;
import static com.opengamma.strata.product.swap.CompoundingMethod.NONE;
import static com.opengamma.strata.product.swap.CompoundingMethod.STRAIGHT;
import static com.opengamma.strata.product.swap.PriceIndexCalculationMethod.INTERPOLATED;
import static com.opengamma.strata.product.swap.PriceIndexCalculationMethod.MONTHLY;
Expand Down Expand Up @@ -88,6 +92,8 @@ public class RateCalculationSwapLegTest {
private static final LocalDate DATE_06_09 = date(2014, 6, 9);
private static final LocalDate DATE_14_06_09 = date(2014, 6, 9);
private static final LocalDate DATE_19_06_09 = date(2019, 6, 9);
private static final LocalDate DATE_24_07_05 = date(2024, 7, 5);
private static final LocalDate DATE_25_07_07 = date(2025, 7, 7);
private static final DaysAdjustment PLUS_THREE_DAYS = DaysAdjustment.ofBusinessDays(3, GBLO);
private static final DaysAdjustment PLUS_TWO_DAYS = DaysAdjustment.ofBusinessDays(2, GBLO);
private static final DaysAdjustment MINUS_TWO_DAYS = DaysAdjustment.ofBusinessDays(-2, GBLO);
Expand Down Expand Up @@ -528,6 +534,53 @@ public void test_resolve_threeAccrualsPerPayment() {
.build());
}

@Test
public void test_resolve_combinePeriods() {
// test case
RateCalculationSwapLeg test = RateCalculationSwapLeg.builder()
.payReceive(PAY)
.accrualSchedule(PeriodicSchedule.builder()
.startDate(DATE_24_07_05)
.endDate(DATE_25_07_07)
.frequency(P12M)
.businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, USGS))
.stubConvention(SHORT_FINAL)
.build())
.paymentSchedule(PaymentSchedule.builder()
.paymentFrequency(P12M)
.paymentDateOffset(DaysAdjustment.ofBusinessDays(0, USGS))
.compoundingMethod(NONE)
.build())
.notionalSchedule(NotionalSchedule.of(USD, 1000d))
.calculation(FixedRateCalculation.builder()
.dayCount(ACT_360)
.rate(ValueSchedule.of(0.025d))
.build())
.build();
// expected
RatePaymentPeriod rpp1 = RatePaymentPeriod.builder()
.paymentDate(DATE_25_07_07)
.accrualPeriods(
RateAccrualPeriod.builder()
.startDate(DATE_24_07_05)
.endDate(DATE_25_07_07)
.unadjustedStartDate(DATE_24_07_05)
.yearFraction(ACT_360.yearFraction(DATE_24_07_05, DATE_25_07_07))
.rateComputation(FixedRateComputation.of(0.025d))
.build())
.dayCount(ACT_360)
.currency(USD)
.notional(-1000d)
.compoundingMethod(NONE)
.build();
// assertion
assertThat(test.resolve(REF_DATA)).isEqualTo(ResolvedSwapLeg.builder()
.type(FIXED)
.payReceive(PAY)
.paymentPeriods(rpp1)
.build());
}

//-------------------------------------------------------------------------
@Test
public void test_resolve_oneAccrualPerPayment_fxReset() {
Expand Down