internal override DoubleArray computedBucketedCs01(ResolvedCdsTrade trade, IList <ResolvedCdsTrade> bucketCds, CreditRatesProvider ratesProvider, ReferenceData refData)
        {
            checkCdsBucket(trade, bucketCds);
            ResolvedCds product       = trade.Product;
            Currency    currency      = product.Currency;
            StandardId  legalEntityId = product.LegalEntityId;
            LocalDate   valuationDate = ratesProvider.ValuationDate;

            int         nBucket          = bucketCds.Count;
            DoubleArray impSp            = impliedSpread(bucketCds, ratesProvider, refData);
            NodalCurve  creditCurveBase  = Calibrator.calibrate(bucketCds, impSp, DoubleArray.filled(nBucket), CurveName.of("baseImpliedCreditCurve"), valuationDate, ratesProvider.discountFactors(currency), ratesProvider.recoveryRates(legalEntityId), refData);
            IsdaCreditDiscountFactors df = IsdaCreditDiscountFactors.of(currency, valuationDate, creditCurveBase);
            CreditRatesProvider       ratesProviderBase = ratesProvider.toImmutableCreditRatesProvider().toBuilder().creditCurves(ImmutableMap.of(Pair.of(legalEntityId, currency), LegalEntitySurvivalProbabilities.of(legalEntityId, df))).build();

            double[][]         res     = new double[nBucket][];
            PointSensitivities pointPv = Pricer.presentValueOnSettleSensitivity(trade, ratesProviderBase, refData);
            DoubleArray        vLambda = ratesProviderBase.singleCreditCurveParameterSensitivity(pointPv, legalEntityId, currency).Sensitivity;

            for (int i = 0; i < nBucket; i++)
            {
                PointSensitivities pointSp = Pricer.parSpreadSensitivity(bucketCds[i], ratesProviderBase, refData);
                res[i] = ratesProviderBase.singleCreditCurveParameterSensitivity(pointSp, legalEntityId, currency).Sensitivity.toArray();
            }
            DoubleMatrix          jacT  = MATRIX_ALGEBRA.getTranspose(DoubleMatrix.ofUnsafe(res));
            LUDecompositionResult luRes = DECOMPOSITION.apply(jacT);
            DoubleArray           vS    = luRes.solve(vLambda);

            return(vS);
        }
        /// <summary>
        /// Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector
        /// This can be done by LU decomposition </summary>
        /// <param name="doubMat"> Matrix A </param>
        /// <param name="doubVec"> Vector B </param>
        /// <returns> Solution to the linear equation, x </returns>
        protected internal virtual double[] matrixEqnSolver(double[][] doubMat, double[] doubVec)
        {
            LUDecompositionResult result = _luObj.apply(DoubleMatrix.copyOf(doubMat));

            double[][]  lMat       = result.L.toArray();
            double[][]  uMat       = result.U.toArray();
            DoubleArray doubVecMod = ((DoubleArray)OG_ALGEBRA.multiply(result.P, DoubleArray.copyOf(doubVec)));

            return(backSubstitution(uMat, forwardSubstitution(lMat, doubVecMod)));
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testRecoverOrginal()
        public virtual void testRecoverOrginal()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.math.linearalgebra.DecompositionResult result = LU.apply(A);
            DecompositionResult result = LU.apply(A);

            assertTrue(result is LUDecompositionResult);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LUDecompositionResult lu = (LUDecompositionResult) result;
            LUDecompositionResult lu = (LUDecompositionResult)result;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.opengamma.strata.collect.array.DoubleMatrix a = (com.opengamma.strata.collect.array.DoubleMatrix) ALGEBRA.multiply(lu.getL(), lu.getU());
            DoubleMatrix a = (DoubleMatrix)ALGEBRA.multiply(lu.L, lu.U);

            checkEquals((DoubleMatrix)ALGEBRA.multiply(lu.P, A), a);
        }
        /// <summary>
        /// Cubic spline and its node sensitivity are respectively obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector and AN=L where N,L are matrices </summary>
        /// <param name="doubMat1"> The matrix A </param>
        /// <param name="doubVec"> The vector b </param>
        /// <param name="doubMat2"> The matrix L </param>
        /// <returns> The solutions to the linear systems, x,N </returns>
        protected internal virtual DoubleArray[] combinedMatrixEqnSolver(double[][] doubMat1, double[] doubVec, double[][] doubMat2)
        {
            int nDataPts = doubVec.Length;
            LUDecompositionResult result = _luObj.apply(DoubleMatrix.copyOf(doubMat1));

            double[][]   lMat       = result.L.toArray();
            double[][]   uMat       = result.U.toArray();
            DoubleMatrix pMat       = result.P;
            DoubleArray  doubVecMod = ((DoubleArray)OG_ALGEBRA.multiply(pMat, DoubleArray.copyOf(doubVec)));

            DoubleMatrix doubMat2Matrix = DoubleMatrix.copyOf(doubMat2);

            DoubleArray[] res = new DoubleArray[nDataPts + 1];
            res[0] = DoubleArray.copyOf(backSubstitution(uMat, forwardSubstitution(lMat, doubVecMod)));
            for (int i = 0; i < nDataPts; ++i)
            {
                DoubleArray doubMat2Colum = doubMat2Matrix.column(i);
                DoubleArray doubVecMod2   = ((DoubleArray)OG_ALGEBRA.multiply(pMat, doubMat2Colum));
                res[i + 1] = DoubleArray.copyOf(backSubstitution(uMat, forwardSubstitution(lMat, doubVecMod2)));
            }
            return(res);
        }