Beispiel #1
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            FxRateScenarioArray rates1 = FxRateScenarioArray.of(Currency.EUR, Currency.USD, DoubleArray.of(1.07, 1.08, 1.09));
            FxRateScenarioArray rates2 = FxRateScenarioArray.of(Currency.GBP, Currency.USD, DoubleArray.of(1.46, 1.47, 1.48));

            coverImmutableBean(rates1);
            coverBeanEquals(rates1, rates2);
        }
Beispiel #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));
        }
Beispiel #3
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");
        }
        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");
        }
Beispiel #5
0
        //-------------------------------------------------------------------------
        private static void assertArraysEqual(FxRateScenarioArray a1, FxRateScenarioArray a2)
        {
            assertThat(a1.ScenarioCount).isEqualTo(a2.ScenarioCount);
            assertThat(a1.Pair).isEqualTo(a2.Pair);

            for (int i = 0; i < a1.ScenarioCount; i++)
            {
                assertThat(a1.fxRate(Currency.GBP, Currency.USD, i)).isEqualTo(a2.fxRate(Currency.GBP, Currency.USD, i), offset(TOLERANCE));
            }
        }
        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));
        }
Beispiel #7
0
        public virtual void getValues()
        {
            FxRateScenarioArray rates = FxRateScenarioArray.of(Currency.EUR, Currency.USD, DoubleArray.of(1.07, 1.08, 1.09));

            assertThat(rates.Pair).isEqualTo(CurrencyPair.of(Currency.EUR, Currency.USD));
            assertThat(rates.ScenarioCount).isEqualTo(3);
            assertThat(rates.get(0)).isEqualTo(FxRate.of(Currency.EUR, Currency.USD, 1.07));
            assertThat(rates.get(1)).isEqualTo(FxRate.of(Currency.EUR, Currency.USD, 1.08));
            assertThat(rates.get(2)).isEqualTo(FxRate.of(Currency.EUR, Currency.USD, 1.09));
            assertThrows(typeof(System.IndexOutOfRangeException), () => rates.get(3));
        }
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
        /// <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 #10
0
        public virtual void convert_inverse()
        {
            FxRateScenarioArray eurGbp    = FxRateScenarioArray.of(Currency.EUR, Currency.GBP, DoubleArray.of(0.76, 0.75));
            DoubleArray         input     = DoubleArray.of(1.11, 1.12);
            DoubleArray         expected  = DoubleArray.of(1.11 * 1 / 0.76, 1.12 * 1 / 0.75);
            DoubleArray         converted = eurGbp.convert(input, Currency.GBP, Currency.EUR);

            for (int i = 0; i < converted.size(); i++)
            {
                assertThat(converted.get(i)).isEqualTo(expected.get(i), offset(TOLERANCE));
            }
        }
Beispiel #11
0
        public virtual void fxRate()
        {
            FxRateScenarioArray rates = FxRateScenarioArray.of(CurrencyPair.of(Currency.EUR, Currency.USD), DoubleArray.of(1.07, 1.08, 1.09));

            assertThat(rates.fxRate(Currency.EUR, Currency.USD, 0)).isEqualTo(1.07);
            assertThat(rates.fxRate(Currency.EUR, Currency.USD, 1)).isEqualTo(1.08);
            assertThat(rates.fxRate(Currency.EUR, Currency.USD, 2)).isEqualTo(1.09);

            assertThat(rates.fxRate(Currency.USD, Currency.EUR, 0)).isEqualTo(1 / 1.07);
            assertThat(rates.fxRate(Currency.USD, Currency.EUR, 1)).isEqualTo(1 / 1.08);
            assertThat(rates.fxRate(Currency.USD, Currency.EUR, 2)).isEqualTo(1 / 1.09);
        }
Beispiel #12
0
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         FxRateScenarioArray other = (FxRateScenarioArray)obj;
         return(JodaBeanUtils.equal(pair, other.pair) && JodaBeanUtils.equal(rates, other.rates));
     }
     return(false);
 }
Beispiel #13
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 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);
        }
        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);
        }
Beispiel #16
0
        private FxRateScenarioArray computeCross(FxRateScenarioArray other, CurrencyPair crossPairAC)
        {
            // aim is to convert AAA/BBB and BBB/CCC to AAA/CCC
            Currency currA = crossPairAC.Base;
            Currency currC = crossPairAC.Counter;
            // given the conventional cross rate pair, order the two rates to match
            bool crossBaseCurrencyInFx1  = pair.contains(currA);
            FxRateScenarioArray fxABorBA = crossBaseCurrencyInFx1 ? this : other;
            FxRateScenarioArray fxBCorCB = crossBaseCurrencyInFx1 ? other : this;
            // extract the rates, taking the inverse if the pair is in the inverse order
            DoubleArray ratesAB = fxABorBA.Pair.Base.Equals(currA) ? fxABorBA.rates : fxABorBA.rates.map(v => 1 / v);
            DoubleArray ratesBC = fxBCorCB.Pair.Counter.Equals(currC) ? fxBCorCB.rates : fxBCorCB.rates.map(v => 1 / v);

            return(FxRateScenarioArray.of(crossPairAC, ratesAB.multipliedBy(ratesBC)));
        }
        //-------------------------------------------------------------------------
        public virtual void test_addScenarioValueMap()
        {
            FxRateId            eurGbpId    = FxRateId.of(Currency.EUR, Currency.GBP);
            FxRateId            eurUsdId    = FxRateId.of(Currency.EUR, Currency.USD);
            FxRateScenarioArray eurGbpRates = FxRateScenarioArray.of(Currency.EUR, Currency.GBP, DoubleArray.of(0.79, 0.8, 0.81));
            FxRateScenarioArray eurUsdRates = FxRateScenarioArray.of(Currency.EUR, Currency.USD, DoubleArray.of(1.09, 1.1, 1.11));
            IDictionary <FxRateId, FxRateScenarioArray> values = ImmutableMap.of(eurGbpId, eurGbpRates, eurUsdId, eurUsdRates);

            ImmutableScenarioMarketData marketData = ImmutableScenarioMarketData.builder(VAL_DATE).addScenarioValueMap(values).build();

            assertEquals(marketData.ScenarioCount, 3);
            assertEquals(marketData.Ids, ImmutableSet.of(eurGbpId, eurUsdId));
            assertEquals(marketData.getValue(eurGbpId), MarketDataBox.ofScenarioValue(eurGbpRates));
            assertEquals(marketData.getValue(eurUsdId), MarketDataBox.ofScenarioValue(eurUsdRates));
        }
Beispiel #18
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 #19
0
        public virtual void crossRatesInvalidInputs()
        {
            // Argument has both currencies the same
            assertThrowsIllegalArg(() => FxRateScenarioArray.of(Currency.GBP, Currency.USD, DoubleArray.of(1)).crossRates(FxRateScenarioArray.of(Currency.EUR, Currency.EUR, DoubleArray.of(1))));

            // Receiver has both currencies the same
            assertThrowsIllegalArg(() => FxRateScenarioArray.of(Currency.GBP, Currency.GBP, DoubleArray.of(1)).crossRates(FxRateScenarioArray.of(Currency.EUR, Currency.USD, DoubleArray.of(1))));

            // No currency in common
            assertThrowsIllegalArg(() => FxRateScenarioArray.of(Currency.GBP, Currency.CHF, DoubleArray.of(1)).crossRates(FxRateScenarioArray.of(Currency.EUR, Currency.USD, DoubleArray.of(1))));

            // Both pairs the same
            assertThrowsIllegalArg(() => FxRateScenarioArray.of(Currency.GBP, Currency.CHF, DoubleArray.of(1)).crossRates(FxRateScenarioArray.of(Currency.GBP, Currency.CHF, DoubleArray.of(1))));

            // Different length arrays
            assertThrowsIllegalArg(() => FxRateScenarioArray.of(Currency.GBP, Currency.CHF, DoubleArray.of(1)).crossRates(FxRateScenarioArray.of(Currency.EUR, Currency.CHF, DoubleArray.of(1, 2))));
        }
Beispiel #20
0
        public virtual void crossRates()
        {
            FxRateScenarioArray eurGbp         = FxRateScenarioArray.of(Currency.EUR, Currency.GBP, DoubleArray.of(0.76, 0.75));
            FxRateScenarioArray eurUsd         = FxRateScenarioArray.of(Currency.EUR, Currency.USD, DoubleArray.of(1.11, 1.12));
            FxRateScenarioArray gbpEur         = FxRateScenarioArray.of(Currency.GBP, Currency.EUR, DoubleArray.of(1 / 0.76, 1 / 0.75));
            FxRateScenarioArray usdEur         = FxRateScenarioArray.of(Currency.USD, Currency.EUR, DoubleArray.of(1 / 1.11, 1 / 1.12));
            FxRateScenarioArray expectedGbpUsd = FxRateScenarioArray.of(Currency.GBP, Currency.USD, DoubleArray.of(1.460526315789474, 1.4933333333333334));

            assertArraysEqual(eurGbp.crossRates(eurUsd), expectedGbpUsd);
            assertArraysEqual(eurGbp.crossRates(usdEur), expectedGbpUsd);
            assertArraysEqual(gbpEur.crossRates(eurUsd), expectedGbpUsd);
            assertArraysEqual(gbpEur.crossRates(usdEur), expectedGbpUsd);

            assertArraysEqual(eurUsd.crossRates(eurGbp), expectedGbpUsd);
            assertArraysEqual(usdEur.crossRates(eurGbp), expectedGbpUsd);
            assertArraysEqual(eurUsd.crossRates(gbpEur), expectedGbpUsd);
            assertArraysEqual(usdEur.crossRates(gbpEur), expectedGbpUsd);
        }
Beispiel #21
0
        public virtual void unknownCurrencyPair()
        {
            FxRateScenarioArray rates = FxRateScenarioArray.of(Currency.EUR, Currency.USD, DoubleArray.of(1.07, 1.08, 1.09));

            assertThrowsIllegalArg(() => rates.fxRate(Currency.AED, Currency.ARS, 0));
        }
Beispiel #22
0
 public virtual void identicalCurrenciesHaveRateOfOne()
 {
     assertThrowsIllegalArg(() => FxRateScenarioArray.of(Currency.EUR, Currency.EUR, DoubleArray.of(1.07, 1.08, 1.09)), "Conversion rate between identical currencies must be one");
 }
Beispiel #23
0
 public TestScenarioFxRateProvider(FxRateScenarioArray rates1, FxRateScenarioArray rates2, FxRateScenarioArray rates3)
 {
     this.rates1 = rates1;
     this.rates2 = rates2;
     this.rates3 = rates3;
 }
Beispiel #24
0
        public virtual void convert_unknown()
        {
            FxRateScenarioArray eurGbp = FxRateScenarioArray.of(Currency.EUR, Currency.GBP, DoubleArray.of(0.76, 0.75));

            assertThrowsIllegalArg(() => eurGbp.convert(DoubleArray.of(1.07, 1.08), Currency.EUR, Currency.USD));
        }
Beispiel #25
0
 /// <summary>
 /// Derives a set of FX rates from these rates and another set of rates.
 /// <para>
 /// For example, given rates for EUR/GBP and EUR/CHF it is possible to derive rates for GBP/CHF.
 /// </para>
 /// <para>
 /// There must be exactly one currency in common between the two currency pairs and
 /// each pair must contain two different currencies. The other rates must have the same scenario count
 /// as these rates.
 /// </para>
 /// <para>
 /// The returned object contains rates for converting between the two currencies which only appear in
 /// one set of rates.
 ///
 /// </para>
 /// </summary>
 /// <param name="other">  the other rates </param>
 /// <returns> a set of FX rates derived from these rates and the other rates </returns>
 public FxRateScenarioArray crossRates(FxRateScenarioArray other)
 {
     return(pair.cross(other.pair).map(cross => computeCross(other, cross)).orElseThrow(() => new System.ArgumentException(Messages.format("Unable to cross when no unique common currency: {} and {}", pair, other.pair))));
 }