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

Support adjusted start date for StandardRollConventions (e.g. IMM). #1580

Merged
merged 6 commits into from Oct 24, 2017

Conversation

Projects
None yet
2 participants
@brianweller89
Contributor

brianweller89 commented Oct 20, 2017

Previous code only supported conversion of adjusted to unadjusted dates for numeric or EOD convention.

This code attempts to calculate an unadjusted date from an adjusted date as follows

  • Calculate the valid unadjusted date for the month of the passed date
  • Adjust the calculated date according to the trade adjustment convention
  • Compare the calculated adjusted date to the passed date.
  • If the passed date matches the calculated adjusted date it is assumed the passed date has been pre-adjusted and the unadjusted date is returned instead.

This relies on the assumption that the adjusted roll date will never be in a different month to the original unadjusted date. This is relatively safe for the existing StandardRollConventions as the rules for choosing a day in the month will never result in a date close to EOM. The latest possible calculated roll day for the existing roll convention is the 21st of the month (for IMM, if the first of the month is a Thursday). This is sufficiently far from EOM that no reasonable adjustment will result in the adjusted date being in the next month. Similarly the earliest possible date is 7th of the month (for IMMNZD).

The existing implementation for numeric roll convention suffers from a similar problem e.g. if unadjusted roll day of 28th is adjusted using FOLLOWING then the resulting adjusted date could be in the following month. This would result in the date not being identified as adjusted.

This logic will not work for weekly roll conventions in most cases. adjust() method for weekly roll conventions calculates the next weekday which matches the convention. If the passed date has been adjusted forward then it will not be identified as a valid adjusted date; the calculated unadjusted date will be the next occurrence of that weekday, rather than the previous e.g.

  • For weekly roll convention = Wednesday
  • If unadjusted start date is a Wednesday which is a bad business day and adjusted start date is the following Thursday.
  • Dow.adjust(startDate) will return the next Wednesday, which, when adjusted, will never equal the passed adjustedDate. Hence unadjusted date will not be calculated

See comments in code for (even) more detail.

An alternative approach could be to associate the logic for converting to unadjusted with each roll convention by adding a new method to the RollConvention interface; this would however be an intrusive and breaking change.

This is still a bit of a hack, so open to suggestions for alternatives!

if (adjDate.equals(baseDate)) {
return rollImpliedDate;
if (rollConvention != null) {

This comment has been minimized.

@jodastephen

jodastephen Oct 23, 2017

Member

Worth checking this in the calling code I think

{date(2018, 3, 22), date(2020, 03, 18), P6M, STUB_NONE, IMM, BDA_JPY_MF, null, null, BDA_NONE,
ImmutableList.of(date(2018, 3, 21), date(2018, 9, 19), date(2019, 3, 20), date(2019, 9, 18), date(2020, 3, 18)),
ImmutableList.of(date(2018, 3, 22), date(2018, 9, 19), date(2019, 3, 20), date(2019, 9, 18), date(2020, 3, 18)), IMM},
{date(2018, 3, 20), date(2019, 03, 20), P6M, STUB_NONE, IMM, BDA_JPY_P, null, null, BDA_NONE,

This comment has been minimized.

@jodastephen

jodastephen Oct 23, 2017

Member

a test without STUB_NONE?

//If the adjusted roll date equals the original base date then that the base date is in fact an adjusted date
//and hence return the unadjusted date for building the schedule.
if (adjustedRollDate.equals(baseDate)) {

This comment has been minimized.

@jodastephen

jodastephen Oct 23, 2017

Member

It would be helpful to use the same local variable names for similar concepts, such as rollInpliedDate and adjDate.

@brianweller89 brianweller89 merged commit 374aa52 into master Oct 24, 2017

15 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
security/snyk No new issues
Details
security/snyk - modules/basics/pom.xml No new issues
Details
security/snyk - modules/calc/pom.xml No new issues
Details
security/snyk - modules/collect/pom.xml No new issues
Details
security/snyk - modules/data/pom.xml No new issues
Details
security/snyk - modules/loader/pom.xml No new issues
Details
security/snyk - modules/market/pom.xml No new issues
Details
security/snyk - modules/math/pom.xml No new issues
Details
security/snyk - modules/measure/pom.xml No new issues
Details
security/snyk - modules/pom.xml No new issues
Details
security/snyk - modules/pricer/pom.xml No new issues
Details
security/snyk - modules/product/pom.xml No new issues
Details
security/snyk - modules/report/pom.xml No new issues
Details

@jodastephen jodastephen deleted the topic/imm_adjusted_start_dates branch Oct 25, 2017

@jodastephen jodastephen added this to the v1.5 milestone Oct 26, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment