public virtual void test_toZonedDateTime_scenario_long()
        {
            ValuationZoneTimeDefinition   test     = ValuationZoneTimeDefinition.of(LOCAL_TIME_1, ZONE_ID, LOCAL_TIME_1, LOCAL_TIME_2);
            MarketDataBox <LocalDate>     dates    = MarketDataBox.ofScenarioValues(LocalDate.of(2016, 10, 21), LocalDate.of(2016, 10, 22), LocalDate.of(2016, 10, 23));
            MarketDataBox <ZonedDateTime> computed = test.toZonedDateTime(dates);
            MarketDataBox <ZonedDateTime> expected = MarketDataBox.ofScenarioValue(ScenarioArray.of(dates.getValue(0).atTime(LOCAL_TIME_1).atZone(ZONE_ID), dates.getValue(1).atTime(LOCAL_TIME_2).atZone(ZONE_ID), dates.getValue(2).atTime(LOCAL_TIME_1).atZone(ZONE_ID)));

            assertEquals(computed, expected);
        }
Пример #2
0
        //-------------------------------------------------------------------------
        // calculates calibrated bucketed PV01 for all scenarios
        internal ScenarioArray <CurrencyParameterSensitivities> pv01RatesCalibratedBucketed(ResolvedSwaptionTrade trade, RatesScenarioMarketData ratesMarketData, SwaptionScenarioMarketData swaptionMarketData)
        {
            IborIndex index = trade.Product.Index;

            return(ScenarioArray.of(ratesMarketData.ScenarioCount, i => pv01RatesCalibratedBucketed(trade, ratesMarketData.scenario(i).ratesProvider(), swaptionMarketData.scenario(i).volatilities(index))));
        }
 //-------------------------------------------------------------------------
 // calculates cash flows for all scenarios
 internal ScenarioArray <CashFlows> cashFlows(ResolvedBulletPaymentTrade trade, RatesScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => cashFlows(trade, marketData.scenario(i).ratesProvider())));
 }
Пример #4
0
        //-------------------------------------------------------------------------
        // calculates calibrated bucketed PV01 for all scenarios
        internal ScenarioArray <CurrencyParameterSensitivities> pv01RatesCalibratedBucketed(ResolvedIborCapFloorTrade trade, RatesScenarioMarketData ratesMarketData, IborCapFloorScenarioMarketData capFloorMarketData)
        {
            IborIndex index = trade.Product.CapFloorLeg.Index;

            return(ScenarioArray.of(ratesMarketData.ScenarioCount, i => pv01RatesCalibratedBucketed(trade, ratesMarketData.scenario(i).ratesProvider(), capFloorMarketData.scenario(i).volatilities(index))));
        }
Пример #5
0
        public virtual void test_pv01()
        {
            ScenarioMarketData             md                      = SwapTradeCalculationFunctionTest.marketData();
            RatesProvider                  provider                = RATES_LOOKUP.marketDataView(md.scenario(0)).ratesProvider();
            DiscountingSwapTradePricer     pricer                  = DiscountingSwapTradePricer.DEFAULT;
            PointSensitivities             pvPointSens             = pricer.presentValueSensitivity(RTRADE, provider);
            CurrencyParameterSensitivities pvParamSens             = provider.parameterSensitivity(pvPointSens);
            MultiCurrencyAmount            expectedPv01Cal         = pvParamSens.total().multipliedBy(1e-4);
            CurrencyParameterSensitivities expectedPv01CalBucketed = pvParamSens.multipliedBy(1e-4);

            assertEquals(SwapTradeCalculations.DEFAULT.pv01CalibratedSum(RTRADE, RATES_LOOKUP, md), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01Cal)));
            assertEquals(SwapTradeCalculations.DEFAULT.pv01CalibratedBucketed(RTRADE, RATES_LOOKUP, md), ScenarioArray.of(ImmutableList.of(expectedPv01CalBucketed)));
        }
 //-------------------------------------------------------------------------
 // calculates calibrated bucketed PV01 for all scenarios
 internal ScenarioArray <CurrencyParameterSensitivities> pv01CalibratedBucketed(ResolvedFxNdfTrade trade, RatesScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => pv01CalibratedBucketed(trade, marketData.scenario(i).ratesProvider())));
 }
Пример #7
0
        //-------------------------------------------------------------------------
        // calculates market quote bucketed PV01 for all scenarios
        internal ScenarioArray <CurrencyParameterSensitivities> pv01MarketQuoteBucketed(ResolvedIborFutureOptionTrade trade, RatesScenarioMarketData ratesMarketData, IborFutureOptionScenarioMarketData optionMarketData)
        {
            IborIndex index = trade.Product.UnderlyingFuture.Index;

            return(ScenarioArray.of(ratesMarketData.ScenarioCount, i => pv01MarketQuoteBucketed(trade, ratesMarketData.scenario(i).ratesProvider(), optionMarketData.scenario(i).volatilities(index))));
        }
Пример #8
0
        public virtual void test_pv01_quote()
        {
            ScenarioMarketData             md                      = BillTradeCalculationFunctionTest.marketData();
            LegalEntityDiscountingProvider provider                = LOOKUP.marketDataView(md.scenario(0)).discountingProvider();
            PointSensitivities             pvPointSens             = PRICER.presentValueSensitivity(RTRADE, provider);
            CurrencyParameterSensitivities pvParamSens             = provider.parameterSensitivity(pvPointSens);
            CurrencyParameterSensitivities expectedPv01CalBucketed = MQ_CALC.sensitivity(pvParamSens, provider).multipliedBy(1e-4);
            MultiCurrencyAmount            expectedPv01Cal         = expectedPv01CalBucketed.total();

            assertEquals(BillTradeCalculations.DEFAULT.pv01MarketQuoteSum(RTRADE, LOOKUP, md), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01Cal)));
            assertEquals(BillTradeCalculations.DEFAULT.pv01MarketQuoteBucketed(RTRADE, LOOKUP, md), ScenarioArray.of(ImmutableList.of(expectedPv01CalBucketed)));
            assertEquals(BillTradeCalculations.DEFAULT.pv01MarketQuoteSum(RTRADE, provider), expectedPv01Cal);
            assertEquals(BillTradeCalculations.DEFAULT.pv01MarketQuoteBucketed(RTRADE, provider), expectedPv01CalBucketed);
        }
Пример #9
0
        //-------------------------------------------------------------------------
        // calculates market quote bucketed PV01 for all scenarios
        internal ScenarioArray <CurrencyParameterSensitivities> pv01RatesMarketQuoteBucketed(ResolvedCmsTrade trade, RatesScenarioMarketData ratesMarketData, SwaptionScenarioMarketData swaptionMarketData)
        {
            IborIndex index = cmsLegIborIndex(trade);

            return(ScenarioArray.of(ratesMarketData.ScenarioCount, i => pv01RatesMarketQuoteBucketed(trade, ratesMarketData.scenario(i).ratesProvider(), swaptionMarketData.scenario(i).volatilities(index))));
        }
Пример #10
0
        public virtual void test_pv01()
        {
            ScenarioMarketData md       = CmsTradeCalculationFunctionTest.marketData();
            RatesProvider      provider = RATES_LOOKUP.marketDataView(md.scenario(0)).ratesProvider();
            SabrExtrapolationReplicationCmsTradePricer pricer      = new SabrExtrapolationReplicationCmsTradePricer(new SabrExtrapolationReplicationCmsProductPricer(new SabrExtrapolationReplicationCmsLegPricer(SabrExtrapolationReplicationCmsPeriodPricer.of(CMS_MODEL.CutOffStrike, CMS_MODEL.Mu))));
            PointSensitivities             pvPointSens             = pricer.presentValueSensitivityRates(RTRADE, provider, VOLS);
            CurrencyParameterSensitivities pvParamSens             = provider.parameterSensitivity(pvPointSens);
            MultiCurrencyAmount            expectedPv01Cal         = pvParamSens.total().multipliedBy(1e-4);
            CurrencyParameterSensitivities expectedPv01CalBucketed = pvParamSens.multipliedBy(1e-4);

            CmsTradeCalculations calcs = CmsTradeCalculations.of(CMS_MODEL);

            assertEquals(calcs.pv01RatesCalibratedSum(RTRADE, RATES_LOOKUP, SWAPTION_LOOKUP, md), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01Cal)));
            assertEquals(calcs.pv01RatesCalibratedBucketed(RTRADE, RATES_LOOKUP, SWAPTION_LOOKUP, md), ScenarioArray.of(ImmutableList.of(expectedPv01CalBucketed)));
        }
        //-------------------------------------------------------------------------
        public virtual void test_presentValue()
        {
            ScenarioMarketData       md                  = BulletPaymentTradeCalculationFunctionTest.marketData();
            RatesProvider            provider            = RATES_LOOKUP.marketDataView(md.scenario(0)).ratesProvider();
            DiscountingPaymentPricer pricer              = DiscountingPaymentPricer.DEFAULT;
            Payment             payment                  = RTRADE.Product.Payment;
            CurrencyAmount      expectedPv               = pricer.presentValue(payment, provider);
            CashFlows           expectedCashFlows        = pricer.cashFlows(payment, provider);
            MultiCurrencyAmount expectedCurrencyExposure = pricer.currencyExposure(payment, provider);
            CurrencyAmount      expectedCurrentCash      = pricer.currentCash(payment, provider);

            assertEquals(BulletPaymentTradeCalculations.DEFAULT.presentValue(RTRADE, RATES_LOOKUP, md), CurrencyScenarioArray.of(ImmutableList.of(expectedPv)));
            assertEquals(BulletPaymentTradeCalculations.DEFAULT.cashFlows(RTRADE, RATES_LOOKUP, md), ScenarioArray.of(ImmutableList.of(expectedCashFlows)));
            assertEquals(BulletPaymentTradeCalculations.DEFAULT.currencyExposure(RTRADE, RATES_LOOKUP, md), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrencyExposure)));
            assertEquals(BulletPaymentTradeCalculations.DEFAULT.currentCash(RTRADE, RATES_LOOKUP, md), CurrencyScenarioArray.of(ImmutableList.of(expectedCurrentCash)));
        }
        public virtual void test_pv01_quote()
        {
            PointSensitivities             pvPointSens          = TRADE_PRICER.presentValueSensitivity(RESOLVED_TRADE, RATES_PROVIDER);
            CurrencyParameterSensitivities pvParamSens          = RATES_PROVIDER.parameterSensitivity(pvPointSens);
            CurrencyParameterSensitivities expectedPv01Bucketed = MQ_CALC.sensitivity(pvParamSens, RATES_PROVIDER).multipliedBy(ONE_BP);
            MultiCurrencyAmount            expectedPv01Sum      = expectedPv01Bucketed.total();

            assertEquals(CALC.pv01MarketQuoteSum(RESOLVED_TRADE, RATES_LOOKUP, MARKET_DATA), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01Sum)));
            assertEquals(CALC.pv01MarketQuoteSum(RESOLVED_TRADE, RATES_PROVIDER), expectedPv01Sum);
            assertEquals(CALC.pv01MarketQuoteBucketed(RESOLVED_TRADE, RATES_LOOKUP, MARKET_DATA), ScenarioArray.of(ImmutableList.of(expectedPv01Bucketed)));
            assertEquals(CALC.pv01MarketQuoteBucketed(RESOLVED_TRADE, RATES_PROVIDER), expectedPv01Bucketed);
        }
        public virtual void test_pv01_calibrated()
        {
            PointSensitivities             pvPointSens             = TRADE_PRICER.presentValueSensitivity(RESOLVED_TRADE, RATES_PROVIDER);
            CurrencyParameterSensitivities pvParamSens             = RATES_PROVIDER.parameterSensitivity(pvPointSens);
            MultiCurrencyAmount            expectedPv01Cal         = pvParamSens.total().multipliedBy(ONE_BP);
            CurrencyParameterSensitivities expectedPv01CalBucketed = pvParamSens.multipliedBy(ONE_BP);

            assertEquals(CALC.pv01CalibratedSum(RESOLVED_TRADE, RATES_LOOKUP, MARKET_DATA), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01Cal)));
            assertEquals(CALC.pv01CalibratedSum(RESOLVED_TRADE, RATES_PROVIDER), expectedPv01Cal);
            assertEquals(CALC.pv01CalibratedBucketed(RESOLVED_TRADE, RATES_LOOKUP, MARKET_DATA), ScenarioArray.of(ImmutableList.of(expectedPv01CalBucketed)));
            assertEquals(CALC.pv01CalibratedBucketed(RESOLVED_TRADE, RATES_PROVIDER), expectedPv01CalBucketed);
        }
 //-------------------------------------------------------------------------
 // calculates explain present value for all scenarios
 internal ScenarioArray <ExplainMap> explainPresentValue(ResolvedBulletPaymentTrade trade, RatesScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => explainPresentValue(trade, marketData.scenario(i).ratesProvider())));
 }
 //-------------------------------------------------------------------------
 // calculates calibrated bucketed PV01 for all scenarios
 internal ScenarioArray <CurrencyParameterSensitivities> pv01CalibratedBucketed(ResolvedCapitalIndexedBondTrade trade, RatesScenarioMarketData ratesMarketData, LegalEntityDiscountingScenarioMarketData legalEntityMarketData)
 {
     return(ScenarioArray.of(legalEntityMarketData.ScenarioCount, i => pv01CalibratedBucketed(trade, ratesMarketData.scenario(i).ratesProvider(), legalEntityMarketData.scenario(i).discountingProvider())));
 }
 //-------------------------------------------------------------------------
 // calculates market quote bucketed PV01 for all scenarios
 internal ScenarioArray <CurrencyParameterSensitivities> pv01MarketQuoteBucketed(ResolvedOvernightFutureTrade trade, RatesScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => pv01MarketQuoteBucketed(trade, marketData.scenario(i).ratesProvider())));
 }
Пример #17
0
        //-------------------------------------------------------------------------
        // calculates calibrated bucketed PV01 for all scenarios
        internal ScenarioArray <CurrencyParameterSensitivities> pv01CalibratedBucketed(ResolvedBondFutureOptionTrade trade, LegalEntityDiscountingScenarioMarketData legalEntityMarketData, BondFutureOptionScenarioMarketData optionMarketData)
        {
            SecurityId securityId = trade.Product.UnderlyingFuture.SecurityId;

            return(ScenarioArray.of(legalEntityMarketData.ScenarioCount, i => pv01CalibratedBucketed(trade, legalEntityMarketData.scenario(i).discountingProvider(), optionMarketData.scenario(i).volatilities(securityId))));
        }
Пример #18
0
        //-------------------------------------------------------------------------
        public virtual void test_presentValue()
        {
            ScenarioMarketData             md         = FxSingleTradeCalculationFunctionTest.marketData();
            RatesProvider                  provider   = RATES_LOOKUP.marketDataView(md.scenario(0)).ratesProvider();
            DiscountingFxSingleTradePricer pricer     = DiscountingFxSingleTradePricer.DEFAULT;
            MultiCurrencyAmount            expectedPv = pricer.presentValue(RTRADE, provider);
            MultiCurrencyAmount            expectedCurrencyExposure = pricer.currencyExposure(RTRADE, provider);
            MultiCurrencyAmount            expectedCurrentCash      = pricer.currentCash(RTRADE, provider);
            FxRate expectedForwardFx = pricer.forwardFxRate(RTRADE, provider);

            assertEquals(FxSingleTradeCalculations.DEFAULT.presentValue(RTRADE, RATES_LOOKUP, md), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv)));
            assertEquals(FxSingleTradeCalculations.DEFAULT.currencyExposure(RTRADE, RATES_LOOKUP, md), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrencyExposure)));
            assertEquals(FxSingleTradeCalculations.DEFAULT.currentCash(RTRADE, RATES_LOOKUP, md), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrentCash)));
            assertEquals(FxSingleTradeCalculations.DEFAULT.forwardFxRate(RTRADE, RATES_LOOKUP, md), ScenarioArray.of(ImmutableList.of(expectedForwardFx)));
        }
 //-------------------------------------------------------------------------
 // calculates market quote bucketed PV01 for all scenarios
 internal ScenarioArray <CurrencyParameterSensitivities> pv01MarketQuoteBucketed(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => pv01MarketQuoteBucketed(trade, marketData.scenario(i).discountingProvider())));
 }
 //-------------------------------------------------------------------------
 // calculates forward FX rate for all scenarios
 internal ScenarioArray <FxRate> forwardFxRate(ResolvedFxNdfTrade trade, RatesScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => forwardFxRate(trade, marketData.scenario(i).ratesProvider())));
 }
Пример #21
0
 //-------------------------------------------------------------------------
 // calculates bucketed CS01 for all scenarios
 internal ScenarioArray <CurrencyParameterSensitivity> cs01Bucketed(ResolvedCdsIndexTrade trade, CreditRatesScenarioMarketData marketData, ReferenceData refData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => cs01Bucketed(trade, marketData.scenario(i).creditRatesProvider(), refData)));
 }
Пример #22
0
        //-------------------------------------------------------------------------
        public virtual void test_presentValue()
        {
            ScenarioMarketData         md                = SwapTradeCalculationFunctionTest.marketData();
            RatesProvider              provider          = RATES_LOOKUP.marketDataView(md.scenario(0)).ratesProvider();
            DiscountingSwapTradePricer pricer            = DiscountingSwapTradePricer.DEFAULT;
            MultiCurrencyAmount        expectedPv        = pricer.presentValue(RTRADE, provider);
            ExplainMap          expectedExplainPv        = pricer.explainPresentValue(RTRADE, provider);
            double              expectedParRate          = pricer.parRate(RTRADE, provider);
            double              expectedParSpread        = pricer.parSpread(RTRADE, provider);
            CashFlows           expectedCashFlows        = pricer.cashFlows(RTRADE, provider);
            MultiCurrencyAmount expectedCurrencyExposure = pricer.currencyExposure(RTRADE, provider);
            MultiCurrencyAmount expectedCurrentCash      = pricer.currentCash(RTRADE, provider);

            assertEquals(SwapTradeCalculations.DEFAULT.presentValue(RTRADE, RATES_LOOKUP, md), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv)));
            assertEquals(SwapTradeCalculations.DEFAULT.explainPresentValue(RTRADE, RATES_LOOKUP, md), ScenarioArray.of(ImmutableList.of(expectedExplainPv)));
            assertEquals(SwapTradeCalculations.DEFAULT.parRate(RTRADE, RATES_LOOKUP, md), DoubleScenarioArray.of(ImmutableList.of(expectedParRate)));
            assertEquals(SwapTradeCalculations.DEFAULT.parSpread(RTRADE, RATES_LOOKUP, md), DoubleScenarioArray.of(ImmutableList.of(expectedParSpread)));
            assertEquals(SwapTradeCalculations.DEFAULT.cashFlows(RTRADE, RATES_LOOKUP, md), ScenarioArray.of(ImmutableList.of(expectedCashFlows)));
            assertEquals(SwapTradeCalculations.DEFAULT.currencyExposure(RTRADE, RATES_LOOKUP, md), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrencyExposure)));
            assertEquals(SwapTradeCalculations.DEFAULT.currentCash(RTRADE, RATES_LOOKUP, md), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedCurrentCash)));
        }
Пример #23
0
 //-------------------------------------------------------------------------
 // calculates jump-to-default for all scenarios
 internal ScenarioArray <JumpToDefault> jumpToDefault(ResolvedCdsIndexTrade trade, CreditRatesScenarioMarketData marketData, ReferenceData refData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => jumpToDefault(trade, marketData.scenario(i).creditRatesProvider(), refData)));
 }
        //-------------------------------------------------------------------------
        // calculates market quote bucketed PV01 for all scenarios
        internal ScenarioArray <CurrencyParameterSensitivities> pv01RatesMarketQuoteBucketed(ResolvedFxVanillaOptionTrade trade, RatesScenarioMarketData ratesMarketData, FxOptionScenarioMarketData optionMarketData, FxVanillaOptionMethod method)
        {
            CurrencyPair currencyPair = trade.Product.CurrencyPair;

            return(ScenarioArray.of(ratesMarketData.ScenarioCount, i => pv01RatesMarketQuoteBucketed(trade, ratesMarketData.scenario(i).ratesProvider(), optionMarketData.scenario(i).volatilities(currencyPair), method)));
        }
Пример #25
0
 //-------------------------------------------------------------------------
 // calculates calibrated bucketed PV01 for all scenarios
 internal ScenarioArray <CurrencyParameterSensitivities> pv01CalibratedBucketed(ResolvedBondFutureTrade trade, LegalEntityDiscountingScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => pv01CalibratedBucketed(trade, marketData.scenario(i).discountingProvider())));
 }
Пример #26
0
        public virtual void test_pv01()
        {
            ScenarioMarketData md       = FxSingleBarrierOptionTradeCalculationFunctionTest.marketData();
            RatesProvider      provider = RATES_LOOKUP.marketDataView(md.scenario(0)).ratesProvider();
            BlackFxSingleBarrierOptionTradePricer pricer           = BlackFxSingleBarrierOptionTradePricer.DEFAULT;
            PointSensitivities             pvPointSens             = pricer.presentValueSensitivityRatesStickyStrike(RTRADE, provider, VOLS);
            CurrencyParameterSensitivities pvParamSens             = provider.parameterSensitivity(pvPointSens);
            MultiCurrencyAmount            expectedPv01Cal         = pvParamSens.total().multipliedBy(1e-4);
            CurrencyParameterSensitivities expectedPv01CalBucketed = pvParamSens.multipliedBy(1e-4);

            assertEquals(FxSingleBarrierOptionTradeCalculations.DEFAULT.pv01RatesCalibratedSum(RTRADE, RATES_LOOKUP, FX_OPTION_LOOKUP, md, BLACK), MultiCurrencyScenarioArray.of(ImmutableList.of(expectedPv01Cal)));
            assertEquals(FxSingleBarrierOptionTradeCalculations.DEFAULT.pv01RatesCalibratedBucketed(RTRADE, RATES_LOOKUP, FX_OPTION_LOOKUP, md, BLACK), ScenarioArray.of(ImmutableList.of(expectedPv01CalBucketed)));
        }
 //-------------------------------------------------------------------------
 // calculates single-node gamma PV01 for all scenarios
 internal ScenarioArray <CurrencyParameterSensitivities> pv01SingleNodeGammaBucketed(ResolvedBulletPaymentTrade trade, RatesScenarioMarketData marketData)
 {
     return(ScenarioArray.of(marketData.ScenarioCount, i => pv01SingleNodeGammaBucketed(trade, marketData.scenario(i).ratesProvider())));
 }