예제 #1
0
        public virtual void requirementsNoConfigForPair()
        {
            FxRateMarketDataFunction function = new FxRateMarketDataFunction();
            CurrencyPair             gbpUsd   = CurrencyPair.of(Currency.GBP, Currency.USD);

            assertThat(function.requirements(FxRateId.of(gbpUsd), config())).isEqualTo(MarketDataRequirements.empty());
        }
        public virtual void nonConventionPair()
        {
            IDictionary <CurrencyPair, QuoteId> ratesMap = ImmutableMap.of(CurrencyPair.of(Currency.USD, Currency.EUR), QUOTE_KEY);
            string regex = "Currency pairs must be quoted using market conventions but USD/EUR is not";

            assertThrowsIllegalArg(() => FxRateConfig.builder().observableRates(ratesMap).build(), regex);
            assertThrowsIllegalArg(() => FxRateConfig.of(ratesMap), regex);
        }
예제 #3
0
        public virtual void buildNoConfigForPair()
        {
            FxRateMarketDataFunction function = new FxRateMarketDataFunction();
            string       regex  = "No FX rate configuration available for GBP/USD";
            CurrencyPair gbpUsd = CurrencyPair.of(Currency.GBP, Currency.USD);

            assertThrowsIllegalArg(() => function.build(FxRateId.of(gbpUsd), config(), ScenarioMarketData.empty(), REF_DATA), regex);
        }
        private static FxIndex parseFxIndex(CsvRow row)
        {
            string            name            = row.getField(NAME_FIELD);
            Currency          baseCurrency    = Currency.parse(row.getField(BASE_CURRENCY_FIELD));
            Currency          counterCurrency = Currency.parse(row.getField(COUNTER_CURRENCY_FIELD));
            HolidayCalendarId fixingCal       = HolidayCalendarId.of(row.getField(FIXING_CALENDAR_FIELD));
            int maturityDays = int.Parse(row.getField(MATURITY_DAYS_FIELD));
            HolidayCalendarId maturityCal = HolidayCalendarId.of(row.getField(MATURITY_CALENDAR_FIELD));

            // build result
            return(ImmutableFxIndex.builder().name(name).currencyPair(CurrencyPair.of(baseCurrency, counterCurrency)).fixingCalendar(fixingCal).maturityDateOffset(DaysAdjustment.ofBusinessDays(maturityDays, maturityCal)).build());
        }
예제 #5
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Creates an {@code ResolvedFxSingle} from two equivalent payments in different currencies.
        /// <para>
        /// The payments must be of the correct type, one pay and one receive.
        /// 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>
        /// </summary>
        /// <param name="payment1">  the first payment </param>
        /// <param name="payment2">  the second payment </param>
        /// <returns> the resolved foreign exchange transaction </returns>
        public static ResolvedFxSingle of(Payment payment1, Payment payment2)
        {
            CurrencyPair pair = CurrencyPair.of(payment2.Currency, payment1.Currency);

            if (pair.Conventional)
            {
                return(new ResolvedFxSingle(payment2, payment1));
            }
            else
            {
                return(new ResolvedFxSingle(payment1, payment2));
            }
        }
예제 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ImmutablePreBuild private static void preBuild(Builder builder)
        private static void preBuild(Builder builder)
        {
            // swap order to be base/counter if reverse is conventional
            // this handled deserialization where the base/counter rules differ from those applicable at serialization
            Payment      @base   = builder.baseCurrencyPayment;
            Payment      counter = builder.counterCurrencyPayment;
            CurrencyPair pair    = CurrencyPair.of(counter.Currency, @base.Currency);

            if (pair.Conventional)
            {
                builder.baseCurrencyPayment    = counter;
                builder.counterCurrencyPayment = @base;
            }
        }
예제 #7
0
        // internal method where adjustment may be null
        private static FxSingle create(Payment payment1, Payment payment2, BusinessDayAdjustment paymentDateAdjustment)
        {
            ArgChecker.notNull(payment1, "payment1");
            ArgChecker.notNull(payment2, "payment2");
            CurrencyPair pair = CurrencyPair.of(payment1.Currency, payment2.Currency);

            if (pair.Conventional)
            {
                return(new FxSingle(payment1, payment2, paymentDateAdjustment));
            }
            else
            {
                return(new FxSingle(payment2, payment1, paymentDateAdjustment));
            }
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            BlackFxOptionInterpolatedNodalSurfaceVolatilitiesSpecification test1 = BlackFxOptionInterpolatedNodalSurfaceVolatilitiesSpecification.builder().name(VOL_NAME).currencyPair(GBP_USD).dayCount(ACT_365F).nodes(NODES).timeInterpolator(PCHIP).timeExtrapolatorLeft(LINEAR).timeExtrapolatorRight(LINEAR).strikeInterpolator(PCHIP).strikeExtrapolatorLeft(LINEAR).strikeExtrapolatorRight(LINEAR).build();

            coverImmutableBean(test1);
            CurrencyPair eurUsd = CurrencyPair.of(EUR, USD);

            ImmutableList.Builder <FxOptionVolatilitiesNode> nodeBuilder = ImmutableList.builder();
            for (int i = 0; i < TENORS.Count; ++i)
            {
                for (int j = 0; j < STRIKES.Count; ++j)
                {
                    QuoteId quoteId = QuoteId.of(StandardId.of("OG", eurUsd.ToString() + "_" + TENORS[i].ToString() + "_" + STRIKES[j]));
                    nodeBuilder.add(FxOptionVolatilitiesNode.of(eurUsd, SPOT_OFFSET, BDA, ValueType.BLACK_VOLATILITY, quoteId, TENORS[i], SimpleStrike.of(STRIKES[j])));
                }
            }
            BlackFxOptionInterpolatedNodalSurfaceVolatilitiesSpecification test2 = BlackFxOptionInterpolatedNodalSurfaceVolatilitiesSpecification.builder().name(FxOptionVolatilitiesName.of("other")).currencyPair(eurUsd).dayCount(ACT_360).nodes(nodeBuilder.build()).timeInterpolator(DOUBLE_QUADRATIC).strikeInterpolator(DOUBLE_QUADRATIC).build();

            coverBeanEquals(test1, test2);
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Returns requirements specifying the market data the function needs to perform its calculations.
        /// </summary>
        /// <param name="refData">  the reference data </param>
        /// <returns> requirements specifying the market data the function needs to perform its calculations </returns>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") public com.opengamma.strata.calc.marketdata.MarketDataRequirements requirements(com.opengamma.strata.basics.ReferenceData refData)
        public MarketDataRequirements requirements(ReferenceData refData)
        {
            // determine market data requirements of the function
            FunctionRequirements functionRequirements = function.requirements(target, Measures, parameters, refData);
            ObservableSource     obsSource            = functionRequirements.ObservableSource;

            // convert function requirements to market data requirements
            MarketDataRequirementsBuilder requirementsBuilder = MarketDataRequirements.builder();

            foreach (ObservableId id in functionRequirements.TimeSeriesRequirements)
            {
                requirementsBuilder.addTimeSeries(id.withObservableSource(obsSource));
            }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (com.opengamma.strata.data.MarketDataId<?> id : functionRequirements.getValueRequirements())
            foreach (MarketDataId <object> id in functionRequirements.ValueRequirements)
            {
                if (id is ObservableId)
                {
                    requirementsBuilder.addValues(((ObservableId)id).withObservableSource(obsSource));
                }
                else
                {
                    requirementsBuilder.addValues(id);
                }
            }

            // add requirements for the FX rates needed to convert the output values into the reporting currency
            foreach (CalculationTaskCell cell in cells)
            {
                if (cell.Measure.CurrencyConvertible && !cell.ReportingCurrency.None)
                {
                    Currency reportingCurrency = cell.reportingCurrency(this, refData);
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
                    IList <MarketDataId <FxRate> > fxRateIds = functionRequirements.OutputCurrencies.Where(outputCurrency => !outputCurrency.Equals(reportingCurrency)).Select(outputCurrency => CurrencyPair.of(outputCurrency, reportingCurrency)).Select(pair => FxRateId.of(pair, obsSource)).collect(toImmutableList());
                    requirementsBuilder.addValues(fxRateIds);
                }
            }
            return(requirementsBuilder.build());
        }
예제 #10
0
 /// <summary>
 /// Returns an array of FX rates for a currency pair.
 /// <para>
 /// The rates are the rates from the base currency to the counter currency
 /// as defined by this formula: {@code (1 * baseCurrency = fxRate * counterCurrency)}.
 ///
 /// </para>
 /// </summary>
 /// <param name="base">  the base currency of the pair </param>
 /// <param name="counter">  the counter currency of the pair </param>
 /// <param name="rates">  the FX rates for the currency pair </param>
 /// <returns> an array of FX rates for a currency pair </returns>
 public static FxRateScenarioArray of(Currency @base, Currency counter, DoubleArray rates)
 {
     return(new FxRateScenarioArray(CurrencyPair.of(@base, counter), rates));
 }
예제 #11
0
 /// <summary>
 /// Obtains an instance representing the FX rate for a currency pair, specifying the source.
 /// </summary>
 /// <param name="base">  the base currency of the pair </param>
 /// <param name="counter">  the counter currency of the pair </param>
 /// <param name="observableSource">  the source of the observable market data used to create the rate </param>
 /// <returns> an ID for the FX rate for the currency pair </returns>
 public static FxRateId of(Currency @base, Currency counter, ObservableSource observableSource)
 {
     return(new FxRateId(CurrencyPair.of(@base, counter), observableSource));
 }
 public virtual void missingPair()
 {
     assertThat(config().getObservableRateKey(CurrencyPair.of(Currency.GBP, Currency.USD))).Empty;
 }
예제 #13
0
        /// <summary>
        /// Constructs the synthetic market data from an existing rates provider and the configuration of the new curves.
        /// </summary>
        /// <param name="group">  the curve group definition for the synthetic curves and instruments </param>
        /// <param name="inputProvider">  the input rates provider </param>
        /// <param name="refData">  the reference data, used to resolve the trades </param>
        /// <returns> the market data </returns>
        public ImmutableMarketData marketData(RatesCurveGroupDefinition group, RatesProvider inputProvider, ReferenceData refData)
        {
            // Retrieve the set of required indices and the list of required currencies
            ISet <Index>     indicesRequired = new HashSet <Index>();
            IList <Currency> ccyRequired     = new List <Currency>();

            foreach (RatesCurveGroupEntry entry in group.Entries)
            {
                indicesRequired.addAll(entry.Indices);
                ((IList <Currency>)ccyRequired).AddRange(entry.DiscountCurrencies);
            }
            // Retrieve the required time series if present in the original provider
            IDictionary <IndexQuoteId, LocalDateDoubleTimeSeries> ts = new Dictionary <IndexQuoteId, LocalDateDoubleTimeSeries>();

            foreach (Index idx in Sets.intersection(inputProvider.TimeSeriesIndices, indicesRequired))
            {
                ts[IndexQuoteId.of(idx)] = inputProvider.timeSeries(idx);
            }

            LocalDate valuationDate = inputProvider.ValuationDate;
            ImmutableList <CurveDefinition> curveGroups = group.CurveDefinitions;
            // Create fake market quotes of 0, only to be able to generate trades
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.data.MarketDataId<?>, double> mapId0 = new java.util.HashMap<>();
            IDictionary <MarketDataId <object>, double> mapId0 = new Dictionary <MarketDataId <object>, double>();

            foreach (CurveDefinition entry in curveGroups)
            {
                ImmutableList <CurveNode> nodes = entry.Nodes;
                for (int i = 0; i < nodes.size(); i++)
                {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (com.opengamma.strata.data.MarketDataId<?> key : nodes.get(i).requirements())
                    foreach (MarketDataId <object> key in nodes.get(i).requirements())
                    {
                        mapId0[key] = 0.0d;
                    }
                }
            }
            ImmutableMarketData marketQuotes0 = ImmutableMarketData.of(valuationDate, mapId0);
            // Generate market quotes from the trades
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.data.MarketDataId<?>, Object> mapIdSy = new java.util.HashMap<>();
            IDictionary <MarketDataId <object>, object> mapIdSy = new Dictionary <MarketDataId <object>, object>();

            foreach (CurveDefinition entry in curveGroups)
            {
                ImmutableList <CurveNode> nodes = entry.Nodes;
                foreach (CurveNode node in nodes)
                {
                    ResolvedTrade trade = node.resolvedTrade(1d, marketQuotes0, refData);
                    double        mq    = measures.value(trade, inputProvider);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.data.MarketDataId<?> k = node.requirements().iterator().next();
                    MarketDataId <object> k = node.requirements().GetEnumerator().next();
                    mapIdSy[k] = mq;
                }
            }
            // Generate quotes for FX pairs. The first currency is arbitrarily selected as starting point.
            // The crosses are automatically generated by the MarketDataFxRateProvider used in calibration.
            for (int loopccy = 1; loopccy < ccyRequired.Count; loopccy++)
            {
                CurrencyPair ccyPair = CurrencyPair.of(ccyRequired[0], ccyRequired[loopccy]);
                FxRateId     fxId    = FxRateId.of(ccyPair);
                mapIdSy[fxId] = FxRate.of(ccyPair, inputProvider.fxRate(ccyPair));
            }
            return(ImmutableMarketData.builder(valuationDate).addValueMap(mapIdSy).addTimeSeriesMap(ts).build());
        }