//------------------------------------------------------------------------- /// <summary> /// Calculates the price of the foreign exchange vanilla option product. /// <para> /// The price of the product is the value on the valuation date for one unit of the base currency /// and is expressed in the counter currency. The price does not take into account the long/short flag. /// See <seealso cref="#presentValue"/> for scaling and currency. /// /// </para> /// </summary> /// <param name="option"> the option product </param> /// <param name="ratesProvider"> the rates provider </param> /// <param name="volatilities"> the Black volatility provider </param> /// <returns> the price of the product </returns> public virtual double price(ResolvedFxVanillaOption option, RatesProvider ratesProvider, BlackFxOptionSmileVolatilities volatilities) { validate(ratesProvider, volatilities); double timeToExpiry = volatilities.relativeTime(option.Expiry); if (timeToExpiry <= 0d) { return(0d); } ResolvedFxSingle underlyingFx = option.Underlying; Currency ccyCounter = option.CounterCurrency; double df = ratesProvider.discountFactor(ccyCounter, underlyingFx.PaymentDate); FxRate forward = fxPricer.forwardFxRate(underlyingFx, ratesProvider); CurrencyPair currencyPair = underlyingFx.CurrencyPair; double forwardRate = forward.fxRate(currencyPair); double strikeRate = option.Strike; bool isCall = option.PutCall.Call; SmileDeltaParameters smileAtTime = volatilities.Smile.smileForExpiry(timeToExpiry); double[] strikes = smileAtTime.strike(forwardRate).toArray(); double[] vols = smileAtTime.Volatility.toArray(); double volAtm = vols[1]; double[] x = vannaVolgaWeights(forwardRate, strikeRate, timeToExpiry, volAtm, strikes); double priceFwd = BlackFormulaRepository.price(forwardRate, strikeRate, timeToExpiry, volAtm, isCall); for (int i = 0; i < 3; i += 2) { double priceFwdAtm = BlackFormulaRepository.price(forwardRate, strikes[i], timeToExpiry, volAtm, isCall); double priceFwdSmile = BlackFormulaRepository.price(forwardRate, strikes[i], timeToExpiry, vols[i], isCall); priceFwd += x[i] * (priceFwdSmile - priceFwdAtm); } return(df * priceFwd); }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(FxNdf beanToCopy) { this.settlementCurrencyNotional_Renamed = beanToCopy.SettlementCurrencyNotional; this.agreedFxRate_Renamed = beanToCopy.AgreedFxRate; this.index_Renamed = beanToCopy.Index; this.paymentDate_Renamed = beanToCopy.PaymentDate; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public <T> com.opengamma.strata.data.scenario.MarketDataBox<T> getValue(com.opengamma.strata.data.MarketDataId<T> id) public override MarketDataBox <T> getValue <T>(MarketDataId <T> id) { // this code exists to ensure that the error messages from market data building // are exposed to users when the failures are not checked // a special case for FX rates containing the same currency twice if (id is FxRateId && ((FxRateId)id).Pair.Identity) { FxRateId fxRateId = (FxRateId)id; FxRate identityRate = FxRate.of(fxRateId.Pair, 1); return(MarketDataBox.ofSingleValue((T)identityRate)); } // find the data and check it against the failures Optional <MarketDataBox <T> > opt = underlying.findValue(id); if (!opt.Present) { Failure failure = valueFailures.get(id); if (failure != null) { throw new FailureException(failure); } throw new MarketDataNotFoundException(Messages.format("Market data not found for identifier '{}' of type '{}'", id, id.GetType().Name)); } return(opt.get()); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 594670010: // settlementCurrencyNotional this.settlementCurrencyNotional_Renamed = (CurrencyAmount)newValue; break; case 1040357930: // agreedFxRate this.agreedFxRate_Renamed = (FxRate)newValue; break; case 122345516: // observation this.observation_Renamed = (FxIndexObservation)newValue; break; case -1540873516: // paymentDate this.paymentDate_Renamed = (LocalDate)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(ResolvedFxNdf beanToCopy) { this.settlementCurrencyNotional_Renamed = beanToCopy.SettlementCurrencyNotional; this.agreedFxRate_Renamed = beanToCopy.AgreedFxRate; this.observation_Renamed = beanToCopy.Observation; this.paymentDate_Renamed = beanToCopy.PaymentDate; }
// loads a single CSV file, filtering by date private static void parseSingle(System.Predicate <LocalDate> datePredicate, CharSource resource, IDictionary <LocalDate, ImmutableMap.Builder <FxRateId, FxRate> > mutableMap) { try { CsvFile csv = CsvFile.of(resource, true); foreach (CsvRow row in csv.rows()) { string dateText = row.getField(DATE_FIELD); LocalDate date = LoaderUtils.parseDate(dateText); if (datePredicate(date)) { string currencyPairStr = row.getField(CURRENCY_PAIR_FIELD); string valueStr = row.getField(VALUE_FIELD); CurrencyPair currencyPair = CurrencyPair.parse(currencyPairStr); double value = Convert.ToDouble(valueStr); ImmutableMap.Builder <FxRateId, FxRate> builderForDate = mutableMap.computeIfAbsent(date, k => ImmutableMap.builder()); builderForDate.put(FxRateId.of(currencyPair), FxRate.of(currencyPair, value)); } } } catch (Exception ex) { throw new System.ArgumentException(Messages.format("Error processing resource as CSV file: {}", resource), ex); } }
/// <summary> /// Save two FxRates (each the inverse of the other) /// </summary> /// <param name="rate">FxRate</param> /// <param name="inverse">Reversed Fx Rate</param> /// <param name="businessId">Business</param> /// <returns>Success/Failure</returns> public bool SaveFxRatePair(FxRate rate, FxRate inverse, long businessId) { const string delSQL = @" DELETE FROM Finance.FxRate WHERE BusinessID = @BusinessId AND BaseCurrencyCode IN (@BaseCurrencyCode, @QuoteCurrencyCode) AND QuoteCurrencyCode IN (@BaseCurrencyCode, @QuoteCurrencyCode)"; const string SQL = @" INSERT INTO Finance.FxRate VALUES ( @BusinessId, @BaseCurrencyCode, @QuoteCurrencyCode, @Rate ) INSERT INTO Finance.FxRate VALUES (@BusinessId, @BaseCurrencyCode2, @QuoteCurrencyCode2, @Rate2)"; var delParameters = new List<SqlParameter> { DbHelper.CreateParameter("BusinessId", businessId), DbHelper.CreateParameter("BaseCurrencyCode", rate.BaseCurrency.ISOCode), DbHelper.CreateParameter("QuoteCurrencyCode", rate.QuoteCurrency.ISOCode), }; var parameters = new List<SqlParameter> { DbHelper.CreateParameter("BusinessId", businessId), DbHelper.CreateParameter("BaseCurrencyCode", rate.BaseCurrency.ISOCode), DbHelper.CreateParameter("QuoteCurrencyCode", rate.QuoteCurrency.ISOCode), DbHelper.CreateParameter("Rate", rate.ConversionRate), DbHelper.CreateParameter("BaseCurrencyCode2", inverse.BaseCurrency.ISOCode), DbHelper.CreateParameter("QuoteCurrencyCode2", inverse.QuoteCurrency.ISOCode), DbHelper.CreateParameter("Rate2", inverse.ConversionRate) }; DbHelper.ExecuteNonQueryCommand(delSQL, parameters: delParameters); return DbHelper.ExecuteNonQueryCommand(SQL, parameters: parameters) == 2; }
public static AssetValuation Copy(AssetValuation baseValuation) { AssetValuation result = null; if (baseValuation != null) { result = new AssetValuation(); if (baseValuation.quote != null) { result.quote = QuotationHelper.Copy(baseValuation.quote).ToArray(); } if (baseValuation.fxRate != null) { var fxRate = new List <FxRate>(); //result.fxRate //if (baseValuation.fxRate!=null) //{ foreach (var rate in baseValuation.fxRate) { var newRate = new FxRate { quotedCurrencyPair = new QuotedCurrencyPair { currency1 = CurrencyHelper.Copy( rate.quotedCurrencyPair. currency1), currency2 = CurrencyHelper.Copy( rate.quotedCurrencyPair. currency2), quoteBasis = rate.quotedCurrencyPair. quoteBasis } }; fxRate.Add(newRate); } result.fxRate = fxRate.ToArray(); } if (baseValuation.valuationScenarioReference != null) { result.valuationScenarioReference = new ValuationScenarioReference { href = baseValuation.valuationScenarioReference.href }; } if (baseValuation.id != null) { result.id = baseValuation.id; } if (baseValuation.objectReference != null) { result.objectReference = new AnyAssetReference { href = baseValuation.objectReference.href }; } } return(result); }
private void assertFile1Date2(IDictionary <FxRateId, FxRate> map) { assertTrue(map.ContainsKey(EUR_USD_ID)); assertTrue(map.ContainsKey(GBP_USD_ID)); assertEquals(map[EUR_USD_ID], FxRate.of(Currency.EUR, Currency.USD, 1.12)); assertEquals(map[GBP_USD_ID], FxRate.of(Currency.GBP, Currency.USD, 1.52)); }
//------------------------------------------------------------------------- public FxForwardRates fxForwardRates(CurrencyPair currencyPair) { DiscountFactors @base = discountFactors(currencyPair.Base); DiscountFactors counter = discountFactors(currencyPair.Counter); FxRate fxRate = FxRate.of(currencyPair, fxRate(currencyPair)); return(DiscountFxForwardRates.of(currencyPair, fxRate, @base, counter)); };
public SwapTrade trade(double quantity, MarketData marketData, ReferenceData refData) { double marketQuote = marketData.getValue(spreadId) + additionalSpread; FxRate fxRate = marketData.getValue(fxRateId); double rate = fxRate.fxRate(template.CurrencyPair); BuySell buySell = quantity > 0 ? BuySell.SELL : BuySell.BUY; return(template.createTrade(marketData.ValuationDate, buySell, Math.Abs(quantity), rate, marketQuote, refData)); }
public FxSwapTrade trade(double quantity, MarketData marketData, ReferenceData refData) { FxRate fxRate = marketData.getValue(fxRateId); double rate = fxRate.fxRate(template.CurrencyPair); double fxPts = marketData.getValue(farForwardPointsId); BuySell buySell = quantity > 0 ? BuySell.BUY : BuySell.SELL; return(template.createTrade(marketData.ValuationDate, buySell, Math.Abs(quantity), rate, fxPts, refData)); }
static CalibrationZeroRateUsdOisIrsEurFxXCcyIrsTest() { USD_DSC_NODES[0] = TermDepositCurveNode.of(TermDepositTemplate.of(Period.ofDays(1), USD_SHORT_DEPOSIT_T0), QuoteId.of(StandardId.of(SCHEME, USD_DSC_ID_VALUE[0]))); USD_DSC_NODES[1] = TermDepositCurveNode.of(TermDepositTemplate.of(Period.ofDays(1), USD_SHORT_DEPOSIT_T1), QuoteId.of(StandardId.of(SCHEME, USD_DSC_ID_VALUE[1]))); for (int i = 0; i < USD_DSC_NB_OIS_NODES; i++) { USD_DSC_NODES[2 + i] = FixedOvernightSwapCurveNode.of(FixedOvernightSwapTemplate.of(Period.ZERO, Tenor.of(USD_DSC_OIS_TENORS[i]), USD_FIXED_1Y_FED_FUND_OIS), QuoteId.of(StandardId.of(SCHEME, USD_DSC_ID_VALUE[2 + i]))); } USD_FWD3_NODES[0] = IborFixingDepositCurveNode.of(IborFixingDepositTemplate.of(USD_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, USD_FWD3_ID_VALUE[0]))); for (int i = 0; i < USD_FWD3_NB_FRA_NODES; i++) { USD_FWD3_NODES[i + 1] = FraCurveNode.of(FraTemplate.of(USD_FWD3_FRA_TENORS[i], USD_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, USD_FWD3_ID_VALUE[i + 1]))); } for (int i = 0; i < USD_FWD3_NB_IRS_NODES; i++) { USD_FWD3_NODES[i + 1 + USD_FWD3_NB_FRA_NODES] = FixedIborSwapCurveNode.of(FixedIborSwapTemplate.of(Period.ZERO, Tenor.of(USD_FWD3_IRS_TENORS[i]), USD_FIXED_6M_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, USD_FWD3_ID_VALUE[i + 1 + USD_FWD3_NB_FRA_NODES]))); } for (int i = 0; i < EUR_DSC_NB_FX_NODES; i++) { EUR_DSC_NODES[i] = FxSwapCurveNode.of(FxSwapTemplate.of(EUR_DSC_FX_TENORS[i], EUR_USD), QuoteId.of(StandardId.of(SCHEME, EUR_DSC_ID_VALUE[i]))); } for (int i = 0; i < EUR_DSC_NB_XCCY_NODES; i++) { EUR_DSC_NODES[EUR_DSC_NB_FX_NODES + i] = XCcyIborIborSwapCurveNode.of(XCcyIborIborSwapTemplate.of(Tenor.of(EUR_DSC_XCCY_TENORS[i]), EUR_EURIBOR_3M_USD_LIBOR_3M), QuoteId.of(StandardId.of(SCHEME, EUR_DSC_ID_VALUE[EUR_DSC_NB_FX_NODES + i]))); } EUR_FWD3_NODES[0] = IborFixingDepositCurveNode.of(IborFixingDepositTemplate.of(EUR_EURIBOR_3M), QuoteId.of(StandardId.of(SCHEME, EUR_FWD3_ID_VALUE[0]))); for (int i = 0; i < EUR_FWD3_NB_FRA_NODES; i++) { EUR_FWD3_NODES[i + 1] = FraCurveNode.of(FraTemplate.of(EUR_FWD3_FRA_TENORS[i], EUR_EURIBOR_3M), QuoteId.of(StandardId.of(SCHEME, EUR_FWD3_ID_VALUE[i + 1]))); } for (int i = 0; i < EUR_FWD3_NB_IRS_NODES; i++) { EUR_FWD3_NODES[i + 1 + EUR_FWD3_NB_FRA_NODES] = FixedIborSwapCurveNode.of(FixedIborSwapTemplate.of(Period.ZERO, Tenor.of(EUR_FWD3_IRS_TENORS[i]), EUR_FIXED_1Y_EURIBOR_3M), QuoteId.of(StandardId.of(SCHEME, EUR_FWD3_ID_VALUE[i + 1 + EUR_FWD3_NB_FRA_NODES]))); } ImmutableMarketDataBuilder builder = ImmutableMarketData.builder(VAL_DATE); for (int i = 0; i < USD_DSC_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, USD_DSC_ID_VALUE[i])), USD_DSC_MARKET_QUOTES[i]); } for (int i = 0; i < USD_FWD3_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, USD_FWD3_ID_VALUE[i])), USD_FWD3_MARKET_QUOTES[i]); } for (int i = 0; i < EUR_DSC_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, EUR_DSC_ID_VALUE[i])), EUR_DSC_MARKET_QUOTES[i]); } for (int i = 0; i < EUR_FWD3_NB_NODES; i++) { builder.addValue(QuoteId.of(StandardId.of(SCHEME, EUR_FWD3_ID_VALUE[i])), EUR_FWD3_MARKET_QUOTES[i]); } builder.addValue(QuoteId.of(StandardId.of(SCHEME, EUR_USD_ID_VALUE)), FX_RATE_EUR_USD); builder.addValue(FxRateId.of(EUR, USD), FxRate.of(EUR, USD, FX_RATE_EUR_USD)); ALL_QUOTES = builder.build(); }
//------------------------------------------------------------------------- public virtual void convertedTo() { LegAmounts @base = LegAmounts.of(LEG_AMOUNT_1, LEG_AMOUNT_2); LegAmounts test = @base.convertedTo(Currency.GBP, FxRate.of(Currency.USD, Currency.GBP, 0.7)); assertThat(test.Amounts.get(0).Amount.Currency).isEqualTo(Currency.GBP); assertThat(test.Amounts.get(0).Amount.Amount).isEqualTo(500d * 0.7d); assertThat(test.Amounts.get(1).Amount.Currency).isEqualTo(Currency.GBP); assertThat(test.Amounts.get(1).Amount.Amount).isEqualTo(420d * 0.7d); }
/// <summary> /// Creates an {@code ResolvedFxSingle} using a rate. /// <para> /// This create an FX specifying a value date, notional in one currency, the second currency /// and the FX rate between the two. /// The currencies of the payments must differ. /// </para> /// <para> /// This factory identifies the currency pair of the exchange and assigns the payments /// to match the base or counter currency of the standardized currency pair. /// For example, a EUR/USD exchange always has EUR as the base payment and USD as the counter payment. /// </para> /// <para> /// No payment date adjustments apply. /// /// </para> /// </summary> /// <param name="amountCurrency1"> the amount of the near leg in the first currency </param> /// <param name="fxRate"> the near FX rate </param> /// <param name="paymentDate"> date that the FX settles </param> /// <returns> the resolved foreign exchange transaction </returns> public static ResolvedFxSingle of(CurrencyAmount amountCurrency1, FxRate fxRate, LocalDate paymentDate) { CurrencyPair pair = fxRate.Pair; ArgChecker.isTrue(pair.contains(amountCurrency1.Currency)); Currency currency2 = pair.Base.Equals(amountCurrency1.Currency) ? pair.Counter : pair.Base; CurrencyAmount amountCurrency2 = amountCurrency1.convertedTo(currency2, fxRate).negated(); return(ResolvedFxSingle.of(Payment.of(amountCurrency1, paymentDate), Payment.of(amountCurrency2, paymentDate))); }
public virtual void buildInverse() { FxRateMarketDataFunction function = new FxRateMarketDataFunction(); MarketDataBox <double> quoteBox = MarketDataBox.ofSingleValue(1.1d); ScenarioMarketData marketData = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addBox(QUOTE_ID, quoteBox).build(); MarketDataBox <FxRate> rateBox = function.build(FxRateId.of(CURRENCY_PAIR.inverse()), config(), marketData, REF_DATA); assertThat(rateBox.SingleValue).True; assertThat(rateBox.SingleValue).isEqualTo(FxRate.of(CURRENCY_PAIR, 1.1d)); }
/// <summary> /// Converts an FX exchange to a string. /// </summary> /// <param name="base"> the base currency amount </param> /// <param name="counter"> the counter currency amount </param> /// <returns> the string form </returns> public static string fx(CurrencyAmount @base, CurrencyAmount counter) { decimal rateDec = decimal.valueOf(counter.Amount / @base.Amount).setScale(@base.Currency.MinorUnitDigits + 2, RoundingMode.HALF_UP).abs(); FxRate rate = FxRate.of(@base.Currency, counter.Currency, rateDec.doubleValue()); decimal baseDec = decimal.valueOf(@base.Amount).stripTrailingZeros(); decimal counterDec = decimal.valueOf(counter.Amount).stripTrailingZeros(); bool roundBase = baseDec.scale() < counterDec.scale(); CurrencyAmount round = roundBase ? @base : counter; return((round.Amount < 0 ? "Pay " : "Rec ") + SummarizerUtils.amount(round.mapAmount(a => Math.Abs(a))) + " " + "@ " + rate); }
/// <summary> /// Creates a {@code ResolvedFxSwap} using forward points. /// <para> /// The FX rate at the near date is specified as {@code fxRate}. /// The FX rate at the far date is equal to {@code fxRate + forwardPoints} /// </para> /// <para> /// The two currencies must not be equal. /// The near date must be before the far date. /// Conventions will be used to determine the base and counter currency. /// /// </para> /// </summary> /// <param name="amountCurrency1"> the amount of the near leg in the first currency </param> /// <param name="currency2"> the second currency </param> /// <param name="nearFxRate"> the near FX rate, where {@code (1.0 * amountCurrency1 = fxRate * amountCurrency2)} </param> /// <param name="forwardPoints"> the forward points, where the far FX rate is {@code (fxRate + forwardPoints)} </param> /// <param name="nearDate"> the near value date </param> /// <param name="farDate"> the far value date </param> /// <returns> the resolved FX swap </returns> public static ResolvedFxSwap ofForwardPoints(CurrencyAmount amountCurrency1, Currency currency2, double nearFxRate, double forwardPoints, LocalDate nearDate, LocalDate farDate) { Currency currency1 = amountCurrency1.Currency; ArgChecker.isFalse(currency1.Equals(currency2), "Currencies must not be equal"); ArgChecker.notNegativeOrZero(nearFxRate, "fxRate"); double farFxRate = nearFxRate + forwardPoints; ResolvedFxSingle nearLeg = ResolvedFxSingle.of(amountCurrency1, FxRate.of(currency1, currency2, nearFxRate), nearDate); ResolvedFxSingle farLeg = ResolvedFxSingle.of(amountCurrency1.negated(), FxRate.of(currency1, currency2, farFxRate), farDate); return(of(nearLeg, farLeg)); }
private FxNdf(CurrencyAmount settlementCurrencyNotional, FxRate agreedFxRate, FxIndex index, LocalDate paymentDate) { JodaBeanUtils.notNull(settlementCurrencyNotional, "settlementCurrencyNotional"); JodaBeanUtils.notNull(agreedFxRate, "agreedFxRate"); JodaBeanUtils.notNull(index, "index"); JodaBeanUtils.notNull(paymentDate, "paymentDate"); this.settlementCurrencyNotional = settlementCurrencyNotional; this.agreedFxRate = agreedFxRate; this.index = index; this.paymentDate = paymentDate; validate(); }
private ResolvedFxNdf(CurrencyAmount settlementCurrencyNotional, FxRate agreedFxRate, FxIndexObservation observation, LocalDate paymentDate) { JodaBeanUtils.notNull(settlementCurrencyNotional, "settlementCurrencyNotional"); JodaBeanUtils.notNull(agreedFxRate, "agreedFxRate"); JodaBeanUtils.notNull(observation, "observation"); JodaBeanUtils.notNull(paymentDate, "paymentDate"); this.settlementCurrencyNotional = settlementCurrencyNotional; this.agreedFxRate = agreedFxRate; this.observation = observation; this.paymentDate = paymentDate; validate(); }
//------------------------------------------------------------------------- /// <summary> /// Calculates the implied Black volatility of the foreign exchange vanilla option product. /// </summary> /// <param name="option"> the option product </param> /// <param name="ratesProvider"> the rates provider </param> /// <param name="volatilities"> the Black volatility provider </param> /// <returns> the implied volatility of the product </returns> /// <exception cref="IllegalArgumentException"> if the option has expired </exception> public virtual double impliedVolatility(ResolvedFxVanillaOption option, RatesProvider ratesProvider, BlackFxOptionVolatilities volatilities) { double timeToExpiry = volatilities.relativeTime(option.Expiry); if (timeToExpiry <= 0d) { throw new System.ArgumentException("valuation is after option's expiry."); } FxRate forward = fxPricer.forwardFxRate(option.Underlying, ratesProvider); CurrencyPair strikePair = option.Underlying.CurrencyPair; return(volatilities.volatility(strikePair, option.Expiry, option.Strike, forward.fxRate(strikePair))); }
/// <summary> /// Computes the present value sensitivity to the black volatility used in the pricing. /// <para> /// The result is a single sensitivity to the volatility used. /// /// </para> /// </summary> /// <param name="option"> the option product </param> /// <param name="ratesProvider"> the rates provider </param> /// <param name="volatilities"> the Black volatility provider </param> /// <returns> the present value sensitivity </returns> public virtual PointSensitivityBuilder presentValueSensitivityModelParamsVolatility(ResolvedFxVanillaOption option, RatesProvider ratesProvider, BlackFxOptionVolatilities volatilities) { if (volatilities.relativeTime(option.Expiry) <= 0d) { return(PointSensitivityBuilder.none()); } ResolvedFxSingle underlying = option.Underlying; FxRate forward = fxPricer.forwardFxRate(underlying, ratesProvider); CurrencyPair strikePair = underlying.CurrencyPair; CurrencyAmount valueVega = presentValueVega(option, ratesProvider, volatilities); return(FxOptionSensitivity.of(volatilities.Name, strikePair, volatilities.relativeTime(option.Expiry), option.Strike, forward.fxRate(strikePair), valueVega.Currency, valueVega.Amount)); }
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 buildScenario() { FxRateMarketDataFunction function = new FxRateMarketDataFunction(); MarketDataBox <double> quoteBox = MarketDataBox.ofScenarioValues(1.1d, 1.2d, 1.3d); ScenarioMarketData marketData = ImmutableScenarioMarketData.builder(LocalDate.of(2011, 3, 8)).addBox(QUOTE_ID, quoteBox).build(); MarketDataBox <FxRate> rateBox = function.build(RATE_ID, config(), marketData, REF_DATA); assertThat(rateBox.SingleValue).False; assertThat(rateBox.ScenarioCount).isEqualTo(3); assertThat(rateBox.getValue(0)).isEqualTo(FxRate.of(CURRENCY_PAIR, 1.1d)); assertThat(rateBox.getValue(1)).isEqualTo(FxRate.of(CURRENCY_PAIR, 1.2d)); assertThat(rateBox.getValue(2)).isEqualTo(FxRate.of(CURRENCY_PAIR, 1.3d)); }
public virtual void test_addBadScenarioCount() { FxRateId eurGbpId = FxRateId.of(Currency.EUR, Currency.GBP); FxRateId eurUsdId = FxRateId.of(Currency.EUR, Currency.USD); FxRate eurGbpRate1 = FxRate.of(Currency.EUR, Currency.GBP, 0.8); FxRate eurGbpRate2 = FxRate.of(Currency.EUR, Currency.GBP, 0.9); FxRate eurGbpRate3 = FxRate.of(Currency.EUR, Currency.GBP, 0.95); FxRate eurUsdRate1 = FxRate.of(Currency.EUR, Currency.USD, 1.1); FxRate eurUsdRate2 = FxRate.of(Currency.EUR, Currency.USD, 1.2); ImmutableScenarioMarketDataBuilder builder = ImmutableScenarioMarketData.builder(VAL_DATE).addBox(eurGbpId, MarketDataBox.ofScenarioValues(eurGbpRate1, eurGbpRate2, eurGbpRate3)); assertThrowsIllegalArg(() => builder.addBox(eurUsdId, MarketDataBox.ofScenarioValues(eurUsdRate1, eurUsdRate2))); }
public virtual void test_simpleMeasures() { FxNdfTradeCalculationFunction function = new FxNdfTradeCalculationFunction(); ScenarioMarketData md = marketData(); RatesProvider provider = RATES_LOOKUP.ratesProvider(md.scenario(0)); DiscountingFxNdfTradePricer pricer = DiscountingFxNdfTradePricer.DEFAULT; CurrencyAmount expectedPv = pricer.presentValue(RTRADE, provider); MultiCurrencyAmount expectedCurrencyExp = pricer.currencyExposure(RTRADE, provider); CurrencyAmount expectedCash = pricer.currentCash(RTRADE, provider); FxRate expectedForwardFx = pricer.forwardFxRate(RTRADE, provider); ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE, Measures.CURRENCY_EXPOSURE, Measures.CURRENT_CASH, Measures.FORWARD_FX_RATE, Measures.RESOLVED_TARGET); assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(Measures.CURRENCY_EXPOSURE, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrencyExp)))).containsEntry(Measures.CURRENT_CASH, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedCash)))).containsEntry(Measures.FORWARD_FX_RATE, Result.success(ScenarioArray.of(ImmutableList.of(expectedForwardFx)))).containsEntry(Measures.RESOLVED_TARGET, Result.success(RTRADE)); }
//------------------------------------------------------------------------- public virtual void test_convertedTo() { CashFlows @base = CashFlows.of(ImmutableList.of(CASH_FLOW_1, CASH_FLOW_2)); CashFlows test = @base.convertedTo(USD, FxRate.of(GBP, USD, 1.5)); assertEquals(test.getCashFlow(0), CASH_FLOW_1); CashFlow converted = test.getCashFlow(1); assertEquals(converted.PaymentDate, CASH_FLOW_2.PaymentDate); assertEquals(converted.DiscountFactor, CASH_FLOW_2.DiscountFactor, TOLERANCE); assertEquals(converted.PresentValue.Currency, USD); assertEquals(converted.PresentValue.Amount, CASH_FLOW_2.PresentValue.Amount * 1.5, TOLERANCE); assertEquals(converted.ForecastValue.Currency, USD); assertEquals(converted.ForecastValue.Amount, CASH_FLOW_2.ForecastValue.Amount * 1.5, TOLERANCE); }
//------------------------------------------------------------------------- public virtual void test_addValueMap() { FxRateId eurGbpId = FxRateId.of(Currency.EUR, Currency.GBP); FxRateId eurUsdId = FxRateId.of(Currency.EUR, Currency.USD); FxRate eurGbpRate = FxRate.of(Currency.EUR, Currency.GBP, 0.8); FxRate eurUsdRate = FxRate.of(Currency.EUR, Currency.USD, 1.1); IDictionary <FxRateId, FxRate> values = ImmutableMap.of(eurGbpId, eurGbpRate, eurUsdId, eurUsdRate); ImmutableScenarioMarketData marketData = ImmutableScenarioMarketData.builder(VAL_DATE).addValueMap(values).build(); assertEquals(marketData.ScenarioCount, 1); assertEquals(marketData.Ids, ImmutableSet.of(eurGbpId, eurUsdId)); assertEquals(marketData.getValue(eurGbpId), MarketDataBox.ofSingleValue(eurGbpRate)); assertEquals(marketData.getValue(eurUsdId), MarketDataBox.ofSingleValue(eurUsdRate)); }
public virtual void test_addSingleAndBox() { FxRateId eurGbpId = FxRateId.of(Currency.EUR, Currency.GBP); FxRateId eurUsdId = FxRateId.of(Currency.EUR, Currency.USD); FxRate eurGbpRate = FxRate.of(Currency.EUR, Currency.GBP, 0.8); FxRate eurUsdRate1 = FxRate.of(Currency.EUR, Currency.USD, 1.1); FxRate eurUsdRate2 = FxRate.of(Currency.EUR, Currency.USD, 1.2); ImmutableScenarioMarketData marketData = ImmutableScenarioMarketData.builder(VAL_DATE).addValue(eurGbpId, eurGbpRate).addBox(eurUsdId, MarketDataBox.ofScenarioValues(eurUsdRate1, eurUsdRate2)).build(); assertEquals(marketData.ScenarioCount, 2); assertEquals(marketData.Ids, ImmutableSet.of(eurGbpId, eurUsdId)); assertEquals(marketData.getValue(eurGbpId), MarketDataBox.ofSingleValue(eurGbpRate)); assertEquals(marketData.getValue(eurUsdId), MarketDataBox.ofScenarioValues(eurUsdRate1, eurUsdRate2)); }
public void PriceUpdate(FxRate fxRate) { try { foreach (var rate in Rates.Where(rate => rate.IsoCode == fxRate.IsoCode)) { rate.CurrentRate = fxRate.Rate; rate.Updated = fxRate.Updated; } } catch (Exception e) { //log here } }
// internal method where adjustment may be null private static FxSingle create(CurrencyAmount amount, FxRate fxRate, LocalDate paymentDate, BusinessDayAdjustment paymentDateAdjustment) { ArgChecker.notNull(amount, "amount"); ArgChecker.notNull(fxRate, "fxRate"); ArgChecker.notNull(paymentDate, "paymentDate"); CurrencyPair pair = fxRate.Pair; if (!pair.contains(amount.Currency)) { throw new System.ArgumentException(Messages.format("FxRate '{}' and CurrencyAmount '{}' must have a currency in common", fxRate, amount)); } Currency currency2 = pair.Base.Equals(amount.Currency) ? pair.Counter : pair.Base; CurrencyAmount amountCurrency2 = amount.convertedTo(currency2, fxRate).negated(); return(create(amount, amountCurrency2, paymentDate, paymentDateAdjustment)); }
public void PriceUpdate(FxRate fxRate) { throw new NotImplementedException(); }