Пример #1
0
        //-------------------------------------------------------------------------
        public virtual void calibration_present_value()
        {
            RatesProvider result2 = CALIBRATOR.calibrate(CURVE_GROUP_DEFN, ALL_QUOTES, REF_DATA);

            // Test PV
            CurveNode[]           fwd3Nodes  = CURVES_NODES[0][0];
            IList <ResolvedTrade> fwd3Trades = new List <ResolvedTrade>();

            for (int i = 0; i < fwd3Nodes.Length; i++)
            {
                fwd3Trades.Add(fwd3Nodes[i].resolvedTrade(1d, ALL_QUOTES, REF_DATA));
            }
            // Fixing
            CurrencyAmount pvFixing2 = FIXING_PRICER.presentValue(((ResolvedIborFixingDepositTrade)fwd3Trades[0]).Product, result2);

            assertEquals(pvFixing2.Amount, 0.0, TOLERANCE_PV);
            // FRA
            for (int i = 0; i < FWD3_NB_FRA_NODES; i++)
            {
                CurrencyAmount pvFra2 = FRA_PRICER.presentValue(((ResolvedFraTrade)fwd3Trades[i + 1]), result2);
                assertEquals(pvFra2.Amount, 0.0, TOLERANCE_PV);
            }
            // IRS
            for (int i = 0; i < FWD3_NB_IRS_NODES; i++)
            {
                MultiCurrencyAmount pvIrs2 = SWAP_PRICER.presentValue(((ResolvedSwapTrade)fwd3Trades[i + 1 + FWD3_NB_FRA_NODES]).Product, result2);
                assertEquals(pvIrs2.getAmount(USD).Amount, 0.0, TOLERANCE_PV);
            }
        }
        private void assertResult(RatesProvider result)
        {
            // Test PV Dsc
            CurveNode[]           dscNodes  = CURVES_NODES[0][0];
            IList <ResolvedTrade> dscTrades = new List <ResolvedTrade>();

            for (int i = 0; i < dscNodes.Length; i++)
            {
                dscTrades.Add(dscNodes[i].resolvedTrade(1d, ALL_QUOTES_BD, REF_DATA));
            }
            // Depo
            for (int i = 0; i < DSC_NB_DEPO_NODES; i++)
            {
                CurrencyAmount pvIrs = DEPO_PRICER.presentValue(((ResolvedTermDepositTrade)dscTrades[i]).Product, result);
                assertEquals(pvIrs.Amount, 0.0, TOLERANCE_PV);
            }
            // OIS
            for (int i = 0; i < DSC_NB_OIS_NODES; i++)
            {
                MultiCurrencyAmount pvIrs = SWAP_PRICER.presentValue(((ResolvedSwapTrade)dscTrades[DSC_NB_DEPO_NODES + i]).Product, result);
                assertEquals(pvIrs.getAmount(USD).Amount, 0.0, TOLERANCE_PV);
            }
            // Test PV Fwd3
            CurveNode[]           fwd3Nodes  = CURVES_NODES[1][0];
            IList <ResolvedTrade> fwd3Trades = new List <ResolvedTrade>();

            for (int i = 0; i < fwd3Nodes.Length; i++)
            {
                fwd3Trades.Add(fwd3Nodes[i].resolvedTrade(1d, ALL_QUOTES_BD, REF_DATA));
            }
            // Fixing
            CurrencyAmount pvFixing = FIXING_PRICER.presentValue(((ResolvedIborFixingDepositTrade)fwd3Trades[0]).Product, result);

            assertEquals(pvFixing.Amount, 0.0, TOLERANCE_PV);
            // FRA
            for (int i = 0; i < FWD3_NB_FRA_NODES; i++)
            {
                CurrencyAmount pvFra = FRA_PRICER.presentValue(((ResolvedFraTrade)fwd3Trades[i + 1]), result);
                assertEquals(pvFra.Amount, 0.0, TOLERANCE_PV);
            }
            // IRS
            for (int i = 0; i < FWD3_NB_IRS_NODES; i++)
            {
                MultiCurrencyAmount pvIrs = SWAP_PRICER.presentValue(((ResolvedSwapTrade)fwd3Trades[i + 1 + FWD3_NB_FRA_NODES]).Product, result);
                assertEquals(pvIrs.getAmount(USD).Amount, 0.0, TOLERANCE_PV);
            }
        }
        public virtual void test_simpleMeasures()
        {
            FraTradeCalculationFunction function         = new FraTradeCalculationFunction();
            ScenarioMarketData          md               = marketData();
            RatesProvider             provider           = RATES_LOOKUP.marketDataView(md.scenario(0)).ratesProvider();
            DiscountingFraTradePricer pricer             = DiscountingFraTradePricer.DEFAULT;
            CurrencyAmount            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);
            CurrencyAmount      expectedCurrentCash      = pricer.currentCash(RTRADE, provider);

            ISet <Measure> measures = ImmutableSet.of(Measures.PRESENT_VALUE, Measures.EXPLAIN_PRESENT_VALUE, Measures.PAR_RATE, Measures.PAR_SPREAD, Measures.CASH_FLOWS, 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.EXPLAIN_PRESENT_VALUE, Result.success(ScenarioArray.of(ImmutableList.of(expectedExplainPv)))).containsEntry(Measures.PAR_RATE, Result.success(DoubleScenarioArray.of(ImmutableList.of(expectedParRate)))).containsEntry(Measures.PAR_SPREAD, Result.success(DoubleScenarioArray.of(ImmutableList.of(expectedParSpread)))).containsEntry(Measures.CASH_FLOWS, Result.success(ScenarioArray.of(ImmutableList.of(expectedCashFlows)))).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));
        }
Пример #4
0
 // present value for one scenario
 internal CurrencyAmount presentValue(ResolvedFraTrade trade, RatesProvider ratesProvider)
 {
     return(tradePricer.presentValue(trade, ratesProvider));
 }
        private void assertPresentValue(RatesProvider result)
        {
            // Test PV USD;
            IList <ResolvedTrade> usdTrades = new List <ResolvedTrade>();

            foreach (CurveNode USD_DSC_NODE in USD_DSC_NODES)
            {
                usdTrades.Add(USD_DSC_NODE.resolvedTrade(1d, ALL_QUOTES, REF_DATA));
            }
            // Depo
            for (int i = 0; i < 2; i++)
            {
                CurrencyAmount pvDep = DEPO_PRICER.presentValue(((ResolvedTermDepositTrade)usdTrades[i]).Product, result);
                assertEquals(pvDep.Amount, 0.0, TOLERANCE_PV);
            }
            // OIS
            for (int i = 0; i < USD_DSC_NB_OIS_NODES; i++)
            {
                MultiCurrencyAmount pvOis = SWAP_PRICER.presentValue(((ResolvedSwapTrade)usdTrades[2 + i]).Product, result);
                assertEquals(pvOis.getAmount(USD).Amount, 0.0, TOLERANCE_PV);
            }
            // Test PV USD Fwd3
            IList <ResolvedTrade> fwd3Trades = new List <ResolvedTrade>();

            for (int i = 0; i < USD_FWD3_NB_NODES; i++)
            {
                fwd3Trades.Add(USD_FWD3_NODES[i].resolvedTrade(1d, ALL_QUOTES, REF_DATA));
            }
            // Fixing
            CurrencyAmount pvFixing = FIXING_PRICER.presentValue(((ResolvedIborFixingDepositTrade)fwd3Trades[0]).Product, result);

            assertEquals(pvFixing.Amount, 0.0, TOLERANCE_PV);
            // FRA
            for (int i = 0; i < USD_FWD3_NB_FRA_NODES; i++)
            {
                CurrencyAmount pvFra = FRA_PRICER.presentValue(((ResolvedFraTrade)fwd3Trades[i + 1]), result);
                assertEquals(pvFra.Amount, 0.0, TOLERANCE_PV);
            }
            // IRS
            for (int i = 0; i < USD_FWD3_NB_IRS_NODES; i++)
            {
                MultiCurrencyAmount pvIrs = SWAP_PRICER.presentValue(((ResolvedSwapTrade)fwd3Trades[i + 1 + USD_FWD3_NB_FRA_NODES]).Product, result);
                assertEquals(pvIrs.getAmount(USD).Amount, 0.0, TOLERANCE_PV);
            }
            // Test DSC EUR;
            IList <ResolvedTrade> eurTrades = new List <ResolvedTrade>();

            foreach (CurveNode EUR_DSC_NODE in EUR_DSC_NODES)
            {
                eurTrades.Add(EUR_DSC_NODE.resolvedTrade(1d, ALL_QUOTES, REF_DATA));
            }
            // FX
            for (int i = 0; i < EUR_DSC_NB_FX_NODES; i++)
            {
                MultiCurrencyAmount pvFx = FX_PRICER.presentValue(((ResolvedFxSwapTrade)eurTrades[i]).Product, result);
                assertEquals(pvFx.convertedTo(USD, result).Amount, 0.0, TOLERANCE_PV);
            }
            // XCCY
            for (int i = 0; i < EUR_DSC_NB_XCCY_NODES; i++)
            {
                MultiCurrencyAmount pvFx = SWAP_PRICER.presentValue(((ResolvedSwapTrade)eurTrades[EUR_DSC_NB_FX_NODES + i]).Product, result);
                assertEquals(pvFx.convertedTo(USD, result).Amount, 0.0, TOLERANCE_PV);
            }
            // Test PV EUR Fwd3
            IList <ResolvedTrade> eurFwd3Trades = new List <ResolvedTrade>();

            for (int i = 0; i < EUR_FWD3_NB_NODES; i++)
            {
                eurFwd3Trades.Add(EUR_FWD3_NODES[i].resolvedTrade(1d, ALL_QUOTES, REF_DATA));
            }
            // Fixing
            CurrencyAmount eurPvFixing = FIXING_PRICER.presentValue(((ResolvedIborFixingDepositTrade)eurFwd3Trades[0]).Product, result);

            assertEquals(eurPvFixing.Amount, 0.0, TOLERANCE_PV);
            // FRA
            for (int i = 0; i < EUR_FWD3_NB_FRA_NODES; i++)
            {
                CurrencyAmount pvFra = FRA_PRICER.presentValue(((ResolvedFraTrade)eurFwd3Trades[i + 1]), result);
                assertEquals(pvFra.Amount, 0.0, TOLERANCE_PV);
            }
            // IRS
            for (int i = 0; i < EUR_FWD3_NB_IRS_NODES; i++)
            {
                MultiCurrencyAmount pvIrs = SWAP_PRICER.presentValue(((ResolvedSwapTrade)eurFwd3Trades[i + 1 + EUR_FWD3_NB_FRA_NODES]).Product, result);
                assertEquals(pvIrs.getAmount(EUR).Amount, 0.0, TOLERANCE_PV);
            }
        }