All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opengamma.strata.pricer.impl.rate.ForwardInflationMonthlyRateComputationFn Maven / Gradle / Ivy

There is a newer version: 2.12.46
Show newest version
/*
 * Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.strata.pricer.impl.rate;

import java.time.LocalDate;

import com.opengamma.strata.basics.index.PriceIndex;
import com.opengamma.strata.market.explain.ExplainKey;
import com.opengamma.strata.market.explain.ExplainMapBuilder;
import com.opengamma.strata.market.sensitivity.PointSensitivityBuilder;
import com.opengamma.strata.pricer.rate.PriceIndexValues;
import com.opengamma.strata.pricer.rate.RateComputationFn;
import com.opengamma.strata.pricer.rate.RatesProvider;
import com.opengamma.strata.product.rate.InflationMonthlyRateComputation;

/**
 * Rate computation implementation for a price index.
 * 

* The pay-off for a unit notional is {@code (IndexEnd / IndexStart - 1)}, where * start index value and end index value are simply returned by {@code RatesProvider}. */ public class ForwardInflationMonthlyRateComputationFn implements RateComputationFn { /** * Default instance. */ public static final ForwardInflationMonthlyRateComputationFn DEFAULT = new ForwardInflationMonthlyRateComputationFn(); /** * Creates an instance. */ public ForwardInflationMonthlyRateComputationFn() { } //------------------------------------------------------------------------- @Override public double rate( InflationMonthlyRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { PriceIndex index = computation.getIndex(); PriceIndexValues values = provider.priceIndexValues(index); double indexStart = values.value(computation.getStartObservation()); double indexEnd = values.value(computation.getEndObservation()); return indexEnd / indexStart - 1d; } @Override public PointSensitivityBuilder rateSensitivity( InflationMonthlyRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { PriceIndex index = computation.getIndex(); PriceIndexValues values = provider.priceIndexValues(index); double indexStart = values.value(computation.getStartObservation()); double indexEnd = values.value(computation.getEndObservation()); double indexStartInv = 1d / indexStart; PointSensitivityBuilder sensi1 = values.valuePointSensitivity(computation.getStartObservation()) .multipliedBy(-indexEnd * indexStartInv * indexStartInv); PointSensitivityBuilder sensi2 = values.valuePointSensitivity(computation.getEndObservation()) .multipliedBy(indexStartInv); return sensi1.combinedWith(sensi2); } @Override public double explainRate( InflationMonthlyRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider, ExplainMapBuilder builder) { PriceIndex index = computation.getIndex(); PriceIndexValues values = provider.priceIndexValues(index); double indexStart = values.value(computation.getStartObservation()); double indexEnd = values.value(computation.getEndObservation()); builder.addListEntry(ExplainKey.OBSERVATIONS, child -> child .put(ExplainKey.ENTRY_TYPE, "InflationObservation") .put(ExplainKey.FIXING_DATE, computation.getStartObservation().getFixingMonth().atEndOfMonth()) .put(ExplainKey.INDEX, index) .put(ExplainKey.INDEX_VALUE, indexStart)); builder.addListEntry(ExplainKey.OBSERVATIONS, child -> child .put(ExplainKey.ENTRY_TYPE, "InflationObservation") .put(ExplainKey.FIXING_DATE, computation.getEndObservation().getFixingMonth().atEndOfMonth()) .put(ExplainKey.INDEX, index) .put(ExplainKey.INDEX_VALUE, indexEnd)); double rate = rate(computation, startDate, endDate, provider); builder.put(ExplainKey.COMBINED_RATE, rate); return rate; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy