Skip to content

Commit

Permalink
SXSD-9063: Updated java docs, intendation and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiruthvik committed Dec 3, 2024
1 parent a692498 commit 1539bdb
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*
* Copyright (C) 2016 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.measure.fxopt;

import static com.opengamma.strata.measure.fxopt.FxCalculationUtils.checkBlackVolatilities;

import java.time.LocalDate;

import com.opengamma.strata.basics.currency.CurrencyAmount;
import com.opengamma.strata.basics.currency.CurrencyPair;
import com.opengamma.strata.basics.currency.MultiCurrencyAmount;
Expand All @@ -20,6 +23,7 @@
import com.opengamma.strata.pricer.rate.RatesProvider;
import com.opengamma.strata.pricer.sensitivity.MarketQuoteSensitivityCalculator;
import com.opengamma.strata.product.fxopt.ResolvedFxCollarTrade;
import java.time.LocalDate;

/**
* Multi-scenario measure calculations for FX collar trades.
Expand Down Expand Up @@ -61,6 +65,7 @@ MultiCurrencyScenarioArray presentValue(
ResolvedFxCollarTrade trade,
RatesScenarioMarketData ratesMarketData,
FxOptionScenarioMarketData optionMarketData) {

CurrencyPair currencyPair = trade.getProduct().getOption1().getCurrencyPair();
return MultiCurrencyScenarioArray.of(
ratesMarketData.getScenarioCount(),
Expand All @@ -75,6 +80,7 @@ MultiCurrencyAmount presentValue(
ResolvedFxCollarTrade trade,
RatesProvider ratesProvider,
FxOptionVolatilities volatilities) {

return tradePricer.presentValue(trade, ratesProvider, checkBlackVolatilities(volatilities));
}

Expand Down Expand Up @@ -108,6 +114,7 @@ ScenarioArray<CurrencyParameterSensitivities> pv01RatesCalibratedBucketed(
ResolvedFxCollarTrade trade,
RatesScenarioMarketData ratesMarketData,
FxOptionScenarioMarketData optionMarketData) {

CurrencyPair currencyPair = trade.getProduct().getOption1().getCurrencyPair();
return ScenarioArray.of(
ratesMarketData.getScenarioCount(),
Expand Down Expand Up @@ -181,6 +188,7 @@ private CurrencyParameterSensitivities pointSensitivity(
ResolvedFxCollarTrade trade,
RatesProvider ratesProvider,
FxOptionVolatilities volatilities) {

PointSensitivities pointSens = tradePricer.presentValueSensitivityRatesStickyStrike(
trade, ratesProvider, checkBlackVolatilities(volatilities));
return ratesProvider.parameterSensitivity(pointSens);
Expand All @@ -207,10 +215,10 @@ CurrencyParameterSensitivities vegaMarketQuoteBucketed(
RatesProvider ratesProvider,
FxOptionVolatilities volatilities) {

BlackFxOptionVolatilities blackVols = checkBlackVolatilities(volatilities);
PointSensitivities pointSens =
tradePricer.presentValueSensitivityModelParamsVolatility(trade, ratesProvider, blackVols);
return blackVols.parameterSensitivity(pointSens);
BlackFxOptionVolatilities blackVols = checkBlackVolatilities(volatilities);
PointSensitivities pointSens =
tradePricer.presentValueSensitivityModelParamsVolatility(trade, ratesProvider, blackVols);
return blackVols.parameterSensitivity(pointSens);
}

// calculates currency exposure for all scenarios
Expand All @@ -233,7 +241,8 @@ MultiCurrencyAmount currencyExposure(
ResolvedFxCollarTrade trade,
RatesProvider ratesProvider,
FxOptionVolatilities volatilities) {
return tradePricer.currencyExposure(trade, ratesProvider, checkBlackVolatilities(volatilities));

return tradePricer.currencyExposure(trade, ratesProvider, checkBlackVolatilities(volatilities));
}

// calculates current cash for all scenarios
Expand All @@ -253,6 +262,7 @@ CurrencyScenarioArray currentCash(
CurrencyAmount currentCash(
ResolvedFxCollarTrade trade,
LocalDate valuationDate) {
return tradePricer.currentCash(trade, valuationDate);

return tradePricer.currentCash(trade, valuationDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
*/
package com.opengamma.strata.measure.fxopt;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.opengamma.strata.basics.ReferenceData;
Expand All @@ -28,7 +23,32 @@
import com.opengamma.strata.product.fxopt.FxCollar;
import com.opengamma.strata.product.fxopt.FxCollarTrade;
import com.opengamma.strata.product.fxopt.ResolvedFxCollarTrade;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
* Perform calculations on an FX collar trade for each of a set of scenarios.
* <p>
* This uses Black FX option volatilities, which must be specified using {@link FxOptionMarketDataLookup}.
* An instance of {@link RatesMarketDataLookup} must also be specified.
* <p>
* The supported built-in measures are:
* <ul>
* <li>{@linkplain Measures#PRESENT_VALUE Present value}
* <li>{@linkplain Measures#PV01_CALIBRATED_SUM PV01 calibrated sum on rate curves}
* <li>{@linkplain Measures#PV01_CALIBRATED_BUCKETED PV01 calibrated bucketed on rate curves}
* <li>{@linkplain Measures#PV01_MARKET_QUOTE_SUM PV01 market quote sum on rate curves}
* <li>{@linkplain Measures#PV01_MARKET_QUOTE_BUCKETED PV01 market quote bucketed on rate curves}
* <li>{@linkplain Measures#CURRENCY_EXPOSURE Currency exposure}
* <li>{@linkplain Measures#CURRENT_CASH Current cash}
* <li>{@linkplain Measures#VEGA_MARKET_QUOTE_BUCKETED Vega market quote bucketed on volatility curves/surfaces}
* <li>{@linkplain Measures#RESOLVED_TARGET Resolved trade}
* </ul>
* <p>
* The "natural" currency is the market convention base currency of the underlying FX.
*/
public class FxCollarTradeCalculationFunction implements CalculationFunction<FxCollarTrade> {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (C) 2016 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.measure.fxopt;

import com.opengamma.strata.basics.currency.CurrencyAmount;
Expand All @@ -13,6 +18,19 @@
import com.opengamma.strata.pricer.rate.RatesProvider;
import com.opengamma.strata.product.fxopt.ResolvedFxCollarTrade;

/**
* Calculates pricing and risk measures for FX collar trades.
* <p>
* This provides a high-level entry point for FX collar pricing and risk measures.
* Pricing is performed using the Black method.
* <p>
* Each method takes a {@link ResolvedFxCollarTrade}, whereas application code will
* typically work with {@link com.opengamma.strata.product.fxopt.FxCollarTrade}
* . Call
* {@link com.opengamma.strata.product.fxopt.FxCollarTrade
* #resolve(com.opengamma.strata.basics.ReferenceData) FxVanillaOptionTrade::resolve(ReferenceData)}
* to convert {@code FxVanillaOptionTrade} to {@code ResolvedFxVanillaOptionTrade}.
*/
public class FxCollarTradeCalculations {

/**
Expand Down Expand Up @@ -52,6 +70,7 @@ public MultiCurrencyScenarioArray presentValue(
RatesMarketDataLookup ratesLookup,
FxOptionMarketDataLookup fxLookup,
ScenarioMarketData marketData) {

return calc.presentValue(
trade,
ratesLookup.marketDataView(marketData),
Expand All @@ -70,6 +89,7 @@ public MultiCurrencyAmount presentValue(
ResolvedFxCollarTrade trade,
RatesProvider ratesProvider,
FxOptionVolatilities volatilities) {

return calc.presentValue(trade, ratesProvider, volatilities);
}

Expand All @@ -90,6 +110,7 @@ public MultiCurrencyScenarioArray pv01RatesCalibratedSum(
RatesMarketDataLookup ratesLookup,
FxOptionMarketDataLookup fxLookup,
ScenarioMarketData marketData) {

return calc.pv01RatesCalibratedSum(
trade,
ratesLookup.marketDataView(marketData),
Expand All @@ -111,6 +132,7 @@ public MultiCurrencyAmount pv01RatesCalibratedSum(
ResolvedFxCollarTrade trade,
RatesProvider ratesProvider,
FxOptionVolatilities volatilities) {

return calc.pv01RatesCalibratedSum(trade, ratesProvider, volatilities);
}

Expand All @@ -131,6 +153,7 @@ public ScenarioArray<CurrencyParameterSensitivities> pv01RatesCalibratedBucketed
RatesMarketDataLookup ratesLookup,
FxOptionMarketDataLookup fxLookup,
ScenarioMarketData marketData) {

return calc.pv01RatesCalibratedBucketed(
trade,
ratesLookup.marketDataView(marketData),
Expand All @@ -152,6 +175,7 @@ public CurrencyParameterSensitivities pv01RatesCalibratedBucketed(
ResolvedFxCollarTrade trade,
RatesProvider ratesProvider,
FxOptionVolatilities volatilities) {

return calc.pv01RatesCalibratedBucketed(trade, ratesProvider, volatilities);
}

Expand All @@ -173,6 +197,7 @@ public MultiCurrencyScenarioArray pv01RatesMarketQuoteSum(
RatesMarketDataLookup ratesLookup,
FxOptionMarketDataLookup fxLookup,
ScenarioMarketData marketData) {

return calc.pv01RatesMarketQuoteSum(
trade,
ratesLookup.marketDataView(marketData),
Expand All @@ -195,6 +220,7 @@ public MultiCurrencyAmount pv01RatesMarketQuoteSum(
ResolvedFxCollarTrade trade,
RatesProvider ratesProvider,
FxOptionVolatilities volatilities) {

return calc.pv01RatesMarketQuoteSum(trade, ratesProvider, volatilities);
}

Expand All @@ -216,6 +242,7 @@ public ScenarioArray<CurrencyParameterSensitivities> pv01RatesMarketQuoteBuckete
RatesMarketDataLookup ratesLookup,
FxOptionMarketDataLookup fxLookup,
ScenarioMarketData marketData) {

return calc.pv01RatesMarketQuoteBucketed(
trade,
ratesLookup.marketDataView(marketData),
Expand All @@ -238,6 +265,7 @@ public CurrencyParameterSensitivities pv01RatesMarketQuoteBucketed(
ResolvedFxCollarTrade trade,
RatesProvider ratesProvider,
FxOptionVolatilities volatilities) {

return calc.pv01RatesMarketQuoteBucketed(trade, ratesProvider, volatilities);
}

Expand All @@ -258,6 +286,7 @@ public ScenarioArray<CurrencyParameterSensitivities> vegaMarketQuoteBucketed(
RatesMarketDataLookup ratesLookup,
FxOptionMarketDataLookup fxLookup,
ScenarioMarketData marketData) {

return calc.vegaMarketQuoteBucketed(
trade,
ratesLookup.marketDataView(marketData),
Expand All @@ -279,6 +308,7 @@ public CurrencyParameterSensitivities vegaMarketQuoteBucketed(
ResolvedFxCollarTrade trade,
RatesProvider ratesProvider,
FxOptionVolatilities volatilities) {

return calc.vegaMarketQuoteBucketed(trade, ratesProvider, volatilities);
}

Expand All @@ -298,6 +328,7 @@ public MultiCurrencyScenarioArray currencyExposure(
RatesMarketDataLookup ratesLookup,
FxOptionMarketDataLookup fxLookup,
ScenarioMarketData marketData) {

return calc.currencyExposure(
trade,
ratesLookup.marketDataView(marketData),
Expand All @@ -318,6 +349,7 @@ public MultiCurrencyAmount currencyExposure(
ResolvedFxCollarTrade trade,
RatesProvider ratesProvider,
FxOptionVolatilities volatilities) {

return calc.currencyExposure(trade, ratesProvider, volatilities);
}

Expand All @@ -329,13 +361,15 @@ public MultiCurrencyAmount currencyExposure(
* @param trade the trade
* @param ratesLookup the lookup used to query the market data
* @param marketData the market data
* @param fxLookup the market data lookup
* @return the current cash, one entry per scenario
*/
public CurrencyScenarioArray currentCash(
ResolvedFxCollarTrade trade,
RatesMarketDataLookup ratesLookup,
FxOptionMarketDataLookup fxLookup,
ScenarioMarketData marketData) {

return calc.currentCash(
trade,
ratesLookup.marketDataView(marketData),
Expand All @@ -354,6 +388,7 @@ public CurrencyScenarioArray currentCash(
public CurrencyAmount currentCash(
ResolvedFxCollarTrade trade,
RatesProvider ratesProvider) {

return calc.currentCash(trade, ratesProvider.getValuationDate());
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (C) 2016 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.measure.fxopt;

import static com.opengamma.strata.basics.currency.Currency.EUR;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (C) 2016 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.measure.fxopt;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.pricer.fxopt;

import static com.opengamma.strata.basics.currency.Currency.EUR;
Expand Down Expand Up @@ -34,7 +39,6 @@
*/
public class DiscountingFxCollarProductPricerTest {


private static final ZoneId ZONE = ZoneId.of("Z");
private static final ZonedDateTime EXPIRY = ZonedDateTime.of(2014, 5, 9, 13, 10, 0, 0, ZONE);
private static final LocalDate VAL_DATE = RatesProviderDataSets.VAL_DATE_2014_01_22;
Expand All @@ -55,7 +59,6 @@ public class DiscountingFxCollarProductPricerTest {
private static final BlackFxOptionSmileVolatilities VOLS_AFTER =
FxVolatilitySmileDataSet.createVolatilitySmileProvider6(VAL_DATETIME_AFTER);


private static final CurrencyPair CURRENCY_PAIR = CurrencyPair.of(EUR, USD);
private static final double NOTIONAL = 1.0e6;
private static final LocalDate PAYMENT_DATE = LocalDate.of(2014, 5, 13);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.pricer.fxopt;

import static com.opengamma.strata.basics.currency.Currency.EUR;
Expand Down

0 comments on commit 1539bdb

Please sign in to comment.