/// <summary> /// Filters the parameters, matching only those that are applicable for the target and measure. /// <para> /// The resulting parameters are filtered to the target and measure. /// The implementation of each parameter may be changed by this process. /// If two parameters are filtered to the same <seealso cref="CalculationParameter#queryType() query type"/> /// then an exception will be thrown /// /// </para> /// </summary> /// <param name="target"> the calculation target, such as a trade </param> /// <param name="measure"> the measure to be calculated </param> /// <returns> the filtered calculation parameters </returns> /// <exception cref="IllegalArgumentException"> if two parameters are filtered to the same query type </exception> public CalculationParameters filter(CalculationTarget target, Measure measure) { //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: ImmutableList <CalculationParameter> filtered = parameters.values().Select(cp => cp.filter(target, measure)).Where(opt => opt.Present).Select(opt => opt.get()).collect(toImmutableList()); return(of(filtered)); }
//------------------------------------------------------------------------- public Optional <T> findData <T>(MarketDataName <T> name) { if (name is CurveName) { return(Stream.concat(discountCurves.values().stream(), indexCurves.values().stream()).filter(c => c.Name.Equals(name)).map(v => name.MarketDataType.cast(v)).findFirst()); } return(null); }
//------------------------------------------------------------------------- public virtual void test_of_map() { ImmutableMap <ParameterMetadata, double> map = ImmutableMap.of(TenorParameterMetadata.of(Tenor.TENOR_1Y), 12d, TenorParameterMetadata.of(Tenor.TENOR_2Y), -32d, TenorParameterMetadata.of(Tenor.TENOR_5Y), 5d); CurrencyParameterSensitivity test = CurrencyParameterSensitivity.of(NAME1, USD, map); assertEquals(test.MarketDataName, NAME1); assertEquals(test.ParameterCount, 3); assertEquals(test.ParameterMetadata, map.Keys.asList()); assertEquals(test.Currency, USD); assertEquals(test.Sensitivity, DoubleArray.copyOf(map.values())); assertEquals(test.sensitivities().toMap(), map); assertEquals(test.toSensitivityMap(typeof(Tenor)), MapStream.of(map).mapKeys(pm => pm.Identifier).toMap()); }
//------------------------------------------------------------------------- /// <summary> /// Calculates the present value sensitivity of the swaption product. /// <para> /// The present value sensitivity of the product is the sensitivity of the present value to /// the underlying curves. /// /// </para> /// </summary> /// <param name="swaption"> the product </param> /// <param name="ratesProvider"> the rates provider </param> /// <param name="hwProvider"> the Hull-White model parameter provider </param> /// <returns> the point sensitivity to the rate curves </returns> public virtual PointSensitivityBuilder presentValueSensitivityRates(ResolvedSwaption swaption, RatesProvider ratesProvider, HullWhiteOneFactorPiecewiseConstantParametersProvider hwProvider) { validate(swaption, ratesProvider, hwProvider); ResolvedSwap swap = swaption.Underlying; LocalDate expiryDate = swaption.ExpiryDate; if (expiryDate.isBefore(ratesProvider.ValuationDate)) { // Option has expired already return(PointSensitivityBuilder.none()); } ImmutableMap <Payment, PointSensitivityBuilder> cashFlowEquivSensi = CashFlowEquivalentCalculator.cashFlowEquivalentAndSensitivitySwap(swap, ratesProvider); ImmutableList <Payment> list = cashFlowEquivSensi.Keys.asList(); ImmutableList <PointSensitivityBuilder> listSensi = cashFlowEquivSensi.values().asList(); int nPayments = list.size(); double[] alpha = new double[nPayments]; double[] discountedCashFlow = new double[nPayments]; for (int loopcf = 0; loopcf < nPayments; loopcf++) { Payment payment = list.get(loopcf); alpha[loopcf] = hwProvider.alpha(ratesProvider.ValuationDate, expiryDate, expiryDate, payment.Date); discountedCashFlow[loopcf] = paymentPricer.presentValueAmount(payment, ratesProvider); } double omega = (swap.getLegs(SwapLegType.FIXED).get(0).PayReceive.Pay ? -1d : 1d); double kappa = computeKappa(hwProvider, discountedCashFlow, alpha, omega); PointSensitivityBuilder point = PointSensitivityBuilder.none(); for (int loopcf = 0; loopcf < nPayments; loopcf++) { Payment payment = list.get(loopcf); double cdf = NORMAL.getCDF(omega * (kappa + alpha[loopcf])); point = point.combinedWith(paymentPricer.presentValueSensitivity(payment, ratesProvider).multipliedBy(cdf)); if (!listSensi.get(loopcf).Equals(PointSensitivityBuilder.none())) { point = point.combinedWith(listSensi.get(loopcf).multipliedBy(cdf * ratesProvider.discountFactor(payment.Currency, payment.Date))); } } return(swaption.LongShort.Long ? point : point.multipliedBy(-1d)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableValidator private void validate() private void validate() { ISet <RepoGroup> uniqueRepoGroups = new HashSet <RepoGroup>(repoCurveGroups.values()); uniqueRepoGroups.addAll(repoCurveSecurityGroups.values()); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: ISet <RepoGroup> uniqueRepoCurves = repoCurves.Keys.Select(p => p.First).collect(toImmutableSet()); //JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method: if (!uniqueRepoCurves.containsAll(uniqueRepoGroups)) { throw new System.ArgumentException("Repo curve groups defined without matching curve mappings: " + Sets.difference(uniqueRepoGroups, uniqueRepoCurves)); } ISet <LegalEntityGroup> uniqueIssuerGroups = new HashSet <LegalEntityGroup>(issuerCurveGroups.values()); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: ISet <LegalEntityGroup> uniqueIssuerCurves = issuerCurves.Keys.Select(p => p.First).collect(toImmutableSet()); //JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method: if (!uniqueIssuerCurves.containsAll(uniqueIssuerGroups)) { throw new System.ArgumentException("Issuer curve groups defined without matching curve mappings: " + Sets.difference(uniqueIssuerGroups, uniqueIssuerCurves)); } }
//------------------------------------------------------------------------- public FunctionRequirements requirements(ISet <IborIndex> indices) { foreach (Index index in indices) { if (!volatilityIds.Keys.Contains(index)) { throw new System.ArgumentException(msgIndexNotFound(index)); } } return(FunctionRequirements.builder().valueRequirements(ImmutableSet.copyOf(volatilityIds.values())).build()); }
//------------------------------------------------------------------------- public FunctionRequirements requirements(ISet <CurrencyPair> currencyPairs) { foreach (CurrencyPair currencyPair in currencyPairs) { if (!volatilityIds.Keys.Contains(currencyPair)) { throw new System.ArgumentException(msgPairNotFound(currencyPair)); } } return(FunctionRequirements.builder().valueRequirements(ImmutableSet.copyOf(volatilityIds.values())).build()); }
public virtual void test_swapIndicies() { ImmutableMap <string, SwapIndex> mapAll = SwapIndices.ENUM_LOOKUP.lookupAll(); ImmutableList <SwapIndex> indexAll = mapAll.values().asList(); ImmutableList <string> nameAll = mapAll.Keys.asList(); int size = indexAll.size(); for (int i = 0; i < size; ++i) { // check no duplication for (int j = i + 1; j < size; ++j) { assertFalse(nameAll.get(i).Equals(nameAll.get(j))); assertFalse(indexAll.get(i).Equals(indexAll.get(j))); } } foreach (string name in nameAll) { SwapIndex index = mapAll.get(name); assertEquals(SwapIndex.of(name), index); assertEquals(index.Active, true); FixedIborSwapTemplate temp = index.Template; FixedIborSwapConvention conv = temp.Convention; Tenor tenor = temp.Tenor; LocalTime time = index.FixingTime; ZoneId zone = index.FixingZone; // test consistency between name and template assertTrue(name.Contains(tenor.ToString())); if (name.StartsWith("USD", StringComparison.Ordinal)) { assertTrue(name.Contains("1100") || name.Contains("1500")); assertTrue(conv.Equals(FixedIborSwapConventions.USD_FIXED_6M_LIBOR_3M)); assertTrue(zone.Equals(NEY_YORK)); } if (name.StartsWith("GBP", StringComparison.Ordinal)) { assertTrue(name.Contains("1100")); if (tenor.Equals(Tenor.TENOR_1Y)) { assertTrue(conv.Equals(FixedIborSwapConventions.GBP_FIXED_1Y_LIBOR_3M)); } else { assertTrue(conv.Equals(FixedIborSwapConventions.GBP_FIXED_6M_LIBOR_6M)); } assertTrue(zone.Equals(LONDON)); } if (name.StartsWith("EUR", StringComparison.Ordinal)) { assertTrue(name.Contains("1100") || name.Contains("1200")); if (tenor.Equals(Tenor.TENOR_1Y)) { assertTrue(conv.Equals(FixedIborSwapConventions.EUR_FIXED_1Y_EURIBOR_3M)); } else { assertTrue(conv.Equals(FixedIborSwapConventions.EUR_FIXED_1Y_EURIBOR_6M)); } assertTrue(zone.Equals(FRANKFURT)); } if (name.Contains("1100")) { assertTrue(time.Equals(LocalTime.of(11, 0))); } if (name.Contains("1200")) { assertTrue(time.Equals(LocalTime.of(12, 0))); } if (name.Contains("1500")) { assertTrue(time.Equals(LocalTime.of(15, 0))); } assertEquals(index.calculateFixingDateTime(date(2015, 6, 30)), date(2015, 6, 30).atTime(time).atZone(zone)); } }
//------------------------------------------------------------------------- /// <summary> /// Finds the curve with the specified name. /// <para> /// If the curve cannot be found, empty is returned. /// /// </para> /// </summary> /// <param name="name"> the curve name </param> /// <returns> the curve, empty if not found </returns> public Optional <Curve> findCurve(CurveName name) { return(Stream.concat(discountCurves.values().stream(), forwardCurves.values().stream()).filter(c => c.Name.Equals(name)).findFirst()); }