Skip to content

Commit

Permalink
PROD-38570: Fixing ValueStepSequence resolving with RollConvensions (#…
Browse files Browse the repository at this point in the history
…2653)

Co-authored-by: Michael Rollins <[email protected]>
  • Loading branch information
MichaelRol and MichaelRol authored Jun 4, 2024
1 parent 2c097d0 commit 355b84a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,18 @@ private void validate() {
List<ValueStep> resolve(List<ValueStep> existingSteps, RollConvention rollConv) {
ImmutableList.Builder<ValueStep> steps = ImmutableList.builder();
steps.addAll(existingSteps);
LocalDate prev = firstStepDate;
LocalDate date = firstStepDate;
while (!date.isAfter(lastStepDate)) {
LocalDate prev = rollConv.adjust(firstStepDate);
LocalDate date = rollConv.adjust(firstStepDate);
LocalDate adjustedLastStepDate = rollConv.adjust(lastStepDate);
while (!date.isAfter(adjustedLastStepDate)) {
steps.add(ValueStep.of(date, adjustment));
prev = date;
date = rollConv.next(date, frequency);
}
if (!prev.equals(lastStepDate)) {
if (!prev.equals(adjustedLastStepDate)) {
throw new IllegalArgumentException(Messages.format(
"ValueStepSequence lastStepDate did not match frequency '{}' using roll convention '{}', {} != {}",
frequency, rollConv, lastStepDate, prev));
frequency, rollConv, adjustedLastStepDate, prev));
}
return steps.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ public void test_resolve() {
assertThat(steps.get(3)).isEqualTo(ValueStep.of(date(2016, 10, 20), ADJ));
}

@Test
public void test_resolve_with_roll_convention() {
ValueStepSequence test = ValueStepSequence.of(date(2022, 9, 21), date(2026, 9, 21), Frequency.P12M, ADJ);
List<ValueStep> steps = test.resolve(ImmutableList.of(), RollConventions.IMM);
assertThat(steps.size()).isEqualTo(5);
assertThat(steps.get(0)).isEqualTo(ValueStep.of(date(2022, 9, 21), ADJ));
assertThat(steps.get(1)).isEqualTo(ValueStep.of(date(2023, 9, 20), ADJ));
assertThat(steps.get(2)).isEqualTo(ValueStep.of(date(2024, 9, 18), ADJ));
assertThat(steps.get(3)).isEqualTo(ValueStep.of(date(2025, 9, 17), ADJ));
assertThat(steps.get(4)).isEqualTo(ValueStep.of(date(2026, 9, 16), ADJ));
}

@Test
public void test_resolve_invalid() {
ValueStepSequence test = ValueStepSequence.of(date(2016, 4, 20), date(2016, 10, 20), Frequency.P12M, ADJ);
Expand Down

0 comments on commit 355b84a

Please sign in to comment.