Esempio n. 1
0
        public virtual void test_bind_no_seasonality()
        {
            RatesCurveGroupDefinition test = RatesCurveGroupDefinition.builder().name(CurveGroupName.of("Test")).addCurve(CURVE_DEFN1, GBP, GBP_LIBOR_1M, GBP_LIBOR_3M).addForwardCurve(CURVE_DEFN_I, GB_RPI).build();
            LocalDate valuationDate        = LocalDate.of(2015, 11, 10);
            LocalDate lastFixingDate       = LocalDate.of(2015, 10, 31);
            LocalDate otherFixingDate      = LocalDate.of(2015, 9, 30);
            double    lastFixingValue      = 234.56;
            IDictionary <Index, LocalDateDoubleTimeSeries> map = ImmutableMap.of(GB_RPI, LocalDateDoubleTimeSeries.builder().put(lastFixingDate, 234.56).put(otherFixingDate, lastFixingValue - 1).build());
            RatesCurveGroupDefinition testBound = test.bindTimeSeries(valuationDate, map);
            IList <CurveDefinition>   list      = testBound.CurveDefinitions;

            assertEquals(list.Count, 2);
            assertTrue(list[0] is InterpolatedNodalCurveDefinition);
            assertTrue(list[1] is InflationNodalCurveDefinition);
            InflationNodalCurveDefinition seasonDef = (InflationNodalCurveDefinition)list[1];

            assertEquals(seasonDef.CurveWithoutFixingDefinition, CURVE_DEFN_I);
            assertEquals(seasonDef.LastFixingMonth, YearMonth.from(lastFixingDate));
            assertEquals(seasonDef.LastFixingValue, lastFixingValue);
            assertEquals(seasonDef.Name, CURVE_NAME_I);
            assertEquals(seasonDef.YValueType, ValueType.PRICE_INDEX);
            // Check the default
            assertTrue(seasonDef.SeasonalityDefinition.SeasonalityMonthOnMonth.equalWithTolerance(DoubleArray.filled(12, 1d), 1.0E-10));
            assertEquals(seasonDef.SeasonalityDefinition.AdjustmentType, ShiftType.SCALED);
        }
        // creates the rate computation
        private RateComputation createRateComputation(SchedulePeriod period, int scheduleIndex)
        {
            // handle where index value at start date is known
            LocalDate endDate = period.EndDate;

            if (firstIndexValue != null && scheduleIndex == 0)
            {
                return(createRateComputation(endDate));
            }
            YearMonth referenceStartMonth = YearMonth.from(period.StartDate.minus(lag));
            YearMonth referenceEndMonth   = YearMonth.from(endDate.minus(lag));

            if (indexCalculationMethod.Equals(PriceIndexCalculationMethod.INTERPOLATED))
            {
                // interpolate between data from two different months
                double weight = 1d - (endDate.DayOfMonth - 1d) / endDate.lengthOfMonth();
                return(InflationInterpolatedRateComputation.of(index, referenceStartMonth, referenceEndMonth, weight));
            }
            else if (indexCalculationMethod.Equals(PriceIndexCalculationMethod.MONTHLY))
            {
                // no interpolation
                return(InflationMonthlyRateComputation.of(index, referenceStartMonth, referenceEndMonth));
            }
            else
            {
                throw new System.ArgumentException("PriceIndexCalculationMethod " + indexCalculationMethod.ToString() + " is not supported");
            }
        }
Esempio n. 3
0
        //-------------------------------------------------------------------------
        public IborFutureTrade createTrade(LocalDate tradeDate, SecurityId securityId, Period minimumPeriod, int sequenceNumber, double quantity, double notional, double price, ReferenceData refData)
        {
            LocalDate referenceDate = calculateReferenceDateFromTradeDate(tradeDate, minimumPeriod, sequenceNumber, refData);
            LocalDate lastTradeDate = index.calculateFixingFromEffective(referenceDate, refData);
            YearMonth yearMonth     = YearMonth.from(lastTradeDate);

            return(createTrade(tradeDate, securityId, quantity, notional, price, yearMonth, lastTradeDate, referenceDate));
        }
        public DatedParameterMetadata metadata(LocalDate valuationDate, ReferenceData refData)
        {
            LocalDate nodeDate      = date(valuationDate, refData);
            LocalDate referenceDate = template.calculateReferenceDateFromTradeDate(valuationDate, refData);

            if (label.Length == 0)
            {
                return(YearMonthDateParameterMetadata.of(nodeDate, YearMonth.from(referenceDate)));
            }
            return(YearMonthDateParameterMetadata.of(nodeDate, YearMonth.from(referenceDate), label));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "quarterly10th") public void test_nextOrSameQuarterly10th(java.time.LocalDate super, java.time.LocalDate expect1, java.time.LocalDate expect2, java.time.LocalDate expect3)
	  public virtual void test_nextOrSameQuarterly10th(LocalDate @base, LocalDate expect1, LocalDate expect2, LocalDate expect3)
	  {
		LocalDate date = @base.plusDays(1);
		while (!date.isAfter(expect1))
		{
		  assertEquals(DateSequences.QUARTERLY_10TH.nextOrSame(date), expect1);
		  assertEquals(DateSequences.QUARTERLY_10TH.nthOrSame(date, 1), expect1);
		  assertEquals(DateSequences.QUARTERLY_10TH.nthOrSame(date, 2), expect2);
		  assertEquals(DateSequences.QUARTERLY_10TH.nthOrSame(date, 3), expect3);
		  date = date.plusDays(1);
		}
		assertEquals(DateSequences.QUARTERLY_10TH.dateMatching(YearMonth.from(date)), expect1);
	  }
Esempio n. 6
0
        public virtual void test_metadata_end()
        {
            IborFutureCurveNode node          = IborFutureCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD, LABEL);
            LocalDate           date          = LocalDate.of(2015, 10, 20);
            LocalDate           referenceDate = TEMPLATE.calculateReferenceDateFromTradeDate(date, REF_DATA);
            LocalDate           maturityDate  = TEMPLATE.Index.calculateMaturityFromEffective(referenceDate, REF_DATA);
            ParameterMetadata   metadata      = node.metadata(date, REF_DATA);

            assertEquals(metadata.Label, LABEL);
            assertTrue(metadata is YearMonthDateParameterMetadata);
            assertEquals(((YearMonthDateParameterMetadata)metadata).Date, maturityDate);
            assertEquals(((YearMonthDateParameterMetadata)metadata).YearMonth, YearMonth.from(referenceDate));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "quarterlyImm") public void test_nextOrSameQuarterlyImm(java.time.LocalDate super, java.time.LocalDate immDate1, java.time.LocalDate immDate2, java.time.LocalDate immDate3)
	  public virtual void test_nextOrSameQuarterlyImm(LocalDate @base, LocalDate immDate1, LocalDate immDate2, LocalDate immDate3)
	  {
		LocalDate date = @base.plusDays(1);
		while (!date.isAfter(immDate1))
		{
		  assertEquals(DateSequences.QUARTERLY_IMM.nextOrSame(date), immDate1);
		  assertEquals(DateSequences.QUARTERLY_IMM.nthOrSame(date, 1), immDate1);
		  assertEquals(DateSequences.QUARTERLY_IMM.nthOrSame(date, 2), immDate2);
		  assertEquals(DateSequences.QUARTERLY_IMM.nthOrSame(date, 3), immDate3);
		  date = date.plusDays(1);
		}
		assertEquals(DateSequences.QUARTERLY_IMM.dateMatching(YearMonth.from(date)), immDate1);
	  }
Esempio n. 8
0
        public virtual void test_metadata_last_fixing()
        {
            IborFutureCurveNode    node       = IborFutureCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD, LABEL).withDate(CurveNodeDate.LAST_FIXING);
            ImmutableMarketData    marketData = ImmutableMarketData.builder(VAL_DATE).addValue(QUOTE_ID, 0.0d).build();
            IborFutureTrade        trade      = node.trade(1d, marketData, REF_DATA);
            LocalDate              fixingDate = trade.Product.FixingDate;
            DatedParameterMetadata metadata   = node.metadata(VAL_DATE, REF_DATA);

            assertEquals(metadata.Date, fixingDate);
            LocalDate referenceDate = TEMPLATE.calculateReferenceDateFromTradeDate(VAL_DATE, REF_DATA);

            assertEquals(((YearMonthDateParameterMetadata)metadata).YearMonth, YearMonth.from(referenceDate));
        }
        private UnitParameterSensitivities unitParameterSensitivity(YearMonth month)
        {
            // If fixing in the past, check time series and returns the historic month price index if present
            if (month.isBefore(YearMonth.from(valuationDate)))
            {
                if (fixings.get(month.atEndOfMonth()).HasValue)
                {
                    return(UnitParameterSensitivities.empty());
                }
            }
            double nbMonth = numberOfMonths(month);

            return(UnitParameterSensitivities.of(curve.yValueParameterSensitivity(nbMonth)));
        }
        //-------------------------------------------------------------------------
        public PointSensitivityBuilder valuePointSensitivity(PriceIndexObservation observation)
        {
            YearMonth fixingMonth = observation.FixingMonth;

            // If fixing in the past, check time series and returns the historic month price index if present
            if (fixingMonth.isBefore(YearMonth.from(valuationDate)))
            {
                if (fixings.get(fixingMonth.atEndOfMonth()).HasValue)
                {
                    return(PointSensitivityBuilder.none());
                }
            }
            return(InflationRateSensitivity.of(observation, 1d));
        }
        public virtual void value_multiplicative()
        {
            InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE, SEASONALITY_MULTIPLICATIVE_DEF);

            for (int i = 1; i < TEST_MONTHS.Length; i++)
            {
                double nbMonths      = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS);
                double valueComputed = curveComputed.yValue(nbMonths);
                int    x             = (int)((nbMonths + 12) % 12);
                double valueNoAdj    = EXTENDED_CURVE_2.yValue(nbMonths);
                double adj           = SEASONALITY_MULTIPLICATIVE_COMP_2.get(x);
                double valueExpected = valueNoAdj * adj;
                assertEquals(valueExpected, valueComputed, TOLERANCE_VALUE);
            }
        }
        private static DoubleArray seasonalityCompounded(LocalDate valDate, YearMonth fixingMonth, DoubleArray seasonality, System.Func <double, double, double> adjustmentFunction)
        {
            double nbMonths = YearMonth.from(valDate).until(fixingMonth, MONTHS);

            double[] seasonalityCompoundedArray = new double[12];
            int      lastMonthIndex             = fixingMonth.Month.Value - 2;

            seasonalityCompoundedArray[(int)((nbMonths + 12 + 1) % 12)] = seasonality.get((lastMonthIndex + 1) % 12);
            for (int i = 1; i < 12; i++)
            {
                int j = (int)((nbMonths + 12 + 1 + i) % 12);
                seasonalityCompoundedArray[j] = adjustmentFunction(seasonalityCompoundedArray[(j - 1 + 12) % 12], seasonality.get((lastMonthIndex + 1 + i) % 12));
            }
            return(DoubleArray.ofUnsafe(seasonalityCompoundedArray));
        }
        public virtual void value_additive()
        {
            InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE, SEASONALITY_ADDITIVE_DEF);

            for (int i = 1; i < TEST_MONTHS.Length; i++)
            {
                double      nbMonths      = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS);
                double      valueComputed = curveComputed.yValue(nbMonths);
                int         x             = (int)((nbMonths + 12) % 12);
                double      valueNoAdj    = EXTENDED_CURVE_2.yValue(nbMonths);
                DoubleArray seasonalityAdditiveCompounded = seasonalityCompounded(VAL_DATE_2, LAST_FIX_MONTH_2, SEASONALITY_ADDITIVE, (v, a) => v + a);
                double      adj           = seasonalityAdditiveCompounded.get(x);
                double      valueExpected = valueNoAdj + adj;
                assertEquals(valueExpected, valueComputed, TOLERANCE_VALUE);
            }
        }
Esempio n. 14
0
 public virtual void test_value_parameter_sensitivity_futfixing()
 {
     for (int i = 0; i < TEST_MONTHS.Length; i++)
     {
         YearMonth fixingMonth = TEST_OBS[i].FixingMonth;
         if (!fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && !USCPI_TS.containsDate(fixingMonth.atEndOfMonth()))
         {
             InflationRateSensitivity       ptsExpected = (InflationRateSensitivity)InflationRateSensitivity.of(TEST_OBS[i], 1d);
             CurrencyParameterSensitivities psComputed  = INSTANCE_WITH_FUTFIXING.parameterSensitivity(ptsExpected);
             double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS);
             UnitParameterSensitivities     sens1      = UnitParameterSensitivities.of(CURVE_INFL2.yValueParameterSensitivity(x));
             CurrencyParameterSensitivities psExpected = sens1.multipliedBy(ptsExpected.Currency, ptsExpected.Sensitivity);
             assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_DELTA), "test " + i);
         }
     }
 }
        //-------------------------------------------------------------------------
        public double value(PriceIndexObservation observation)
        {
            YearMonth fixingMonth = observation.FixingMonth;

            // If fixing in the past, check time series and returns the historic month price index if present
            if (fixingMonth.isBefore(YearMonth.from(valuationDate)))
            {
                double?fixing = fixings.get(fixingMonth.atEndOfMonth());
                if (fixing.HasValue)
                {
                    return(fixing.Value);
                }
            }
            // otherwise, return the estimate from the curve.
            double nbMonth = numberOfMonths(fixingMonth);

            return(curve.yValue(nbMonth));
        }
Esempio n. 16
0
 public virtual void test_value_pts_sensitivity_futfixing()
 {
     for (int i = 0; i < TEST_MONTHS.Length; i++)
     {
         PointSensitivityBuilder ptsComputed = INSTANCE_WITH_FUTFIXING.valuePointSensitivity(TEST_OBS[i]);
         YearMonth fixingMonth = TEST_OBS[i].FixingMonth;
         PointSensitivityBuilder ptsExpected;
         if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth()))
         {
             ptsExpected = PointSensitivityBuilder.none();
         }
         else
         {
             ptsExpected = InflationRateSensitivity.of(TEST_OBS[i], 1d);
         }
         assertTrue(ptsComputed.build().equalWithTolerance(ptsExpected.build(), TOLERANCE_VALUE), "test " + i);
     }
 }
Esempio n. 17
0
 /* Test values when a fixing in the futures in present in the TS. */
 public virtual void test_value_futfixing()
 {
     for (int i = 0; i < TEST_MONTHS.Length; i++)
     {
         double    valueComputed = INSTANCE_WITH_FUTFIXING.value(TEST_OBS[i]);
         YearMonth fixingMonth   = TEST_OBS[i].FixingMonth;
         double    valueExpected;
         if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth()))
         {
             valueExpected = USCPI_TS.get(fixingMonth.atEndOfMonth()).Value;
         }
         else
         {
             double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS);
             valueExpected = CURVE_INFL2.yValue(x);
         }
         assertEquals(valueComputed, valueExpected, TOLERANCE_VALUE, "test " + i);
     }
 }
        /// <summary>
        /// Creates a rate observation where the start index value is known.
        /// <para>
        /// This is typically used for capital indexed bonds.
        /// The rate is calculated between the value of {@code firstIndexValue}
        /// and the observed value at the end month linked to the specified end date.
        /// This method requires that {@code firstIndexValue} is present.
        ///
        /// </para>
        /// </summary>
        /// <param name="endDate">  the end date of the period </param>
        /// <returns> the rate observation </returns>
        public RateComputation createRateComputation(LocalDate endDate)
        {
            if (firstIndexValue == null)
            {
                throw new System.InvalidOperationException("First index value must be specified");
            }
            YearMonth referenceEndMonth = YearMonth.from(endDate.minus(lag));

            if (indexCalculationMethod.Equals(PriceIndexCalculationMethod.INTERPOLATED))
            {
                // interpolate between data from two different months
                double weight = 1d - (endDate.DayOfMonth - 1d) / endDate.lengthOfMonth();
                return(InflationEndInterpolatedRateComputation.of(index, firstIndexValue.Value, referenceEndMonth, weight));
            }
            else if (indexCalculationMethod.Equals(PriceIndexCalculationMethod.MONTHLY))
            {
                // no interpolation
                return(InflationEndMonthRateComputation.of(index, firstIndexValue.Value, referenceEndMonth));
            }
            else if (indexCalculationMethod.Equals(PriceIndexCalculationMethod.INTERPOLATED_JAPAN))
            {
                // interpolation, Japan
                double weight     = 1d;
                int    dayOfMonth = endDate.DayOfMonth;
                if (dayOfMonth > 10)
                {
                    weight -= (dayOfMonth - 10d) / endDate.lengthOfMonth();
                }
                else if (dayOfMonth < 10)
                {
                    weight           -= (dayOfMonth + endDate.minusMonths(1).lengthOfMonth() - 10d) / endDate.minusMonths(1).lengthOfMonth();
                    referenceEndMonth = referenceEndMonth.minusMonths(1);
                }
                return(InflationEndInterpolatedRateComputation.of(index, firstIndexValue.Value, referenceEndMonth, weight));
            }
            else
            {
                throw new System.ArgumentException("PriceIndexCalculationMethod " + indexCalculationMethod.ToString() + " is not supported");
            }
        }
        public virtual void pointAndParameterPriceIndex()
        {
            double                 eps           = 1.0e-13;
            LocalDate              valuationDate = LocalDate.of(2014, 1, 22);
            DoubleArray            x             = DoubleArray.of(0.5, 1.0, 2.0);
            DoubleArray            y             = DoubleArray.of(224.2, 262.6, 277.5);
            CurveInterpolator      interp        = CurveInterpolators.NATURAL_CUBIC_SPLINE;
            string                 curveName     = "GB_RPI_CURVE";
            InterpolatedNodalCurve interpCurve   = InterpolatedNodalCurve.of(Curves.prices(curveName), x, y, interp);
            ImmutableRatesProvider provider      = ImmutableRatesProvider.builder(VAL_DATE).priceIndexCurve(GB_RPI, interpCurve).timeSeries(GB_RPI, LocalDateDoubleTimeSeries.of(date(2013, 11, 30), 200)).build();

            double    pointSensiValue = 2.5;
            YearMonth refMonth        = YearMonth.from(valuationDate.plusMonths(9));
            InflationRateSensitivity       pointSensi = InflationRateSensitivity.of(PriceIndexObservation.of(GB_RPI, refMonth), pointSensiValue);
            CurrencyParameterSensitivities computed   = provider.parameterSensitivity(pointSensi.build());
            DoubleArray sensiComputed = computed.Sensitivities.get(0).Sensitivity;

            InflationRateSensitivity pointSensi1 = InflationRateSensitivity.of(PriceIndexObservation.of(GB_RPI, refMonth), 1);
            DoubleArray sensiExpectedUnit        = provider.priceIndexValues(GB_RPI).parameterSensitivity(pointSensi1).Sensitivities.get(0).Sensitivity;

            assertTrue(sensiComputed.equalWithTolerance(sensiExpectedUnit.multipliedBy(pointSensiValue), eps));
        }
Esempio n. 20
0
        /// <summary>
        /// Obtains an instance from a curve without initial fixing point and month-on-month seasonal adjustment.
        /// <para>
        /// The total adjustment is computed by accumulation of the monthly adjustment, starting with no adjustment for the
        /// last fixing month.
        ///
        /// </para>
        /// </summary>
        /// <param name="curveWithoutFixing">  the curve without the fixing </param>
        /// <param name="valuationDate">  the valuation date of the curve </param>
        /// <param name="lastMonth">  the last month for which the fixing is known </param>
        /// <param name="lastFixingValue">  the value of the last fixing </param>
        /// <param name="seasonalityDefinition">  the seasonality definition, which is made of month-on-month adjustment
        ///   and the adjustment type </param>
        /// <returns> the seasonal curve instance </returns>
        public static InflationNodalCurve of(NodalCurve curveWithoutFixing, LocalDate valuationDate, YearMonth lastMonth, double lastFixingValue, SeasonalityDefinition seasonalityDefinition)
        {
            YearMonth valuationMonth = YearMonth.from(valuationDate);

            ArgChecker.isTrue(lastMonth.isBefore(valuationMonth), "Last fixing month must be before valuation date");
            double      nbMonth = valuationMonth.until(lastMonth, MONTHS);
            DoubleArray x       = curveWithoutFixing.XValues;

            ArgChecker.isTrue(nbMonth < x.get(0), "The first estimation month should be after the last known index fixing");
            NodalCurve extendedCurve = curveWithoutFixing.withNode(nbMonth, lastFixingValue, ParameterMetadata.empty());

            double[] seasonalityCompoundedArray = new double[12];
            int      lastMonthIndex             = lastMonth.Month.Value - 1;

            seasonalityCompoundedArray[(int)((nbMonth + 12 + 1) % 12)] = seasonalityDefinition.SeasonalityMonthOnMonth.get(lastMonthIndex % 12);
            for (int i = 1; i < 12; i++)
            {
                int j = (int)((nbMonth + 12 + 1 + i) % 12);
                seasonalityCompoundedArray[j] = seasonalityDefinition.AdjustmentType.applyShift(seasonalityCompoundedArray[(j - 1 + 12) % 12], seasonalityDefinition.SeasonalityMonthOnMonth.get((lastMonthIndex + i) % 12));
            }
            return(new InflationNodalCurve(extendedCurve, DoubleArray.ofUnsafe(seasonalityCompoundedArray), seasonalityDefinition.AdjustmentType));
        }
Esempio n. 21
0
        //-------------------------------------------------------------------------
        public virtual void test_bind()
        {
            RatesCurveGroupDefinition test = RatesCurveGroupDefinition.builder().name(CurveGroupName.of("Test")).addCurve(CURVE_DEFN1, GBP, GBP_LIBOR_1M, GBP_LIBOR_3M).addForwardCurve(CURVE_DEFN_I, GB_RPI).addSeasonality(CURVE_NAME_I, SEASONALITY_ADDITIVE_DEF).build();
            LocalDate valuationDate        = LocalDate.of(2015, 11, 10);
            LocalDate lastFixingDate       = LocalDate.of(2015, 10, 31);
            LocalDate otherFixingDate      = LocalDate.of(2015, 9, 30);
            double    lastFixingValue      = 234.56;
            IDictionary <Index, LocalDateDoubleTimeSeries> map = ImmutableMap.of(GB_RPI, LocalDateDoubleTimeSeries.builder().put(lastFixingDate, 234.56).put(otherFixingDate, lastFixingValue - 1).build());
            RatesCurveGroupDefinition testBound = test.bindTimeSeries(valuationDate, map);
            IList <CurveDefinition>   list      = testBound.CurveDefinitions;

            assertEquals(list.Count, 2);
            assertTrue(list[0] is InterpolatedNodalCurveDefinition);
            assertTrue(list[1] is InflationNodalCurveDefinition);
            InflationNodalCurveDefinition seasonDef = (InflationNodalCurveDefinition)list[1];

            assertEquals(seasonDef.CurveWithoutFixingDefinition, CURVE_DEFN_I);
            assertEquals(seasonDef.LastFixingMonth, YearMonth.from(lastFixingDate));
            assertEquals(seasonDef.LastFixingValue, lastFixingValue);
            assertEquals(seasonDef.Name, CURVE_NAME_I);
            assertEquals(seasonDef.SeasonalityDefinition, SEASONALITY_ADDITIVE_DEF);
            assertEquals(seasonDef.YValueType, ValueType.PRICE_INDEX);
        }
Esempio n. 22
0
 // builds node times from node dates
 private DoubleArray buildNodeTimes(LocalDate valuationDate, CurveMetadata metadata)
 {
     if (metadata.XValueType.Equals(ValueType.YEAR_FRACTION))
     {
         return(DoubleArray.of(ParameterCount, i =>
         {
             LocalDate nodeDate = ((DatedParameterMetadata)metadata.ParameterMetadata.get().get(i)).Date;
             return DayCount.get().yearFraction(valuationDate, nodeDate);
         }));
     }
     else if (metadata.XValueType.Equals(ValueType.MONTHS))
     {
         return(DoubleArray.of(ParameterCount, i =>
         {
             LocalDate nodeDate = ((DatedParameterMetadata)metadata.ParameterMetadata.get().get(i)).Date;
             return YearMonth.from(valuationDate).until(YearMonth.from(nodeDate), MONTHS);
         }));
     }
     else
     {
         throw new System.ArgumentException("Metadata XValueType should be YearFraction or Months in curve definition");
     }
 }
        public virtual void parameter_sensitivity_additive()
        {
            InflationNodalCurve curve = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE, SEASONALITY_ADDITIVE_DEF);
            double shift = 1.0E-2;

            for (int i = 1; i < TEST_MONTHS.Length; i++)
            {
                double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS);
                UnitParameterSensitivity psComputed = curve.yValueParameterSensitivity(nbMonths);
                for (int j = 0; j < TIMES.size(); j++)
                {
                    double[] valuePM = new double[2];
                    for (int pm = 0; pm < 2; pm++)
                    {
                        DoubleArray            shiftedValues   = VALUES.with(j, VALUES.get(j) + (1 - 2 * pm) * shift);
                        InterpolatedNodalCurve intCurveShifted = InterpolatedNodalCurve.of(METADATA, TIMES, shiftedValues, INTERPOLATOR);
                        InflationNodalCurve    seaCurveShifted = InflationNodalCurve.of(intCurveShifted, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE, SEASONALITY_ADDITIVE_DEF);
                        valuePM[pm] = seaCurveShifted.yValue(nbMonths);
                    }
                    assertEquals(psComputed.Sensitivity.get(j), (valuePM[0] - valuePM[1]) / (2 * shift), TOLERANCE_DELTA);
                }
            }
        }
Esempio n. 24
0
        //-------------------------------------------------------------------------
        public virtual void test_createRateComputation_Monthly()
        {
            InflationRateCalculation         test = InflationRateCalculation.builder().index(GB_HICP).lag(Period.ofMonths(3)).indexCalculationMethod(MONTHLY).firstIndexValue(START_INDEX).build();
            InflationEndMonthRateComputation obs1 = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, YearMonth.from(DATE_2015_02_05).minusMonths(3));
            InflationEndMonthRateComputation obs2 = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, YearMonth.from(DATE_2015_03_07).minusMonths(3));
            InflationEndMonthRateComputation obs3 = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, YearMonth.from(DATE_2015_04_05).minusMonths(3));

            assertEquals(test.createRateComputation(DATE_2015_02_05), obs1);
            assertEquals(test.createRateComputation(DATE_2015_03_07), obs2);
            assertEquals(test.createRateComputation(DATE_2015_04_05), obs3);
        }
        public virtual void test_inflation_interpolated()
        {
            BusinessDayAdjustment    bda              = BusinessDayAdjustment.of(FOLLOWING, GBLO);
            PeriodicSchedule         accrualSchedule  = PeriodicSchedule.builder().startDate(DATE_14_06_09).endDate(DATE_19_06_09).frequency(Frequency.ofYears(5)).businessDayAdjustment(bda).build();
            PaymentSchedule          paymentSchedule  = PaymentSchedule.builder().paymentFrequency(Frequency.ofYears(5)).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            InflationRateCalculation rateCalc         = InflationRateCalculation.builder().index(GB_RPI).indexCalculationMethod(INTERPOLATED).lag(Period.ofMonths(3)).build();
            NotionalSchedule         notionalSchedule = NotionalSchedule.of(GBP, 1000d);
            RateCalculationSwapLeg   test             = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(rateCalc).build();

            assertEquals(test.StartDate, AdjustableDate.of(DATE_14_06_09, bda));
            assertEquals(test.EndDate, AdjustableDate.of(DATE_19_06_09, bda));
            assertEquals(test.Currency, GBP);
            assertEquals(test.PayReceive, RECEIVE);
            assertEquals(test.AccrualSchedule, accrualSchedule);
            assertEquals(test.PaymentSchedule, paymentSchedule);
            assertEquals(test.NotionalSchedule, notionalSchedule);
            assertEquals(test.Calculation, rateCalc);

            double            weight     = 1.0 - 9.0 / 30.0;
            RatePaymentPeriod rpp0       = RatePaymentPeriod.builder().paymentDate(DaysAdjustment.ofBusinessDays(2, GBLO).adjust(bda.adjust(DATE_19_06_09, REF_DATA), REF_DATA)).accrualPeriods(RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09, REF_DATA)).endDate(bda.adjust(DATE_19_06_09, REF_DATA)).unadjustedStartDate(DATE_14_06_09).unadjustedEndDate(DATE_19_06_09).yearFraction(1.0).rateComputation(InflationInterpolatedRateComputation.of(GB_RPI, YearMonth.from(bda.adjust(DATE_14_06_09, REF_DATA)).minusMonths(3), YearMonth.from(bda.adjust(DATE_19_06_09, REF_DATA)).minusMonths(3), weight)).build()).dayCount(ONE_ONE).currency(GBP).notional(1000d).build();
            ResolvedSwapLeg   expected   = ResolvedSwapLeg.builder().paymentPeriods(rpp0).payReceive(RECEIVE).type(SwapLegType.INFLATION).build();
            ResolvedSwapLeg   testExpand = test.resolve(REF_DATA);

            assertEquals(testExpand, expected);
        }
Esempio n. 26
0
        public virtual void test_createAccrualPeriods_Interpolated()
        {
            InflationRateCalculation test             = InflationRateCalculation.builder().index(CH_CPI).lag(Period.ofMonths(3)).indexCalculationMethod(INTERPOLATED).build();
            double            weight1                 = 1.0 - 4.0 / 28.0;
            double            weight2                 = 1.0 - 6.0 / 31.0;
            double            weight3                 = 1.0 - 4.0 / 30.0;
            RateAccrualPeriod rap1                    = RateAccrualPeriod.builder(ACCRUAL1).yearFraction(1.0).rateComputation(InflationInterpolatedRateComputation.of(CH_CPI, YearMonth.from(DATE_2015_01_05).minusMonths(3), YearMonth.from(DATE_2015_02_05).minusMonths(3), weight1)).build();
            RateAccrualPeriod rap2                    = RateAccrualPeriod.builder(ACCRUAL2).yearFraction(1.0).rateComputation(InflationInterpolatedRateComputation.of(CH_CPI, YearMonth.from(DATE_2015_02_05).minusMonths(3), YearMonth.from(DATE_2015_03_07).minusMonths(3), weight2)).build();
            RateAccrualPeriod rap3                    = RateAccrualPeriod.builder(ACCRUAL3).yearFraction(1.0).rateComputation(InflationInterpolatedRateComputation.of(CH_CPI, YearMonth.from(DATE_2015_03_07).minusMonths(3), YearMonth.from(DATE_2015_04_05).minusMonths(3), weight3)).build();
            ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA);

            assertEquals(periods, ImmutableList.of(rap1, rap2, rap3));
        }
Esempio n. 27
0
        public virtual void test_createRateComputation_InterpolatedJapan()
        {
            LocalDate date1 = LocalDate.of(2013, 3, 9);
            LocalDate date2 = LocalDate.of(2013, 3, 10);
            LocalDate date3 = LocalDate.of(2013, 3, 11);
            InflationRateCalculation test = InflationRateCalculation.builder().index(JP_CPI_EXF).lag(Period.ofMonths(3)).indexCalculationMethod(INTERPOLATED_JAPAN).firstIndexValue(START_INDEX).build();
            double weight1 = 1.0 - (9.0 + 28.0 - 10.0) / 28.0;
            double weight2 = 1.0;
            double weight3 = 1.0 - 1.0 / 31.0;
            InflationEndInterpolatedRateComputation obs1 = InflationEndInterpolatedRateComputation.of(JP_CPI_EXF, START_INDEX, YearMonth.from(date1).minusMonths(4), weight1);
            InflationEndInterpolatedRateComputation obs2 = InflationEndInterpolatedRateComputation.of(JP_CPI_EXF, START_INDEX, YearMonth.from(date2).minusMonths(3), weight2);
            InflationEndInterpolatedRateComputation obs3 = InflationEndInterpolatedRateComputation.of(JP_CPI_EXF, START_INDEX, YearMonth.from(date3).minusMonths(3), weight3);

            assertEquals(test.createRateComputation(date1), obs1);
            assertEquals(test.createRateComputation(date2), obs2);
            assertEquals(test.createRateComputation(date3), obs3);
        }
Esempio n. 28
0
        public virtual void test_createAccrualPeriods_Monthly_firstKnown()
        {
            InflationRateCalculation          test    = InflationRateCalculation.builder().index(GB_HICP).lag(Period.ofMonths(3)).indexCalculationMethod(MONTHLY).firstIndexValue(123d).build();
            RateAccrualPeriod                 rap1    = RateAccrualPeriod.builder(ACCRUAL1).yearFraction(1.0).rateComputation(InflationEndMonthRateComputation.of(GB_HICP, 123d, YearMonth.from(DATE_2015_02_05).minusMonths(3))).build();
            RateAccrualPeriod                 rap2    = RateAccrualPeriod.builder(ACCRUAL2).yearFraction(1.0).rateComputation(InflationMonthlyRateComputation.of(GB_HICP, YearMonth.from(DATE_2015_02_05).minusMonths(3), YearMonth.from(DATE_2015_03_07).minusMonths(3))).build();
            RateAccrualPeriod                 rap3    = RateAccrualPeriod.builder(ACCRUAL3).yearFraction(1.0).rateComputation(InflationMonthlyRateComputation.of(GB_HICP, YearMonth.from(DATE_2015_03_07).minusMonths(3), YearMonth.from(DATE_2015_04_05).minusMonths(3))).build();
            ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA);

            assertEquals(periods, ImmutableList.of(rap1, rap2, rap3));
        }
 private double numberOfMonths(YearMonth month)
 {
     return(YearMonth.from(valuationDate).until(month, MONTHS));
 }
Esempio n. 30
0
        public virtual void test_createRateComputation_Interpolated()
        {
            InflationRateCalculation test = InflationRateCalculation.builder().index(CH_CPI).lag(Period.ofMonths(3)).indexCalculationMethod(INTERPOLATED).firstIndexValue(START_INDEX).build();
            double weight1 = 1.0 - 4.0 / 28.0;
            double weight2 = 1.0 - 6.0 / 31.0;
            double weight3 = 1.0 - 4.0 / 30.0;
            InflationEndInterpolatedRateComputation obs1 = InflationEndInterpolatedRateComputation.of(CH_CPI, START_INDEX, YearMonth.from(DATE_2015_02_05).minusMonths(3), weight1);
            InflationEndInterpolatedRateComputation obs2 = InflationEndInterpolatedRateComputation.of(CH_CPI, START_INDEX, YearMonth.from(DATE_2015_03_07).minusMonths(3), weight2);
            InflationEndInterpolatedRateComputation obs3 = InflationEndInterpolatedRateComputation.of(CH_CPI, START_INDEX, YearMonth.from(DATE_2015_04_05).minusMonths(3), weight3);

            assertEquals(test.createRateComputation(DATE_2015_02_05), obs1);
            assertEquals(test.createRateComputation(DATE_2015_03_07), obs2);
            assertEquals(test.createRateComputation(DATE_2015_04_05), obs3);
        }