Examples of VolatilitySurfaceInterpolator


Examples of com.opengamma.analytics.financial.model.volatility.surface.VolatilitySurfaceInterpolator

  public static Builder builder() {
    return new Builder();
  }

  private EquityVarianceSwapStaticReplicationPricer(final Builder builder) {
    _surfaceInterpolator = new VolatilitySurfaceInterpolator(builder.getSmileInterpolator(), builder.getTimeInterpolator(), builder.useLogTime(),
        builder.useIntegratedVariance(), builder.useLogValue());
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.surface.VolatilitySurfaceInterpolator

  public static Builder builder() {
    return new Builder();
  }

  private EquityVarianceSwapPricer(final Builder builder) {
    _surfaceInterpolator = new VolatilitySurfaceInterpolator(builder.getSmileInterpolator(), builder.getTimeInterpolator(), builder.useLogTime(),
        builder.useIntegratedVariance(), builder.useLogValue());
  }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.surface.VolatilitySurfaceInterpolator

      final double[] forwards = volGrid.getForwards();
      final double[] volExpiries = volGrid.getExpiries();
      final int nExpiries = volGrid.getNumExpiries();
      final double[][] strikes = volGrid.getStrikes();
      final double[][] vols = volGrid.getVolatilities();
      final VolatilitySurfaceInterpolator surfaceInterpolator = surfaceBundle.getInterpolator();
      final GeneralSmileInterpolator strikeInterpolator = surfaceInterpolator.getSmileInterpolator();

      // Base price and set of independent smile fits (one function vol(k) for each expiry)
      final Double pvBase = option.accept(_pricer, market);
      final Function1D<Double, Double>[] smileFitsBase = surfaceInterpolator.getIndependentSmileFits(volGrid);

      // Bump and reprice - loop over expiry and strike
      final List<Triple<Double, Double, Double>> triplesExpiryStrikeVega = new ArrayList<>();
      // TODO: REVIEW: We can drastically reduce the time it takes to compute this if we are sensible about avoiding points which almost certainly won't have any sensitivity
      // Of course, this is all based upon the interpolor's scheme...
      final int expiryIndex = SurfaceArrayUtils.getLowerBoundIndex(volExpiries, option.getTimeToExpiry());
      for (int t = Math.max(0, expiryIndex - 3); t < Math.min(nExpiries, expiryIndex + 4); t++) {
        final int nStrikes = strikes[t].length;
        final int strikeIndex = SurfaceArrayUtils.getLowerBoundIndex(strikes[t], option.getStrike());
        for (int k = Math.max(0, strikeIndex - 6); k < Math.min(nStrikes, strikeIndex + 7); k++) {
          // TODO: REVIEW We only recompute the smile function for the specific expiry we are bumping..
          final double[] bumpedVols = Arrays.copyOf(vols[t], nStrikes);
          bumpedVols[k] = vols[t][k] - shift;
          final Function1D<Double, Double> thisExpirysSmile = strikeInterpolator.getVolatilityFunction(forwards[t], strikes[t], volExpiries[t], bumpedVols);
          final Function1D<Double, Double>[] scenarioSmileFits = Arrays.copyOf(smileFitsBase, smileFitsBase.length);
          scenarioSmileFits[t] = thisExpirysSmile;
          final BlackVolatilitySurfaceMoneynessFcnBackedByGrid shiftedSurface = surfaceInterpolator.combineIndependentSmileFits(scenarioSmileFits, volGrid);
          //BlackVolatilitySurfaceMoneynessFcnBackedByGrid shiftedSurface = surfaceInterpolator.getBumpedVolatilitySurface(volGrid, t, k, -shift);
          final StaticReplicationDataBundle shiftedMarket = market.withShiftedSurface(shiftedSurface);
          final Double pvScenario = option.accept(_pricer, shiftedMarket);

          ArgumentChecker.notNull(pvScenario, "Null PV in shifted scenario, T = " + volExpiries[t] + ", k = " + strikes[t][k]);
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.surface.VolatilitySurfaceInterpolator

      final GeneralSmileInterpolator smileInterpolator = deserializer.fieldValueToObject(GeneralSmileInterpolator.class, message.getByName(SMILE_INTERPOLATOR_FIELD_NAME));
      final Interpolator1D timeInterpolator = deserializer.fieldValueToObject(Interpolator1D.class, message.getByName(TIME_INTERPOLATOR_FIELD_NAME));
      final boolean useLogTime = message.getBoolean(LOG_TIME_FIELD_NAME);
      final boolean useIntegratedVariance = message.getBoolean(INTEGRATED_VARIANCE_FIELD_NAME);
      final boolean useLogValue = message.getBoolean(LOG_VALUE_FIELD_NAME);
      return new VolatilitySurfaceInterpolator(smileInterpolator, timeInterpolator, useLogTime, useIntegratedVariance, useLogValue);
    }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.surface.VolatilitySurfaceInterpolator

  public static void SABRSurface() {

    final SmileSurfaceDataBundle surfdatabundle = new StandardSmileSurfaceDataBundle(fwd, datearray, strikematrix, volsmatrix);

    final VolatilitySurfaceInterpolator surf = new VolatilitySurfaceInterpolator(DEFAULT_SMILE_INTERPOLATOR);
    final BlackVolatilitySurfaceMoneynessFcnBackedByGrid surf1 = surf.getVolatilitySurface(surfdatabundle);

    for (int i = 0; i < 11; i++) {
      System.out.println(fwd.getForward(datearray[i]));
      for (int j = 0; j < 13; j++) {
        System.out.println("Expiry = " + datearray[i] + ", Strike = " + strikematrix[2][j] + ", " + "Vol = " + surf1.getVolatility(datearray[i], strikematrix[2][j]));
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.surface.VolatilitySurfaceInterpolator

    @Override
    public BlackVolatilitySurfaceMoneynessFcnBackedByGrid buildObject(final FudgeDeserializer deserializer, final FudgeMsg message) {
      final Object surface = deserializer.fieldValueToObject(message.getByName(SURFACE_FIELD_NAME));
      final Object forwardCurve = deserializer.fieldValueToObject(message.getByName(FORWARD_CURVE_FIELD_NAME));
      final SmileSurfaceDataBundle grid = deserializer.fieldValueToObject(SmileSurfaceDataBundle.class, message.getByName(GRID_FIELD_NAME));
      final VolatilitySurfaceInterpolator interpolator = deserializer.fieldValueToObject(VolatilitySurfaceInterpolator.class, message.getByName(INTERPOLATOR_FIELD_NAME));
      if (surface instanceof Surface) {
        return new BlackVolatilitySurfaceMoneynessFcnBackedByGrid((Surface<Double, Double, Double>) surface, (ForwardCurve) forwardCurve, grid, interpolator);
      }
      throw new OpenGammaRuntimeException("Expected Surface, got " + surface);
    }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.surface.VolatilitySurfaceInterpolator

  public void testMoneynessSurfaceBackedByGrid() {
    final ConstantDoublesSurface surface = ConstantDoublesSurface.from(0.5);
    final ForwardCurve curve = new ForwardCurve(1);
    final StandardSmileSurfaceDataBundle gridData = new StandardSmileSurfaceDataBundle(100.0, new double[] {101,102,103}, new double[] {1,2,3},
        new double[][] {{80,80},{100,100},{120,120}}, new double[][] {{.3,.25},{.2,.2},{.3,.25}}, new LinearInterpolator1D() );
    final VolatilitySurfaceInterpolator interpolator = new VolatilitySurfaceInterpolator();
    final BlackVolatilitySurfaceMoneynessFcnBackedByGrid moneyness1 = new BlackVolatilitySurfaceMoneynessFcnBackedByGrid(surface, curve, gridData, interpolator);
    BlackVolatilitySurfaceMoneynessFcnBackedByGrid moneyness2 = cycleObject(BlackVolatilitySurfaceMoneynessFcnBackedByGrid.class, moneyness1);
    assertArrayEquals(moneyness1.getGridData().getExpiries(), moneyness2.getGridData().getExpiries(), 0);
    assertArrayEquals(moneyness1.getGridData().getForwards(), moneyness2.getGridData().getForwards(), 0);
    assert2DArrayEquals(moneyness1.getGridData().getStrikes(), moneyness2.getGridData().getStrikes(), 0);
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.surface.VolatilitySurfaceInterpolator

    assertEquals(interpolator, cycleObject(SmileInterpolatorSABR.class, interpolator));
  }

  @Test
  public void testVolatilitySurfaceInterpolator() {
    final VolatilitySurfaceInterpolator fitter = cycleObject(VolatilitySurfaceInterpolator.class, VOLATILITY_SURFACE_INTERPOLATOR);
    assertEquals(VOLATILITY_SURFACE_INTERPOLATOR.getSmileInterpolator(), fitter.getSmileInterpolator());
    assertEquals(VOLATILITY_SURFACE_INTERPOLATOR, fitter);
    final BlackVolatilitySurfaceMoneyness surface1 = VOLATILITY_SURFACE_INTERPOLATOR.getVolatilitySurface(FOREX_DATA);
    final BlackVolatilitySurfaceMoneyness surface2 = cycleObject(BlackVolatilitySurfaceMoneyness.class, surface1);
    assertEquals(surface1.getForwardCurve().getSpot(), surface2.getForwardCurve().getSpot());
    assertCurveEquals(surface1.getForwardCurve().getForwardCurve(), surface2.getForwardCurve().getForwardCurve());
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.surface.VolatilitySurfaceInterpolator

    final ValueSpecification resultSpec = new ValueSpecification(getValueRequirementNames()[0], targetSpec, resultProperties);
    final NodalDoublesSurface vegaSurface;
    if (market.getVolatilitySurface() instanceof BlackVolatilitySurfaceMoneynessFcnBackedByGrid) {
      // unpack the market data, including the interpolators
      final BlackVolatilitySurfaceMoneynessFcnBackedByGrid surfaceBundle = (BlackVolatilitySurfaceMoneynessFcnBackedByGrid) market.getVolatilitySurface();
      final VolatilitySurfaceInterpolator surfaceInterpolator = surfaceBundle.getInterpolator();
      final GeneralSmileInterpolator strikeInterpolator = surfaceInterpolator.getSmileInterpolator();
      final SmileSurfaceDataBundle volGrid = surfaceBundle.getGridData();
      final double[] forwards = volGrid.getForwards();
      final double[] expiries = volGrid.getExpiries();
      final int nExpiries = volGrid.getNumExpiries();
      final double optionExpiry = vanillaOptions.iterator().next().getTimeToExpiry();
      final double[][] strikes = volGrid.getStrikes();
      final double[][] vols = volGrid.getVolatilities();

      // Prices of vanillas in base scenario
      final int nVanillas = vanillaOptions.size();
      final EquityIndexOption[] vanillas = vanillaOptions.toArray(new EquityIndexOption[nVanillas]);
      final Double[] basePrices = new Double[nVanillas];
      for (int v = 0; v < nVanillas; v++) {
        basePrices[v] = PVC.visitEquityIndexOption(vanillas[v], market);
      }

      // Smile fits across strikes in base scenario, one per expiry
      final Function1D<Double, Double>[] smileFitsBase = surfaceInterpolator.getIndependentSmileFits(volGrid);

      // Bump market at each expiry and strike scenario
      // In each scenario, reprice each of the underlying vanillaOptions
      // NOTE: Only computing down-shift as this appears to produce more stable risk, and is faster
      final List<Triple<Double, Double, Double>> triplesExpiryStrikeVega = new ArrayList<>();
      final int expiryIndex = SurfaceArrayUtils.getLowerBoundIndex(expiries, optionExpiry);
      for (int t = Math.max(0, expiryIndex - 3); t < Math.min(nExpiries, expiryIndex + 4); t++) {
        final int nStrikes = strikes[t].length;
        int idxLow = SurfaceArrayUtils.getLowerBoundIndex(strikes[t], vanillas[0].getStrike());
        int idxHigh = idxLow;
        for (int v = 1; v < nVanillas; v++) {
          final int idxV = SurfaceArrayUtils.getLowerBoundIndex(strikes[t], vanillas[v].getStrike());
          idxLow = Math.min(idxLow, idxV);
          idxHigh = Math.max(idxHigh, idxV);
        }

        for (int k = Math.max(0, idxLow - 6); k < Math.min(nStrikes, idxHigh + 16); k++) {
          // Scenario (t,k)
          // TODO: REVIEW Each scenario only requires a single new smile fit in k. We only recompute the smile function for the expiry we are bumping..
          final double[] bumpedVols = Arrays.copyOf(vols[t], nStrikes);
          bumpedVols[k] = vols[t][k] - SHIFT;
          final Function1D<Double, Double> thisExpirysSmile = strikeInterpolator.getVolatilityFunction(forwards[t], strikes[t], expiries[t], bumpedVols);
          final Function1D<Double, Double>[] scenarioSmileFits = Arrays.copyOf(smileFitsBase, smileFitsBase.length);
          scenarioSmileFits[t] = thisExpirysSmile;
          final BlackVolatilitySurfaceMoneynessFcnBackedByGrid shiftedSurface = surfaceInterpolator.combineIndependentSmileFits(scenarioSmileFits, volGrid);
          final StaticReplicationDataBundle shiftedMarket = market.withShiftedSurface(shiftedSurface);
          // Sensitivities
          for (int v = 0; v < nVanillas; v++) {
            final Double shiftedPV = vanillas[v].accept(PVC, shiftedMarket);
            Validate.notNull(shiftedPV, "Null PV in shifted scenario, T = " + expiries[t] + ", k = " + strikes[t][k]);
View Full Code Here

Examples of com.opengamma.analytics.financial.model.volatility.surface.VolatilitySurfaceInterpolator

    final GeneralSmileInterpolator smileInterpolator = getSmileInterpolator(desiredValue);
    final String interpolator = desiredValue.getConstraint(PROPERTY_TIME_INTERPOLATOR);
    final String leftExtrapolator = desiredValue.getConstraint(PROPERTY_TIME_LEFT_EXTRAPOLATOR);
    final String rightExtrapolator = desiredValue.getConstraint(PROPERTY_TIME_RIGHT_EXTRAPOLATOR);
    final Interpolator1D timeInterpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(interpolator, leftExtrapolator, rightExtrapolator);
    final VolatilitySurfaceInterpolator surfaceInterpolator = new VolatilitySurfaceInterpolator(smileInterpolator, timeInterpolator, useLogTime, useIntegratedVariance, useLogValue);
    final ValueProperties properties = getResultProperties(desiredValue);
    final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.BLACK_VOLATILITY_SURFACE_INTERPOLATOR, target.toSpecification(), properties);
    return Collections.singleton(new ComputedValue(spec, surfaceInterpolator));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.