MultiCapFloorPricer { public DoubleMatrix2D capVolVega(double[] capletVols) { DoubleMatrix2D vega = vegaFromCapletVols(capletVols); double[] capPrices = priceFromCapletVols(capletVols); double[] capVols = impliedVols(capPrices); double[] capVega = vega(capVols); int nCaplets = capletVols.length; DoubleMatrix2D capVolVega = new DoubleMatrix2D(_nCaps, nCaplets); for (int i = 0; i < _nCaps; i++) { double[] temp = capVolVega.getData()[i]; double[] vegaRow = vega.getData()[i]; double invVega = 1.0 / capVega[i]; for (int j = 0; j < nCaplets; j++) { temp[j] = invVega * vegaRow[j]; } } return capVolVega; } MultiCapFloorPricer(List<CapFloor> caps,  MulticurveProviderInterface curves); double[] getCapletVols(VolatilitySurface volSurface); double[] price(VolatilitySurface volSurface); double[] priceFromCapletVols(double[] capletVols); double[] price(double[] capVolatilities); double[] impliedVols(double[] capPrices); double[] impliedVols(VolatilitySurface volSurface); double[] vega(double[] capVolatilities); DoubleMatrix2D vegaFromCapletVols(double[] capletVols); DoubleMatrix2D capVolVega(double[] capletVols); double[] getCapletExpiries(); double[] getStrikes(); double[] getIntrinsicCapValues(); double[] getCapStartTimes(); double[] getCapEndTimes(); DoublesPair[] getExpiryStrikeArray(); int getNumCaps(); int getNumCaplets(); double[] getCapletForwardRates();  }
@Test public void capVolVegaTest() { double eps = 1e-5; MulticurveProviderDiscount yieldCurve = getYieldCurves(); List<CapFloor> caps = getAllCaps(); int n = caps.size(); MultiCapFloorPricer multiPricer = new MultiCapFloorPricer(caps, yieldCurve); int m = multiPricer.getNumCaplets(); double[] capletVols = new double[m]; Arrays.fill(capletVols, 0.35); double[] capVols = multiPricer.impliedVols(multiPricer.priceFromCapletVols(capletVols)); assertEquals(n, capVols.length); for (int i = 0; i < n; i++) { assertEquals("cap vol", 0.35, capVols[i], 1e-9); } DoubleMatrix2D capVolVega = multiPricer.capVolVega(capletVols); DoubleMatrix2D fdVega = new DoubleMatrix2D(n, m); double[][] data = fdVega.getData(); for (int j = 0; j < m; j++) { double temp = capletVols[j]; capletVols[j] += eps; double[] up = multiPricer.impliedVols(multiPricer.priceFromCapletVols(capletVols)); capletVols[j] -= 2 * eps; double[] down = multiPricer.impliedVols(multiPricer.priceFromCapletVols(capletVols)); capletVols[j] = temp; for (int i = 0; i < n; i++) { data[i][j] = (up[i] - down[i]) / 2 / eps; } } AssertMatrix.assertEqualsMatrix(fdVega, capVolVega, 5e-6); }