Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
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'");
        }
Ejemplo n.º 3
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);
        }