public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 1005147787: // currencyPair this.currencyPair = (CurrencyPair)newValue; break; case -1499624221: // fxRateProvider this.fxRateProvider = (FxRateProvider)newValue; break; case 1151357473: // baseCurrencyDiscountFactors this.baseCurrencyDiscountFactors = (DiscountFactors)newValue; break; case -453959018: // counterCurrencyDiscountFactors this.counterCurrencyDiscountFactors = (DiscountFactors)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
public virtual void test_convertedTo_rateProvider() { FxRateProvider provider = (ccy1, ccy2) => 2.5d; assertEquals(CCY_AMOUNT.convertedTo(CCY2, provider), CurrencyAmount.of(CCY2, AMT1 * 2.5d)); assertEquals(CCY_AMOUNT.convertedTo(CCY1, provider), CCY_AMOUNT); }
//------------------------------------------------------------------------- //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableConstructor private DiscountFxForwardRates(com.opengamma.strata.basics.currency.CurrencyPair currencyPair, com.opengamma.strata.basics.currency.FxRateProvider fxRateProvider, com.opengamma.strata.pricer.DiscountFactors baseCurrencyDiscountFactors, com.opengamma.strata.pricer.DiscountFactors counterCurrencyDiscountFactors) private DiscountFxForwardRates(CurrencyPair currencyPair, FxRateProvider fxRateProvider, DiscountFactors baseCurrencyDiscountFactors, DiscountFactors counterCurrencyDiscountFactors) { JodaBeanUtils.notNull(currencyPair, "currencyPair"); JodaBeanUtils.notNull(fxRateProvider, "fxRateProvider"); JodaBeanUtils.notNull(baseCurrencyDiscountFactors, "baseCurrencyDiscountFactors"); JodaBeanUtils.notNull(counterCurrencyDiscountFactors, "counterCurrencyDiscountFactors"); if (!baseCurrencyDiscountFactors.Currency.Equals(currencyPair.Base)) { throw new System.ArgumentException(Messages.format("Index base currency {} did not match discount factor base currency {}", currencyPair.Base, baseCurrencyDiscountFactors.Currency)); } if (!counterCurrencyDiscountFactors.Currency.Equals(currencyPair.Counter)) { throw new System.ArgumentException(Messages.format("Index counter currency {} did not match discount factor counter currency {}", currencyPair.Counter, counterCurrencyDiscountFactors.Currency)); } if (!baseCurrencyDiscountFactors.ValuationDate.Equals(counterCurrencyDiscountFactors.ValuationDate)) { throw new System.ArgumentException("Curves must have the same valuation date"); } this.currencyPair = currencyPair; this.fxRateProvider = fxRateProvider; this.baseCurrencyDiscountFactors = baseCurrencyDiscountFactors; this.counterCurrencyDiscountFactors = counterCurrencyDiscountFactors; this.valuationDate = baseCurrencyDiscountFactors.ValuationDate; this.paramCombiner = ParameterizedDataCombiner.of(baseCurrencyDiscountFactors, counterCurrencyDiscountFactors); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testConvertedToWithRateProvider() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testConvertedToWithRateProvider() { FxRateProvider provider = (ccy1, ccy2) => 2.5d; assertEquals(Money.of(Currency.RON, 250.30), MONEY_100_AUD.convertedTo(CCY_RON, provider)); assertEquals(Money.of(Currency.RON, 200.23), MONEY_200_RON.convertedTo(CCY_RON, provider)); }
public LegAmounts convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: IList <LegAmount> convertedAmounts = amounts.Select(amount => amount.convertedTo(resultCurrency, rateProvider)).collect(toImmutableList()); return(of(convertedAmounts)); }
//------------------------------------------------------------------------- public virtual void test_convertedTo_rateProvider() { Payment test = Payment.ofReceive(GBP_P1000, DATE_2015_06_30); FxRateProvider provider = (ccy1, ccy2) => 1.6d; assertEquals(test.convertedTo(EUR, provider), Payment.ofReceive(EUR_P1600, DATE_2015_06_30)); assertEquals(test.convertedTo(GBP, provider), test); }
/// <summary> /// Converts this payment to an equivalent payment in the specified currency. /// <para> /// The result will be expressed in terms of the given currency. /// If conversion is needed, the provider will be used to supply the FX rate. /// /// </para> /// </summary> /// <param name="resultCurrency"> the currency of the result </param> /// <param name="rateProvider"> the provider of FX rates </param> /// <returns> the converted instance, in the specified currency </returns> /// <exception cref="RuntimeException"> if no FX rate could be found </exception> public Payment convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { if (Currency.Equals(resultCurrency)) { return(this); } return(Payment.of(value.convertedTo(resultCurrency, rateProvider), date)); }
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 emptyMatrixCanHandleTrivialRate() { FxRateProvider test = (ccy1, ccy2) => { return(2.5d); }; assertThat(test.fxRate(CurrencyPair.of(GBP, USD))).isEqualTo(2.5d); }
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); }
/// <summary> /// Converts this amount to an equivalent amount in the specified currency. /// <para> /// The result will be expressed in terms of the given currency. /// If conversion is needed, the provider will be used to supply the FX rate. /// /// </para> /// </summary> /// <param name="resultCurrency"> the currency of the result </param> /// <param name="rateProvider"> the provider of FX rates </param> /// <returns> the converted instance, in the specified currency </returns> /// <exception cref="RuntimeException"> if no FX rate could be found </exception> public CurrencyAmount convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { if (currency.Equals(resultCurrency)) { return(this); } double converted = rateProvider.convert(amount, currency, resultCurrency); return(CurrencyAmount.of(resultCurrency, converted)); }
//------------------------------------------------------------------------- public virtual void test_convertedTo_rateProvider_noConversionSize1() { FxRateProvider provider = (ccy1, ccy2) => { throw new System.ArgumentException(); }; MultiCurrencyAmount test = MultiCurrencyAmount.of(CA2); assertEquals(test.convertedTo(CCY2, provider), CA2); }
//------------------------------------------------------------------------- /// <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 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)); }
/// <summary> /// Converts this amount to an equivalent amount in the specified currency. /// <para> /// The result will be expressed in terms of the given currency. /// If conversion is needed, the provider will be used to supply the FX rate. /// /// </para> /// </summary> /// <param name="resultCurrency"> the currency of the result </param> /// <param name="rateProvider"> the provider of FX rates </param> /// <returns> the converted instance, in the specified currency </returns> /// <exception cref="RuntimeException"> if no FX rate could be found </exception> public virtual Money convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { if (currency.Equals(resultCurrency)) { return(this); } double converted = rateProvider.convert(amount.doubleValue(), currency, resultCurrency); return(Money.of(resultCurrency, converted)); }
//------------------------------------------------------------------------- public PointSensitivities convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { IList <PointSensitivity> mutable = new List <PointSensitivity>(); foreach (PointSensitivity sensi in sensitivities) { insert(mutable, sensi.convertedTo(resultCurrency, rateProvider)); } return(new PointSensitivities(mutable)); }
//------------------------------------------------------------------------- /// <summary> /// Converts this cash flow to an equivalent amount in the specified currency. /// <para> /// The result will have both the present and forecast value expressed in terms of the given currency. /// If conversion is needed, the provider will be used to supply the FX rate. /// /// </para> /// </summary> /// <param name="resultCurrency"> the currency of the result </param> /// <param name="rateProvider"> the provider of FX rates </param> /// <returns> the converted instance, in the specified currency </returns> /// <exception cref="RuntimeException"> if no FX rate could be found </exception> public CashFlow convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { if (presentValue.Currency.Equals(resultCurrency) && forecastValue.Currency.Equals(resultCurrency)) { return(this); } CurrencyAmount pv = presentValue.convertedTo(resultCurrency, rateProvider); CurrencyAmount fv = forecastValue.convertedTo(resultCurrency, rateProvider); return(new CashFlow(paymentDate, pv, fv, discountFactor)); }
//------------------------------------------------------------------------- public JumpToDefault convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { IDictionary <StandardId, double> mutable = new Dictionary <StandardId, double>(); foreach (KeyValuePair <StandardId, double> entry in amounts.entrySet()) { double converted = rateProvider.convert(entry.Value, currency, resultCurrency); mutable[entry.Key] = converted; } return(JumpToDefault.of(resultCurrency, mutable)); }
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)); }
//------------------------------------------------------------------------- /// <summary> /// Combines a number of rates providers. /// <para> /// If the two providers have curves or time series for the same currency or index, /// an <seealso cref="IllegalAccessException"/> is thrown. /// The FxRateProviders is not populated with the given provider; no attempt is done on merging the embedded FX providers. /// /// </para> /// </summary> /// <param name="fx"> the FX provider for the resulting rate provider </param> /// <param name="providers"> the rates providers to be merged </param> /// <returns> the combined rates provider </returns> public static ImmutableRatesProvider combined(FxRateProvider fx, params ImmutableRatesProvider[] providers) { ArgChecker.isTrue(providers.Length > 0, "at least one provider requested"); ImmutableRatesProvider merged = ImmutableRatesProvider.builder(providers[0].ValuationDate).build(); foreach (ImmutableRatesProvider provider in providers) { merged = merged.combinedWith(provider, fx); } return(merged); }
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 test_convertedTo_rateProvider_conversionSize1() { FxRateProvider provider = (ccy1, ccy2) => { if (ccy1.Equals(CCY1) && ccy2.Equals(CCY2)) { return(2.5d); } throw new System.ArgumentException(); }; MultiCurrencyAmount test = MultiCurrencyAmount.of(CA1); assertEquals(test.convertedTo(CCY2, provider), CurrencyAmount.of(CCY2, AMT1 * 2.5d)); }
//------------------------------------------------------------------------- /// <summary> /// Converts this amount to an equivalent amount the specified currency. /// <para> /// The result will be expressed in terms of the given currency. /// If conversion is needed, the provider will be used to supply the FX rate. /// /// </para> /// </summary> /// <param name="resultCurrency"> the currency of the result </param> /// <param name="rateProvider"> the provider of FX rates </param> /// <returns> the converted instance, which should be expressed in the specified currency </returns> /// <exception cref="RuntimeException"> if no FX rate could be found </exception> public CurrencyAmount convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { if (amounts.size() == 1) { return(amounts.first().convertedTo(resultCurrency, rateProvider)); } double total = 0d; foreach (CurrencyAmount amount in amounts) { total += rateProvider.convert(amount.Amount, amount.Currency, resultCurrency); } return(CurrencyAmount.of(resultCurrency, total)); }
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 override DummyPointSensitivity convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { return((DummyPointSensitivity)PointSensitivity.this.convertedTo(resultCurrency, rateProvider)); }
//------------------------------------------------------------------------- /// <summary> /// Sets the FX rate provider. /// </summary> /// <param name="fxRateProvider"> the rate provider </param> /// <returns> this, for chaining </returns> public ImmutableRatesProviderBuilder fxRateProvider(FxRateProvider fxRateProvider) { this.fxRateProvider_Renamed = ArgChecker.notNull(fxRateProvider, "fxRateProvider"); return(this); }
public override BondFutureOptionSensitivity convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { return((BondFutureOptionSensitivity)PointSensitivity.this.convertedTo(resultCurrency, rateProvider)); }
//------------------------------------------------------------------------- public override SwapLegAmount convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { CurrencyAmount convertedAmount = amount.convertedTo(resultCurrency, rateProvider); return(this.toBuilder().amount(convertedAmount).build()); }
//------------------------------------------------------------------------- /// <summary> /// Converts this collection of cash flows to an equivalent amount in the specified currency. /// <para> /// This ensures that the result will have all currency amounts expressed in terms of the given currency. /// If conversion is needed, the provider will be used to supply the FX rate. /// /// </para> /// </summary> /// <param name="resultCurrency"> the currency of the result </param> /// <param name="rateProvider"> the provider of FX rates </param> /// <returns> the converted instance, in the specified currency </returns> /// <exception cref="RuntimeException"> if no FX rate could be found </exception> public CashFlows convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: return(CashFlows.of(cashFlows.Select(cf => cf.convertedTo(resultCurrency, rateProvider)).collect(toImmutableList()))); }
public override SwaptionSabrSensitivity convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { return((SwaptionSabrSensitivity)PointSensitivity.this.convertedTo(resultCurrency, rateProvider)); }