Exemple #1
0
        public virtual void test_parameter_secenarioDefinition()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<com.opengamma.strata.calc.marketdata.PerturbationMapping<?>> perturbationMapping = new java.util.ArrayList<>();
            IList <PerturbationMapping <object> > perturbationMapping = new List <PerturbationMapping <object> >();
            int nVolParams             = EXP_VOLS.ParameterCount;
            int nScenarios             = 3;
            PointShiftsBuilder builder = PointShifts.builder(ShiftType.SCALED);

            for (int i = 0; i < nVolParams; ++i)
            {
                object id = EXP_VOLS.getParameterMetadata(i).Identifier;
                for (int j = 0; j < nScenarios; ++j)
                {
                    builder.addShift(j, id, Math.Pow(0.9, j));
                }
            }
            ScenarioPerturbation <ParameterizedData> perturb = builder.build();

            perturbationMapping.Add(PerturbationMapping.of(MarketDataFilter.ofId(VOL_ID), perturb));
            ScenarioDefinition    scenarioDefinition   = ScenarioDefinition.ofMappings(perturbationMapping);
            ScenarioMarketData    marketDataCalibrated = StandardComponents.marketDataFactory().createMultiScenario(REQUIREMENTS, SCENARIO_CONFIG, MARKET_DATA, REF_DATA, scenarioDefinition);
            Results               results = CALC_RUNNER.calculateMultiScenario(RULES, TARGETS, COLUMN, marketDataCalibrated, REF_DATA);
            CurrencyScenarioArray pvs     = results.get(0, 0, typeof(CurrencyScenarioArray)).Value;

            for (int i = 0; i < nScenarios; ++i)
            {
                int index = i;
                BlackFxOptionSmileVolatilities shiftedSmile = EXP_VOLS.withPerturbation((j, v, m) => Math.Pow(0.9, index) * v);
                CurrencyAmount pv = PRICER.presentValue(OPTION_TRADE.resolve(REF_DATA), EXP_RATES, shiftedSmile).convertedTo(USD, EXP_RATES);
                assertEquals(pvs.get(i), pv);
            }
        }
Exemple #2
0
        public virtual void test_quote_secenarioDefinition()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<com.opengamma.strata.calc.marketdata.PerturbationMapping<?>> perturbationMapping = new java.util.ArrayList<>();
            IList <PerturbationMapping <object> > perturbationMapping = new List <PerturbationMapping <object> >();
            int nScenarios = 3;

            foreach (KeyValuePair <QuoteId, double> entry in MARKET_QUOTES.entrySet())
            {
                DoubleArray shifts = DoubleArray.of(nScenarios, n => Math.Pow(0.9, n));
                ScenarioPerturbation <double> perturb = GenericDoubleShifts.of(ShiftType.SCALED, shifts);
                perturbationMapping.Add(PerturbationMapping.of(MarketDataFilter.ofId(entry.Key), perturb));
            }
            ScenarioDefinition    scenarioDefinition   = ScenarioDefinition.ofMappings(perturbationMapping);
            ScenarioMarketData    marketDataCalibrated = StandardComponents.marketDataFactory().createMultiScenario(REQUIREMENTS, SCENARIO_CONFIG, MARKET_DATA, REF_DATA, scenarioDefinition);
            Results               results = CALC_RUNNER.calculateMultiScenario(RULES, TARGETS, COLUMN, marketDataCalibrated, REF_DATA);
            CurrencyScenarioArray pvs     = results.get(0, 0, typeof(CurrencyScenarioArray)).Value;

            for (int i = 0; i < nScenarios; ++i)
            {
                ImmutableMap.Builder <QuoteId, double> builder = ImmutableMap.builder();
                foreach (KeyValuePair <QuoteId, double> entry in MARKET_QUOTES.entrySet())
                {
                    builder.put(entry.Key, entry.Value * Math.Pow(0.9, i));
                }
                ImmutableMarketData shiftedMarketData           = ImmutableMarketData.builder(VALUATION_DATE).addValueMap(builder.build()).addValueMap(MARKET_FX_QUOTES).build();
                MarketData          shiftedMarketDataCalibrated = StandardComponents.marketDataFactory().create(REQUIREMENTS, CONFIG, shiftedMarketData, REF_DATA);
                Results             shiftedResults = CALC_RUNNER.calculate(RULES, TARGETS, COLUMN, shiftedMarketDataCalibrated, REF_DATA);
                CurrencyAmount      pv             = shiftedResults.get(0, 0, typeof(CurrencyAmount)).Value;
                assertEquals(pvs.get(i), pv);
            }
        }
        /// <summary>
        /// Returns a collector that builds a single-currency scenerio result.
        /// <para>
        /// This is used at the end of a stream to collect per-scenario instances of <seealso cref="CurrencyAmount"/>
        /// into a single instance of <seealso cref="CurrencyScenarioArray"/>, which is designed to be space-efficient.
        ///
        /// </para>
        /// </summary>
        /// <returns> a collector used at the end of a stream of <seealso cref="CurrencyAmount"/> to build a <seealso cref="CurrencyScenarioArray"/> </returns>
        public static Collector <CurrencyAmount, IList <CurrencyAmount>, CurrencyScenarioArray> toCurrencyValuesArray()
        {
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            return(Collector.of(List <CurrencyAmount>::new, (a, b) => a.add(b), (l, r) =>
            {
                l.addAll(r);
                return l;
            }, list => CurrencyScenarioArray.of(list)));
        }
Exemple #4
0
        public virtual void test_scenarioMarketData()
        {
            ScenarioMarketData    marketDataCalibrated = StandardComponents.marketDataFactory().createMultiScenario(REQUIREMENTS, SCENARIO_CONFIG, SCENARIO_MARKET_DATA, REF_DATA, ScenarioDefinition.empty());
            Results               results = CALC_RUNNER.calculateMultiScenario(RULES, TARGETS, COLUMN, marketDataCalibrated, REF_DATA);
            CurrencyScenarioArray pvs     = results.get(0, 0, typeof(CurrencyScenarioArray)).Value;
            CurrencyAmount        pv0     = PRICER.presentValue(OPTION_TRADE.resolve(REF_DATA), EXP_RATES, EXP_VOLS).convertedTo(USD, EXP_RATES);
            CurrencyAmount        pv1     = PRICER.presentValue(OPTION_TRADE.resolve(REF_DATA), EXP_RATES_1, EXP_VOLS_1).convertedTo(USD, EXP_RATES_1);

            assertEquals(pvs.get(0), pv0);
            assertEquals(pvs.get(1), pv1);
        }
Exemple #5
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 #6
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 #7
0
        public virtual void test_builtData()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<com.opengamma.strata.calc.marketdata.PerturbationMapping<?>> perturbationMapping = new java.util.ArrayList<>();
            IList <PerturbationMapping <object> > perturbationMapping = new List <PerturbationMapping <object> >();
            int nScenarios = 3;

            foreach (KeyValuePair <QuoteId, double> entry in MARKET_QUOTES.entrySet())
            {
                DoubleArray shifts = DoubleArray.of(nScenarios, n => Math.Pow(0.9, n));
                ScenarioPerturbation <double> perturb = GenericDoubleShifts.of(ShiftType.SCALED, shifts);
                perturbationMapping.Add(PerturbationMapping.of(MarketDataFilter.ofId(entry.Key), perturb));
            }
            ScenarioDefinition    scenarioDefinition   = ScenarioDefinition.ofMappings(perturbationMapping);
            ImmutableMarketData   dataWithSurface      = ImmutableMarketData.builder(VALUATION_DATE).addValueMap(MARKET_QUOTES).addValueMap(MARKET_FX_QUOTES).addValue(VOL_ID, EXP_VOLS).addValue(RatesCurveGroupId.of(CURVE_GROUP_NAME), RatesCurveGroup.ofCurves(CURVE_GROUP_DEFINITION, EXP_RATES.toImmutableRatesProvider().DiscountCurves.values())).build();
            ScenarioMarketData    marketDataCalibrated = StandardComponents.marketDataFactory().createMultiScenario(REQUIREMENTS, SCENARIO_CONFIG, dataWithSurface, REF_DATA, scenarioDefinition);
            Results               results  = CALC_RUNNER.calculateMultiScenario(RULES, TARGETS, COLUMN, marketDataCalibrated, REF_DATA);
            CurrencyScenarioArray computed = results.get(0, 0, typeof(CurrencyScenarioArray)).Value;
            CurrencyAmount        expected = PRICER.presentValue(OPTION_TRADE.resolve(REF_DATA), EXP_RATES, EXP_VOLS).convertedTo(USD, EXP_RATES);

            // dependency graph is absent, thus scenarios are not created
            assertTrue(computed.ScenarioCount == 1);
            assertEquals(computed.get(0), expected);
        }
        public virtual void test_simpleMeasures()
        {
            TermDepositTradeCalculationFunction function = new TermDepositTradeCalculationFunction();
            ScenarioMarketData md       = marketData();
            RatesProvider      provider = RATES_LOOKUP.ratesProvider(md.scenario(0));
            DiscountingTermDepositTradePricer pricer     = DiscountingTermDepositTradePricer.DEFAULT;
            CurrencyAmount      expectedPv               = pricer.presentValue(RTRADE, provider);
            double              expectedParRate          = pricer.parRate(RTRADE, provider);
            double              expectedParSpread        = pricer.parSpread(RTRADE, provider);
            MultiCurrencyAmount expectedCurrencyExposure = pricer.currencyExposure(RTRADE, provider);
            CurrencyAmount      expectedCurrentCash      = pricer.currentCash(RTRADE, provider);

            ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE, Measures.PAR_RATE, Measures.PAR_SPREAD, Measures.CURRENCY_EXPOSURE, Measures.CURRENT_CASH, Measures.RESOLVED_TARGET);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(Measures.PAR_RATE, Result.success(DoubleScenarioArray.of(ImmutableList.of(expectedParRate)))).containsEntry(Measures.PAR_SPREAD, Result.success(DoubleScenarioArray.of(ImmutableList.of(expectedParSpread)))).containsEntry(Measures.CURRENCY_EXPOSURE, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrencyExposure)))).containsEntry(Measures.CURRENT_CASH, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedCurrentCash)))).containsEntry(Measures.RESOLVED_TARGET, Result.success(RTRADE));
        }
        public virtual void test_curveSensitivityMeasures()
        {
            double                         oneBp                   = 1e-4;
            PointSensitivities             pvPointSens             = PRICER.presentValueSensitivity(RTRADE, RATES_PROVIDER, CreditDataSet.REF_DATA);
            CurrencyParameterSensitivities pvParamSens             = RATES_PROVIDER.parameterSensitivity(pvPointSens);
            MultiCurrencyAmount            expectedPv01Cal         = pvParamSens.total().multipliedBy(oneBp);
            CurrencyParameterSensitivities expectedPv01CalBucketed = pvParamSens.multipliedBy(oneBp);
            CurrencyParameterSensitivity   expectedCs01Bucketed    = CS01_CALC.bucketedCs01(RTRADE, RATES_PROVIDER, CreditDataSet.REF_DATA);
            CurrencyAmount                 expectedCs01Parallel    = CS01_CALC.parallelCs01(RTRADE, RATES_PROVIDER, CreditDataSet.REF_DATA);
            PointSensitivities             pvPointSensOnSettle     = PRICER.presentValueOnSettleSensitivity(RTRADE, RATES_PROVIDER, CreditDataSet.REF_DATA);
            CurrencyParameterSensitivity   ir01                    = RATES_PROVIDER.singleDiscountCurveParameterSensitivity(pvPointSensOnSettle, USD);
            CurrencyAmount                 expectedIr01Cal         = ir01.total().multipliedBy(oneBp);
            CurrencyParameterSensitivity   expectedIr01CalBucketed = ir01.multipliedBy(oneBp);

            ISet <Measure> measures = ImmutableSet.of(Measures.PV01_CALIBRATED_SUM, Measures.PV01_CALIBRATED_BUCKETED, CreditMeasures.CS01_PARALLEL, CreditMeasures.CS01_BUCKETED, CreditMeasures.IR01_CALIBRATED_PARALLEL, CreditMeasures.IR01_CALIBRATED_BUCKETED);

            assertThat(FUNCTION.calculate(TRADE, measures, CreditDataSet.CDS_PARAMS, CreditDataSet.MARKET_DATA, CreditDataSet.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)))).containsEntry(CreditMeasures.CS01_PARALLEL, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedCs01Parallel)))).containsEntry(CreditMeasures.CS01_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedCs01Bucketed)))).containsEntry(CreditMeasures.IR01_CALIBRATED_PARALLEL, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedIr01Cal)))).containsEntry(CreditMeasures.IR01_CALIBRATED_BUCKETED, Result.success(ScenarioArray.of(ImmutableList.of(expectedIr01CalBucketed))));
        }
        public virtual void test_simpleMeasures()
        {
            CurrencyAmount expectedPv  = PRICER.presentValue(RTRADE, RATES_PROVIDER, PriceType.DIRTY, CreditDataSet.REF_DATA);
            CurrencyAmount expectedPr  = PRICER.presentValueOnSettle(RTRADE, RATES_PROVIDER, PriceType.CLEAN, CreditDataSet.REF_DATA);
            double         expectedCp  = 1d - PRICER.price(RTRADE, RATES_PROVIDER, PriceType.CLEAN, CreditDataSet.REF_DATA);
            JumpToDefault  expectedJtd = PRICER.jumpToDefault(RTRADE, RATES_PROVIDER, CreditDataSet.REF_DATA);
            CurrencyAmount expectedEl  = PRICER.expectedLoss(RTRADE, RATES_PROVIDER);
            CurrencyAmount expectedR01 = PRICER.recovery01OnSettle(RTRADE, RATES_PROVIDER, CreditDataSet.REF_DATA);

            ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE, CreditMeasures.PRINCIPAL, Measures.UNIT_PRICE, CreditMeasures.JUMP_TO_DEFAULT, CreditMeasures.EXPECTED_LOSS, CreditMeasures.RECOVERY01);

            assertThat(FUNCTION.calculate(TRADE, measures, CreditDataSet.CDS_PARAMS, CreditDataSet.MARKET_DATA, CreditDataSet.REF_DATA)).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(CreditMeasures.PRINCIPAL, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPr)))).containsEntry(Measures.UNIT_PRICE, Result.success(DoubleScenarioArray.of(ImmutableList.of(expectedCp)))).containsEntry(CreditMeasures.JUMP_TO_DEFAULT, Result.success(ScenarioArray.of(ImmutableList.of(expectedJtd)))).containsEntry(CreditMeasures.EXPECTED_LOSS, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedEl)))).containsEntry(CreditMeasures.RECOVERY01, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedR01))));
        }
Exemple #11
0
        public virtual void test_simpleMeasures()
        {
            FxVanillaOptionTradeCalculationFunction function = new FxVanillaOptionTradeCalculationFunction();
            ScenarioMarketData md                               = marketData();
            RatesProvider      provider                         = RATES_LOOKUP.ratesProvider(md.scenario(0));
            BlackFxVanillaOptionTradePricer pricer              = BlackFxVanillaOptionTradePricer.DEFAULT;
            MultiCurrencyAmount             expectedPv          = pricer.presentValue(RTRADE, provider, VOLS);
            MultiCurrencyAmount             expectedCurrencyExp = pricer.currencyExposure(RTRADE, provider, VOLS);
            CurrencyAmount expectedCash                         = pricer.currentCash(RTRADE, VAL_DATE);

            ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE, Measures.PAR_SPREAD, Measures.CURRENCY_EXPOSURE, Measures.CURRENT_CASH, Measures.RESOLVED_TARGET);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PRESENT_VALUE, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(Measures.CURRENCY_EXPOSURE, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrencyExp)))).containsEntry(Measures.CURRENT_CASH, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedCash)))).containsEntry(Measures.RESOLVED_TARGET, Result.success(RTRADE));
        }
Exemple #12
0
        public virtual void test_simpleMeasures()
        {
            DsfTradeCalculationFunction <DsfTrade> function = DsfTradeCalculationFunction.TRADE;
            ScenarioMarketData        md                 = marketData();
            RatesProvider             provider           = RATES_LOOKUP.ratesProvider(md.scenario(0));
            DiscountingDsfTradePricer pricer             = DiscountingDsfTradePricer.DEFAULT;
            double              expectedPrice            = pricer.price(RTRADE, provider);
            CurrencyAmount      expectedPv               = pricer.presentValue(RTRADE, provider, REF_PRICE);
            MultiCurrencyAmount expectedCurrencyExposure = pricer.currencyExposure(RTRADE, provider, REF_PRICE);

            ISet <Measure> measures = ImmutableSet.of(Measures.UNIT_PRICE, Measures.PRESENT_VALUE, Measures.CURRENCY_EXPOSURE, Measures.RESOLVED_TARGET);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.UNIT_PRICE, Result.success(DoubleScenarioArray.of(ImmutableList.of(expectedPrice)))).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(Measures.CURRENCY_EXPOSURE, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrencyExposure)))).containsEntry(Measures.RESOLVED_TARGET, Result.success(RTRADE));
        }
Exemple #13
0
        public virtual void test_simpleMeasures()
        {
            BondFutureOptionTradeCalculationFunction <BondFutureOptionTrade> function = BondFutureOptionTradeCalculationFunction.TRADE;
            ScenarioMarketData                       md       = marketData();
            LegalEntityDiscountingProvider           provider = LED_LOOKUP.marketDataView(md.scenario(0)).discountingProvider();
            BlackBondFutureOptionMarginedTradePricer pricer   = BlackBondFutureOptionMarginedTradePricer.DEFAULT;
            CurrencyAmount      expectedPv = pricer.presentValue(RTRADE, provider, VOLS, SETTLE_PRICE);
            MultiCurrencyAmount expectedCurrencyExposure = pricer.currencyExposure(RTRADE, provider, VOLS, SETTLE_PRICE);

            ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE, Measures.CURRENCY_EXPOSURE, Measures.RESOLVED_TARGET);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(Measures.CURRENCY_EXPOSURE, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrencyExposure)))).containsEntry(Measures.RESOLVED_TARGET, Result.success(RTRADE));
        }
Exemple #14
0
        public virtual void test_simpleMeasures()
        {
            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;
            CurrencyAmount                           expectedPv               = pricer.presentValue(RTRADE, ratesProvider, ledProvider);
            MultiCurrencyAmount                      expectedCurrencyExposure = pricer.currencyExposure(RTRADE, ratesProvider, ledProvider);
            CurrencyAmount                           expectedCurrentCash      = pricer.currentCash(RTRADE, ratesProvider);

            ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE, Measures.CURRENCY_EXPOSURE, Measures.CURRENT_CASH, Measures.RESOLVED_TARGET);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(Measures.CURRENCY_EXPOSURE, Result.success(MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrencyExposure)))).containsEntry(Measures.CURRENT_CASH, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedCurrentCash)))).containsEntry(Measures.RESOLVED_TARGET, Result.success(RTRADE));
        }
Exemple #15
0
        public virtual void test_simpleMeasures()
        {
            SwaptionTradeCalculationFunction function = new SwaptionTradeCalculationFunction();
            ScenarioMarketData        md         = marketData();
            RatesProvider             provider   = RATES_LOOKUP.ratesProvider(md.scenario(0));
            NormalSwaptionTradePricer pricer     = NormalSwaptionTradePricer.DEFAULT;
            ResolvedSwaptionTrade     resolved   = TRADE.resolve(REF_DATA);
            CurrencyAmount            expectedPv = pricer.presentValue(resolved, provider, NORMAL_VOL_SWAPTION_PROVIDER_USD);

            ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE, Measures.RESOLVED_TARGET);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(Measures.RESOLVED_TARGET, Result.success(RTRADE));
        }
        public virtual void test_simpleMeasures()
        {
            BulletPaymentTradeCalculationFunction function = new BulletPaymentTradeCalculationFunction();
            ScenarioMarketData       md       = marketData();
            RatesProvider            provider = RATES_LOOKUP.ratesProvider(md.scenario(0));
            DiscountingPaymentPricer pricer   = DiscountingPaymentPricer.DEFAULT;
            Payment        payment            = RTRADE.Product.Payment;
            CurrencyAmount expectedPv         = pricer.presentValue(payment, provider);
            CashFlows      expectedCashFlows  = pricer.cashFlows(payment, provider);

            ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE, Measures.CASH_FLOWS, Measures.RESOLVED_TARGET);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(Measures.CASH_FLOWS, Result.success(ScenarioArray.of(ImmutableList.of(expectedCashFlows)))).containsEntry(Measures.RESOLVED_TARGET, Result.success(RTRADE));
        }
        public virtual void test_presentValue()
        {
            GenericSecurityPositionCalculationFunction function = new GenericSecurityPositionCalculationFunction();
            ScenarioMarketData md = marketData();

            double         unitPv     = (MARKET_PRICE / TICK_SIZE) * TICK_VALUE;
            CurrencyAmount expectedPv = CurrencyAmount.of(CURRENCY, unitPv * QUANTITY);

            ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv))));
        }
Exemple #18
0
        public virtual void test_simpleMeasures()
        {
            OvernightFutureTradeCalculationFunction <OvernightFutureTrade> function = OvernightFutureTradeCalculationFunction.TRADE;
            ScenarioMarketData md                = marketData(FORWARD_CURVE_ID.CurveName);
            RatesProvider      provider          = RATES_LOOKUP.ratesProvider(md.scenario(0));
            double             expectedPrice     = TRADE_PRICER.price(RESOLVED_TRADE, provider);
            CurrencyAmount     expectedPv        = TRADE_PRICER.presentValue(RESOLVED_TRADE, provider, MARKET_PRICE / 100d);
            double             expectedParSpread = TRADE_PRICER.parSpread(RESOLVED_TRADE, provider, MARKET_PRICE / 100d);

            ISet <Measure> measures = ImmutableSet.of(Measures.UNIT_PRICE, Measures.PRESENT_VALUE, Measures.PAR_SPREAD, Measures.RESOLVED_TARGET);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.UNIT_PRICE, Result.success(DoubleScenarioArray.of(ImmutableList.of(expectedPrice)))).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(Measures.PAR_SPREAD, Result.success(DoubleScenarioArray.of(ImmutableList.of(expectedParSpread)))).containsEntry(Measures.RESOLVED_TARGET, Result.success(RESOLVED_TRADE));
        }
Exemple #19
0
 //-------------------------------------------------------------------------
 // calculates present value for all scenarios
 internal CurrencyScenarioArray presentValue(ResolvedFraTrade trade, RatesScenarioMarketData marketData)
 {
     return(CurrencyScenarioArray.of(marketData.ScenarioCount, i => presentValue(trade, marketData.scenario(i).ratesProvider())));
 }
        public virtual void test_simpleMeasures()
        {
            IborFutureOptionTradeCalculationFunction <IborFutureOptionTrade> function = IborFutureOptionTradeCalculationFunction.TRADE;
            ScenarioMarketData md       = marketData();
            RatesProvider      provider = RATES_LOOKUP.ratesProvider(md.scenario(0));
            NormalIborFutureOptionMarginedTradePricer pricer   = NormalIborFutureOptionMarginedTradePricer.DEFAULT;
            ResolvedIborFutureOptionTrade             resolved = TRADE.resolve(REF_DATA);
            CurrencyAmount expectedPv = pricer.presentValue(resolved, provider, VOL_SIMPLE_MONEY_PRICE, SETTLEMENT_PRICE);

            ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE, Measures.RESOLVED_TARGET);

            assertThat(function.calculate(TRADE, measures, PARAMS, md, REF_DATA)).containsEntry(Measures.PRESENT_VALUE, Result.success(CurrencyScenarioArray.of(ImmutableList.of(expectedPv)))).containsEntry(Measures.RESOLVED_TARGET, Result.success(resolved));
        }