MultiCapFloorPricer { public double[] vega(double[] capVolatilities) { ArgumentChecker.notEmpty(capVolatilities, "null cap volatilities"); ArgumentChecker.isTrue(_nCaps == capVolatilities.length, "capVolatilities wrong length"); double[] res = new double[_nCaps]; for (int i = 0; i < _nCaps; i++) { int n = _capToCapletsMap[i].length; double sum = 0.0; for (int j = 0; j < n; j++) { sum += BlackFormulaRepository.vega(_capToOptionsMap[i][j], capVolatilities[i]); } res[i] = sum; } return res; } 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 vegaFromCapVolsTest() { MulticurveProviderDiscount yieldCurve = getYieldCurves(); double[] capVols = getAllCapVols(); List<CapFloor> caps = getAllCaps(); int n = caps.size(); MultiCapFloorPricer multiPricer = new MultiCapFloorPricer(caps, yieldCurve); double[] vega = multiPricer.vega(capVols); assertEquals("wrong number of vegas", n, vega.length); for (int j = 0; j < n; j++) { CapFloorPricer pricer = new CapFloorPricer(caps.get(j), yieldCurve); double v = pricer.vega(capVols[j]); assertEquals(v, vega[j], 1e-9); } }
@Test public void vegaTest() { 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.5); double[] capletPrices = multiPricer.priceFromCapletVols(capletVols); double[][] fdVega = new double[n][m]; for (int j = 0; j < m; j++) { double temp = capletVols[j]; capletVols[j] += eps; double[] up = multiPricer.priceFromCapletVols(capletVols); capletVols[j] -= 2 * eps; double[] down = multiPricer.priceFromCapletVols(capletVols); capletVols[j] = temp; for (int i = 0; i < n; i++) { fdVega[i][j] = (up[i] - down[i]) / 2 / eps; } } double[][] vega = multiPricer.vegaFromCapletVols(capletVols).getData(); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { assertEquals(i + "\t" + j, fdVega[i][j], vega[i][j], Math.max(1e-12, 1e-8 * capletPrices[i])); } } }