Example #1
0
        //-------------------------------------------------------------------------
        public virtual void test_valuePointSensitivity_fixing()
        {
            SimplePriceIndexValues test = SimplePriceIndexValues.of(US_CPI_U, VAL_DATE, CURVE_NOFIX, USCPI_TS);
            PriceIndexObservation  obs  = PriceIndexObservation.of(US_CPI_U, VAL_MONTH.minusMonths(3));

            assertEquals(test.valuePointSensitivity(obs), PointSensitivityBuilder.none());
        }
        /// <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");
            }
        }