final double[] sensitivity = new double[nbNodePoint];
for (int loopnode = 0; loopnode < nbNodePoint; loopnode++) {
final double[] yieldBumped = curveInt.getYDataAsPrimitive().clone();
yieldBumped[loopnode] += _shift;
final YieldAndDiscountCurve dscBumped = new YieldCurve(curveInt.getName(), new InterpolatedDoublesCurve(curveInt.getXDataAsPrimitive(), yieldBumped, curveInt.getInterpolator(), true));
final HullWhiteIssuerProviderDiscount marketDscBumped = new HullWhiteIssuerProviderDiscount(new IssuerProviderDiscount(issuercurves.getMulticurveProvider().withDiscountFactor(ccy, dscBumped),
issuercurves.getIssuerProvider().getIssuerCurves()), issuercurves.getHullWhiteParameters(), issuercurves.getHullWhiteIssuerCurrency());
final Double valueBumped = instrument.accept(_valueCalculator, marketDscBumped);
final Double valueDiff = valueBumped + valueInitMinus;
sensitivity[loopnode] = valueDiff / _shift;
}
final String name = issuercurves.getMulticurveProvider().getName(ccy);
result = result.plus(name, new DoubleMatrix1D(sensitivity));
}
// Forward ON
final Set<IndexON> indexON = issuercurves.getMulticurveProvider().getIndexesON();
for (final IndexON index : indexON) {
final YieldAndDiscountCurve curve = issuercurves.getMulticurveProvider().getCurve(index);
ArgumentChecker.isTrue(curve instanceof YieldCurve, "Curve should be a YieldCurve");
final YieldCurve curveYield = (YieldCurve) curve;
ArgumentChecker.isTrue(curveYield.getCurve() instanceof InterpolatedDoublesCurve, "Yield curve should be based on InterpolatedDoublesCurve");
final InterpolatedDoublesCurve curveInt = (InterpolatedDoublesCurve) curveYield.getCurve();
final int nbNodePoint = curveInt.getXDataAsPrimitive().length;
final double[] sensitivity = new double[nbNodePoint];
for (int loopnode = 0; loopnode < nbNodePoint; loopnode++) {
final double[] yieldBumped = curveInt.getYDataAsPrimitive().clone();
yieldBumped[loopnode] += _shift;
final YieldAndDiscountCurve fwdBumped = new YieldCurve(curveInt.getName(), new InterpolatedDoublesCurve(curveInt.getXDataAsPrimitive(), yieldBumped, curveInt.getInterpolator(), true));
final HullWhiteIssuerProviderDiscount marketFwdBumped = new HullWhiteIssuerProviderDiscount(new IssuerProviderDiscount(issuercurves.getMulticurveProvider().withForward(index, fwdBumped),
issuercurves.getIssuerProvider().getIssuerCurves()), issuercurves.getHullWhiteParameters(), issuercurves.getHullWhiteIssuerCurrency());
final Double valueBumped = instrument.accept(_valueCalculator, marketFwdBumped);
final Double valueDiff = valueBumped + valueInitMinus;
sensitivity[loopnode] = valueDiff / _shift;
}
final String name = issuercurves.getMulticurveProvider().getName(index);
result = result.plus(name, new DoubleMatrix1D(sensitivity));
}
// Forward Ibor - symmetrical
final Set<IborIndex> indexForward = issuercurves.getMulticurveProvider().getIndexesIbor();
for (final IborIndex index : indexForward) {
final YieldAndDiscountCurve curve = issuercurves.getMulticurveProvider().getCurve(index);
ArgumentChecker.isTrue(curve instanceof YieldCurve, "Curve should be a YieldCurve");
final YieldCurve curveYield = (YieldCurve) curve;
ArgumentChecker.isTrue(curveYield.getCurve() instanceof InterpolatedDoublesCurve, "Yield curve should be based on InterpolatedDoublesCurve");
final InterpolatedDoublesCurve curveInt = (InterpolatedDoublesCurve) curveYield.getCurve();
final int nbNodePoint = curveInt.getXDataAsPrimitive().length;
final double[] sensitivity = new double[nbNodePoint];
for (int loopnode = 0; loopnode < nbNodePoint; loopnode++) {
final double[] yieldBumpedPlus = curveInt.getYDataAsPrimitive().clone();
yieldBumpedPlus[loopnode] += _shift;
final YieldAndDiscountCurve fwdBumpedPlus = new YieldCurve(curveInt.getName(), new InterpolatedDoublesCurve(curveInt.getXDataAsPrimitive(), yieldBumpedPlus, curveInt.getInterpolator(), true));
final HullWhiteIssuerProviderDiscount marketFwdBumpedPlus = new HullWhiteIssuerProviderDiscount(new IssuerProviderDiscount(issuercurves.getMulticurveProvider().withForward(index,
fwdBumpedPlus),
issuercurves.getIssuerProvider().getIssuerCurves()), issuercurves.getHullWhiteParameters(), issuercurves.getHullWhiteIssuerCurrency());
final Double valueBumpedPlus = instrument.accept(_valueCalculator, marketFwdBumpedPlus);
final double[] yieldBumpedMinus = curveInt.getYDataAsPrimitive().clone();
yieldBumpedMinus[loopnode] -= _shift;
final YieldAndDiscountCurve fwdBumpedMinus = new YieldCurve(curveInt.getName(),
new InterpolatedDoublesCurve(curveInt.getXDataAsPrimitive(), yieldBumpedMinus, curveInt.getInterpolator(), true));
final HullWhiteIssuerProviderDiscount marketFwdBumpedMinus = new HullWhiteIssuerProviderDiscount(new IssuerProviderDiscount(issuercurves.getMulticurveProvider().withForward(index,
fwdBumpedMinus),
issuercurves.getIssuerProvider().getIssuerCurves()), issuercurves.getHullWhiteParameters(), issuercurves.getHullWhiteIssuerCurrency());
final Double valueBumpedMinus = instrument.accept(_valueCalculator, marketFwdBumpedMinus);
final Double valueDiff = valueBumpedPlus - valueBumpedMinus;
sensitivity[loopnode] = valueDiff / (2 * _shift);
}
final String name = issuercurves.getMulticurveProvider().getName(index);
result = result.plus(name, new DoubleMatrix1D(sensitivity));
}
// Discounting issuer
final Set<Pair<String, Currency>> issuerCcies = issuercurves.getIssuerProvider().getIssuersCurrencies();
for (final Pair<String, Currency> ic : issuerCcies) {
final YieldAndDiscountCurve curve = issuercurves.getIssuerProvider().getCurve(ic);
ArgumentChecker.isTrue(curve instanceof YieldCurve, "Curve should be a YieldCurve");
final YieldCurve curveYield = (YieldCurve) curve;
ArgumentChecker.isTrue(curveYield.getCurve() instanceof InterpolatedDoublesCurve, "Yield curve should be based on InterpolatedDoublesCurve");
final InterpolatedDoublesCurve curveInt = (InterpolatedDoublesCurve) curveYield.getCurve();
final int nbNodePoint = curveInt.getXDataAsPrimitive().length;
final double[] sensitivity = new double[nbNodePoint];
for (int loopnode = 0; loopnode < nbNodePoint; loopnode++) {
final double[] yieldBumped = curveInt.getYDataAsPrimitive().clone();
yieldBumped[loopnode] += _shift;
final YieldAndDiscountCurve icBumped = new YieldCurve(curveInt.getName(), new InterpolatedDoublesCurve(curveInt.getXDataAsPrimitive(), yieldBumped, curveInt.getInterpolator(), true));
final HullWhiteIssuerProviderDiscount providerIcBumped = new HullWhiteIssuerProviderDiscount(issuercurves.getIssuerProvider().withIssuerCurrency(ic, icBumped),
issuercurves.getHullWhiteParameters(), issuercurves.getHullWhiteIssuerCurrency());
final Double valueBumped = instrument.accept(_valueCalculator, providerIcBumped);
final Double valueDiff = valueBumped + valueInitMinus;
sensitivity[loopnode] = valueDiff / _shift;
}