private CurrencyParameterSensitivity parameterSensitivity(FxOptionSensitivity point) { double expiryTime = point.Expiry; double strike = currencyPair.isInverse(point.CurrencyPair) ? 1d / point.Strike : point.Strike; double forward = currencyPair.isInverse(point.CurrencyPair) ? 1d / point.Forward : point.Forward; double pointValue = point.Sensitivity; DoubleMatrix bucketedSensi = smile.volatilityAndSensitivities(expiryTime, strike, forward).Sensitivities; double[] times = smile.Expiries.toArray(); int nTimes = times.Length; IList <double> sensiList = new List <double>(); IList <ParameterMetadata> paramList = new List <ParameterMetadata>(); for (int i = 0; i < nTimes; ++i) { DoubleArray deltas = smile.VolatilityTerm.get(i).Delta; int nDeltas = deltas.size(); int nDeltasTotal = 2 * nDeltas + 1; double[] deltasTotal = new double[nDeltasTotal]; // absolute delta deltasTotal[nDeltas] = 0.5d; for (int j = 0; j < nDeltas; ++j) { deltasTotal[j] = 1d - deltas.get(j); deltasTotal[2 * nDeltas - j] = deltas.get(j); } for (int j = 0; j < nDeltasTotal; ++j) { sensiList.Add(bucketedSensi.get(i, j) * pointValue); DeltaStrike absoluteDelta = DeltaStrike.of(deltasTotal[j]); ParameterMetadata parameterMetadata = FxVolatilitySurfaceYearFractionParameterMetadata.of(times[i], absoluteDelta, currencyPair); paramList.Add(parameterMetadata); } } return(CurrencyParameterSensitivity.of(name, paramList, point.Currency, DoubleArray.copyOf(sensiList))); }
//------------------------------------------------------------------------- private static ImmutableList <ParameterMetadata> createParameterMetadata(double expiry, DoubleArray delta) { ArgChecker.notNull(delta, "delta"); int nbDelta = delta.size(); ParameterMetadata[] parameterMetadata = new ParameterMetadata[2 * nbDelta + 1]; parameterMetadata[nbDelta] = GenericVolatilitySurfaceYearFractionParameterMetadata.of(expiry, DeltaStrike.of(0.5d)); for (int i = 0; i < nbDelta; i++) { parameterMetadata[i] = GenericVolatilitySurfaceYearFractionParameterMetadata.of(expiry, DeltaStrike.of(1d - delta.get(i))); // Put parameterMetadata[2 * nbDelta - i] = GenericVolatilitySurfaceYearFractionParameterMetadata.of(expiry, DeltaStrike.of(delta.get(i))); // Call } return(ImmutableList.copyOf(parameterMetadata)); }