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

Clean up inflation swaps convention #1539

Merged
merged 3 commits into from Jul 28, 2017
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 @@ -113,24 +113,52 @@ public final class InflationRateSwapLegConvention
private final BusinessDayAdjustment accrualBusinessDayAdjustment;

//-------------------------------------------------------------------------

/**
* Obtains a convention based on the specified index, defaulting the PriceIndexCalculationMethod to MONTHLY.
* <p>
* The standard market convention for an Inflation rate leg is based on the index.
* Use the {@linkplain #builder() builder} for unusual conventions.
*
* @param index the index, the market convention values are extracted from the index
* @param lag the lag between the price index and the accrual date, typically a number of months
* @param businessDayAdjustment the business day
* @return the convention
* @deprecated Use of() method which takes {@link PriceIndexCalculationMethod} parameter
*/
@Deprecated
public static InflationRateSwapLegConvention of(
PriceIndex index,
Period lag,
BusinessDayAdjustment businessDayAdjustment) {
return of(index, lag, PriceIndexCalculationMethod.MONTHLY, businessDayAdjustment);
}

/**
* Obtains a convention based on the specified index.
* <p>
* The standard market convention for an Inflation rate leg is based on the index.
* Use the {@linkplain #builder() builder} for unusual conventions.
*
*
* @param index the index, the market convention values are extracted from the index
* @param lag the lag between the price index and the accrual date, typically a number of months
* @param businessDayAdjustment the business day
* @param priceIndexCalculationMethod the price index calculation method, typically interpolated or monthly
* @param businessDayAdjustment the business day
* @return the convention
*/
public static InflationRateSwapLegConvention of(
PriceIndex index,
Period lag,
PriceIndexCalculationMethod priceIndexCalculationMethod,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an incompatible change. Need to add an overload.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Have deprecated the old method as the client should have to provide interpolation style when defining conventions. Defaulting to monthly seems slightly arbitrary.

BusinessDayAdjustment businessDayAdjustment) {

return new InflationRateSwapLegConvention(index, lag, PriceIndexCalculationMethod.MONTHLY, false,
DaysAdjustment.NONE, businessDayAdjustment);
return new InflationRateSwapLegConvention(
index,
lag,
priceIndexCalculationMethod,
false,
DaysAdjustment.NONE,
businessDayAdjustment);
}

//-------------------------------------------------------------------------
Expand All @@ -140,16 +168,18 @@ private static void applyDefaults(Builder builder) {
}

//-------------------------------------------------------------------------

/**
* Gets the currency of the leg from the index.
*
*
* @return the currency
*/
public Currency getCurrency() {
return index.getCurrency();
}

//-------------------------------------------------------------------------

/**
* Creates a leg based on this convention.
* <p>
Expand All @@ -158,10 +188,10 @@ public Currency getCurrency() {
* If the leg is 'Pay', the fixed rate is paid to the counterparty.
* If the leg is 'Receive', the fixed rate is received from the counterparty.
*
* @param startDate the start date
* @param endDate the end date
* @param payReceive determines if the leg is to be paid or received
* @param notional the business day adjustment to apply to accrual schedule dates
* @param startDate the start date
* @param endDate the end date
* @param payReceive determines if the leg is to be paid or received
* @param notional the business day adjustment to apply to accrual schedule dates
* @return the leg
*/
public RateCalculationSwapLeg toLeg(
Expand Down
Expand Up @@ -28,6 +28,7 @@
import com.opengamma.strata.basics.index.PriceIndices;
import com.opengamma.strata.basics.schedule.Frequency;
import com.opengamma.strata.product.swap.CompoundingMethod;
import com.opengamma.strata.product.swap.PriceIndexCalculationMethod;

/**
* Fixed-Inflation swap conventions.
Expand All @@ -51,7 +52,11 @@ final class StandardFixedInflationSwapConventions {
ImmutableFixedInflationSwapConvention.of(
"GBP-FIXED-ZC-GB-HCIP",
fixedLegZcConvention(GBP, GBLO),
InflationRateSwapLegConvention.of(PriceIndices.GB_HICP, LAG_3M, BusinessDayAdjustment.of(MODIFIED_FOLLOWING, GBLO)),
InflationRateSwapLegConvention.of(
PriceIndices.GB_HICP,
LAG_2M,
PriceIndexCalculationMethod.MONTHLY,
BusinessDayAdjustment.of(MODIFIED_FOLLOWING, GBLO)),
DaysAdjustment.ofBusinessDays(2, GBLO));

/**
Expand All @@ -62,7 +67,11 @@ final class StandardFixedInflationSwapConventions {
ImmutableFixedInflationSwapConvention.of(
"GBP-FIXED-ZC-GB-RPI",
fixedLegZcConvention(GBP, GBLO),
InflationRateSwapLegConvention.of(PriceIndices.GB_RPI, LAG_2M, BusinessDayAdjustment.of(MODIFIED_FOLLOWING, GBLO)),
InflationRateSwapLegConvention.of(
PriceIndices.GB_RPI,
LAG_2M,
PriceIndexCalculationMethod.MONTHLY,
BusinessDayAdjustment.of(MODIFIED_FOLLOWING, GBLO)),
DaysAdjustment.ofBusinessDays(2, GBLO));

/**
Expand All @@ -73,7 +82,11 @@ final class StandardFixedInflationSwapConventions {
ImmutableFixedInflationSwapConvention.of(
"GBP-FIXED-ZC-GB-RPIX",
fixedLegZcConvention(GBP, GBLO),
InflationRateSwapLegConvention.of(PriceIndices.GB_RPIX, LAG_3M, BusinessDayAdjustment.of(MODIFIED_FOLLOWING, GBLO)),
InflationRateSwapLegConvention.of(
PriceIndices.GB_RPIX,
LAG_2M,
PriceIndexCalculationMethod.MONTHLY,
BusinessDayAdjustment.of(MODIFIED_FOLLOWING, GBLO)),
DaysAdjustment.ofBusinessDays(2, GBLO));

/**
Expand All @@ -84,7 +97,11 @@ final class StandardFixedInflationSwapConventions {
ImmutableFixedInflationSwapConvention.of(
"CHF-FIXED-ZC-CH-CPI",
fixedLegZcConvention(CHF, CHZU),
InflationRateSwapLegConvention.of(PriceIndices.CH_CPI, LAG_3M, BusinessDayAdjustment.of(MODIFIED_FOLLOWING, CHZU)),
InflationRateSwapLegConvention.of(
PriceIndices.CH_CPI,
LAG_3M,
PriceIndexCalculationMethod.MONTHLY,
BusinessDayAdjustment.of(MODIFIED_FOLLOWING, CHZU)),
DaysAdjustment.ofBusinessDays(2, CHZU));

/**
Expand All @@ -95,7 +112,11 @@ final class StandardFixedInflationSwapConventions {
ImmutableFixedInflationSwapConvention.of(
"EUR-FIXED-ZC-EU-AI-CPI",
fixedLegZcConvention(EUR, EUTA),
InflationRateSwapLegConvention.of(PriceIndices.EU_AI_CPI, LAG_3M, BusinessDayAdjustment.of(MODIFIED_FOLLOWING, EUTA)),
InflationRateSwapLegConvention.of(
PriceIndices.EU_AI_CPI,
LAG_3M,
PriceIndexCalculationMethod.MONTHLY,
BusinessDayAdjustment.of(MODIFIED_FOLLOWING, EUTA)),
DaysAdjustment.ofBusinessDays(2, EUTA));

/**
Expand All @@ -106,7 +127,11 @@ final class StandardFixedInflationSwapConventions {
ImmutableFixedInflationSwapConvention.of(
"EUR-FIXED-ZC-EU-EXT-CPI",
fixedLegZcConvention(EUR, EUTA),
InflationRateSwapLegConvention.of(PriceIndices.EU_EXT_CPI, LAG_3M, BusinessDayAdjustment.of(MODIFIED_FOLLOWING, EUTA)),
InflationRateSwapLegConvention.of(
PriceIndices.EU_EXT_CPI,
LAG_3M,
PriceIndexCalculationMethod.MONTHLY,
BusinessDayAdjustment.of(MODIFIED_FOLLOWING, EUTA)),
DaysAdjustment.ofBusinessDays(2, EUTA));

/**
Expand All @@ -117,7 +142,11 @@ final class StandardFixedInflationSwapConventions {
ImmutableFixedInflationSwapConvention.of(
"JPY-FIXED-ZC-JP-CPI",
fixedLegZcConvention(JPY, JPTO),
InflationRateSwapLegConvention.of(PriceIndices.JP_CPI_EXF, LAG_3M, BusinessDayAdjustment.of(MODIFIED_FOLLOWING, JPTO)),
InflationRateSwapLegConvention.of(
PriceIndices.JP_CPI_EXF,
LAG_3M,
PriceIndexCalculationMethod.INTERPOLATED_JAPAN,
BusinessDayAdjustment.of(MODIFIED_FOLLOWING, JPTO)),
DaysAdjustment.ofBusinessDays(2, JPTO));

/**
Expand All @@ -128,7 +157,11 @@ final class StandardFixedInflationSwapConventions {
ImmutableFixedInflationSwapConvention.of(
"USD-FIXED-ZC-US-CPI",
fixedLegZcConvention(USD, USNY),
InflationRateSwapLegConvention.of(PriceIndices.US_CPI_U, LAG_3M, BusinessDayAdjustment.of(MODIFIED_FOLLOWING, USNY)),
InflationRateSwapLegConvention.of(
PriceIndices.US_CPI_U,
LAG_3M,
PriceIndexCalculationMethod.INTERPOLATED,
BusinessDayAdjustment.of(MODIFIED_FOLLOWING, USNY)),
DaysAdjustment.ofBusinessDays(2, USNY));

/**
Expand All @@ -139,7 +172,11 @@ final class StandardFixedInflationSwapConventions {
ImmutableFixedInflationSwapConvention.of(
"EUR-FIXED-ZC-FR-CPI",
fixedLegZcConvention(EUR, EUTA),
InflationRateSwapLegConvention.of(PriceIndices.FR_EXT_CPI, LAG_3M, BusinessDayAdjustment.of(MODIFIED_FOLLOWING, FRPA)),
InflationRateSwapLegConvention.of(
PriceIndices.FR_EXT_CPI,
LAG_3M,
PriceIndexCalculationMethod.MONTHLY,
BusinessDayAdjustment.of(MODIFIED_FOLLOWING, FRPA)),
DaysAdjustment.ofBusinessDays(2, EUTA));

// Create a zero-coupon fixed leg convention
Expand Down
Expand Up @@ -22,6 +22,7 @@
import static com.opengamma.strata.product.common.BuySell.BUY;
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.PriceIndexCalculationMethod.MONTHLY;
import static org.testng.Assert.assertEquals;

import java.time.LocalDate;
Expand Down Expand Up @@ -56,9 +57,9 @@ public class FixedInflationSwapConventionTest {
private static final FixedRateSwapLegConvention FIXED = fixedLegZcConvention(GBP, GBLO);
private static final FixedRateSwapLegConvention FIXED2 =
FixedRateSwapLegConvention.of(GBP, ACT_365F, P3M, BDA_MOD_FOLLOW);
private static final InflationRateSwapLegConvention INFL = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, BDA_MOD_FOLLOW);
private static final InflationRateSwapLegConvention INFL2 = InflationRateSwapLegConvention.of(GB_RPI, LAG_3M, BDA_MOD_FOLLOW);
private static final InflationRateSwapLegConvention INFL3 = InflationRateSwapLegConvention.of(GB_RPIX, LAG_3M, BDA_MOD_FOLLOW);
private static final InflationRateSwapLegConvention INFL = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, MONTHLY, BDA_MOD_FOLLOW);
private static final InflationRateSwapLegConvention INFL2 = InflationRateSwapLegConvention.of(GB_RPI, LAG_3M, MONTHLY, BDA_MOD_FOLLOW);
private static final InflationRateSwapLegConvention INFL3 = InflationRateSwapLegConvention.of(GB_RPIX, LAG_3M, MONTHLY, BDA_MOD_FOLLOW);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could back this out when compatibility overload added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would rather keep the test changes in order to discourage the use of the now deprecated method.


//-------------------------------------------------------------------------
public void test_of() {
Expand Down
Expand Up @@ -25,6 +25,8 @@
import static com.opengamma.strata.product.common.BuySell.BUY;
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.PriceIndexCalculationMethod.INTERPOLATED;
import static com.opengamma.strata.product.swap.PriceIndexCalculationMethod.MONTHLY;
import static org.testng.Assert.assertEquals;

import java.time.LocalDate;
Expand Down Expand Up @@ -58,8 +60,8 @@ public class FixedInflationSwapTemplateTest {
FixedRateSwapLegConvention.of(GBP, ACT_360, P6M, BDA_FOLLOW);
private static final FixedRateSwapLegConvention FIXED2 =
FixedRateSwapLegConvention.of(USD, ACT_365F, P3M, BDA_MOD_FOLLOW);
private static final InflationRateSwapLegConvention INFL = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, BDA_MOD_FOLLOW);
private static final InflationRateSwapLegConvention INFL2 = InflationRateSwapLegConvention.of(US_CPI_U, LAG_3M, BDA_MOD_FOLLOW);
private static final InflationRateSwapLegConvention INFL = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, MONTHLY, BDA_MOD_FOLLOW);
private static final InflationRateSwapLegConvention INFL2 = InflationRateSwapLegConvention.of(US_CPI_U, LAG_3M, INTERPOLATED, BDA_MOD_FOLLOW);
private static final FixedInflationSwapConvention CONV = ImmutableFixedInflationSwapConvention.of(
NAME,
FIXED,
Expand Down
Expand Up @@ -14,6 +14,7 @@
import static com.opengamma.strata.collect.TestHelper.coverBeanEquals;
import static com.opengamma.strata.collect.TestHelper.coverImmutableBean;
import static com.opengamma.strata.product.common.PayReceive.PAY;
import static com.opengamma.strata.product.swap.PriceIndexCalculationMethod.MONTHLY;
import static org.testng.Assert.assertEquals;

import java.time.LocalDate;
Expand Down Expand Up @@ -44,10 +45,10 @@ public class InflationRateSwapLegConventionTest {

//-------------------------------------------------------------------------
public void test_of() {
InflationRateSwapLegConvention test = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, BDA_MOD_FOLLOW);
InflationRateSwapLegConvention test = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, MONTHLY, BDA_MOD_FOLLOW);
assertEquals(test.getIndex(), GB_HICP);
assertEquals(test.getLag(), LAG_3M);
assertEquals(test.getIndexCalculationMethod(), PriceIndexCalculationMethod.MONTHLY);
assertEquals(test.getIndexCalculationMethod(), MONTHLY);
assertEquals(test.isNotionalExchange(), false);
assertEquals(test.getCurrency(), GBP);
}
Expand All @@ -59,7 +60,7 @@ public void test_builder() {
.build();
assertEquals(test.getIndex(), GB_HICP);
assertEquals(test.getLag(), LAG_3M);
assertEquals(test.getIndexCalculationMethod(), PriceIndexCalculationMethod.MONTHLY);
assertEquals(test.getIndexCalculationMethod(), MONTHLY);
assertEquals(test.isNotionalExchange(), false);
assertEquals(test.getCurrency(), GBP);
}
Expand All @@ -85,7 +86,7 @@ public void test_builderAllSpecified() {

//-------------------------------------------------------------------------
public void test_toLeg() {
InflationRateSwapLegConvention base = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, BDA_MOD_FOLLOW);
InflationRateSwapLegConvention base = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, MONTHLY, BDA_MOD_FOLLOW);
LocalDate startDate = LocalDate.of(2015, 5, 5);
LocalDate endDate = LocalDate.of(2020, 5, 5);
RateCalculationSwapLeg test = base.toLeg(
Expand All @@ -107,7 +108,7 @@ public void test_toLeg() {
.paymentDateOffset(DaysAdjustment.NONE)
.build())
.notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M))
.calculation(InflationRateCalculation.of(GB_HICP, 3, PriceIndexCalculationMethod.MONTHLY))
.calculation(InflationRateCalculation.of(GB_HICP, 3, MONTHLY))
.build();
assertEquals(test, expected);
}
Expand All @@ -129,7 +130,7 @@ public void coverage() {
}

public void test_serialization() {
InflationRateSwapLegConvention test = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, BDA_MOD_FOLLOW);
InflationRateSwapLegConvention test = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, MONTHLY, BDA_MOD_FOLLOW);
assertSerialization(test);
}

Expand Down