/** * Gets the currency counter to the reference currency. * <p> * The currency pair contains two currencies. One is the reference currency. * This method returns the other. * * @return the counter currency */ public Currency getReferenceCounterCurrency() { boolean inverse = referenceCurrency.equals(currencyPair.getBase()); return inverse ? currencyPair.getCounter() : currencyPair.getBase(); }
@ImmutableValidator private void validate() { if (pair.getBase().equals(pair.getCounter()) && rate != 1d) { throw new IllegalArgumentException("Conversion rate between identical currencies must be one"); } }
/** * Gets the FX rate for the specified currency pair. * <p> * The rate returned is the rate from the base currency to the counter currency * as defined by this formula: {@code (1 * baseCurrency = fxRate * counterCurrency)}. * * @param currencyPair the ordered currency pair defining the rate required * @return the FX rate for the currency pair * @throws RuntimeException if no FX rate could be found */ public default double fxRate(CurrencyPair currencyPair) { return fxRate(currencyPair.getBase(), currencyPair.getCounter()); }
/** * Gets the FX rate for the specified currency pair on the valuation date. * <p> * The rate returned is the rate from the base currency to the counter currency * as defined by this formula: {@code (1 * baseCurrency = fxRate * counterCurrency)}. * * @param currencyPair the ordered currency pair defining the rate required * @return the current FX rate for the currency pair * @throws IllegalArgumentException if the rate is not available */ @Override public default double fxRate(CurrencyPair currencyPair) { return fxRate(currencyPair.getBase(), currencyPair.getCounter()); }
private double forwardRate(FxIndexObservation observation) { return fxForwardRates.rate(index.getCurrencyPair().getBase(), observation.getMaturityDate()); }
/** * Adds a new rate for a currency pair to the builder. See * {@link #addRate(Currency, Currency, double)} for full * explanation. * * @param currencyPair the currency pair to be added * @param rate the FX rate between the base currency of the pair and the * counter currency. The rate indicates the value of one unit of the base * currency in terms of the counter currency. * @return the builder updated with the new rate */ public FxMatrixBuilder addRate(CurrencyPair currencyPair, double rate) { ArgChecker.notNull(currencyPair, "currencyPair"); return addRate(currencyPair.getBase(), currencyPair.getCounter(), rate); }
@ImmutableValidator private void validate() { if (pair.getBase().equals(pair.getCounter()) && !rates.stream().allMatch(v -> v == 1d)) { throw new IllegalArgumentException("Conversion rate between identical currencies must be one"); } }
/** * Gets the non-deliverable currency. * <p> * Returns the currency that is not the settlement currency. * * @return the currency that is not to be settled */ public Currency getNonDeliverableCurrency() { FxIndex index = getIndex(); return index.getCurrencyPair().getBase().equals(getSettlementCurrency()) ? index.getCurrencyPair().getCounter() : index.getCurrencyPair().getBase(); }
@Override public FxForwardRates fxForwardRates(CurrencyPair currencyPair) { DiscountFactors base = discountFactors(currencyPair.getBase()); DiscountFactors counter = discountFactors(currencyPair.getCounter()); return DiscountFxForwardRates.of(currencyPair, fxRateProvider, base, counter); };
private static FxRate computeCross(FxRate fx1, FxRate fx2, CurrencyPair crossPairAC) { // aim is to convert AAA/BBB and BBB/CCC to AAA/CCC Currency currA = crossPairAC.getBase(); Currency currC = crossPairAC.getCounter(); // given the conventional cross rate pair, order the two rates to match boolean crossBaseCurrencyInFx1 = fx1.pair.contains(currA); FxRate fxABorBA = crossBaseCurrencyInFx1 ? fx1 : fx2; FxRate fxBCorCB = crossBaseCurrencyInFx1 ? fx2 : fx1; // extract the rates, taking the inverse if the pair is in the inverse order double rateAB = fxABorBA.getPair().getBase().equals(currA) ? fxABorBA.rate : 1d / fxABorBA.rate; double rateBC = fxBCorCB.getPair().getCounter().equals(currC) ? fxBCorCB.rate : 1d / fxBCorCB.rate; return FxRate.of(crossPairAC, rateAB * rateBC); }
@Override public PortfolioItemSummary summarize() { // Long Barrier Pay USD 1mm Premium USD 100k @ GBP/USD 1.32 : 21Jan18 StringBuilder buf = new StringBuilder(96); CurrencyAmount base = product.getUnderlyingOption().getUnderlying().getBaseCurrencyAmount(); CurrencyAmount counter = product.getUnderlyingOption().getUnderlying().getCounterCurrencyAmount(); buf.append(product.getUnderlyingOption().getLongShort()); buf.append(" Barrier "); buf.append(SummarizerUtils.fx(base, counter)); buf.append(" Premium "); buf.append(SummarizerUtils.amount(premium.getValue().mapAmount(v -> Math.abs(v)))); buf.append(" : "); buf.append(SummarizerUtils.date(product.getUnderlyingOption().getExpiryDate())); CurrencyPair currencyPair = product.getCurrencyPair(); return SummarizerUtils.summary( this, ProductType.FX_SINGLE_BARRIER_OPTION, buf.toString(), currencyPair.getBase(), currencyPair.getCounter()); }
public void test_of_CurrencyCurrency() { CurrencyPair test = CurrencyPair.of(GBP, USD); assertEquals(test.getBase(), GBP); assertEquals(test.getCounter(), USD); assertEquals(test.isIdentity(), false); assertEquals(test.toSet(), ImmutableSet.of(GBP, USD)); assertEquals(test.toString(), "GBP/USD"); }
public void test_of_CurrencyCurrency_same() { CurrencyPair test = CurrencyPair.of(USD, USD); assertEquals(test.getBase(), USD); assertEquals(test.getCounter(), USD); assertEquals(test.isIdentity(), true); assertEquals(test.toString(), "USD/USD"); }
/** * Gets the non-deliverable currency. * <p> * Returns the currency that is not the settlement currency. * * @return the currency that is not to be settled */ public Currency getNonDeliverableCurrency() { Currency base = agreedFxRate.getPair().getBase(); return base.equals(getSettlementCurrency()) ? agreedFxRate.getPair().getCounter() : base; }
public void test_of_CurrencyCurrency_reverseStandardOrder() { CurrencyPair test = CurrencyPair.of(USD, GBP); assertEquals(test.getBase(), USD); assertEquals(test.getCounter(), GBP); assertEquals(test.isIdentity(), false); assertEquals(test.toSet(), ImmutableSet.of(GBP, USD)); assertEquals(test.toString(), "USD/GBP"); }
private FxRateScenarioArray computeCross(FxRateScenarioArray other, CurrencyPair crossPairAC) { // aim is to convert AAA/BBB and BBB/CCC to AAA/CCC Currency currA = crossPairAC.getBase(); Currency currC = crossPairAC.getCounter(); // given the conventional cross rate pair, order the two rates to match boolean 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.getPair().getBase().equals(currA) ? fxABorBA.rates : fxABorBA.rates.map(v -> 1 / v); DoubleArray ratesBC = fxBCorCB.getPair().getCounter().equals(currC) ? fxBCorCB.rates : fxBCorCB.rates.map(v -> 1 / v); return FxRateScenarioArray.of(crossPairAC, ratesAB.multipliedBy(ratesBC)); }
@Override public PortfolioItemSummary summarize() { // Pay USD 1mm @ GBP/USD 1.32 : Rec USD 1mm @ GBP/USD 1.35 : 21Jan18-21Apr18 StringBuilder buf = new StringBuilder(96); CurrencyAmount base1 = product.getNearLeg().getBaseCurrencyAmount(); CurrencyAmount counter1 = product.getNearLeg().getCounterCurrencyAmount(); CurrencyAmount base2 = product.getFarLeg().getBaseCurrencyAmount(); CurrencyAmount counter2 = product.getFarLeg().getCounterCurrencyAmount(); buf.append(SummarizerUtils.fx(base1, counter1)); buf.append(" / "); buf.append(SummarizerUtils.fx(base2, counter2)); buf.append(" : "); buf.append(SummarizerUtils.dateRange(product.getNearLeg().getPaymentDate(), product.getFarLeg().getPaymentDate())); CurrencyPair currencyPair = product.getNearLeg().getCurrencyPair(); return SummarizerUtils.summary(this, ProductType.FX_SWAP, buf.toString(), currencyPair.getBase(), currencyPair.getCounter()); }
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.getPair(); if (!pair.contains(amount.getCurrency())) { throw new IllegalArgumentException(Messages.format( "FxRate '{}' and CurrencyAmount '{}' must have a currency in common", fxRate, amount)); } Currency currency2 = pair.getBase().equals(amount.getCurrency()) ? pair.getCounter() : pair.getBase(); CurrencyAmount amountCurrency2 = amount.convertedTo(currency2, fxRate).negated(); return create(amount, amountCurrency2, paymentDate, paymentDateAdjustment); }
/** * Gets the payment currency. * <p> * This returns the currency that the payment is made in. * ISDA refers to this as the <i>variable currency</i>. * * @return the payment currency */ @Override public Currency getCurrency() { FxIndex index = observation.getIndex(); Currency indexBase = index.getCurrencyPair().getBase(); Currency indexCounter = index.getCurrencyPair().getCounter(); return (getReferenceCurrency().equals(indexBase) ? indexCounter : indexBase); }
@Override public double fxRate(Currency baseCurrency, Currency counterCurrency) { if (baseCurrency.equals(counterCurrency)) { return 1; } if (baseCurrency.equals(rates1.getPair().getBase())) { return rates1.fxRate(baseCurrency, counterCurrency, scenarioIndex); } else if (baseCurrency.equals(rates2.getPair().getBase())) { return rates2.fxRate(baseCurrency, counterCurrency, scenarioIndex); } else { return rates3.fxRate(baseCurrency, counterCurrency, scenarioIndex); } } };