Exemple #1
0
        public virtual void test_ofSingleValue()
        {
            ScenarioArray <string>       test     = ScenarioArray.ofSingleValue(3, "aaa");
            SingleScenarioArray <string> expected = SingleScenarioArray.of(3, "aaa");

            assertEquals(test, expected);
        }
Exemple #2
0
        public virtual void test_of_list()
        {
            ScenarioArray <string>        test     = ScenarioArray.of(ImmutableList.of("1", "2", "3"));
            DefaultScenarioArray <string> expected = DefaultScenarioArray.of("1", "2", "3");

            assertEquals(test, expected);
        }
Exemple #3
0
        public virtual void test_of_function()
        {
            ScenarioArray <string>        test     = ScenarioArray.of(3, i => Convert.ToString(i + 1));
            DefaultScenarioArray <string> expected = DefaultScenarioArray.of("1", "2", "3");

            assertEquals(test, expected);
        }
        /// <summary>
        /// Test that ScenarioArrays containing a single value are unwrapped when calling calculateAsync().
        /// </summary>
        public virtual void unwrapScenarioResultsAsync()
        {
            ScenarioArray <string> scenarioResult = ScenarioArray.of("foo");
            ScenarioResultFunction fn             = new ScenarioResultFunction(TestingMeasures.PRESENT_VALUE, scenarioResult);
            CalculationTaskCell    cell           = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, NATURAL);
            CalculationTask        task           = CalculationTask.of(TARGET, fn, cell);
            Column           column = Column.of(TestingMeasures.PRESENT_VALUE);
            CalculationTasks tasks  = CalculationTasks.of(ImmutableList.of(task), ImmutableList.of(column));

            // using the direct executor means there is no need to close/shutdown the runner
            CalculationTaskRunner test = CalculationTaskRunner.of(MoreExecutors.newDirectExecutorService());
            Listener listener          = new Listener();

            MarketData marketData = MarketData.empty(VAL_DATE);

            test.calculateAsync(tasks, marketData, REF_DATA, listener);
            CalculationResult calculationResult1 = listener.result;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result1 = calculationResult1.getResult();
            Result <object> result1 = calculationResult1.Result;

            // Check the result contains the string directly, not the result wrapping the string
            assertThat(result1).hasValue("foo");

            test.calculateMultiScenarioAsync(tasks, ScenarioMarketData.of(1, marketData), REF_DATA, listener);
            CalculationResult calculationResult2 = listener.result;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result2 = calculationResult2.getResult();
            Result <object> result2 = calculationResult2.Result;

            // Check the result contains the scenario result wrapping the string
            assertThat(result2).hasValue(scenarioResult);
        }
Exemple #5
0
        public virtual void test_of_array()
        {
            ScenarioArray <string>        test     = ScenarioArray.of("1", "2", "3");
            DefaultScenarioArray <string> expected = DefaultScenarioArray.of("1", "2", "3");

            assertEquals(test, expected);
        }
        private MarketDataBox <R> combineWithMultiple <U, R>(MarketDataBox <U> other, System.Func <T, U, R> fn)
        {
            ScenarioArray <U> otherValue = other.ScenarioValue;
            int scenarioCount            = otherValue.ScenarioCount;

            IList <R> values = IntStream.range(0, scenarioCount).mapToObj(i => fn(value, other.getValue(i))).collect(toImmutableList());

            return(MarketDataBox.ofScenarioValues(values));
        }
Exemple #7
0
        public virtual void getScenarioValue()
        {
            MarketDataBox <int> box           = MarketDataBox.ofScenarioValues(27, 28, 29);
            ScenarioArray <int> scenarioValue = box.ScenarioValue;

            assertThat(scenarioValue.ScenarioCount).isEqualTo(3);
            assertThat(scenarioValue.get(0)).isEqualTo(27);
            assertThat(scenarioValue.get(1)).isEqualTo(28);
            assertThat(scenarioValue.get(2)).isEqualTo(29);
        }
        public virtual void toScenarioArray2()
        {
            IList <MultiCurrencyAmount> amounts = ImmutableList.of(MultiCurrencyAmount.of(Currency.GBP, 1), MultiCurrencyAmount.of(CurrencyAmount.of(Currency.USD, 2), CurrencyAmount.of(Currency.GBP, 3)));

            ScenarioArray <MultiCurrencyAmount> expectedResult = ScenarioArray.of(amounts);
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            ScenarioArray <MultiCurrencyAmount> result = amounts.collect(FunctionUtils.toScenarioArray());

            assertThat(result).isEqualTo(expectedResult);
        }
        // obtains the data and calculates the grid of results
        private static void calculate(CalculationRunner runner)
        {
            // the trade that will have measures calculated
            IList <Trade> trades = ImmutableList.of(createVanillaFixedVsLibor3mSwap());

            // the columns, specifying the measures to be calculated
            IList <Column> columns = ImmutableList.of(Column.of(Measures.PRESENT_VALUE), Column.of(Measures.PV01_CALIBRATED_SUM));

            // use the built-in example market data
            ExampleMarketDataBuilder marketDataBuilder = ExampleMarketData.builder();

            // the complete set of rules for calculating measures
            LocalDate            valuationDate = LocalDate.of(2014, 1, 22);
            CalculationFunctions functions     = StandardComponents.calculationFunctions();
            CalculationRules     rules         = CalculationRules.of(functions, Currency.USD, marketDataBuilder.ratesLookup(valuationDate));

            // mappings that select which market data to apply perturbations to
            // this applies the perturbations above to all curves
            PerturbationMapping <Curve> mapping = PerturbationMapping.of(MarketDataFilter.ofIdType(typeof(CurveId)), CurveParallelShifts.absolute(0, ONE_BP));

            // create a scenario definition containing the single mapping above
            // this creates two scenarios - one for each perturbation in the mapping
            ScenarioDefinition scenarioDefinition = ScenarioDefinition.ofMappings(mapping);

            // build a market data snapshot for the valuation date
            MarketData marketData = marketDataBuilder.buildSnapshot(valuationDate);

            // the reference data, such as holidays and securities
            ReferenceData refData = ReferenceData.standard();

            // calculate the results
            MarketDataRequirements reqs = MarketDataRequirements.of(rules, trades, columns, refData);
            ScenarioMarketData     scenarioMarketData = marketDataFactory().createMultiScenario(reqs, MarketDataConfig.empty(), marketData, refData, scenarioDefinition);
            Results results = runner.calculateMultiScenario(rules, trades, columns, scenarioMarketData, refData);

            // TODO Replace the results processing below with a report once the reporting framework supports scenarios

            // The results are lists of currency amounts containing one value for each scenario
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.data.scenario.ScenarioArray<?> pvList = (com.opengamma.strata.data.scenario.ScenarioArray<?>) results.get(0, 0).getValue();
            ScenarioArray <object> pvList = (ScenarioArray <object>)results.get(0, 0).Value;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.data.scenario.ScenarioArray<?> pv01List = (com.opengamma.strata.data.scenario.ScenarioArray<?>) results.get(0, 1).getValue();
            ScenarioArray <object> pv01List = (ScenarioArray <object>)results.get(0, 1).Value;

            double       pvBase       = ((CurrencyAmount)pvList.get(0)).Amount;
            double       pvShifted    = ((CurrencyAmount)pvList.get(1)).Amount;
            double       pv01Base     = ((CurrencyAmount)pv01List.get(0)).Amount;
            NumberFormat numberFormat = new DecimalFormat("###,##0.00", new DecimalFormatSymbols(Locale.ENGLISH));

            Console.WriteLine("                         PV (base) = " + numberFormat.format(pvBase));
            Console.WriteLine("             PV (1 bp curve shift) = " + numberFormat.format(pvShifted));
            Console.WriteLine("PV01 (algorithmic differentiation) = " + numberFormat.format(pv01Base));
            Console.WriteLine("          PV01 (finite difference) = " + numberFormat.format(pvShifted - pvBase));
        }
        private MarketDataBox <R> combineWithMultiple <R, U>(MarketDataBox <U> other, System.Func <T, U, R> fn)
        {
            ScenarioArray <U> otherValue = other.ScenarioValue;

            if (otherValue.ScenarioCount != value.ScenarioCount)
            {
                string message = Messages.format("Scenario values must have the same number of scenarios. {} has {} scenarios, {} has {}", value, value.ScenarioCount, otherValue, otherValue.ScenarioCount);
                throw new System.ArgumentException(message);
            }
            return(applyToScenarios(i => fn(value.get(i), otherValue.get(i))));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public Builder<T> set(String propertyName, Object newValue)
            public override Builder <T> set(string propertyName, object newValue)
            {
                switch (propertyName.GetHashCode())
                {
                case 111972721:         // value
                    this.value_Renamed = (ScenarioArray <T>)newValue;
                    break;

                default:
                    throw new NoSuchElementException("Unknown property: " + propertyName);
                }
                return(this);
            }
        public virtual void notConvertible()
        {
            FxRateScenarioArray    rates      = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63));
            ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates);

            IList <string> values = ImmutableList.of("a", "b", "c");
            DefaultScenarioArray <string> test = DefaultScenarioArray.of(values);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: ScenarioArray<?> convertedList = test.convertedTo(com.opengamma.strata.basics.currency.Currency.GBP, fxProvider);
            ScenarioArray <object> convertedList = test.convertedTo(Currency.GBP, fxProvider);

            assertThat(convertedList).isEqualTo(test);
        }
        public virtual void convertCurrencyAmount()
        {
            FxRateScenarioArray    rates              = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63));
            ScenarioFxRateProvider fxProvider         = new TestScenarioFxRateProvider(rates);
            SingleScenarioArray <CurrencyAmount> test = SingleScenarioArray.of(3, CurrencyAmount.of(GBP, 2));

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: ScenarioArray<?> convertedList = test.convertedTo(USD, fxProvider);
            ScenarioArray <object> convertedList  = test.convertedTo(USD, fxProvider);
            IList <CurrencyAmount> expectedValues = ImmutableList.of(CurrencyAmount.of(USD, 2 * 1.61), CurrencyAmount.of(USD, 2 * 1.62), CurrencyAmount.of(USD, 2 * 1.63));
            DefaultScenarioArray <CurrencyAmount> expectedList = DefaultScenarioArray.of(expectedValues);

            assertThat(convertedList).isEqualTo(expectedList);
        }
Exemple #14
0
        /// <summary>
        /// Test the result is returned unchanged if using ReportingCurrency.NONE.
        /// </summary>
        public virtual void convertResultCurrencyNoConversionRequested()
        {
            SupplierFunction <CurrencyAmount> fn = SupplierFunction.of(() => CurrencyAmount.of(EUR, 1d));
            CalculationTaskCell cell             = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, ReportingCurrency.NONE);
            CalculationTask     task             = CalculationTask.of(TARGET, fn, cell);
            ScenarioMarketData  marketData       = ImmutableScenarioMarketData.builder(date(2011, 3, 8)).build();

            CalculationResults calculationResults = task.execute(marketData, REF_DATA);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = calculationResults.getCells().get(0).getResult();
            Result <object> result = calculationResults.Cells.get(0).Result;

            assertThat(result).hasValue(ScenarioArray.of(CurrencyAmount.of(EUR, 1d)));
        }
Exemple #15
0
        /// <summary>
        /// Tests that executing a function that returns a success result returns the underlying result without wrapping it.
        /// </summary>
        public virtual void executeSuccessResultValue()
        {
            SupplierFunction <Result <ScenarioArray <string> > > fn = SupplierFunction.of(() => Result.success(ScenarioArray.of("foo")));
            CalculationTaskCell cell       = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD);
            CalculationTask     task       = CalculationTask.of(TARGET, fn, cell);
            ScenarioMarketData  marketData = ImmutableScenarioMarketData.builder(date(2011, 3, 8)).build();

            CalculationResults calculationResults = task.execute(marketData, REF_DATA);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = calculationResults.getCells().get(0).getResult();
            Result <object> result = calculationResults.Cells.get(0).Result;

            assertThat(result).hasValue(ScenarioArray.of("foo"));
        }
Exemple #16
0
        /// <summary>
        /// Test a non-convertible result is returned even if there is no reporting currency.
        /// </summary>
        public virtual void nonConvertibleResultReturnedWhenNoReportingCurrency()
        {
            TestFunction        fn         = new TestFunction();
            CalculationTaskCell cell       = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, NATURAL);
            CalculationTask     task       = CalculationTask.of(TARGET, fn, cell);
            ScenarioMarketData  marketData = ImmutableScenarioMarketData.builder(date(2011, 3, 8)).build();

            CalculationResults calculationResults = task.execute(marketData, REF_DATA);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = calculationResults.getCells().get(0).getResult();
            Result <object> result = calculationResults.Cells.get(0).Result;

            assertThat(result).hasValue(ScenarioArray.of("bar"));
        }
Exemple #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> calculate(TestTarget target, java.util.Set<com.opengamma.strata.calc.Measure> measures, CalculationParameters parameters, com.opengamma.strata.data.scenario.ScenarioMarketData marketData, com.opengamma.strata.basics.ReferenceData refData)
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
            public IDictionary <Measure, Result <object> > calculate(TestTarget target, ISet <Measure> measures, CalculationParameters parameters, ScenarioMarketData marketData, ReferenceData refData)
            {
                T obj = supplier.get();

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: if (obj instanceof com.opengamma.strata.collect.result.Result<?>)
                if (obj is Result <object> )
                {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: return com.google.common.collect.ImmutableMap.of(com.opengamma.strata.calc.TestingMeasures.PRESENT_VALUE, (com.opengamma.strata.collect.result.Result<?>) obj);
                    return(ImmutableMap.of(TestingMeasures.PRESENT_VALUE, (Result <object>)obj));
                }
                ScenarioArray <object> array = ScenarioArray.of(obj);

                return(ImmutableMap.of(TestingMeasures.PRESENT_VALUE, Result.success(array)));
            }
Exemple #18
0
        private static void outputPnl <T1>(IList <LocalDate> scenarioDates, ScenarioArray <T1> scenarioValuations)
        {
            NumberFormat numberFormat = new DecimalFormat("0.00", new DecimalFormatSymbols(Locale.ENGLISH));
            double       basePv       = ((CurrencyAmount)scenarioValuations.get(0)).Amount;

            Console.WriteLine("Base PV (USD): " + numberFormat.format(basePv));
            Console.WriteLine();
            Console.WriteLine("P&L series (USD):");
            for (int i = 1; i < scenarioValuations.ScenarioCount; i++)
            {
                double    scenarioPv   = ((CurrencyAmount)scenarioValuations.get(i)).Amount;
                double    pnl          = scenarioPv - basePv;
                LocalDate scenarioDate = scenarioDates[i];
                Console.WriteLine(Messages.format("{} = {}", scenarioDate, numberFormat.format(pnl)));
            }
        }
        /// <summary>
        /// Test that ScenarioArrays containing multiple values are an error.
        /// </summary>
        public virtual void unwrapMultipleScenarioResults()
        {
            ScenarioArray <string> scenarioResult = ScenarioArray.of("foo", "bar");
            ScenarioResultFunction fn             = new ScenarioResultFunction(TestingMeasures.PAR_RATE, scenarioResult);
            CalculationTaskCell    cell           = CalculationTaskCell.of(0, 0, TestingMeasures.PAR_RATE, NATURAL);
            CalculationTask        task           = CalculationTask.of(TARGET, fn, cell);
            Column           column = Column.of(TestingMeasures.PAR_RATE);
            CalculationTasks tasks  = CalculationTasks.of(ImmutableList.of(task), ImmutableList.of(column));

            // using the direct executor means there is no need to close/shutdown the runner
            CalculationTaskRunner test = CalculationTaskRunner.of(MoreExecutors.newDirectExecutorService());

            MarketData marketData = MarketData.empty(VAL_DATE);

            assertThrowsIllegalArg(() => test.calculate(tasks, marketData, REF_DATA));
        }
Exemple #20
0
        // obtains the data and calculates the grid of results
        private static void calculate(CalculationRunner runner)
        {
            // the trades for which to calculate a P&L series
            IList <Trade> trades = ImmutableList.of(createTrade());

            // the columns, specifying the measures to be calculated
            IList <Column> columns = ImmutableList.of(Column.of(Measures.PRESENT_VALUE));

            // use the built-in example historical scenario market data
            ExampleMarketDataBuilder marketDataBuilder = ExampleMarketDataBuilder.ofResource(MARKET_DATA_RESOURCE_ROOT);

            // the complete set of rules for calculating measures
            CalculationFunctions functions = StandardComponents.calculationFunctions();
            CalculationRules     rules     = CalculationRules.of(functions, marketDataBuilder.ratesLookup(LocalDate.of(2015, 4, 23)));

            // load the historical calibrated curves from which we will build our scenarios
            // these curves are provided in the example data environment
            SortedDictionary <LocalDate, RatesCurveGroup> historicalCurves = marketDataBuilder.loadAllRatesCurves();

            // sorted list of dates for the available series of curves
            // the entries in the P&L vector we produce will correspond to these dates
            IList <LocalDate> scenarioDates = new List <LocalDate>(historicalCurves.Keys);

            // build the historical scenarios
            ScenarioDefinition historicalScenarios = buildHistoricalScenarios(historicalCurves, scenarioDates);

            // build a market data snapshot for the valuation date
            // this is the base snapshot which will be perturbed by the scenarios
            LocalDate  valuationDate = LocalDate.of(2015, 4, 23);
            MarketData marketData    = marketDataBuilder.buildSnapshot(valuationDate);

            // the reference data, such as holidays and securities
            ReferenceData refData = ReferenceData.standard();

            // calculate the results
            MarketDataRequirements reqs = MarketDataRequirements.of(rules, trades, columns, refData);
            ScenarioMarketData     scenarioMarketData = marketDataFactory().createMultiScenario(reqs, MarketDataConfig.empty(), marketData, refData, historicalScenarios);
            Results results = runner.calculateMultiScenario(rules, trades, columns, scenarioMarketData, refData);

            // the results contain the one measure requested (Present Value) for each scenario
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.data.scenario.ScenarioArray<?> scenarioValuations = (com.opengamma.strata.data.scenario.ScenarioArray<?>) results.get(0, 0).getValue();
            ScenarioArray <object> scenarioValuations = (ScenarioArray <object>)results.get(0, 0).Value;

            outputPnl(scenarioDates, scenarioValuations);
        }
        //-------------------------------------------------------------------------
        // Test that ScenarioArrays containing a single value are unwrapped.
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void unwrapScenarioResults() throws Exception
        public virtual void unwrapScenarioResults()
        {
            ScenarioArray <string> scenarioResult = ScenarioArray.of("foo");
            ScenarioResultFunction fn             = new ScenarioResultFunction(TestingMeasures.PRESENT_VALUE, scenarioResult);
            CalculationTaskCell    cell           = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, NATURAL);
            CalculationTask        task           = CalculationTask.of(TARGET, fn, cell);
            Column           column = Column.of(TestingMeasures.PRESENT_VALUE);
            CalculationTasks tasks  = CalculationTasks.of(ImmutableList.of(task), ImmutableList.of(column));

            // using the direct executor means there is no need to close/shutdown the runner
            CalculationTaskRunner test = CalculationTaskRunner.of(MoreExecutors.newDirectExecutorService());

            MarketData marketData = MarketData.empty(VAL_DATE);
            Results    results1   = test.calculate(tasks, marketData, REF_DATA);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result1 = results1.get(0, 0);
            Result <object> result1 = results1.get(0, 0);

            // Check the result contains the string directly, not the result wrapping the string
            assertThat(result1).hasValue("foo");

            Results results2 = test.calculateMultiScenario(tasks, ScenarioMarketData.of(1, marketData), REF_DATA);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result2 = results2.get(0, 0);
            Result <object> result2 = results2.get(0, 0);

            // Check the result contains the scenario result wrapping the string
            assertThat(result2).hasValue(scenarioResult);

            ResultsListener resultsListener = new ResultsListener();

            test.calculateAsync(tasks, marketData, REF_DATA, resultsListener);
            CompletableFuture <Results> future = resultsListener.Future;

            // The future is guaranteed to be done because everything is running on a single thread
            assertThat(future.Done).True;
            Results results3 = future.get();
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result3 = results3.get(0, 0);
            Result <object> result3 = results3.get(0, 0);

            // Check the result contains the string directly, not the result wrapping the string
            assertThat(result3).hasValue("foo");
        }
Exemple #22
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Unwraps the result from an instance of <seealso cref="ScenarioArray"/> containing a single result.
        /// <para>
        /// When the user executes a single scenario the functions are invoked with a set of scenario market data
        /// of size 1. This means the functions are simpler and always deal with scenarios. But if the user has
        /// asked for a single set of results they don't want to see a collection of size 1 so the scenario results
        /// need to be unwrapped.
        /// </para>
        /// <para>
        /// If {@code result} is a failure or doesn't contain a {@code ScenarioArray} it is returned.
        /// </para>
        /// <para>
        /// If this method is called with a {@code ScenarioArray} containing more than one value it throws an exception.
        /// </para>
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: private static com.opengamma.strata.collect.result.Result<?> unwrapScenarioResult(com.opengamma.strata.collect.result.Result<?> result)
        private static Result <object> unwrapScenarioResult <T1>(Result <T1> result)
        {
            if (result.Failure)
            {
                return(result);
            }
            object value = result.Value;

            if (!(value is ScenarioArray))
            {
                return(result);
            }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.data.scenario.ScenarioArray<?> scenarioResult = (com.opengamma.strata.data.scenario.ScenarioArray<?>) value;
            ScenarioArray <object> scenarioResult = (ScenarioArray <object>)value;

            if (scenarioResult.ScenarioCount != 1)
            {
                throw new System.ArgumentException(Messages.format("Expected one result but found {} in {}", scenarioResult.ScenarioCount, scenarioResult));
            }
            return(Result.success(scenarioResult.get(0)));
        }
Exemple #23
0
        public virtual void test_pv01_quote()
        {
            FixedCouponBondTradeCalculationFunction <FixedCouponBondTrade> function = FixedCouponBondTradeCalculationFunction.TRADE;
            ScenarioMarketData                    md                      = marketData();
            LegalEntityDiscountingProvider        provider                = LOOKUP.marketDataView(md.scenario(0)).discountingProvider();
            DiscountingFixedCouponBondTradePricer pricer                  = DiscountingFixedCouponBondTradePricer.DEFAULT;
            PointSensitivities                    pvPointSens             = pricer.presentValueSensitivity(RTRADE, provider);
            CurrencyParameterSensitivities        pvParamSens             = provider.parameterSensitivity(pvPointSens);
            CurrencyParameterSensitivities        expectedPv01CalBucketed = MQ_CALC.sensitivity(pvParamSens, provider).multipliedBy(1e-4);
            MultiCurrencyAmount                   expectedPv01Cal         = expectedPv01CalBucketed.total();

            ISet <Measure> measures = ImmutableSet.of(Measures.PV01_MARKET_QUOTE_SUM, Measures.PV01_MARKET_QUOTE_BUCKETED);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> computed = function.calculate(TRADE, measures, PARAMS, md, REF_DATA);
            IDictionary <Measure, Result <object> > computed = function.calculate(TRADE, measures, PARAMS, md, REF_DATA);
            MultiCurrencyScenarioArray sumComputed           = (MultiCurrencyScenarioArray)computed[Measures.PV01_MARKET_QUOTE_SUM].Value;
            ScenarioArray <CurrencyParameterSensitivities> bucketedComputed = (ScenarioArray <CurrencyParameterSensitivities>)computed[Measures.PV01_MARKET_QUOTE_BUCKETED].Value;

            assertEquals(sumComputed.ScenarioCount, 1);
            assertEquals(sumComputed.get(0).Currencies, ImmutableSet.of(GBP));
            assertTrue(DoubleMath.fuzzyEquals(sumComputed.get(0).getAmount(GBP).Amount, expectedPv01Cal.getAmount(GBP).Amount, 1.0e-10));
            assertEquals(bucketedComputed.ScenarioCount, 1);
            assertTrue(bucketedComputed.get(0).equalWithTolerance(expectedPv01CalBucketed, 1.0e-10));
        }
Exemple #24
0
 //-------------------------------------------------------------------------
 // calculates cash flows for all scenarios
 internal ScenarioArray <CashFlows> cashFlows(ResolvedFraTrade trade, RatesScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => cashFlows(trade, marketData.scenario(i).ratesProvider())));
 }
Exemple #25
0
 //-------------------------------------------------------------------------
 // calculates explain present value for all scenarios
 internal ScenarioArray <ExplainMap> explainPresentValue(ResolvedFraTrade trade, RatesScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => explainPresentValue(trade, marketData.scenario(i).ratesProvider())));
 }
Exemple #26
0
 //-------------------------------------------------------------------------
 // calculates single-node gamma PV01 for all scenarios
 internal ScenarioArray <CurrencyParameterSensitivities> pv01SingleNodeGammaBucketed(ResolvedFraTrade trade, RatesScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => pv01SingleNodeGammaBucketed(trade, marketData.scenario(i).ratesProvider())));
 }
Exemple #27
0
 //-------------------------------------------------------------------------
 // calculates semi-parallel gamma PV01 for all scenarios
 internal ScenarioArray <CurrencyParameterSensitivities> pv01SemiParallelGammaBucketed(ResolvedFraTrade trade, RatesScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => pv01SemiParallelGammaBucketed(trade, marketData.scenario(i))));
 }
Exemple #28
0
        public virtual void test_pv01()
        {
            CapitalIndexedBondTradeCalculationFunction <CapitalIndexedBondTrade> function = CapitalIndexedBondTradeCalculationFunction.TRADE;
            ScenarioMarketData                       md                      = marketData();
            RatesProvider                            ratesProvider           = RATES_LOOKUP.marketDataView(md.scenario(0)).ratesProvider();
            LegalEntityDiscountingProvider           ledProvider             = LED_LOOKUP.marketDataView(md.scenario(0)).discountingProvider();
            DiscountingCapitalIndexedBondTradePricer pricer                  = DiscountingCapitalIndexedBondTradePricer.DEFAULT;
            PointSensitivities                       pvPointSens             = pricer.presentValueSensitivity(RTRADE, ratesProvider, ledProvider);
            CurrencyParameterSensitivities           pvParamSens             = ledProvider.parameterSensitivity(pvPointSens);
            MultiCurrencyAmount                      expectedPv01Cal         = pvParamSens.total().multipliedBy(1e-4);
            CurrencyParameterSensitivities           expectedPv01CalBucketed = pvParamSens.multipliedBy(1e-4);

            ISet <Measure> measures = ImmutableSet.of(Measures.PV01_CALIBRATED_SUM, Measures.PV01_CALIBRATED_BUCKETED);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PV01_CALIBRATED_SUM, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01Cal)))).containsEntry(Measures.PV01_CALIBRATED_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedPv01CalBucketed))));
        }
        public virtual void test_pv01()
        {
            TermDepositTradeCalculationFunction function = new TermDepositTradeCalculationFunction();
            ScenarioMarketData md       = marketData();
            RatesProvider      provider = RATES_LOOKUP.ratesProvider(md.scenario(0));
            DiscountingTermDepositProductPricer pricer          = DiscountingTermDepositProductPricer.DEFAULT;
            ResolvedTermDeposit            resolved             = TRADE.Product.resolve(REF_DATA);
            PointSensitivities             pvPointSens          = pricer.presentValueSensitivity(resolved, provider);
            CurrencyParameterSensitivities pvParamSens          = provider.parameterSensitivity(pvPointSens);
            MultiCurrencyAmount            expectedPv01         = pvParamSens.total().multipliedBy(1e-4);
            CurrencyParameterSensitivities expectedBucketedPv01 = pvParamSens.multipliedBy(1e-4);

            ISet <Measure> measures = ImmutableSet.of(Measures.PV01_CALIBRATED_SUM, Measures.PV01_CALIBRATED_BUCKETED);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PV01_CALIBRATED_SUM, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01)))).containsEntry(Measures.PV01_CALIBRATED_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedBucketedPv01))));
        }
Exemple #30
0
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: @Override public java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> calculate(TestTarget target, java.util.Set<com.opengamma.strata.calc.Measure> measures, CalculationParameters parameters, com.opengamma.strata.data.scenario.ScenarioMarketData marketData, com.opengamma.strata.basics.ReferenceData refData)
            public IDictionary <Measure, Result <object> > calculate(TestTarget target, ISet <Measure> measures, CalculationParameters parameters, ScenarioMarketData marketData, ReferenceData refData)
            {
                ScenarioArray <string> array = ScenarioArray.of("bar");

                return(ImmutableMap.of(TestingMeasures.PRESENT_VALUE, Result.success(array)));
            }