Esempio n. 1
0
        //-------------------------------------------------------------------------
        protected internal virtual void testJacobian(LegalEntitySurvivalProbabilities curve, ImmutableCreditRatesProvider ratesProvider, IList <CdsIndexIsdaCreditCurveNode> nodes, double[] quotes)
        {
            int nNode = nodes.Count;
            IsdaCreditDiscountFactors df = (IsdaCreditDiscountFactors)curve.SurvivalProbabilities;
            int nCurveNode = df.ParameterCount;

            for (int i = 0; i < nCurveNode; ++i)
            {
                double[] quotesUp = Arrays.copyOf(quotes, nNode);
                double[] quotesDw = Arrays.copyOf(quotes, nNode);
                quotesUp[i] += EPS;
                quotesDw[i] -= EPS;
                ImmutableMarketDataBuilder builderCreditUp = MARKET_DATA.toBuilder();
                ImmutableMarketDataBuilder builderCreditDw = MARKET_DATA.toBuilder();
                for (int j = 0; j < nNode; ++j)
                {
                    builderCreditUp.addValue(nodes[j].ObservableId, quotesUp[j]);
                    builderCreditDw.addValue(nodes[j].ObservableId, quotesDw[j]);
                }
                ImmutableMarketData       marketDataUp = builderCreditUp.build();
                ImmutableMarketData       marketDataDw = builderCreditDw.build();
                IsdaCreditCurveDefinition definition   = IsdaCreditCurveDefinition.of(df.Curve.Name, df.Currency, df.ValuationDate, df.DayCount, nodes, false, false);
                IsdaCreditDiscountFactors ccUp         = (IsdaCreditDiscountFactors)CALIBRATOR.calibrate(definition, marketDataUp, ratesProvider, REF_DATA).SurvivalProbabilities;
                IsdaCreditDiscountFactors ccDw         = (IsdaCreditDiscountFactors)CALIBRATOR.calibrate(definition, marketDataDw, ratesProvider, REF_DATA).SurvivalProbabilities;
                for (int j = 0; j < nNode; ++j)
                {
                    double computed = df.Curve.Metadata.findInfo(CurveInfoType.JACOBIAN).get().JacobianMatrix.get(j, i);
                    double expected = 0.5 * (ccUp.Curve.YValues.get(j) - ccDw.Curve.YValues.get(j)) / EPS;
                    assertEquals(computed, expected, EPS * 10d);
                }
            }
        }