public RecoveryRates recoveryRates(StandardId legalEntityId) { CurveId curveId = lookup.RecoveryRateCurveIds.get(legalEntityId); if (curveId == null) { throw new MarketDataNotFoundException("Unable to find recovery rate curve: " + legalEntityId); } Curve curve = marketData.getValue(curveId); return(RecoveryRates.of(legalEntityId, ValuationDate, curve)); }
public virtual void test_of_interface() { ConstantCurve curve = ConstantCurve.of(DefaultCurveMetadata.builder().yValueType(ValueType.RECOVERY_RATE).curveName("recoveryRate").build(), RECOVERY_RATE); ConstantRecoveryRates test = (ConstantRecoveryRates)RecoveryRates.of(LEGAL_ENTITY, VALUATION, curve); assertEquals(test.LegalEntityId, LEGAL_ENTITY); assertEquals(test.RecoveryRate, RECOVERY_RATE); assertEquals(test.ValuationDate, VALUATION); assertEquals(test.recoveryRate(DATE_AFTER), RECOVERY_RATE); assertEquals(test.findData(CurveName.of("Rubbish")), null); assertEquals(test.getParameter(0), RECOVERY_RATE); assertEquals(test.ParameterCount, 1); assertEquals(test.getParameterMetadata(0), ParameterMetadata.empty()); assertEquals(test.withParameter(0, 0.5), ConstantRecoveryRates.of(LEGAL_ENTITY, VALUATION, 0.5)); }
//------------------------------------------------------------------------- public ImmutableCreditRatesProvider toImmutableCreditRatesProvider() { LocalDate valuationDate = ValuationDate; // credit curves IDictionary <Pair <StandardId, Currency>, LegalEntitySurvivalProbabilities> creditCurves = new Dictionary <Pair <StandardId, Currency>, LegalEntitySurvivalProbabilities>(); foreach (Pair <StandardId, Currency> pair in lookup.CreditCurveIds.Keys) { CurveId curveId = lookup.CreditCurveIds.get(pair); if (marketData.containsValue(curveId)) { Curve curve = marketData.getValue(curveId); CreditDiscountFactors survivalProbabilities = CreditDiscountFactors.of(pair.Second, valuationDate, curve); creditCurves[pair] = LegalEntitySurvivalProbabilities.of(pair.First, survivalProbabilities); } } // discount curves IDictionary <Currency, CreditDiscountFactors> discountCurves = new Dictionary <Currency, CreditDiscountFactors>(); foreach (Currency currency in lookup.DiscountCurveIds.Keys) { CurveId curveId = lookup.DiscountCurveIds.get(currency); if (marketData.containsValue(curveId)) { Curve curve = marketData.getValue(curveId); discountCurves[currency] = CreditDiscountFactors.of(currency, valuationDate, curve); } } // recovery rate curves IDictionary <StandardId, RecoveryRates> recoveryRateCurves = new Dictionary <StandardId, RecoveryRates>(); foreach (StandardId legalEntityId in lookup.RecoveryRateCurveIds.Keys) { CurveId curveId = lookup.RecoveryRateCurveIds.get(legalEntityId); if (marketData.containsValue(curveId)) { Curve curve = marketData.getValue(curveId); RecoveryRates recoveryRate = RecoveryRates.of(legalEntityId, valuationDate, curve); recoveryRateCurves[legalEntityId] = recoveryRate; } } // build result return(ImmutableCreditRatesProvider.builder().valuationDate(valuationDate).creditCurves(creditCurves).discountCurves(discountCurves).recoveryRateCurves(recoveryRateCurves).build()); }