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

Fix DaysAdjustment.ofBusinessDays #2181

Merged
merged 1 commit into from Jun 16, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,6 +5,8 @@
*/
package com.opengamma.strata.basics.date;

import static com.opengamma.strata.basics.date.BusinessDayConventions.FOLLOWING;

import java.io.Serializable;
import java.time.LocalDate;
import java.util.Map;
Expand Down Expand Up @@ -149,12 +151,18 @@ public static DaysAdjustment ofCalendarDays(int numberOfDays, BusinessDayAdjustm
* This is equivalent to repeatedly finding the next business day.
* <p>
* No business day adjustment is applied to the result of the addition.
* <p>
* If the input is a holiday, the first business day counted will be the next business day.
* If the input is a holiday and the number of days to add is zero, the result will be the next business day.
*
* @param numberOfDays the number of days
* @param holidayCalendar the calendar that defines holidays and business days
* @return the days adjustment
*/
public static DaysAdjustment ofBusinessDays(int numberOfDays, HolidayCalendarId holidayCalendar) {
if (numberOfDays == 0) {
return new DaysAdjustment(0, HolidayCalendarIds.NO_HOLIDAYS, BusinessDayAdjustment.of(FOLLOWING, holidayCalendar));
}
return new DaysAdjustment(numberOfDays, holidayCalendar, BusinessDayAdjustment.NONE);
}

Expand Down
Expand Up @@ -100,6 +100,14 @@ public void test_ofCalendarDays2_adjust() {
assertThat(test.resolve(REF_DATA).adjust(base)).isEqualTo(date(2014, 8, 18)); // Mon
}

@Test
public void test_ofCalendarDays2_adjustHoliday() {
DaysAdjustment test = DaysAdjustment.ofCalendarDays(2, BDA_FOLLOW_SAT_SUN);
LocalDate base = date(2014, 8, 16); // Sat
assertThat(test.adjust(base, REF_DATA)).isEqualTo(date(2014, 8, 18)); // Mon
assertThat(test.resolve(REF_DATA).adjust(base)).isEqualTo(date(2014, 8, 18)); // Mon
}

@Test
public void test_ofCalendarDays2_null() {
assertThatIllegalArgumentException().isThrownBy(() -> DaysAdjustment.ofCalendarDays(2, null));
Expand Down Expand Up @@ -175,6 +183,20 @@ public void test_ofBusinessDays3_null() {
assertThatIllegalArgumentException().isThrownBy(() -> DaysAdjustment.ofBusinessDays(3, null, null));
}

//-------------------------------------------------------------------------
@Test
public void test_ofBusinessDays0() {
DaysAdjustment test = DaysAdjustment.ofBusinessDays(0, SAT_SUN);
assertThat(test.getDays()).isEqualTo(0);
assertThat(test.getCalendar()).isEqualTo(NO_HOLIDAYS);
assertThat(test.getAdjustment()).isEqualTo(BDA_FOLLOW_SAT_SUN);
assertThat(test.toString()).isEqualTo("0 calendar days then apply Following using calendar Sat/Sun");
assertThat(test.adjust(date(2014, 8, 15), REF_DATA)).isEqualTo(date(2014, 8, 15)); // Fri
assertThat(test.adjust(date(2014, 8, 16), REF_DATA)).isEqualTo(date(2014, 8, 18)); // Sat -> Mon
assertThat(test.adjust(date(2014, 8, 17), REF_DATA)).isEqualTo(date(2014, 8, 18)); // Sun -> Mon
assertThat(test.adjust(date(2014, 8, 18), REF_DATA)).isEqualTo(date(2014, 8, 18)); // Mon
}

//-------------------------------------------------------------------------
@Test
public void test_getResultCalendar1() {
Expand Down
Expand Up @@ -6,6 +6,7 @@
package com.opengamma.strata.product.swap.type;

import static com.opengamma.strata.collect.TestHelper.coverPrivateConstructor;
import static com.opengamma.strata.collect.TestHelper.date;
import static org.assertj.core.api.Assertions.assertThat;

import java.time.LocalDate;
Expand Down Expand Up @@ -175,6 +176,13 @@ public void test_stub_overnight(FixedOvernightSwapConvention convention, Tenor t
assertThat(endDate.isBefore(tradeDate.plus(tenor).plusMonths(1))).isTrue();
}

//-------------------------------------------------------------------------
@Test
public void test_spotFromHoliday() {
FixedOvernightSwapConvention convention = FixedOvernightSwapConventions.GBP_FIXED_TERM_SONIA_OIS;
assertThat(convention.getSpotDateOffset().adjust(date(2020, 6, 14), REF_DATA)).isEqualTo(date(2020, 6, 15));
}

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