Package com.opengamma.analytics.math.surface

Examples of com.opengamma.analytics.math.surface.InterpolatedDoublesSurface


   * @return The node sensitivities.
   */
  public PresentValueBlackSwaptionSensitivity calculateNodeSensitivities(final PresentValueBlackSwaptionSensitivity sensitivities, final BlackFlatSwaptionParameters parameters) {
    Validate.isTrue(parameters.getGeneratorSwap().equals(sensitivities.getGeneratorSwap()), "Sensitivities and parameters should refer to the same swap generator");
    ArgumentChecker.isTrue(parameters.getVolatilitySurface() instanceof InterpolatedDoublesSurface, "Can only calculate node sensitivities for interpolated double surfaces");
    final InterpolatedDoublesSurface interpolatedSurface = (InterpolatedDoublesSurface) parameters.getVolatilitySurface();
    final Map<Double, Interpolator1DDataBundle> volatilityData = (Map<Double, Interpolator1DDataBundle>) interpolatedSurface.getInterpolatorData();
    SurfaceValue volatilityNode = new SurfaceValue();
    for (final Entry<DoublesPair, Double> entry : sensitivities.getSensitivity().getMap().entrySet()) {
      final Map<DoublesPair, Double> weight = interpolatedSurface.getInterpolator().getNodeSensitivitiesForValue(volatilityData, entry.getKey());
      volatilityNode = SurfaceValue.plus(volatilityNode, SurfaceValue.multiplyBy(SurfaceValue.from(weight), entry.getValue()));
    }
    return new PresentValueBlackSwaptionSensitivity(volatilityNode, parameters.getGeneratorSwap());
  }
View Full Code Here


  public NodalDoublesSurface calcBlackVegaForEntireSurface(final InstrumentDerivative derivative, final StaticReplicationDataBundle market, final double shift) {
    ArgumentChecker.notNull(derivative, "null EquityDerivative");
    ArgumentChecker.notNull(market, "null EquityOptionDataBundle");

    if (market.getVolatilitySurface().getSurface() instanceof InterpolatedDoublesSurface) {
      final InterpolatedDoublesSurface blackSurf = (InterpolatedDoublesSurface) market.getVolatilitySurface().getSurface();
      final Double[] maturities = blackSurf.getXData();
      final Double[] strikes = blackSurf.getYData();
      final int nNodes = maturities.length;
      ArgumentChecker.isTrue(nNodes == strikes.length, "Number of strikes must match number of nodes");
      // Bump and reprice
      final Double[] vegas = new Double[nNodes];
      for (int j = 0; j < nNodes; j++) {
View Full Code Here

      final double shift) {

    final Surface<Double, Double, Double> surface = market.getVolatilitySurface().getSurface();
    ArgumentChecker.isTrue(surface instanceof InterpolatedDoublesSurface, "Currently will only accept a Equity VolatilitySurfaces based on an InterpolatedDoublesSurface");

    final InterpolatedDoublesSurface blackSurf = (InterpolatedDoublesSurface) surface;
    final InterpolatedSurfaceAdditiveShiftFunction volShifter = new InterpolatedSurfaceAdditiveShiftFunction();

    // shift UP
    final InterpolatedDoublesSurface bumpedVolUp = volShifter.evaluate(blackSurf, maturity, strike, shift);
    StaticReplicationDataBundle bumpedMarket = new StaticReplicationDataBundle(market.getVolatilitySurface().withSurface(bumpedVolUp), market.getDiscountCurve(),
        market.getForwardCurve());
    final double pvUp = derivative.accept(_pricer, bumpedMarket);

    // shift DOWN
    final InterpolatedDoublesSurface bumpedVolDown = volShifter.evaluate(blackSurf, maturity, strike, -shift);
    bumpedMarket = new StaticReplicationDataBundle(market.getVolatilitySurface().withSurface(bumpedVolDown), market.getDiscountCurve(), market.getForwardCurve());
    final double pvDown = derivative.accept(_pricer, bumpedMarket);

    // Centered-difference result
    return (pvUp - pvDown) / (2.0 * shift);
 
View Full Code Here

    /** Field name. */
    public static final String INVERSE_JACOBIANS_MATRICES_FIELD_NAME = "matrices";

    @Override
    public SABRFittedSurfaces buildObject(final FudgeDeserializer deserializer, final FudgeMsg message) {
      final InterpolatedDoublesSurface alphaSurface = deserializer.fieldValueToObject(InterpolatedDoublesSurface.class, message.getByName(ALPHA_SURFACE_FIELD_NAME));
      final InterpolatedDoublesSurface betaSurface = deserializer.fieldValueToObject(InterpolatedDoublesSurface.class, message.getByName(BETA_SURFACE_FIELD_NAME));
      final InterpolatedDoublesSurface nuSurface = deserializer.fieldValueToObject(InterpolatedDoublesSurface.class, message.getByName(NU_SURFACE_FIELD_NAME));
      final InterpolatedDoublesSurface rhoSurface = deserializer.fieldValueToObject(InterpolatedDoublesSurface.class, message.getByName(RHO_SURFACE_FIELD_NAME));
      final List<FudgeField> pairFields = message.getAllByName(INVERSE_JACOBIANS_PAIRS_FIELD_NAME);
      final List<FudgeField> matricesFields = message.getAllByName(INVERSE_JACOBIANS_MATRICES_FIELD_NAME);
      if (pairFields.size() != matricesFields.size()) {
        throw new OpenGammaRuntimeException("Should never happen");
      }
View Full Code Here

    /** Field name. */
    public static final String CURRENCY_FIELD_NAME = "Currency";

    @Override
    public HestonFittedSurfaces buildObject(final FudgeDeserializer deserializer, final FudgeMsg message) {
      final InterpolatedDoublesSurface kappaSurface = deserializer.fieldValueToObject(InterpolatedDoublesSurface.class, message.getByName(KAPPA_SURFACE_FIELD_NAME));
      final InterpolatedDoublesSurface thetaSurface = deserializer.fieldValueToObject(InterpolatedDoublesSurface.class, message.getByName(THETA_SURFACE_FIELD_NAME));
      final InterpolatedDoublesSurface vol0Surface = deserializer.fieldValueToObject(InterpolatedDoublesSurface.class, message.getByName(VOL0_SURFACE_FIELD_NAME));
      final InterpolatedDoublesSurface omegaSurface = deserializer.fieldValueToObject(InterpolatedDoublesSurface.class, message.getByName(OMEGA_SURFACE_FIELD_NAME));
      final InterpolatedDoublesSurface rhoSurface = deserializer.fieldValueToObject(InterpolatedDoublesSurface.class, message.getByName(RHO_SURFACE_FIELD_NAME));
      final Currency currency = deserializer.fieldValueToObject(Currency.class, message.getByName(CURRENCY_FIELD_NAME));
      final List<FudgeField> pairFields = message.getAllByName(INVERSE_JACOBIANS_PAIRS_FIELD_NAME);
      final List<FudgeField> matricesFields = message.getAllByName(INVERSE_JACOBIANS_MATRICES_FIELD_NAME);
      if (pairFields.size() != matricesFields.size()) {
        throw new OpenGammaRuntimeException("Should never happen");
View Full Code Here

   */
  @Test(expectedExceptions = IllegalArgumentException.class)
  public void testSurfaceWithoutStrikeExtrapolation() {
    final CombinedInterpolatorExtrapolator interpOnlyStrike = getInterpolator(Interpolator1DFactory.LINEAR);
    final Interpolator2D interp2D = new GridInterpolator2D(INTERPOLATOR_1D_EXPIRY, interpOnlyStrike);
    final InterpolatedDoublesSurface surface = new InterpolatedDoublesSurface(EXPIRIES, STRIKES, VOLS, interp2D);
    final BlackVolatilitySurfaceStrike volSurface = new BlackVolatilitySurfaceStrike(surface);
    PRICER.expectedVariance(swap1, new StaticReplicationDataBundle(volSurface, DISCOUNT, FORWARD_CURVE));
  }
View Full Code Here

   * If the smile/skew translates with the forward, we always expect zero forward sensitivity.
   */
  @Test
  public void testForwardSensitivityForDeltaStrikeParameterisation() {

    final InterpolatedDoublesSurface DELTA_SURFACE = new InterpolatedDoublesSurface(EXPIRIES, CALLDELTAs, VOLS, new GridInterpolator2D(INTERPOLATOR_1D_LINEAR, INTERPOLATOR_1D_DBLQUAD));
    final BlackVolatilitySurfaceDelta DELTA_VOL_SURFACE = new BlackVolatilitySurfaceDelta(DELTA_SURFACE, FORWARD_CURVE);
    final StaticReplicationDataBundle DELTA_MARKET = new StaticReplicationDataBundle(DELTA_VOL_SURFACE, FUNDING, FORWARD_CURVE);

    final double relShift = 0.1;

View Full Code Here

  parallelVega = 4583.95175875458
   */
  @Test
  public void testBlackVegaForDeltaSurface() {

    final InterpolatedDoublesSurface DELTA_SURFACE = new InterpolatedDoublesSurface(EXPIRIES, CALLDELTAs, VOLS, new GridInterpolator2D(INTERPOLATOR_1D_LINEAR, INTERPOLATOR_1D_DBLQUAD));
    final BlackVolatilitySurfaceDelta DELTA_VOL_SURFACE = new BlackVolatilitySurfaceDelta(DELTA_SURFACE, FORWARD_CURVE);
    final StaticReplicationDataBundle DELTA_MARKET = new StaticReplicationDataBundle(DELTA_VOL_SURFACE, FUNDING, FORWARD_CURVE);

    // Compute the surface
    final NodalDoublesSurface vegaSurface = DELTA_CAL.calcBlackVegaForEntireSurface(swapStartsNow, DELTA_MARKET);
View Full Code Here

  @Test
  public void testBuilders() {
    VolatilitySurface other = VOL.withParallelShift(0);
    assertFalse(other.equals(VOL));
    other = VOL.withParallelShift(2);
    InterpolatedDoublesSurface underlying = (InterpolatedDoublesSurface) SurfaceShiftFunctionFactory.getShiftedSurface(SURFACE, 2, true);
    assertEquals(underlying.getClass(), other.getSurface().getClass());
    assertEquals(((InterpolatedDoublesSurface) other.getSurface()).getInterpolator(), underlying.getInterpolator());
    assertArrayEquals(other.getSurface().getXData(), underlying.getXData());
    assertArrayEquals(other.getSurface().getYData(), underlying.getYData());
    assertArrayEquals(other.getSurface().getZData(), underlying.getZData());
    other = VOL.withSingleAdditiveShift(0, 1, 0);
    assertFalse(other.equals(VOL));
    other = VOL.withSingleAdditiveShift(0, 1, 2);
    underlying = (InterpolatedDoublesSurface) SurfaceShiftFunctionFactory.getShiftedSurface(SURFACE, 0, 1, 2, true);
    assertEquals(underlying.getClass(), other.getSurface().getClass());
    assertEquals(((InterpolatedDoublesSurface) other.getSurface()).getInterpolator(), underlying.getInterpolator());
    assertArrayEquals(other.getSurface().getXData(), underlying.getXData());
    assertArrayEquals(other.getSurface().getYData(), underlying.getYData());
    assertArrayEquals(other.getSurface().getZData(), underlying.getZData());
    other = VOL.withMultipleAdditiveShifts(new double[] {0, 1}, new double[] {0, 1}, new double[] {0, 0});
    assertFalse(other.equals(VOL));
    other = VOL.withMultipleAdditiveShifts(new double[] {0, 1}, new double[] {0, 1}, new double[] {0.9, 0.8});
    underlying = (InterpolatedDoublesSurface) SurfaceShiftFunctionFactory.getShiftedSurface(SURFACE, new double[] {0, 1}, new double[] {0, 1}, new double[] {0.9, 0.8}, true);
    assertEquals(underlying.getClass(), other.getSurface().getClass());
    assertEquals(((InterpolatedDoublesSurface) other.getSurface()).getInterpolator(), underlying.getInterpolator());
    assertArrayEquals(other.getSurface().getXData(), underlying.getXData());
    assertArrayEquals(other.getSurface().getYData(), underlying.getYData());
    assertArrayEquals(other.getSurface().getZData(), underlying.getZData());

    other = VOL.withConstantMultiplicativeShift(0);
    assertFalse(other.equals(VOL));
    other = VOL.withConstantMultiplicativeShift(2);
    underlying = (InterpolatedDoublesSurface) SurfaceShiftFunctionFactory.getShiftedSurface(SURFACE, 2, false);
    assertEquals(underlying.getClass(), other.getSurface().getClass());
    assertEquals(((InterpolatedDoublesSurface) other.getSurface()).getInterpolator(), underlying.getInterpolator());
    assertArrayEquals(other.getSurface().getXData(), underlying.getXData());
    assertArrayEquals(other.getSurface().getYData(), underlying.getYData());
    assertArrayEquals(other.getSurface().getZData(), underlying.getZData());
    other = VOL.withSingleMultiplicativeShift(0, 1, 0);
    assertFalse(other.equals(VOL));
    other = VOL.withSingleMultiplicativeShift(0, 1, 2);
    underlying = (InterpolatedDoublesSurface) SurfaceShiftFunctionFactory.getShiftedSurface(SURFACE, 0, 1, 2, false);
    assertEquals(underlying.getClass(), other.getSurface().getClass());
    assertEquals(((InterpolatedDoublesSurface) other.getSurface()).getInterpolator(), underlying.getInterpolator());
    assertArrayEquals(other.getSurface().getXData(), underlying.getXData());
    assertArrayEquals(other.getSurface().getYData(), underlying.getYData());
    assertArrayEquals(other.getSurface().getZData(), underlying.getZData());
    other = VOL.withMultipleMultiplicativeShifts(new double[] {0, 1}, new double[] {0, 1}, new double[] {0, 0});
    assertFalse(other.equals(VOL));
    other = VOL.withMultipleMultiplicativeShifts(new double[] {0, 1}, new double[] {0, 1}, new double[] {0.9, 0.8});
    underlying = (InterpolatedDoublesSurface) SurfaceShiftFunctionFactory.getShiftedSurface(SURFACE, new double[] {0, 1}, new double[] {0, 1}, new double[] {0.9, 0.8}, false);
    assertEquals(underlying.getClass(), other.getSurface().getClass());
    assertEquals(((InterpolatedDoublesSurface) other.getSurface()).getInterpolator(), underlying.getInterpolator());
    assertArrayEquals(other.getSurface().getXData(), underlying.getXData());
    assertArrayEquals(other.getSurface().getYData(), underlying.getYData());
    assertArrayEquals(other.getSurface().getZData(), underlying.getZData());
  }
View Full Code Here

   * Create a set of SABR parameter surface (linearly interpolated and flat extrapolated) with a given SABR function.
   * The expirations and tenors are not on a full grid (short expiries with shorter tenors).
   * @return The SABR parameters parameters.
   */
  public static SABRInterestRateParameters createSABR3() {
    final InterpolatedDoublesSurface alphaSurface = InterpolatedDoublesSurface.from(new double[] {0.25, 0.25, 0.25, 0.50, 0.50, 0.50, 0.50, 1.0, 1.0, 1.0, 1.0, 1.0, 5.0, 5.0, 5.0, 5.0, 10.0, 10.0,
        10.0, 10.0, 20.0, 20.0, 20.0}, new double[] {1.0, 2.0, 5.0, 1.0, 2.0, 5.0, 10.0, 1.0, 2.0, 5.0, 10.0, 20, 2.0, 5.0, 10.0, 20.0, 2.0, 5.0, 10.0, 20.0, 5.0, 10.0, 20.0}, new double[] {0.03,
        0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.026, 0.026, 0.022, 0.020, 0.029, 0.028, 0.027, 0.026, 0.03, 0.031, 0.032}, INTERPOLATOR_2D);
    final InterpolatedDoublesSurface betaSurface = InterpolatedDoublesSurface.from(new double[] {0.25, 0.25, 0.25, 0.50, 0.50, 0.50, 0.50, 1.0, 1.0, 1.0, 1.0, 1.0, 5.0, 5.0, 5.0, 5.0, 10.0, 10.0,
        10.0, 10.0, 20.0, 20.0, 20.0}, new double[] {1.0, 2.0, 5.0, 1.0, 2.0, 5.0, 10.0, 1.0, 2.0, 5.0, 10.0, 20, 2.0, 5.0, 10.0, 20.0, 2.0, 5.0, 10.0, 20.0, 5.0, 10.0, 20.0}, new double[] {0.25,
        0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25}, INTERPOLATOR_2D);
    final InterpolatedDoublesSurface rhoSurface = InterpolatedDoublesSurface.from(new double[] {0.25, 0.25, 0.25, 0.50, 0.50, 0.50, 0.50, 1.0, 1.0, 1.0, 1.0, 1.0, 5.0, 5.0, 5.0, 5.0, 10.0, 10.0,
        10.0, 10.0, 20.0, 20.0, 20.0}, new double[] {1.0, 2.0, 5.0, 1.0, 2.0, 5.0, 10.0, 1.0, 2.0, 5.0, 10.0, 20, 2.0, 5.0, 10.0, 20.0, 2.0, 5.0, 10.0, 20.0, 5.0, 10.0, 20.0}, new double[] {-0.15,
        -0.15, -0.15, -0.10, -0.10, -0.10, -0.10, -0.10, -0.10, -0.10, -0.10, -0.10, -0.00, 0.25, 0.10, 0.40, 0.00, 0.00, 0.00, 0.00, 0.10, 0.10, 0.10}, INTERPOLATOR_2D);
    final InterpolatedDoublesSurface nuSurface = InterpolatedDoublesSurface.from(new double[] {0.25, 0.25, 0.25, 0.50, 0.50, 0.50, 0.50, 1.0, 1.0, 1.0, 1.0, 1.0, 5.0, 5.0, 5.0, 5.0, 10.0, 10.0, 10.0,
        10.0, 20.0, 20.0, 20.0}, new double[] {1.0, 2.0, 5.0, 1.0, 2.0, 5.0, 10.0, 1.0, 2.0, 5.0, 10.0, 20, 2.0, 5.0, 10.0, 20.0, 2.0, 5.0, 10.0, 20.0, 5.0, 10.0, 20.0}, new double[] {0.50, 0.50,
        0.50, 0.40, 0.40, 0.40, 0.40, 0.40, 0.40, 0.40, 0.40, 0.40, 0.45, 0.25, 0.25, 0.40, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35}, INTERPOLATOR_2D);
    return new SABRInterestRateParameters(alphaSurface, betaSurface, rhoSurface, nuSurface, DAY_COUNT, new SABRHaganVolatilityFunction());
  }
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.math.surface.InterpolatedDoublesSurface

Copyright © 2018 www.massapicom. 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.