public virtual void collectorDifferentArrayLengths() { IList <CurrencyScenarioArray> arrays = ImmutableList.of(CurrencyScenarioArray.of(USD, DoubleArray.of(10, 20, 30)), CurrencyScenarioArray.of(GBP, DoubleArray.of(1, 2))); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: assertThrowsIllegalArg(() => arrays.collect(toMultiCurrencyScenarioArray())); }
/// <summary> /// Test the expected exception is thrown if there are not the same number of rates as there are values. /// </summary> public virtual void wrongNumberOfFxRates() { DoubleArray values = DoubleArray.of(1, 2, 3); FxRateScenarioArray rates = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62)); ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates); CurrencyScenarioArray test = CurrencyScenarioArray.of(GBP, values); assertThrows(() => test.convertedTo(USD, fxProvider), typeof(System.ArgumentException), "Expected 3 FX rates but received 2"); }
/// <summary> /// Test the expected exception is thrown when there are no FX rates available to convert the values. /// </summary> public virtual void missingFxRates() { DoubleArray values = DoubleArray.of(1, 2, 3); FxRateScenarioArray rates = FxRateScenarioArray.of(EUR, USD, DoubleArray.of(1.61, 1.62, 1.63)); ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates); CurrencyScenarioArray test = CurrencyScenarioArray.of(GBP, values); assertThrows(() => test.convertedTo(USD, fxProvider), typeof(System.ArgumentException)); }
public virtual void total() { IList <CurrencyScenarioArray> arrays = ImmutableList.of(CurrencyScenarioArray.of(USD, DoubleArray.of(10, 20, 30)), CurrencyScenarioArray.of(USD, DoubleArray.of(5, 6, 7)), CurrencyScenarioArray.of(EUR, DoubleArray.of(2, 4, 6)), CurrencyScenarioArray.of(GBP, DoubleArray.of(11, 12, 13)), CurrencyScenarioArray.of(GBP, DoubleArray.of(1, 2, 3))); IDictionary <Currency, DoubleArray> expectedMap = ImmutableMap.of(USD, DoubleArray.of(15, 26, 37), EUR, DoubleArray.of(2, 4, 6), GBP, DoubleArray.of(12, 14, 16)); MultiCurrencyScenarioArray expected = MultiCurrencyScenarioArray.of(expectedMap); assertThat(MultiCurrencyScenarioArray.total(arrays)).isEqualTo(expected); }
public virtual void collector() { IList <CurrencyScenarioArray> arrays = ImmutableList.of(CurrencyScenarioArray.of(USD, DoubleArray.of(10, 20, 30)), CurrencyScenarioArray.of(USD, DoubleArray.of(5, 6, 7)), CurrencyScenarioArray.of(EUR, DoubleArray.of(2, 4, 6)), CurrencyScenarioArray.of(GBP, DoubleArray.of(11, 12, 13)), CurrencyScenarioArray.of(GBP, DoubleArray.of(1, 2, 3))); IDictionary <Currency, DoubleArray> expectedMap = ImmutableMap.of(USD, DoubleArray.of(15, 26, 37), EUR, DoubleArray.of(2, 4, 6), GBP, DoubleArray.of(12, 14, 16)); MultiCurrencyScenarioArray expected = MultiCurrencyScenarioArray.of(expectedMap); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: assertThat(arrays.collect(toMultiCurrencyScenarioArray())).isEqualTo(expected); }
public virtual void coverage() { DoubleArray values = DoubleArray.of(1, 2, 3); CurrencyScenarioArray test = CurrencyScenarioArray.of(GBP, values); coverImmutableBean(test); DoubleArray values2 = DoubleArray.of(1, 2, 3); CurrencyScenarioArray test2 = CurrencyScenarioArray.of(USD, values2); coverBeanEquals(test, test2); }
/// <summary> /// Test that no conversion is done and no rates are used if the values are already in the reporting currency. /// </summary> public virtual void noConversionNecessary() { DoubleArray values = DoubleArray.of(1, 2, 3); FxRateScenarioArray rates = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63)); ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates); CurrencyScenarioArray test = CurrencyScenarioArray.of(GBP, values); CurrencyScenarioArray convertedList = test.convertedTo(GBP, fxProvider); assertThat(convertedList).isEqualTo(test); }
public virtual void create_fromFunction() { IList <CurrencyAmount> values = ImmutableList.of(CurrencyAmount.of(GBP, 1), CurrencyAmount.of(GBP, 2), CurrencyAmount.of(GBP, 3)); CurrencyScenarioArray test = CurrencyScenarioArray.of(3, i => values[i]); assertThat(test.Currency).isEqualTo(GBP); assertThat(test.Amounts.Values).isEqualTo(DoubleArray.of(1d, 2d, 3d)); assertThat(test.ScenarioCount).isEqualTo(3); assertThat(test.get(0)).isEqualTo(CurrencyAmount.of(GBP, 1)); assertThat(test.get(1)).isEqualTo(CurrencyAmount.of(GBP, 2)); assertThat(test.get(2)).isEqualTo(CurrencyAmount.of(GBP, 3)); assertThat(test.ToList()).containsExactly(CurrencyAmount.of(GBP, 1), CurrencyAmount.of(GBP, 2), CurrencyAmount.of(GBP, 3)); }
public virtual void create() { DoubleArray values = DoubleArray.of(1, 2, 3); CurrencyScenarioArray test = CurrencyScenarioArray.of(GBP, values); assertThat(test.Currency).isEqualTo(GBP); assertThat(test.Amounts.Values).isEqualTo(values); assertThat(test.ScenarioCount).isEqualTo(3); assertThat(test.get(0)).isEqualTo(CurrencyAmount.of(GBP, 1)); assertThat(test.get(1)).isEqualTo(CurrencyAmount.of(GBP, 2)); assertThat(test.get(2)).isEqualTo(CurrencyAmount.of(GBP, 3)); assertThat(test.ToList()).containsExactly(CurrencyAmount.of(GBP, 1), CurrencyAmount.of(GBP, 2), CurrencyAmount.of(GBP, 3)); }
//------------------------------------------------------------------------- /// <summary> /// Test that values are converted to the reporting currency using the rates in the market data. /// </summary> public virtual void convert() { DoubleArray values = DoubleArray.of(1, 2, 3); FxRateScenarioArray rates = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63)); ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates); CurrencyScenarioArray test = CurrencyScenarioArray.of(GBP, values); CurrencyScenarioArray convertedList = test.convertedTo(USD, fxProvider); DoubleArray expectedValues = DoubleArray.of(1 * 1.61, 2 * 1.62, 3 * 1.63); CurrencyScenarioArray expectedList = CurrencyScenarioArray.of(USD, expectedValues); assertThat(convertedList).isEqualTo(expectedList); }
/// <summary> /// Test the minus() methods work as expected. /// </summary> public virtual void minus() { CurrencyScenarioArray currencyScenarioArray = CurrencyScenarioArray.of(GBP, DoubleArray.of(1, 2, 3)); CurrencyScenarioArray arrayToSubtract = CurrencyScenarioArray.of(GBP, DoubleArray.of(3, 2, 1)); CurrencyScenarioArray minusArrayResult = currencyScenarioArray.minus(arrayToSubtract); assertThat(minusArrayResult).isEqualTo(CurrencyScenarioArray.of(GBP, DoubleArray.of(-2, 0, 2))); CurrencyAmount amountToSubtract = CurrencyAmount.of(Currency.GBP, 2); CurrencyScenarioArray minusAmountResult = currencyScenarioArray.minus(amountToSubtract); assertThat(minusAmountResult).isEqualTo(CurrencyScenarioArray.of(GBP, DoubleArray.of(-1, 0, 1))); }
/// <summary> /// Test the plus() methods work as expected. /// </summary> public virtual void plus() { CurrencyScenarioArray currencyScenarioArray = CurrencyScenarioArray.of(GBP, DoubleArray.of(1, 2, 3)); CurrencyScenarioArray arrayToAdd = CurrencyScenarioArray.of(GBP, DoubleArray.of(4, 5, 6)); CurrencyScenarioArray plusArraysResult = currencyScenarioArray.plus(arrayToAdd); assertThat(plusArraysResult).isEqualTo(CurrencyScenarioArray.of(GBP, DoubleArray.of(5, 7, 9))); CurrencyAmount amountToAdd = CurrencyAmount.of(Currency.GBP, 10); CurrencyScenarioArray plusAmountResult = currencyScenarioArray.plus(amountToAdd); assertThat(plusAmountResult).isEqualTo(CurrencyScenarioArray.of(GBP, DoubleArray.of(11, 12, 13))); }
//------------------------------------------------------------------------- public CurrencyScenarioArray convertedTo(Currency reportingCurrency, ScenarioFxRateProvider fxRateProvider) { int size = ScenarioCount; if (fxRateProvider.ScenarioCount != size) { throw new System.ArgumentException(Messages.format("Expected {} FX rates but received {}", size, fxRateProvider.ScenarioCount)); } double[] singleCurrencyValues = new double[size]; foreach (KeyValuePair <Currency, DoubleArray> entry in amounts.Values.entrySet()) { Currency currency = entry.Key; DoubleArray currencyValues = entry.Value; for (int i = 0; i < size; i++) { double convertedValue = currencyValues.get(i) * fxRateProvider.fxRate(currency, reportingCurrency, i); singleCurrencyValues[i] += convertedValue; } } return(CurrencyScenarioArray.of(reportingCurrency, DoubleArray.ofUnsafe(singleCurrencyValues))); }
/// <summary> /// Returns a new array containing the values from this array with the specified amount subtracted. /// <para> /// The amount is subtracted from each element in this array. /// The currency must be the same as the currency of this array. /// /// </para> /// </summary> /// <param name="amount"> the amount to subtract </param> /// <returns> a new array containing the values from this array with the specified amount subtracted </returns> /// <exception cref="IllegalArgumentException"> if the array and the amount have different currencies </exception> public CurrencyScenarioArray minus(CurrencyAmount amount) { return(CurrencyScenarioArray.of(amounts.minus(amount))); }
/// <summary> /// Returns a new array containing the values from this array with the values from the other array subtracted. /// <para> /// The amounts are subtracted from the matching element in this array. /// The currency must be the same as the currency of this array. /// The arrays must have the same size. /// /// </para> /// </summary> /// <param name="other"> another array of multiple currency values. </param> /// <returns> a new array containing the values from this array with the values from the other array subtracted </returns> /// <exception cref="IllegalArgumentException"> if the arrays have different sizes or different currencies </exception> public CurrencyScenarioArray minus(CurrencyScenarioArray other) { return(CurrencyScenarioArray.of(amounts.minus(other.amounts))); }
public virtual void create_fromFunction_mixedCurrency() { IList <CurrencyAmount> values = ImmutableList.of(CurrencyAmount.of(GBP, 1), CurrencyAmount.of(USD, 2), CurrencyAmount.of(GBP, 3)); assertThrowsIllegalArg(() => CurrencyScenarioArray.of(3, i => values[i])); }