private static MarketDataFxRateProvider provider2()
        {
            IDictionary <FxRateId, FxRate> marketDataMap = ImmutableMap.of(FxRateId.of(EUR, USD), FxRate.of(EUR, USD, EUR_USD), FxRateId.of(EUR, BEF), FxRate.of(EUR, BEF, EUR_BEF), FxRateId.of(GBP, USD), FxRate.of(GBP, USD, GBP_USD));
            MarketData marketData = ImmutableMarketData.of(VAL_DATE, marketDataMap);

            return(MarketDataFxRateProvider.of(marketData, ObservableSource.NONE, GBP));
        }
        //-------------------------------------------------------------------------
        private static MarketDataFxRateProvider provider()
        {
            IDictionary <FxRateId, FxRate> marketDataMap = ImmutableMap.of(FxRateId.of(EUR, USD, OBS_SOURCE), FxRate.of(EUR, USD, EUR_USD));
            MarketData marketData = ImmutableMarketData.of(VAL_DATE, marketDataMap);

            return(MarketDataFxRateProvider.of(marketData, OBS_SOURCE, GBP));
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            FxRateId test = FxRateId.of(GBP, USD);

            coverImmutableBean(test);
            FxRateId test2 = FxRateId.of(EUR, CHF, OBS_SOURCE);

            coverBeanEquals(test, test2);
        }
        public virtual void cross_counter()
        {
            IDictionary <FxRateId, FxRate> marketDataMap = ImmutableMap.of(FxRateId.of(EUR, USD), FxRate.of(EUR, USD, EUR_USD), FxRateId.of(EUR, BEF), FxRate.of(EUR, BEF, EUR_BEF));
            MarketData     marketData = ImmutableMarketData.of(VAL_DATE, marketDataMap);
            FxRateProvider fx         = MarketDataFxRateProvider.of(marketData);

            assertEquals(fx.fxRate(USD, BEF), EUR_BEF / EUR_USD, 1.0E-10);
            assertEquals(fx.fxRate(BEF, USD), EUR_USD / EUR_BEF, 1.0E-10);
        }
        public virtual void cross_base()
        {
            IDictionary <FxRateId, FxRate> marketDataMap = ImmutableMap.of(FxRateId.of(EUR, USD), FxRate.of(EUR, USD, EUR_USD), FxRateId.of(GBP, USD), FxRate.of(GBP, USD, GBP_USD));
            MarketData     marketData = ImmutableMarketData.of(VAL_DATE, marketDataMap);
            FxRateProvider fx         = MarketDataFxRateProvider.of(marketData);

            assertEquals(fx.fxRate(GBP, EUR), GBP_USD / EUR_USD, 1.0E-10);
            assertEquals(fx.fxRate(EUR, GBP), EUR_USD / GBP_USD, 1.0E-10);
        }
        //-------------------------------------------------------------------------
        public double fxRate(Currency baseCurrency, Currency counterCurrency)
        {
            if (baseCurrency.Equals(counterCurrency))
            {
                return(1);
            }
            // Try direct pair
            Optional <FxRate> rate = marketData.findValue(FxRateId.of(baseCurrency, counterCurrency, fxRatesSource));

            if (rate.Present)
            {
                return(rate.get().fxRate(baseCurrency, counterCurrency));
            }
            // try specified triangulation currency
            if (triangulationCurrency != null)
            {
                Optional <FxRate> rateBase1 = marketData.findValue(FxRateId.of(baseCurrency, triangulationCurrency, fxRatesSource));
                Optional <FxRate> rateBase2 = marketData.findValue(FxRateId.of(triangulationCurrency, counterCurrency, fxRatesSource));
                if (rateBase1.Present && rateBase2.Present)
                {
                    return(rateBase1.get().crossRate(rateBase2.get()).fxRate(baseCurrency, counterCurrency));
                }
            }
            // Try triangulation on base currency
            Currency          triangularBaseCcy = baseCurrency.TriangulationCurrency;
            Optional <FxRate> rateBase1         = marketData.findValue(FxRateId.of(baseCurrency, triangularBaseCcy, fxRatesSource));
            Optional <FxRate> rateBase2         = marketData.findValue(FxRateId.of(triangularBaseCcy, counterCurrency, fxRatesSource));

            if (rateBase1.Present && rateBase2.Present)
            {
                return(rateBase1.get().crossRate(rateBase2.get()).fxRate(baseCurrency, counterCurrency));
            }
            // Try triangulation on counter currency
            Currency          triangularCounterCcy = counterCurrency.TriangulationCurrency;
            Optional <FxRate> rateCounter1         = marketData.findValue(FxRateId.of(baseCurrency, triangularCounterCcy, fxRatesSource));
            Optional <FxRate> rateCounter2         = marketData.findValue(FxRateId.of(triangularCounterCcy, counterCurrency, fxRatesSource));

            if (rateCounter1.Present && rateCounter2.Present)
            {
                return(rateCounter1.get().crossRate(rateCounter2.get()).fxRate(baseCurrency, counterCurrency));
            }
            // Double triangulation
            if (rateBase1.Present && rateCounter2.Present)
            {
                Optional <FxRate> rateTriangular2 = marketData.findValue(FxRateId.of(triangularBaseCcy, triangularCounterCcy, fxRatesSource));
                if (rateTriangular2.Present)
                {
                    return(rateBase1.get().crossRate(rateTriangular2.get()).crossRate(rateCounter2.get()).fxRate(baseCurrency, counterCurrency));
                }
            }
            if (fxRatesSource.Equals(ObservableSource.NONE))
            {
                throw new MarketDataNotFoundException(Messages.format("No FX rate market data for {}/{}", baseCurrency, counterCurrency));
            }
            throw new MarketDataNotFoundException(Messages.format("No FX rate market data for {}/{} using source '{}'", baseCurrency, counterCurrency, fxRatesSource));
        }
        public virtual void test_of_currenciesAndSource()
        {
            FxRateId test    = FxRateId.of(GBP, USD, OBS_SOURCE);
            FxRateId inverse = FxRateId.of(USD, GBP);

            assertEquals(test.Pair, PAIR);
            assertEquals(inverse.Pair, PAIR);
            assertEquals(test.ObservableSource, OBS_SOURCE);
            assertEquals(test.MarketDataType, typeof(FxRate));
        }
        //-------------------------------------------------------------------------
        public virtual void test_of_pairAndSource()
        {
            FxRateId test    = FxRateId.of(PAIR, OBS_SOURCE);
            FxRateId inverse = FxRateId.of(INVERSE);

            assertEquals(test.Pair, PAIR);
            assertEquals(inverse.Pair, PAIR);
            assertEquals(test.ObservableSource, OBS_SOURCE);
            assertEquals(test.MarketDataType, typeof(FxRate));
        }
        public virtual void cross_specified()
        {
            IDictionary <FxRateId, FxRate> marketDataMap = ImmutableMap.of(FxRateId.of(EUR, CHF), FxRate.of(EUR, CHF, EUR_CHF), FxRateId.of(GBP, CHF), FxRate.of(GBP, CHF, GBP_CHF));
            MarketData     marketData = ImmutableMarketData.of(VAL_DATE, marketDataMap);
            FxRateProvider fx         = MarketDataFxRateProvider.of(marketData, ObservableSource.NONE, CHF);

            assertEquals(fx.fxRate(GBP, EUR), GBP_CHF / EUR_CHF, 1.0E-10);
            assertEquals(fx.fxRate(EUR, GBP), EUR_CHF / GBP_CHF, 1.0E-10);
            assertThrows(() => fx.fxRate(EUR, USD), typeof(MarketDataNotFoundException));
        }
        //-------------------------------------------------------------------------
        public virtual void test_of_pair()
        {
            FxRateId test    = FxRateId.of(PAIR);
            FxRateId inverse = FxRateId.of(INVERSE);

            assertEquals(test.Pair, PAIR);
            assertEquals(inverse.Pair, PAIR);
            assertEquals(test.ObservableSource, ObservableSource.NONE);
            assertEquals(test.MarketDataType, typeof(FxRate));
            assertEquals(test.ToString(), "FxRateId:GBP/USD");
        }
Пример #11
0
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         FxRateId other = (FxRateId)obj;
         return(JodaBeanUtils.equal(pair, other.pair) && JodaBeanUtils.equal(observableSource, other.observableSource));
     }
     return(false);
 }
        public virtual void test_serialization()
        {
            FxRateId test = FxRateId.of(GBP, USD);

            assertSerialization(test);
        }