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 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_fxProvider() { RatesMarketDataLookup test = RatesMarketDataLookup.of(ImmutableMap.of(), ImmutableMap.of()); LocalDate valDate = date(2015, 6, 30); FxRateId gbpUsdId = FxRateId.of(GBP, USD); FxRate gbpUsdRate = FxRate.of(GBP, USD, 1.6); MarketData md = ImmutableMarketData.of(valDate, ImmutableMap.of(gbpUsdId, gbpUsdRate)); FxRateProvider fxProvider = test.fxRateProvider(md); assertEquals(fxProvider.fxRate(GBP, USD), 1.6); assertEquals(test.marketDataView(md).fxRateProvider().fxRate(GBP, USD), 1.6); assertThrows(() => fxProvider.fxRate(EUR, USD), typeof(MarketDataNotFoundException)); }
public virtual void emptyMatrixCanHandleTrivialRate() { FxRateProvider test = (ccy1, ccy2) => { return(2.5d); }; assertThat(test.fxRate(CurrencyPair.of(GBP, USD))).isEqualTo(2.5d); }
//------------------------------------------------------------------------- /// <summary> /// Converts this sensitivity to an equivalent in the specified currency. /// <para> /// Any FX conversion that is required will use rates from the provider. /// /// </para> /// </summary> /// <param name="resultCurrency"> the currency of the result </param> /// <param name="rateProvider"> the provider of FX rates </param> /// <returns> the sensitivity object expressed in terms of the result currency </returns> /// <exception cref="RuntimeException"> if no FX rate could be found </exception> public CrossGammaParameterSensitivity convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { if (currency.Equals(resultCurrency)) { return(this); } double fxRate = rateProvider.fxRate(currency, resultCurrency); return(mapSensitivity(s => s * fxRate, resultCurrency)); }
public CurrencyAmountArray convertedTo(Currency resultCurrency, FxRateProvider fxRateProvider) { if (currency.Equals(resultCurrency)) { return(this); } double fxRate = fxRateProvider.fxRate(currency, resultCurrency); DoubleArray convertedValues = values.multipliedBy(fxRate); return(new CurrencyAmountArray(resultCurrency, convertedValues)); }
public CurrencyAmountArray convertedTo(Currency resultCurrency, FxRateProvider fxRateProvider) { double[] singleCurrencyValues = new double[size_Renamed]; foreach (KeyValuePair <Currency, DoubleArray> entry in values.entrySet()) { Currency currency = entry.Key; DoubleArray currencyValues = entry.Value; for (int i = 0; i < size_Renamed; i++) { singleCurrencyValues[i] += currencyValues.get(i) * fxRateProvider.fxRate(currency, resultCurrency); } } return(CurrencyAmountArray.of(resultCurrency, DoubleArray.ofUnsafe(singleCurrencyValues))); }
//------------------------------------------------------------------------- public double fxRate(Currency baseCurrency, Currency counterCurrency) { return(fxRateProvider.fxRate(baseCurrency, counterCurrency)); }