Exemple #1
0
        public virtual void requirements()
        {
            CalculationTaskCell    cell         = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, NATURAL);
            CalculationTask        task         = CalculationTask.of(TARGET, new TestFunction(), cell);
            MarketDataRequirements requirements = task.requirements(REF_DATA);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Set<? extends com.opengamma.strata.data.MarketDataId<?>> nonObservables = requirements.getNonObservables();
            ISet <MarketDataId <object> > nonObservables = requirements.NonObservables;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.google.common.collect.ImmutableSet<? extends com.opengamma.strata.data.ObservableId> observables = requirements.getObservables();
            ImmutableSet <ObservableId> observables = requirements.Observables;
            ImmutableSet <ObservableId> timeSeries  = requirements.TimeSeries;

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.data.MarketDataId<?> timeSeriesId = com.opengamma.strata.calc.marketdata.TestObservableId.of("3", OBS_SOURCE);
            MarketDataId <object> timeSeriesId = TestObservableId.of("3", OBS_SOURCE);

            assertThat(timeSeries).hasSize(1);
            assertThat(timeSeries.GetEnumerator().next()).isEqualTo(timeSeriesId);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.data.MarketDataId<?> nonObservableId = new com.opengamma.strata.calc.marketdata.TestId("1");
            MarketDataId <object> nonObservableId = new TestId("1");

            assertThat(nonObservables).hasSize(1);
            assertThat(nonObservables.GetEnumerator().next()).isEqualTo(nonObservableId);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.data.MarketDataId<?> observableId = com.opengamma.strata.calc.marketdata.TestObservableId.of("2", OBS_SOURCE);
            MarketDataId <object> observableId = TestObservableId.of("2", OBS_SOURCE);

            assertThat(observables).hasSize(1);
            assertThat(observables.GetEnumerator().next()).isEqualTo(observableId);
        }
Exemple #2
0
 // submits a task to the executor to be run
 private void runTask(CalculationTask task, ScenarioMarketData marketData, ReferenceData refData, System.Action <CalculationResults> consumer)
 {
     // the task is executed, with the result passed to the consumer
     // the consumer wraps the listener to ensure thread-safety
     System.Func <CalculationResults> taskExecutor = () => task.execute(marketData, refData);
     CompletableFuture.supplyAsync(taskExecutor, executor).thenAccept(consumer);
 }
        // creates the tasks for a single target
        private static IList <CalculationTask> createTargetTasks <T1>(CalculationTarget resolvedTarget, int rowIndex, CalculationFunction <T1> function, IList <Column> columns)
        {
            // create the cells and group them
            ListMultimap <CalculationParameters, CalculationTaskCell> grouped = ArrayListMultimap.create();

            for (int colIndex = 0; colIndex < columns.Count; colIndex++)
            {
                Column  column  = columns[colIndex];
                Measure measure = column.Measure;

                ReportingCurrency   reportingCurrency = column.ReportingCurrency.orElse(ReportingCurrency.NATURAL);
                CalculationTaskCell cell = CalculationTaskCell.of(rowIndex, colIndex, measure, reportingCurrency);
                // group to find cells that can be shared, with same mappings and params (minus reporting currency)
                CalculationParameters @params = column.Parameters.filter(resolvedTarget, measure);
                grouped.put(@params, cell);
            }

            // build tasks
            ImmutableList.Builder <CalculationTask> taskBuilder = ImmutableList.builder();
            foreach (CalculationParameters @params in grouped.Keys)
            {
                taskBuilder.add(CalculationTask.of(resolvedTarget, function, @params, grouped.get(@params)));
            }
            return(taskBuilder.build());
        }
        /// <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 testToString()
        {
            OutputCurrenciesFunction fn   = new OutputCurrenciesFunction();
            CalculationTaskCell      cell = CalculationTaskCell.of(1, 2, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD);
            CalculationTask          task = CalculationTask.of(TARGET, fn, cell);

            assertThat(task.ToString()).isEqualTo("CalculationTask[CalculationTaskCell[(1, 2), measure=PresentValue, currency=Specific:USD]]");
        }
Exemple #6
0
        /// <summary>
        /// Tests that no requirements are added when not performing currency conversion.
        /// </summary>
        public virtual void fxConversionRequirements_noConversion()
        {
            OutputCurrenciesFunction fn           = new OutputCurrenciesFunction();
            CalculationTaskCell      cell         = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, ReportingCurrency.NONE);
            CalculationTask          task         = CalculationTask.of(TARGET, fn, cell);
            MarketDataRequirements   requirements = task.requirements(REF_DATA);

            assertThat(requirements.NonObservables).Empty;
        }
Exemple #7
0
        /// <summary>
        /// Tests that requirements are added for the FX rates needed to convert the results into the reporting currency.
        /// </summary>
        public virtual void fxConversionRequirements()
        {
            OutputCurrenciesFunction fn           = new OutputCurrenciesFunction();
            CalculationTaskCell      cell         = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD);
            CalculationTask          task         = CalculationTask.of(TARGET, fn, cell);
            MarketDataRequirements   requirements = task.requirements(REF_DATA);

            assertThat(requirements.NonObservables).containsOnly(FxRateId.of(GBP, USD, OBS_SOURCE), FxRateId.of(EUR, USD, OBS_SOURCE));
        }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Determines the reporting currency.
 /// <para>
 /// The reporting currency is specified using <seealso cref="ReportingCurrency"/>.
 /// If the currency is defined to be the "natural" currency, then the function
 /// is used to determine the natural currency.
 ///
 /// </para>
 /// </summary>
 /// <param name="task">  the calculation task </param>
 /// <param name="refData">  the reference data </param>
 /// <returns> the reporting currency </returns>
 internal Currency reportingCurrency(CalculationTask task, ReferenceData refData)
 {
     if (reportingCurrency_Renamed.Specific)
     {
         return(reportingCurrency_Renamed.Currency);
     }
     // this should never throw an exception, because it is only called if the measure is currency-convertible
     return(task.naturalCurrency(refData));
 }
        // converts the value, if appropriate
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: private com.opengamma.strata.collect.result.Result<?> convertCurrencyIfNecessary(CalculationTask task, com.opengamma.strata.collect.result.Result<?> result, com.opengamma.strata.data.scenario.ScenarioFxRateProvider fxProvider, com.opengamma.strata.basics.ReferenceData refData)
        private Result <object> convertCurrencyIfNecessary <T1>(CalculationTask task, Result <T1> result, ScenarioFxRateProvider fxProvider, ReferenceData refData)
        {
            // the result is only converted if it is a success and both the measure and value are convertible
            if (measure.CurrencyConvertible && !reportingCurrency_Renamed.None && result.Success && result.Value is ScenarioFxConvertible)
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.data.scenario.ScenarioFxConvertible<?> convertible = (com.opengamma.strata.data.scenario.ScenarioFxConvertible<?>) result.getValue();
                ScenarioFxConvertible <object> convertible = (ScenarioFxConvertible <object>)result.Value;
                return(convertCurrency(task, convertible, fxProvider, refData));
            }
            return(result);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeOut = 5000) public void interruptHangingResultsListener() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void interruptHangingResultsListener()
        {
            HangingFunction     fn   = new HangingFunction();
            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));

            ExecutorService executor = Executors.newSingleThreadExecutor();

            try
            {
                CalculationTaskRunner test       = CalculationTaskRunner.of(executor);
                MarketData            marketData = MarketData.empty(VAL_DATE);

                AtomicBoolean shouldNeverComplete    = new AtomicBoolean();
                AtomicBoolean interrupted            = new AtomicBoolean();
                AtomicReference <Exception> thrown   = new AtomicReference <Exception>();
                ResultsListener             listener = new ResultsListener();
                test.calculateAsync(tasks, marketData, REF_DATA, listener);
                System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1);
                Thread thread = new Thread(() =>
                {
                    try
                    {
                        listener.result();
                        shouldNeverComplete.set(true);
                    }
                    catch (Exception ex)
                    {
                        interrupted.set(Thread.CurrentThread.Interrupted);
                        thrown.set(ex);
                    }
                    latch.Signal();
                });
                // run the thread, wait until properly started, then interrupt, wait until properly handled
                thread.Start();
                while (!fn.started)
                {
                }
                thread.Interrupt();
                latch.await();
                // asserts
                assertEquals(interrupted.get(), true);
                assertEquals(shouldNeverComplete.get(), false);
                assertEquals(thrown.get() is Exception, true);
                assertEquals(thrown.get().Cause is InterruptedException, true);
            }
            finally
            {
                executor.shutdownNow();
            }
        }
        // converts the value
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: private com.opengamma.strata.collect.result.Result<?> convertCurrency(CalculationTask task, com.opengamma.strata.data.scenario.ScenarioFxConvertible<?> value, com.opengamma.strata.data.scenario.ScenarioFxRateProvider fxProvider, com.opengamma.strata.basics.ReferenceData refData)
        private Result <object> convertCurrency <T1>(CalculationTask task, ScenarioFxConvertible <T1> value, ScenarioFxRateProvider fxProvider, ReferenceData refData)
        {
            Currency resolvedReportingCurrency = reportingCurrency(task, refData);

            try
            {
                return(Result.success(value.convertedTo(resolvedReportingCurrency, fxProvider)));
            }
            catch (Exception ex)
            {
                return(Result.failure(FailureReason.CURRENCY_CONVERSION, ex, "Failed to convert value '{}' to currency '{}'", value, resolvedReportingCurrency));
            }
        }
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         CalculationTask other = (CalculationTask)obj;
         return(JodaBeanUtils.equal(target, other.target) && JodaBeanUtils.equal(function, other.function) && JodaBeanUtils.equal(parameters, other.parameters) && JodaBeanUtils.equal(cells, other.cells));
     }
     return(false);
 }
Exemple #13
0
        /// <summary>
        /// Tests that executing a function that returns a failure result returns the underlying result without wrapping it.
        /// </summary>
        public virtual void executeFailureResultValue()
        {
            SupplierFunction <Result <string> > fn = SupplierFunction.of(() => Result.failure(FailureReason.NOT_APPLICABLE, "bar"));
            CalculationTaskCell cell       = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD);
            CalculationTask     task       = CalculationTask.of(TARGET, fn, cell);
            ScenarioMarketData  marketData = ScenarioMarketData.empty();

            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).isFailure(FailureReason.NOT_APPLICABLE).hasFailureMessageMatching("bar");
        }
        //-------------------------------------------------------------------------
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeOut = 5000) public void interruptHangingCalculate() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void interruptHangingCalculate()
        {
            HangingFunction     fn   = new HangingFunction();
            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);

            AtomicBoolean             shouldNeverThrow = new AtomicBoolean();
            AtomicBoolean             interrupted      = new AtomicBoolean();
            AtomicReference <Results> results          = new AtomicReference <Results>();

            System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1);
            Thread thread = new Thread(() =>
            {
                try
                {
                    Results result = test.calculate(tasks, marketData, REF_DATA);
                    interrupted.set(Thread.CurrentThread.Interrupted);
                    results.set(result);
                }
                catch (Exception)
                {
                    shouldNeverThrow.set(true);
                }
                latch.Signal();
            });

            // run the thread, wait until properly started, then interrupt, wait until properly handled
            thread.Start();
            while (!fn.started)
            {
            }
            thread.Interrupt();
            latch.await();
            // asserts
            assertEquals(interrupted.get(), true);
            assertEquals(shouldNeverThrow.get(), false);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result00 = results.get().get(0, 0);
            Result <object> result00 = results.get().get(0, 0);

            assertEquals(result00.Failure, true);
            assertEquals(result00.Failure.Reason, FailureReason.CALCULATION_FAILED);
            assertEquals(result00.Failure.Message.Contains("Runtime interrupted"), true);
        }
Exemple #15
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 #16
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 #17
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 #18
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            OutputCurrenciesFunction fn   = new OutputCurrenciesFunction();
            CalculationTaskCell      cell = CalculationTaskCell.of(1, 2, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD);
            CalculationTask          test = CalculationTask.of(TARGET, fn, cell);

            coverImmutableBean(test);

            OutputCurrenciesFunction fn2   = new OutputCurrenciesFunction();
            CalculationTaskCell      cell2 = CalculationTaskCell.of(1, 3, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD);
            CalculationTask          test2 = CalculationTask.of(new TestTarget(), fn2, cell2);

            coverBeanEquals(test, test2);
            assertNotNull(CalculationTask.meta());
        }
        /// <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
        /// <summary>
        /// Tests that executing a function that throws an unsupported exception wraps the exception in a failure result.
        /// </summary>
        public virtual void executeException_unsupported()
        {
            SupplierFunction <string> fn = SupplierFunction.of(() =>
            {
                throw new System.NotSupportedException("foo");
            });
            CalculationTaskCell cell       = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD);
            CalculationTask     task       = CalculationTask.of(TARGET, fn, cell);
            ScenarioMarketData  marketData = ScenarioMarketData.empty();

            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).isFailure(FailureReason.UNSUPPORTED).hasFailureMessageMatching("Unsupported operation when invoking function 'SupplierFunction' for ID '123': foo");
        }
Exemple #21
0
        /// <summary>
        /// Test that a failure is returned if currency conversion fails.
        /// </summary>
        public virtual void convertResultCurrencyConversionFails()
        {
            DoubleArray           values = DoubleArray.of(1, 2, 3);
            CurrencyScenarioArray list   = CurrencyScenarioArray.of(GBP, values);
            // Market data doesn't include FX rates, conversion to USD will fail
            ScenarioMarketData  marketData = ScenarioMarketData.empty();
            ConvertibleFunction fn         = ConvertibleFunction.of(() => list, GBP);
            CalculationTaskCell cell       = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD);
            CalculationTask     task       = CalculationTask.of(TARGET, fn, cell);

            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).isFailure(FailureReason.CURRENCY_CONVERSION).hasFailureMessageMatching("Failed to convert value '.*' to currency 'USD'");
        }
Exemple #22
0
        /// <summary>
        /// Test that the result is returned unchanged if it is a failure.
        /// </summary>
        public virtual void convertResultCurrencyFailure()
        {
            ConvertibleFunction fn = ConvertibleFunction.of(() =>
            {
                throw new Exception("This is a failure");
            }, GBP);
            CalculationTaskCell cell       = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD);
            CalculationTask     task       = CalculationTask.of(TARGET, fn, cell);
            ScenarioMarketData  marketData = ScenarioMarketData.empty();

            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).isFailure(FailureReason.CALCULATION_FAILED).hasFailureMessageMatching("Error when invoking function 'ConvertibleFunction' for ID '123': This is a failure");
        }
        /// <summary>
        /// Creates the result from the map of calculated measures.
        /// <para>
        /// This extracts the calculated measure and performs currency conversion if necessary.
        ///
        /// </para>
        /// </summary>
        /// <param name="task">  the calculation task </param>
        /// <param name="target">  the target of the calculation </param>
        /// <param name="results">  the map of result by measure </param>
        /// <param name="fxProvider">  the market data </param>
        /// <param name="refData">  the reference data </param>
        /// <returns> the calculation result </returns>
        internal CalculationResult createResult <T1>(CalculationTask task, CalculationTarget target, IDictionary <T1> results, ScenarioFxRateProvider fxProvider, ReferenceData refData)
        {
            // caller expects that this method does not throw an exception
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> calculated = results.get(measure);
            Result <object> calculated = results[measure];

            if (calculated == null)
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                calculated = Result.failure(FailureReason.CALCULATION_FAILED, "Measure '{}' was not calculated by the function for target type '{}'", measure, target.GetType().FullName);
            }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = convertCurrencyIfNecessary(task, calculated, fxProvider, refData);
            Result <object> result = convertCurrencyIfNecessary(task, calculated, fxProvider, refData);

            return(CalculationResult.of(rowIndex, columnIndex, result));
        }
        //-------------------------------------------------------------------------
        // 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 #25
0
        /// <summary>
        /// Test that the result is not converted if the isCurrencyConvertible flag on the measure is false.
        /// </summary>
        public virtual void currencyConversionHonoursConvertibleFlagOnMeasure()
        {
            DoubleArray values = DoubleArray.of(1, 2, 3);
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            IList <FxRate>        rates      = ImmutableList.of(1.61, 1.62, 1.63).Select(rate => FxRate.of(GBP, USD, rate)).collect(toImmutableList());
            CurrencyScenarioArray list       = CurrencyScenarioArray.of(GBP, values);
            ScenarioMarketData    marketData = ImmutableScenarioMarketData.builder(date(2011, 3, 8)).addScenarioValue(FxRateId.of(GBP, USD), rates).build();
            ConvertibleFunction   fn         = ConvertibleFunction.of(() => list, GBP);
            CalculationTaskCell   cell       = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE_MULTI_CCY, REPORTING_CURRENCY_USD);
            CalculationTask       task       = CalculationTask.of(TARGET, fn, cell);

            CurrencyScenarioArray expectedArray = CurrencyScenarioArray.of(GBP, values);

            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(expectedArray);
        }
Exemple #26
0
        /// <summary>
        /// Test executing a bad function that fails to return expected measure.
        /// </summary>
        public virtual void executeMissingMeasure()
        {
            // function claims it supports 'PresentValueMultiCurrency' but fails to return it when asked
            MeasureCheckFunction fn         = new MeasureCheckFunction(ImmutableSet.of(TestingMeasures.PRESENT_VALUE), ("123"));
            CalculationTaskCell  cell0      = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD);
            CalculationTaskCell  cell1      = CalculationTaskCell.of(0, 1, TestingMeasures.PRESENT_VALUE_MULTI_CCY, REPORTING_CURRENCY_USD);
            CalculationTask      task       = CalculationTask.of(TARGET, fn, cell0, cell1);
            ScenarioMarketData   marketData = ScenarioMarketData.empty();

            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<?> result0 = calculationResults.getCells().get(0).getResult();
            Result <object> result0 = calculationResults.Cells.get(0).Result;

            assertThat(result0).Success.hasValue(ImmutableSet.of(TestingMeasures.PRESENT_VALUE, TestingMeasures.PRESENT_VALUE_MULTI_CCY));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result1 = calculationResults.getCells().get(1).getResult();
            Result <object> result1 = calculationResults.Cells.get(1).Result;

            assertThat(result1).isFailure(FailureReason.CALCULATION_FAILED).hasFailureMessageMatching("Function 'MeasureCheckFunction' did not return requested measure 'PresentValueMultiCurrency' for ID '123'");
        }
Exemple #27
0
        /// <summary>
        /// Tests that executing a function filters the set of measures sent to function.
        /// </summary>
        public virtual void executeFilterMeasures()
        {
            // function does not support 'ParRate', so it should not be asked for it
            MeasureCheckFunction fn         = new MeasureCheckFunction(ImmutableSet.of(TestingMeasures.PRESENT_VALUE), ("123"));
            CalculationTaskCell  cell0      = CalculationTaskCell.of(0, 0, TestingMeasures.PRESENT_VALUE, REPORTING_CURRENCY_USD);
            CalculationTaskCell  cell1      = CalculationTaskCell.of(0, 1, TestingMeasures.PAR_RATE, REPORTING_CURRENCY_USD);
            CalculationTask      task       = CalculationTask.of(TARGET, fn, cell0, cell1);
            ScenarioMarketData   marketData = ScenarioMarketData.empty();

            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<?> result0 = calculationResults.getCells().get(0).getResult();
            Result <object> result0 = calculationResults.Cells.get(0).Result;

            assertThat(result0).Success.hasValue(ImmutableSet.of(TestingMeasures.PRESENT_VALUE));     // ParRate not requested
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result1 = calculationResults.getCells().get(1).getResult();
            Result <object> result1 = calculationResults.Cells.get(1).Result;

            assertThat(result1).isFailure(FailureReason.UNSUPPORTED).hasFailureMessageMatching("Measure 'ParRate' is not supported by function 'MeasureCheckFunction'");
        }