Examples of YieldCurve


Examples of com.opengamma.analytics.financial.model.interestrate.curve.YieldCurve

    // Discounting
    final Set<Currency> ccyDiscounting = multicurve.getCurrencies();
    for (final Currency ccy : ccyDiscounting) {
      final YieldAndDiscountCurve curve = multicurve.getCurve(ccy);
      ArgumentChecker.isTrue(curve instanceof YieldCurve, "Curve should be a YieldCurve");
      final YieldCurve curveYield = (YieldCurve) curve;
      ArgumentChecker.isTrue(curveYield.getCurve() instanceof InterpolatedDoublesCurve, "Yield curve should be based on InterpolatedDoublesCurve");
      final InterpolatedDoublesCurve curveInt = (InterpolatedDoublesCurve) curveYield.getCurve();
      final int nbNodePoint = curveInt.getXDataAsPrimitive().length;
      final double[][] sensitivity = new double[nbCcy][nbNodePoint];
      for (int loopnode = 0; loopnode < nbNodePoint; loopnode++) {
        final double[] yieldBumped = curveInt.getYDataAsPrimitive().clone();
        yieldBumped[loopnode] += _shift;
        final YieldAndDiscountCurve dscBumped = new YieldCurve(curveInt.getName(), new InterpolatedDoublesCurve(curveInt.getXDataAsPrimitive(), yieldBumped, curveInt.getInterpolator(), true));
        final InflationProviderDiscount marketDscBumped = multicurve.withDiscountFactor(ccy, dscBumped);
        final MultipleCurrencyAmount pvBumped = instrument.accept(_valueCalculator, marketDscBumped);
        final MultipleCurrencyAmount pvDiff = pvBumped.plus(pvInitMinus);
        for (int loopccypv = 0; loopccypv < nbCcy; loopccypv++) {
          sensitivity[loopccypv][loopnode] = pvDiff.getAmount(ccyList.get(loopccypv)) / _shift;
        }
      }
      final String name = multicurve.getName(ccy);
      for (int loopccypv = 0; loopccypv < nbCcy; loopccypv++) {
        result = result.plus(new ObjectsPair<>(name, ccyList.get(loopccypv)), new DoubleMatrix1D(sensitivity[loopccypv]));
      }
    }
    // Forward ON
    final Set<IndexON> indexON = multicurve.getIndexesON();
    for (final IndexON index : indexON) {
      final YieldAndDiscountCurve curve = multicurve.getCurve(index);
      ArgumentChecker.isTrue(curve instanceof YieldCurve, "Curve should be a YieldCurve");
      final YieldCurve curveYield = (YieldCurve) curve;
      ArgumentChecker.isTrue(curveYield.getCurve() instanceof InterpolatedDoublesCurve, "Yield curve should be based on InterpolatedDoublesCurve");
      final InterpolatedDoublesCurve curveInt = (InterpolatedDoublesCurve) curveYield.getCurve();
      final int nbNodePoint = curveInt.getXDataAsPrimitive().length;
      final double[][] sensitivity = new double[nbCcy][nbNodePoint];
      for (int loopnode = 0; loopnode < nbNodePoint; loopnode++) {
        final double[] yieldBumped = curveInt.getYDataAsPrimitive().clone();
        yieldBumped[loopnode] += _shift;
        final YieldAndDiscountCurve fwdBumped = new YieldCurve(curveInt.getName(), new InterpolatedDoublesCurve(curveInt.getXDataAsPrimitive(), yieldBumped, curveInt.getInterpolator(), true));
        final InflationProviderDiscount marketFwdBumped = multicurve.withForward(index, fwdBumped);
        final MultipleCurrencyAmount pvBumped = instrument.accept(_valueCalculator, marketFwdBumped);
        final MultipleCurrencyAmount pvDiff = pvBumped.plus(pvInitMinus);
        for (int loopccypv = 0; loopccypv < nbCcy; loopccypv++) {
          sensitivity[loopccypv][loopnode] = pvDiff.getAmount(ccyList.get(loopccypv)) / _shift;
        }
      }
      final String name = multicurve.getName(index);
      for (int loopccypv = 0; loopccypv < nbCcy; loopccypv++) {
        result = result.plus(new ObjectsPair<>(name, ccyList.get(loopccypv)), new DoubleMatrix1D(sensitivity[loopccypv]));
      }
    }
    // Forward Ibor
    final Set<IborIndex> indexForward = multicurve.getIndexesIbor();
    for (final IborIndex index : indexForward) {
      final YieldAndDiscountCurve curve = multicurve.getCurve(index);
      ArgumentChecker.isTrue(curve instanceof YieldCurve, "Curve should be a YieldCurve");
      final YieldCurve curveYield = (YieldCurve) curve;
      ArgumentChecker.isTrue(curveYield.getCurve() instanceof InterpolatedDoublesCurve, "Yield curve should be based on InterpolatedDoublesCurve");
      final InterpolatedDoublesCurve curveInt = (InterpolatedDoublesCurve) curveYield.getCurve();
      final int nbNodePoint = curveInt.getXDataAsPrimitive().length;
      final double[][] sensitivity = new double[nbCcy][nbNodePoint];
      for (int loopnode = 0; loopnode < nbNodePoint; loopnode++) {
        final double[] yieldBumped = curveInt.getYDataAsPrimitive().clone();
        yieldBumped[loopnode] += _shift;
        final YieldAndDiscountCurve fwdBumped = new YieldCurve(curveInt.getName(), new InterpolatedDoublesCurve(curveInt.getXDataAsPrimitive(), yieldBumped, curveInt.getInterpolator(), true));
        final InflationProviderDiscount marketFwdBumped = multicurve.withForward(index, fwdBumped);
        final MultipleCurrencyAmount pvBumped = instrument.accept(_valueCalculator, marketFwdBumped);
        final MultipleCurrencyAmount pvDiff = pvBumped.plus(pvInitMinus);
        for (int loopccypv = 0; loopccypv < nbCcy; loopccypv++) {
          sensitivity[loopccypv][loopnode] = pvDiff.getAmount(ccyList.get(loopccypv)) / _shift;
View Full Code Here

Examples of com.opengamma.analytics.financial.model.interestrate.curve.YieldCurve

    // NodeSensitivityCalculator.curveToNodeSensitivities(curveSensitivities, interpolatedCurves)

    if (!(market.getDiscountCurve() instanceof YieldCurve)) {
      throw new IllegalArgumentException("Can only handle YieldCurve");
    }
    final YieldCurve discCrv = (YieldCurve) market.getDiscountCurve();

    final double settlement = derivative.accept(SETTLEMENT_CALCULATOR);
    final double sens = calcDiscountRateSensitivity(derivative, market);

    final NodeYieldSensitivityCalculator distributor = PresentValueNodeSensitivityCalculator.getDefaultInstance();
View Full Code Here

Examples of com.opengamma.analytics.financial.model.interestrate.curve.YieldCurve

  @Override
  public DoubleMatrix1D visit(final InstrumentDerivative future, final SimpleFutureDataBundle dataBundle) {
    ArgumentChecker.notNull(future, "future");
    ArgumentChecker.notNull(dataBundle, "data bundle");
    ArgumentChecker.isTrue(dataBundle.getFundingCurve() instanceof YieldCurve, "Calculator expects a YieldCurve, have {}", dataBundle.getFundingCurve().getClass());
    final YieldCurve discCrv = (YieldCurve) dataBundle.getFundingCurve();
    final double settlement = future.accept(SETTLEMENT_TIME);
    SimpleFutureDataBundle bumpedMarket = new SimpleFutureDataBundle(discCrv.withSingleShift(settlement, SHIFT), dataBundle.getMarketPrice(),
        dataBundle.getSpotValue(), dataBundle.getDividendYield(), dataBundle.getCostOfCarry());
    final double pvUp = future.accept(_presentValueCalculator, bumpedMarket);
    bumpedMarket = new SimpleFutureDataBundle(discCrv.withSingleShift(settlement, -SHIFT), dataBundle.getMarketPrice(),
        dataBundle.getSpotValue(), dataBundle.getDividendYield(), dataBundle.getCostOfCarry());
    final double pvDown = future.accept(_presentValueCalculator, bumpedMarket);
    final double sensitivity = (pvUp - pvDown) / (2.0 * SHIFT);
    final NodeYieldSensitivityCalculator distributor = PresentValueNodeSensitivityCalculator.getDefaultInstance();
    final List<Double> result = distributor.curveToNodeSensitivity(Arrays.asList(DoublesPair.of(settlement, sensitivity)), discCrv);
View Full Code Here

Examples of com.opengamma.analytics.financial.model.interestrate.curve.YieldCurve

  @Override
  public DoubleMatrix1D visit(final InstrumentDerivative future, final SimpleFutureDataBundle dataBundle) {
    ArgumentChecker.notNull(future, "future");
    ArgumentChecker.notNull(dataBundle, "data bundle");
    ArgumentChecker.isTrue(dataBundle.getFundingCurve() instanceof YieldCurve, "Calculator expects a YieldCurve, have {}", dataBundle.getFundingCurve().getClass());
    final YieldCurve discCrv = (YieldCurve) dataBundle.getFundingCurve();
    final double settlement = future.accept(SETTLEMENT_TIME);
    final double rhoSettle = -1 * settlement * future.accept(_presentValueCalculator, dataBundle);
    //  We use PresentValueNodeSensitivityCalculator to distribute this risk across the curve
    final NodeYieldSensitivityCalculator distributor = PresentValueNodeSensitivityCalculator.getDefaultInstance();
    final List<Double> result = distributor.curveToNodeSensitivity(Arrays.asList(DoublesPair.of(settlement, rhoSettle)), discCrv);
View Full Code Here

Examples of com.opengamma.analytics.financial.model.interestrate.curve.YieldCurve

    MODEL.getDiscountBondFunction(START, MATURITY).evaluate((VasicekDataBundle) null);
  }

  @Test
  public void test() {
    final YieldCurve shortRate = YieldCurve.from(ConstantDoublesCurve.from(0.05));
    final double longRate = 0.06;
    final double speed = 0.01;
    final VolatilityCurve sigma = new VolatilityCurve(ConstantDoublesCurve.from(0.01));
    VasicekDataBundle data = new VasicekDataBundle(shortRate, sigma, TODAY, longRate, speed);
    assertEquals(MODEL.getDiscountBondFunction(START, START).evaluate(data), 1, 0);
View Full Code Here

Examples of com.opengamma.analytics.financial.model.interestrate.curve.YieldCurve

      if (message.hasField(NAME_FIELD_NAME)) {
        name = message.getString(NAME_FIELD_NAME);
      } else {
        name = curve.getName();
      }
      return new YieldCurve(name, curve);
    }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.interestrate.curve.YieldCurve

      @Override
      public Double evaluate(final DoubleMatrix1D x) {
        final YieldCurveBundle curves = interpolatedCurves.copy();
        int index2 = 0;
        for (final String name : interpolatedCurves.getAllNames()) {
          final YieldCurve curve = (YieldCurve) interpolatedCurves.getCurve(name);
          final Interpolator1DDataBundle dataBundle = ((InterpolatedDoublesCurve) curve.getCurve()).getDataBundle();
          final int numberOfNodes = dataBundle.size();
          final double[] yields1 = Arrays.copyOfRange(x.getData(), index2, index2 + numberOfNodes);
          index2 += numberOfNodes;
          final YieldAndDiscountCurve newCurve = YieldCurve.from(InterpolatedDoublesCurve.from(dataBundle.getKeys(), yields1, ((InterpolatedDoublesCurve) curve.getCurve()).getInterpolator()));
          curves.replaceCurve(name, newCurve);
        }
        if (fixedCurves != null) {
          curves.addAll(fixedCurves);
        }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.interestrate.curve.YieldCurve

  protected DoubleMatrix1D finiteDiffNodeSensitivitiesSpread(final InstrumentDerivative ird, final InstrumentDerivativeVisitor<YieldCurveBundle, Double> valueCalculator,
      final YieldCurveBundle fixedCurves, final YieldCurveBundle spreadCurves) {
    int nNodes = 0;
    for (final String curveName : spreadCurves.getAllNames()) {
      final YieldCurve yieldCurve = (YieldCurve) ((YieldAndDiscountAddZeroSpreadCurve) spreadCurves.getCurve(curveName)).getCurves()[0];
      final Interpolator1DDataBundle dataBundle = ((InterpolatedDoublesCurve) yieldCurve.getCurve()).getDataBundle();
      nNodes += dataBundle.size() + 1; // +1 for spread
    }
    final double[] param = new double[nNodes];
    int index = 0;
    for (final String curveName : spreadCurves.getAllNames()) {
      final YieldCurve yieldCurve = (YieldCurve) ((YieldAndDiscountAddZeroSpreadCurve) spreadCurves.getCurve(curveName)).getCurves()[0];
      final Interpolator1DDataBundle dataBundle = ((InterpolatedDoublesCurve) yieldCurve.getCurve()).getDataBundle();
      for (final double y : dataBundle.getValues()) {
        param[index++] = y;
      }
      final YieldCurve spreadCurve = (YieldCurve) ((YieldAndDiscountAddZeroSpreadCurve) spreadCurves.getCurve(curveName)).getCurves()[1];
      param[index++] = ((ConstantDoublesCurve) (spreadCurve.getCurve())).getYData()[0];
    }

    final Function1D<DoubleMatrix1D, Double> f = new Function1D<DoubleMatrix1D, Double>() {
      @Override
      public Double evaluate(final DoubleMatrix1D x) {
        final YieldCurveBundle curves = spreadCurves.copy();
        int index2 = 0;
        for (final String name : spreadCurves.getAllNames()) {
          final YieldCurve yieldCurve = (YieldCurve) ((YieldAndDiscountAddZeroSpreadCurve) spreadCurves.getCurve(name)).getCurves()[0];
          final Interpolator1DDataBundle dataBundle = ((InterpolatedDoublesCurve) yieldCurve.getCurve()).getDataBundle();
          final int numberOfNodes = dataBundle.size();
          final double[] yields1 = Arrays.copyOfRange(x.getData(), index2, index2 + numberOfNodes);
          final double spread1 = x.getData()[index2 + numberOfNodes];
          index2 += numberOfNodes + 1;
          final YieldCurve newYieldCurve = YieldCurve.from(InterpolatedDoublesCurve.from(dataBundle.getKeys(), yields1, ((InterpolatedDoublesCurve) yieldCurve.getCurve()).getInterpolator()));
          final YieldCurve newSpreadCurve = YieldCurve.from(new ConstantDoublesCurve(spread1));
          final YieldAndDiscountCurve newCurve = new YieldAndDiscountAddZeroSpreadCurve("NewYield+Spread", false, newYieldCurve, newSpreadCurve);
          curves.replaceCurve(name, newCurve);
        }
        if (fixedCurves != null) {
          curves.addAll(fixedCurves);
View Full Code Here

Examples of com.opengamma.analytics.financial.model.interestrate.curve.YieldCurve

      // Get the discount curve
      final Object discountCurveObject = inputs.getValue(ValueRequirementNames.YIELD_CURVE);
      if (discountCurveObject == null) {
        throw new OpenGammaRuntimeException("Could not get discount curve");
      }
      final YieldCurve discountCurve = (YieldCurve) discountCurveObject;
      // Get the forward curve
      final Object forwardCurveObject = inputs.getValue(ValueRequirementNames.FORWARD_CURVE);
      if (forwardCurveObject == null) {
        throw new OpenGammaRuntimeException("Could not get forward curve");
      }
View Full Code Here

Examples of com.opengamma.analytics.financial.model.interestrate.curve.YieldCurve

  public void testBuilders() {
    final ZonedDateTime newDate = DATE.plusDays(1);
    assertEquals(DATA.withDate(newDate), new BlackOptionDataBundle(F, CURVE, SURFACE, newDate));
    final double newForward = F + 1;
    assertEquals(DATA.withForward(newForward), new BlackOptionDataBundle(newForward, CURVE, SURFACE, DATE));
    final YieldCurve newCurve = YieldCurve.from(ConstantDoublesCurve.from(0.05));
    assertEquals(DATA.withInterestRateCurve(newCurve), new BlackOptionDataBundle(F, newCurve, SURFACE, DATE));
    final VolatilitySurface newSurface = new VolatilitySurface(ConstantDoublesSurface.from(0.9));
    assertEquals(DATA.withVolatilitySurface(newSurface), new BlackOptionDataBundle(F, CURVE, newSurface, DATE));
  }
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.