StandardIsdaCompliantCreditCurveFn implements IsdaCompliantCreditCurveFn { @Override public Result<IsdaCreditCurve> buildIsdaCompliantCreditCurve(Environment env, CreditCurveDataKey creditCurveKey) { Result<IsdaYieldCurve> yieldCurveResult = _yieldCurveFn.buildIsdaCompliantCurve(env, creditCurveKey.getCurrency()); Result<CreditCurveData> creditCurveDataResult = _curveDataProviderFn.retrieveCreditCurveData(env, creditCurveKey); if (Result.anyFailures(creditCurveDataResult, yieldCurveResult)) { return Result.failure(creditCurveDataResult, yieldCurveResult); } IsdaYieldCurve yieldCurve = yieldCurveResult.getValue(); Pair<ISDACompliantCreditCurve, List<CDSAnalytic>> curveData = buildWithResolvedData(env, yieldCurve.getCalibratedCurve(), creditCurveDataResult.getValue(), creditCurveKey); return Result.success(IsdaCreditCurve.builder() .calibratedCurve(curveData.getFirst()) .curveData(creditCurveDataResult.getValue()) .yieldCurve(yieldCurve) .calibratedCds(curveData.getSecond()) .build()); } StandardIsdaCompliantCreditCurveFn(IsdaCompliantYieldCurveFn yieldCurveFn,
                                            CreditCurveDataProviderFn curveDataProviderFn, 
                                            HolidaySource holidaySource, 
                                            RegionSource regionSource); @Override Result<IsdaCreditCurve> buildIsdaCompliantCreditCurve(Environment env, 
                                                               CreditCurveDataKey creditCurveKey);  }
@Test public void testCurveBuild() { Result<IsdaCreditCurve> result = _fn.buildIsdaCompliantCreditCurve(_env, _goodKey); assertTrue("Expected success result", result.isSuccess()); ISDACompliantCreditCurve curve = result.getValue().getCalibratedCurve(); for (Map.Entry<LocalDate, Double> entry : EXPECTED.entrySet()) { double t = TimeCalculator.getTimeBetween(VALUATION_DATE, entry.getKey()); double discountFactor = curve.getDiscountFactor(t); System.out.println(entry.getKey() + " " + discountFactor + " " + (discountFactor - entry.getValue())); assertEquals(entry.getValue(), discountFactor, DELTA); } }
@Test public void testMissingCreditCurveData() { when(_yieldCurveFn.buildIsdaCompliantCurve(_env, Currency.GBP)).thenReturn(Result.success(YIELD_CURVE)); when(_curveDataProviderFn.retrieveCreditCurveData(_env, _badKey)) .thenReturn(Result.<CreditCurveData> failure(FailureStatus.ERROR, "Error")); Result<IsdaCreditCurve> result = _fn.buildIsdaCompliantCreditCurve(_env, _badKey); assertFalse("Expected failure result", result.isSuccess()); }
@Test public void testMissingYieldCurveData() { when(_yieldCurveFn.buildIsdaCompliantCurve(_env, Currency.GBP)) .thenReturn(Result.<IsdaYieldCurve> failure(FailureStatus.ERROR, "Error")); when(_curveDataProviderFn.retrieveCreditCurveData(_env, _badKey)) .thenReturn(Result.success(mock(CreditCurveData.class))); Result<IsdaCreditCurve> result = _fn.buildIsdaCompliantCreditCurve(_env, _badKey); assertFalse("Expected failure result", result.isSuccess()); }