/** * Copyright (C) 2011 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.analytics.financial.interestrate.inflation.derivative; import java.util.Arrays; import com.opengamma.analytics.financial.instrument.index.IndexPrice; import com.opengamma.analytics.financial.instrument.inflation.CouponInflationGearing; import com.opengamma.analytics.financial.interestrate.InstrumentDerivativeVisitor; import com.opengamma.util.ArgumentChecker; import com.opengamma.util.money.Currency; /** * Class describing an zero-coupon inflation coupon where the inflation increment is multiplied by a gearing factor. * The start index value is known when the coupon is traded/issued. * The index for a given month is given in the yield curve and in the time series on the first of the month. * The pay-off is factor*(Index_End / Index_Start - X) with X=0 for notional payment and X=1 for no notional payment. */ public class CouponInflationZeroCouponInterpolationGearing extends CouponInflation implements CouponInflationGearing { /** * The index value at the start of the coupon. */ private final double _indexStartValue; /** * The reference times for the index at the coupon end. Two months are required for the interpolation. * There is usually a difference of two or three month between the reference date and the payment date. * The time can be negative (when the price index for the current and last month is not yet published). */ private final double[] _referenceEndTime; /** * The time for which the index at the coupon end is paid by the standard corresponding zero coupon. * There is usually a difference of two or three month between the reference date and the natural payment date. * the natural payment date is equal to the payment date when the lag is the conventional one. * The time can be negative (when the price index for the current and last month is not yet published). */ private final double _naturalPaymentTime; /** * The weight on the first month index in the interpolation. */ private final double _weight; /** * Flag indicating if the notional is paid (true) or not (false). */ private final boolean _payNotional; /** * The gearing (multiplicative) factor applied to the inflation increment rate. */ private final double _factor; /** * Inflation zero-coupon constructor. * @param currency The coupon currency. * @param paymentTime The time to payment. * @param paymentYearFraction Accrual factor of the accrual period. * @param notional Coupon notional. * @param priceIndex The price index associated to the coupon. * @param indexStartValue The index value at the start of the coupon. * @param referenceEndTime The reference time for the index at the coupon end. * @param naturalPaymentTime The time for which the index at the coupon end is paid by the standard corresponding zero coupon. * @param weight The weight on the first month index in the interpolation. * @param payNotional Flag indicating if the notional is paid (true) or not (false). * @param factor The multiplicative factor. */ public CouponInflationZeroCouponInterpolationGearing(final Currency currency, final double paymentTime, final double paymentYearFraction, final double notional, final IndexPrice priceIndex, final double indexStartValue, final double[] referenceEndTime, final double naturalPaymentTime, final double weight, final boolean payNotional, final double factor) { super(currency, paymentTime, paymentYearFraction, notional, priceIndex); _indexStartValue = indexStartValue; _referenceEndTime = referenceEndTime; _naturalPaymentTime = naturalPaymentTime; _weight = weight; _payNotional = payNotional; _factor = factor; } /** * Gets the index value at the start of the coupon. * @return The index value. */ public double getIndexStartValue() { return _indexStartValue; } /** * Gets the reference time for the index at the coupon end. * @return The reference time. */ public double[] getReferenceEndTime() { return _referenceEndTime; } public double getNaturalPaymentTime() { return _naturalPaymentTime; } /** * Gets the weight on the first month index in the interpolation. * @return The weight. */ public double getWeight() { return _weight; } /** * Gets the pay notional flag. * @return The flag. */ public boolean payNotional() { return _payNotional; } @Override public CouponInflationZeroCouponInterpolationGearing withNotional(final double notional) { return new CouponInflationZeroCouponInterpolationGearing(getCurrency(), getPaymentTime(), getPaymentYearFraction(), notional, getPriceIndex(), _indexStartValue, _referenceEndTime, _naturalPaymentTime, _weight, _payNotional, _factor); } @Override public double getFactor() { return _factor; } @Override public <S, T> T accept(final InstrumentDerivativeVisitor<S, T> visitor, final S data) { ArgumentChecker.notNull(visitor, "visitor"); return visitor.visitCouponInflationZeroCouponInterpolationGearing(this, data); } @Override public <T> T accept(final InstrumentDerivativeVisitor<?, T> visitor) { ArgumentChecker.notNull(visitor, "visitor"); return visitor.visitCouponInflationZeroCouponInterpolationGearing(this); } @Override public String toString() { return "CouponInflationZeroCouponInterpolationGearing [_referenceEndTime=" + Arrays.toString(_referenceEndTime) + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); long temp; temp = Double.doubleToLongBits(_factor); result = prime * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(_indexStartValue); result = prime * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(_naturalPaymentTime); result = prime * result + (int) (temp ^ (temp >>> 32)); result = prime * result + (_payNotional ? 1231 : 1237); result = prime * result + Arrays.hashCode(_referenceEndTime); temp = Double.doubleToLongBits(_weight); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (getClass() != obj.getClass()) { return false; } CouponInflationZeroCouponInterpolationGearing other = (CouponInflationZeroCouponInterpolationGearing) obj; if (Double.doubleToLongBits(_factor) != Double.doubleToLongBits(other._factor)) { return false; } if (Double.doubleToLongBits(_indexStartValue) != Double.doubleToLongBits(other._indexStartValue)) { return false; } if (Double.doubleToLongBits(_naturalPaymentTime) != Double.doubleToLongBits(other._naturalPaymentTime)) { return false; } if (_payNotional != other._payNotional) { return false; } if (!Arrays.equals(_referenceEndTime, other._referenceEndTime)) { return false; } if (Double.doubleToLongBits(_weight) != Double.doubleToLongBits(other._weight)) { return false; } return true; } }