SmileDeltaTermStructureParametersStrikeInterpolation extends SmileDeltaTermStructureParameters { public double getVolatility(final double time, final double strike, final double forward) { ArgumentChecker.isTrue(time >= 0, "Positive time"); final SmileDeltaParameters smile = getSmileForTime(time); final double[] strikes = smile.getStrike(forward); final Interpolator1DDataBundle volatilityInterpolation = _strikeInterpolator.getDataBundle(strikes, smile.getVolatility()); final double volatility = _strikeInterpolator.interpolate(volatilityInterpolation, strike); return volatility; } SmileDeltaTermStructureParametersStrikeInterpolation(final SmileDeltaParameters[] volatilityTerm);  SmileDeltaTermStructureParametersStrikeInterpolation(final SmileDeltaParameters[] volatilityTerm, final Interpolator1D strikeInterpolator);  SmileDeltaTermStructureParametersStrikeInterpolation(final SmileDeltaParameters[] volatilityTerm, final Interpolator1D strikeInterpolator, final Interpolator1D timeInterpolator);  SmileDeltaTermStructureParametersStrikeInterpolation(final double[] timeToExpiration, final double[] delta, final double[][] volatility);  SmileDeltaTermStructureParametersStrikeInterpolation(final double[] timeToExpiration, final double[] delta, final double[][] volatility, final Interpolator1D strikeInterpolator);  SmileDeltaTermStructureParametersStrikeInterpolation(final double[] timeToExpiration, final double[] delta, final double[] atm, final double[][] riskReversal, final double[][] strangle);  SmileDeltaTermStructureParametersStrikeInterpolation(final double[] timeToExpiration, final double[] delta, final double[] atm, final double[][] riskReversal, final double[][] strangle,
      final Interpolator1D strikeInterpolator);  SmileDeltaTermStructureParametersStrikeInterpolation(final double[] timeToExpiration, final double[] delta, final double[] atm, final double[][] riskReversal, final double[][] strangle,
      final Interpolator1D strikeInterpolator, final Interpolator1D timeInterpolator); @Override SmileDeltaTermStructureParametersStrikeInterpolation copy(); double getVolatility(final double time, final double strike, final double forward); VolatilityAndBucketedSensitivities getVolatilityAndSensitivities(final double time, final double strike, final double forward); @Override Double getVolatility(final Triple<Double, Double, Double> tsf); @Override VolatilityAndBucketedSensitivities getVolatilityAndSensitivities(final Triple<Double, Double, Double> tsf); Interpolator1D getStrikeInterpolator(); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test public void constructor2() { final double[][] vol = new double[NB_EXP][]; for (int loopexp = 0; loopexp < NB_EXP; loopexp++) { vol[loopexp] = VOLATILITY_TERM[loopexp].getVolatility(); } final SmileDeltaTermStructureParametersStrikeInterpolation smileTermVol = new SmileDeltaTermStructureParametersStrikeInterpolation(TIME_TO_EXPIRY, DELTA, vol); assertEquals("Smile by delta term structure: constructor", SMILE_TERM, smileTermVol); }
@Test public void volatilityAtPoint() { final double forward = 1.40; final double timeToExpiration = 0.50; final double[] strikes = SMILE_TERM.getVolatilityTerm()[2].getStrike(forward); final double volComputed = SMILE_TERM.getVolatility(timeToExpiration, strikes[1], forward); final double volExpected = SMILE_TERM.getVolatilityTerm()[2].getVolatility()[1]; assertEquals("Smile by delta term structure: volatility at a point", volExpected, volComputed, TOLERANCE_VOL); }
@Test public void volatilityStrikeInterpolation() { final double forward = 1.40; final double timeToExpiration = 0.50; final double strike = 1.50; final double[] strikes = SMILE_TERM.getVolatilityTerm()[2].getStrike(forward); final double[] vol = SMILE_TERM.getVolatilityTerm()[2].getVolatility(); final ArrayInterpolator1DDataBundle volatilityInterpolation = new ArrayInterpolator1DDataBundle(strikes, vol); final LinearInterpolator1D interpolator = new LinearInterpolator1D(); final double volExpected = interpolator.interpolate(volatilityInterpolation, strike); final double volComputed = SMILE_TERM.getVolatility(timeToExpiration, strike, forward); assertEquals("Smile by delta term structure: volatility interpolation on strike", volExpected, volComputed, TOLERANCE_VOL); }
@Test public void volatilityBelowFirstExpiry() { final double forward = 1.40; final double timeToExpiration = 0.05; final double strike = 1.45; final SmileDeltaParameters smile = new SmileDeltaParameters(timeToExpiration, ATM[0], DELTA, RISK_REVERSAL[0], STRANGLE[0]); final double[] strikes = smile.getStrike(forward); final double[] vol = smile.getVolatility(); final ArrayInterpolator1DDataBundle volatilityInterpolation = new ArrayInterpolator1DDataBundle(strikes, vol); final double volExpected = INTERPOLATOR_STRIKE.interpolate(volatilityInterpolation, strike); final double volComputed = SMILE_TERM.getVolatility(timeToExpiration, strike, forward); assertEquals("Smile by delta term structure: volatility interpolation on strike", volExpected, volComputed, TOLERANCE_VOL); }
@Test public void volatilityAboveLastExpiry() { final double forward = 1.40; final double timeToExpiration = 5.00; final double strike = 1.45; final SmileDeltaParameters smile = new SmileDeltaParameters(timeToExpiration, ATM[NB_EXP - 1], DELTA, RISK_REVERSAL[NB_EXP - 1], STRANGLE[NB_EXP - 1]); final double[] strikes = smile.getStrike(forward); final double[] vol = smile.getVolatility(); final ArrayInterpolator1DDataBundle volatilityInterpolation = new ArrayInterpolator1DDataBundle(strikes, vol); final double volExpected = INTERPOLATOR_STRIKE.interpolate(volatilityInterpolation, strike); final double volComputed = SMILE_TERM.getVolatility(timeToExpiration, strike, forward); assertEquals("Smile by delta term structure: volatility interpolation on strike", volExpected, volComputed, TOLERANCE_VOL); }
@Test public void volatilityTimeInterpolation() { final double forward = 1.40; final double timeToExpiration = 0.75; final double strike = 1.50; final double[] vol050 = SMILE_TERM.getVolatilityTerm()[2].getVolatility(); final double[] vol100 = SMILE_TERM.getVolatilityTerm()[3].getVolatility(); final double[] vol = new double[vol050.length]; for (int loopvol = 0; loopvol < vol050.length; loopvol++) { vol[loopvol] = Math.sqrt(((vol050[loopvol] * vol050[loopvol] * TIME_TO_EXPIRY[2] + vol100[loopvol] * vol100[loopvol] * TIME_TO_EXPIRY[3]) / 2.0) / timeToExpiration); } final SmileDeltaParameters smile = new SmileDeltaParameters(timeToExpiration, DELTA, vol); final double[] strikes = smile.getStrike(forward); final ArrayInterpolator1DDataBundle volatilityInterpolation = new ArrayInterpolator1DDataBundle(strikes, vol); final LinearInterpolator1D interpolator = new LinearInterpolator1D(); final double volExpected = interpolator.interpolate(volatilityInterpolation, strike); final double volComputed = SMILE_TERM.getVolatility(timeToExpiration, strike, forward); assertEquals("Smile by delta term structure: volatility interpolation on strike", volExpected, volComputed, TOLERANCE_VOL); final double volTriple = SMILE_TERM.getVolatility(new Triple<>(timeToExpiration, strike, forward)); assertEquals("Smile by delta term structure: volatility interpolation on strike", volComputed, volTriple, TOLERANCE_VOL); final SmileDeltaTermStructureParametersStrikeInterpolation smileTerm2 = new SmileDeltaTermStructureParametersStrikeInterpolation(TIME_TO_EXPIRY, DELTA, ATM, RISK_REVERSAL, STRANGLE, INTERPOLATOR_STRIKE, INTERPOLATOR_TIME); final double volComputed2 = smileTerm2.getVolatility(timeToExpiration, strike, forward); assertEquals("Smile by delta term structure: volatility interpolation on strike", volComputed, volComputed2, TOLERANCE_VOL); }
@Test(enabled = false) public void deltaSmile() { final double forward = 1.40; final double expiryMax = 2.0; final int nbExp = 50; final int nbVol = 2 * DELTA.length + 1; final double[][] strikes = new double[nbExp][nbVol]; final double[] expiries = new double[nbExp]; final double[] variancePeriodT = new double[nbVol]; final double[] volatilityT = new double[nbVol]; final double[] variancePeriod0 = new double[nbVol]; final double[] variancePeriod1 = new double[nbVol]; for (int loopexp = 0; loopexp < nbExp; loopexp++) { expiries[loopexp] = loopexp * expiryMax / nbExp; final ArrayInterpolator1DDataBundle interpData = new ArrayInterpolator1DDataBundle(TIME_TO_EXPIRY, new double[NB_EXP]); final int indexLower = interpData.getLowerBoundIndex(expiries[loopexp]); if (expiries[loopexp] < 1.0E-10) { for (int loopvol = 0; loopvol < nbVol; loopvol++) { volatilityT[loopvol] = SMILE_TERM.getVolatilityTerm()[indexLower].getVolatility()[loopvol]; } } else { final double weight0 = (TIME_TO_EXPIRY[indexLower + 1] - expiries[loopexp]) / (TIME_TO_EXPIRY[indexLower + 1] - TIME_TO_EXPIRY[indexLower]); for (int loopvol = 0; loopvol < nbVol; loopvol++) { variancePeriod0[loopvol] = SMILE_TERM.getVolatilityTerm()[indexLower].getVolatility()[loopvol] * SMILE_TERM.getVolatilityTerm()[indexLower].getVolatility()[loopvol] * TIME_TO_EXPIRY[indexLower]; variancePeriod1[loopvol] = SMILE_TERM.getVolatilityTerm()[indexLower + 1].getVolatility()[loopvol] * SMILE_TERM.getVolatilityTerm()[indexLower + 1].getVolatility()[loopvol] * TIME_TO_EXPIRY[indexLower + 1]; variancePeriodT[loopvol] = weight0 * variancePeriod0[loopvol] + (1 - weight0) * variancePeriod1[loopvol]; volatilityT[loopvol] = Math.sqrt(variancePeriodT[loopvol] / expiries[loopexp]); } } final SmileDeltaParameters smile = new SmileDeltaParameters(expiries[loopexp], DELTA, volatilityT); strikes[loopexp] = smile.getStrike(forward); } }
@Test(enabled = false) public void performance() { long startTime, endTime; final int nbTest = 100000; final double forward = 1.40; final double timeToExpiration = 0.50; final double strike = 1.50; @SuppressWarnings("unused") double volComputed; startTime = System.currentTimeMillis(); for (int looptest = 0; looptest < nbTest; looptest++) { volComputed = SMILE_TERM.getVolatility(timeToExpiration, strike, forward); } endTime = System.currentTimeMillis(); System.out.println(nbTest + " Smile Delta volatility: " + (endTime - startTime) + " ms"); }