/// <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);
        }
Пример #2
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);
        }
        // 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());
        }
Пример #4
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]]");
        }
Пример #5
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;
        }
Пример #6
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));
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            CalculationTaskCell test = CalculationTaskCell.of(1, 2, TestingMeasures.PRESENT_VALUE, ReportingCurrency.of(USD));

            coverImmutableBean(test);
            CalculationTaskCell test2 = CalculationTaskCell.of(1, 2, TestingMeasures.PAR_RATE, ReportingCurrency.NATURAL);

            coverBeanEquals(test, test2);
            assertNotNull(CalculationTaskCell.meta());
        }
        public virtual void of()
        {
            CalculationTaskCell test = CalculationTaskCell.of(1, 2, TestingMeasures.PRESENT_VALUE, ReportingCurrency.of(USD));

            assertEquals(test.RowIndex, 1);
            assertEquals(test.ColumnIndex, 2);
            assertEquals(test.Measure, TestingMeasures.PRESENT_VALUE);
            assertEquals(test.ReportingCurrency, ReportingCurrency.of(USD));
            assertEquals(test.ToString(), "CalculationTaskCell[(1, 2), measure=PresentValue, currency=Specific:USD]");
        }
//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();
            }
        }
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         CalculationTaskCell other = (CalculationTaskCell)obj;
         return((rowIndex == other.rowIndex) && (columnIndex == other.columnIndex) && JodaBeanUtils.equal(measure, other.measure) && JodaBeanUtils.equal(reportingCurrency_Renamed, other.reportingCurrency_Renamed));
     }
     return(false);
 }
        //-------------------------------------------------------------------------
//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);
        }
Пример #12
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");
        }
Пример #13
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"));
        }
Пример #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)));
        }
Пример #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"));
        }
Пример #16
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));
        }
Пример #18
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");
        }
Пример #19
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");
        }
Пример #20
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'");
        }
        //-------------------------------------------------------------------------
        // 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");
        }
Пример #22
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);
        }
Пример #23
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'");
        }
Пример #24
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'");
        }