Beispiel #1
0
        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()));
        }
Beispiel #2
0
        /// <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");
        }
Beispiel #3
0
        /// <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));
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        /// <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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        public virtual void convert()
        {
            FxRateScenarioArray    rates1         = FxRateScenarioArray.of(GBP, CAD, DoubleArray.of(2.00, 2.01, 2.02));
            FxRateScenarioArray    rates2         = FxRateScenarioArray.of(USD, CAD, DoubleArray.of(1.30, 1.31, 1.32));
            FxRateScenarioArray    rates3         = FxRateScenarioArray.of(EUR, CAD, DoubleArray.of(1.4, 1.4, 1.4));
            ScenarioFxRateProvider fxProvider     = new TestScenarioFxRateProvider(rates1, rates2, rates3);
            CurrencyScenarioArray  convertedArray = VALUES_ARRAY.convertedTo(Currency.CAD, fxProvider);
            DoubleArray            expected       = DoubleArray.of(20 * 2.00 + 30 * 1.30 + 40 * 1.4, 21 * 2.01 + 32 * 1.31 + 43 * 1.4, 22 * 2.02 + 33 * 1.32 + 44 * 1.4);

            assertThat(convertedArray.Amounts.Values).isEqualTo(expected);
        }
Beispiel #9
0
        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));
        }
Beispiel #10
0
        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));
        }
Beispiel #11
0
        //-------------------------------------------------------------------------
        /// <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);
        }
Beispiel #12
0
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         CurrencyScenarioArray other = (CurrencyScenarioArray)obj;
         return(JodaBeanUtils.equal(amounts, other.amounts));
     }
     return(false);
 }
Beispiel #13
0
        /// <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)));
        }
Beispiel #14
0
        /// <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)));
        }
Beispiel #15
0
        public virtual void convertIntoAnExistingCurrency()
        {
            FxRateScenarioArray    rates1         = FxRateScenarioArray.of(USD, GBP, DoubleArray.of(1 / 1.50, 1 / 1.51, 1 / 1.52));
            FxRateScenarioArray    rates2         = FxRateScenarioArray.of(EUR, GBP, DoubleArray.of(0.7, 0.7, 0.7));
            ScenarioFxRateProvider fxProvider     = new TestScenarioFxRateProvider(rates1, rates2);
            CurrencyScenarioArray  convertedArray = VALUES_ARRAY.convertedTo(Currency.GBP, fxProvider);

            assertThat(convertedArray.Currency).isEqualTo(Currency.GBP);
            double[] expected = new double[] { 20 + 30 / 1.50 + 40 * 0.7, 21 + 32 / 1.51 + 43 * 0.7, 22 + 33 / 1.52 + 44 * 0.7 };

            for (int i = 0; i < 3; i++)
            {
                assertThat(convertedArray.get(i).Amount).isEqualTo(expected[i], offset(1e-6));
            }
        }
Beispiel #16
0
        //-------------------------------------------------------------------------
        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)));
        }
Beispiel #17
0
        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]));
        }
Beispiel #18
0
 /// <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)));
 }
Beispiel #19
0
 /// <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)));
 }