예제 #1
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");
        }
예제 #2
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));
        }
        public virtual void wrongNumberOfFxRates()
        {
            FxRateScenarioArray    rates      = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63));
            ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates);

            IList <CurrencyAmount> values = ImmutableList.of(CurrencyAmount.of(Currency.GBP, 1), CurrencyAmount.of(Currency.GBP, 2));
            DefaultScenarioArray <CurrencyAmount> test = DefaultScenarioArray.of(values);

            assertThrows(() => test.convertedTo(Currency.USD, fxProvider), typeof(System.ArgumentException), "Expected 2 FX rates but received 3");
        }
        public virtual void missingFxRates()
        {
            FxRateScenarioArray    rates      = FxRateScenarioArray.of(EUR, USD, DoubleArray.of(1.61, 1.62, 1.63));
            ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates);

            IList <CurrencyAmount> values = ImmutableList.of(CurrencyAmount.of(Currency.GBP, 1), CurrencyAmount.of(Currency.GBP, 2), CurrencyAmount.of(Currency.GBP, 3));
            DefaultScenarioArray <CurrencyAmount> test = DefaultScenarioArray.of(values);

            assertThrows(() => test.convertedTo(Currency.USD, fxProvider), typeof(System.ArgumentException));
        }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
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);
        }
        public virtual void notConvertible()
        {
            FxRateScenarioArray    rates      = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63));
            ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates);

            IList <string> values = ImmutableList.of("a", "b", "c");
            DefaultScenarioArray <string> test = DefaultScenarioArray.of(values);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: ScenarioArray<?> convertedList = test.convertedTo(com.opengamma.strata.basics.currency.Currency.GBP, fxProvider);
            ScenarioArray <object> convertedList = test.convertedTo(Currency.GBP, fxProvider);

            assertThat(convertedList).isEqualTo(test);
        }
        public virtual void convertCurrencyAmount()
        {
            FxRateScenarioArray    rates              = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63));
            ScenarioFxRateProvider fxProvider         = new TestScenarioFxRateProvider(rates);
            SingleScenarioArray <CurrencyAmount> test = SingleScenarioArray.of(3, CurrencyAmount.of(GBP, 2));

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: ScenarioArray<?> convertedList = test.convertedTo(USD, fxProvider);
            ScenarioArray <object> convertedList  = test.convertedTo(USD, fxProvider);
            IList <CurrencyAmount> expectedValues = ImmutableList.of(CurrencyAmount.of(USD, 2 * 1.61), CurrencyAmount.of(USD, 2 * 1.62), CurrencyAmount.of(USD, 2 * 1.63));
            DefaultScenarioArray <CurrencyAmount> expectedList = DefaultScenarioArray.of(expectedValues);

            assertThat(convertedList).isEqualTo(expectedList);
        }
예제 #10
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));
            }
        }
예제 #11
0
 public FxRateProviderAnonymousInnerClass(TestScenarioFxRateProvider outerInstance, int scenarioIndex)
 {
     this.outerInstance = outerInstance;
     this.scenarioIndex = scenarioIndex;
 }