Package com.opengamma.analytics.math.linearalgebra

Examples of com.opengamma.analytics.math.linearalgebra.LUDecompositionResult


   * @param doubMat Matrix A
   * @param doubVec Vector B
   * @return Solution to the linear equation, x
   */
  protected double[] matrixEqnSolver(final double[][] doubMat, final double[] doubVec) {
    final LUDecompositionResult result = _luObj.evaluate(new DoubleMatrix2D(doubMat));

    final double[][] lMat = result.getL().getData();
    final double[][] uMat = result.getU().getData();
    double[] doubVecMod = ((DoubleMatrix1D) OG_ALGEBRA.multiply(result.getP(), new DoubleMatrix1D(doubVec))).getData();

    return backSubstitution(uMat, forwardSubstitution(lMat, doubVecMod));
  }
View Full Code Here


   * @param doubMat2 The matrix L
   * @return The solutions to the linear systems, x,N
   */
  protected DoubleMatrix1D[] combinedMatrixEqnSolver(final double[][] doubMat1, final double[] doubVec, final double[][] doubMat2) {
    final int nDataPts = doubVec.length;
    final LUDecompositionResult result = _luObj.evaluate(new DoubleMatrix2D(doubMat1));

    final double[][] lMat = result.getL().getData();
    final double[][] uMat = result.getU().getData();
    final DoubleMatrix2D pMat = result.getP();
    double[] doubVecMod = ((DoubleMatrix1D) OG_ALGEBRA.multiply(pMat, new DoubleMatrix1D(doubVec))).getData();

    final DoubleMatrix2D doubMat2Matrix = new DoubleMatrix2D(doubMat2);
    final DoubleMatrix1D[] res = new DoubleMatrix1D[nDataPts + 1];
    res[0] = new DoubleMatrix1D(backSubstitution(uMat, forwardSubstitution(lMat, doubVecMod)));
View Full Code Here

   * @param doubMat Matrix A
   * @param doubVec Vector B
   * @return Solution to the linear equation, x
   */
  protected double[] decompSol(final double[][] doubMat, final double[] doubVec) {
    final LUDecompositionResult result = _luObj.evaluate(new DoubleMatrix2D(doubMat));

    final double[][] lMat = result.getL().getData();
    final double[][] uMat = result.getU().getData();
    final double[] doubVecMod = ((DoubleMatrix1D) OG_ALGEBRA.multiply(result.getP(), new DoubleMatrix1D(doubVec))).getData();

    return backSubstitution(uMat, forwardSubstitution(lMat, doubVecMod));

  }
View Full Code Here

   * @param doubMat Matrix A
   * @param doubVec Vector B
   * @return Solution to the linear equation, x
   */
  protected double[] decompSol(final double[][] doubMat, final double[] doubVec) {
    final LUDecompositionResult result = _luObj.evaluate(new DoubleMatrix2D(doubMat));

    final double[][] lMat = result.getL().getData();
    final double[][] uMat = result.getU().getData();
    final double[] doubVecMod = ((DoubleMatrix1D) OG_ALGEBRA.multiply(result.getP(), new DoubleMatrix1D(doubVec))).getData();

    return backSubstitution(uMat, forwardSubstitution(lMat, doubVecMod));

  }
View Full Code Here

        res[j][i] = _pricer.parSpreadCreditSensitivity(bucketCDSs[i], yieldCurve, creditCurve, j);
      }
    }
    final DoubleMatrix1D vLambda = new DoubleMatrix1D(temp);
    final DoubleMatrix2D jacT = new DoubleMatrix2D(res);
    final LUDecompositionResult luRes = decomp.evaluate(jacT);
    final DoubleMatrix1D vS = luRes.solve(vLambda);
    return vS.getData();
  }
View Full Code Here

      }
    }

    final double[] vLambda = new double[n];
    final double[][] res = new double[m][];
    final LUDecompositionResult luRes = decomp.evaluate(jacT);
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        vLambda[j] = _pricer.pvCreditSensitivity(cds[i], yieldCurve, creditCurve, cdsCoupon[i], j);
      }
      res[i] = luRes.solve(vLambda);
    }
    return res;
  }
View Full Code Here

    final DoubleMatrix1D trueValues = new DoubleMatrix1D(new double[] {1, 1, 0, 0 });
    final DoubleMatrix1D delta = (DoubleMatrix1D) ma.subtract(res.getFitParameters(), trueValues);

    final LUDecompositionCommons decmp = new LUDecompositionCommons();
    final LUDecompositionResult decmpRes = decmp.evaluate(res.getCovariance());
    final DoubleMatrix2D invCovariance = decmpRes.solve(DoubleMatrixUtils.getIdentityMatrix2D(4));

    double z = ma.getInnerProduct(delta, ma.multiply(invCovariance, delta));
    z = Math.sqrt(z);

    assertTrue(z < 3.0);
View Full Code Here

      System.out.println(dVdH);
      System.out.println();
    }

    final LUDecompositionCommons decomp = new LUDecompositionCommons();
    final LUDecompositionResult res = decomp.evaluate(jac);
    final DoubleMatrix1D dVdS = res.solve(dVdH);

    // compare with bump and reprice
    final SpreadSensitivityCalculator bumpCal = new SpreadSensitivityCalculator();
    final double[] fd = bumpCal.bucketedCS01FromParSpreads(CDS, dealSpread, YIELD_CURVE, MARKET_CDS, mrkSpreads, 1e-7, BumpType.ADDITIVE);
    final DoubleMatrix1D fd_dVdS = new DoubleMatrix1D(fd);
View Full Code Here

      }
    }
    final DoubleMatrix2D jacT = new DoubleMatrix2D(res);
    //  System.out.println(jacT.toString());
    final LUDecompositionCommons decomp = new LUDecompositionCommons();
    final LUDecompositionResult luRes = decomp.evaluate(jacT);

    out.append("\\begin{tabular}{");
    for (int i = 0; i < nPillars + 1; i++) {
      out.append("c|");
    }
    out.append("}\n");
    out.append("\\cline{2-" + (nPillars + 1) + "}\n");
    out.append("& \\multicolumn{" + nPillars + "}{c|}{Hedge Instrument Maturity}\\\\\n");
    out.append("\\hline\n");
    out.append("\\multicolumn{1}{|c|}{CDS Maturity}");
    for (int i = 0; i < nPillars; i++) {
      out.append("& " + TENORS[i].toString());
    }
    out.append("\\\\\n");
    out.append("\\hline\n");

    for (int i = 0; i < IMM_DATES.length; i = i + 2) {
      final LocalDate mat = IMM_DATES[i];
      out.append("\\multicolumn{1}{|c|}{" + mat.toString(formatt) + "}");
      final CDSAnalytic cds = factory.makeCDS(TRADE_DATE, STARTDATE, mat);

      final double[] temp = new double[nPillars];
      for (int j = 0; j < nPillars; j++) {
        final double sense = PRICER.pvCreditSensitivity(cds, YIELD_CURVE, CREDIT_CURVE, coupon, j);
        temp[j] = sense;
      }
      final DoubleMatrix1D vLambda = new DoubleMatrix1D(temp);
      //     System.out.println(vLambda);

      final DoubleMatrix1D w = luRes.solve(vLambda);
      for (int j = 0; j < nPillars; j++) {
        out.append(String.format("& %.5f", w.getEntry(j)));
      }

      out.append("\\\\\n");
View Full Code Here

    final double[] coupons = new double[nPillars];
    Arrays.fill(coupons, COUPON);
    final double[][] temp = SPREAD_SENCE_CAL.analyticCS01FromCreditCurve(PILLAR_CDSS, coupons, PILLAR_CDSS, YIELD_CURVE, CREDIT_CURVE);
    final DoubleMatrix2D jacT = MA.getTranspose(new DoubleMatrix2D(temp));
    //System.out.println(jac);
    final LUDecompositionResult decRes = decomp.evaluate(jacT);

    final int nMat = MATURITIES_6M_STEP.length;

    final double[][] res = new double[nMat][];
    final CDSAnalytic[] cds = CDS_FACTORY.makeCDS(TRADE_DATE, STARTDATE, MATURITIES_6M_STEP);
    for (int i = 0; i < nMat; i++) {
      final double[] vs = SPREAD_SENCE_CAL.analyticCS01FromCreditCurve(cds[i], COUPON, PILLAR_CDSS, YIELD_CURVE, CREDIT_CURVE);
      res[i] = decRes.solve(vs);
    }
    final DoubleMatrix2D hedge = new DoubleMatrix2D(res);
    System.out.println(hedge);
  }
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.math.linearalgebra.LUDecompositionResult

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.