/// <summary> /// Tests the tokens() method when the bean has a single property. The tokens should include the single property /// name plus the tokens of the property value. /// </summary> public virtual void tokensSingleProperty() { SwapLegAmount amount = SwapLegAmount.builder().amount(CurrencyAmount.of(Currency.AUD, 7)).payReceive(PayReceive.PAY).type(SwapLegType.FIXED).currency(Currency.AUD).build(); LegAmounts amounts = LegAmounts.of(amount); BeanTokenEvaluator evaluator = new BeanTokenEvaluator(); ISet <string> tokens = evaluator.tokens(amounts); assertThat(tokens).isEqualTo(ImmutableSet.of("amounts", "0", "aud", "pay", "fixed")); }
// leg initial notional, which is the same for all scenarios // package-scoped for testing internal LegAmounts legInitialNotional(ResolvedSwapTrade trade) { IList <Pair <ResolvedSwapLeg, CurrencyAmount> > notionals = trade.Product.Legs.Select(leg => Pair.of(leg, buildLegNotional(leg))).ToList(); CurrencyAmount firstNotional = notionals.Where(pair => pair.Second != NOT_FOUND).Select(pair => pair.Second).First().orElseThrow(() => new System.ArgumentException("No notional found on any swap leg")); notionals = notionals.Select(pair => pair.Second != NOT_FOUND ? pair : Pair.of(pair.First, firstNotional)).ToList(); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: ImmutableList <LegAmount> legAmounts = notionals.Select(pair => SwapLegAmount.of(pair.First, pair.Second)).collect(toImmutableList()); return(LegAmounts.of(legAmounts)); }
/// <summary> /// Tests evaluating a bean with a single property. There are 2 different expected behaviours: /// /// 1) If the token matches the property, the property value is returned and the token is consumed. This is the same /// as the normal bean behaviour. /// 2) If the token doesn't match the property it is assumed to match something on the property's value. In this /// case the property value is returned and no tokens are consumed. /// </summary> public virtual void evaluateSingleProperty() { SwapLegAmount amount = SwapLegAmount.builder().amount(CurrencyAmount.of(Currency.AUD, 7)).payReceive(PayReceive.PAY).type(SwapLegType.FIXED).currency(Currency.AUD).build(); LegAmounts amounts = LegAmounts.of(amount); BeanTokenEvaluator evaluator = new BeanTokenEvaluator(); EvaluationResult result1 = evaluator.evaluate(amounts, FUNCTIONS, "amounts", ImmutableList.of("foo", "bar")); assertThat(result1.Result).hasValue(ImmutableList.of(amount)); assertThat(result1.RemainingTokens).isEqualTo(ImmutableList.of("foo", "bar")); EvaluationResult result2 = evaluator.evaluate(amounts, FUNCTIONS, "baz", ImmutableList.of("foo", "bar")); assertThat(result2.Result).hasValue(ImmutableList.of(amount)); assertThat(result2.RemainingTokens).isEqualTo(ImmutableList.of("baz", "foo", "bar")); }
// present value for a leg private SwapLegAmount legAmount(ResolvedSwapLeg leg, RatesProvider provider) { CurrencyAmount amount = tradePricer.ProductPricer.LegPricer.presentValue(leg, provider); return(SwapLegAmount.of(leg, amount)); }