Exemplo n.º 1
0
        public void TestBondCurvePnLFromUnChangedMkt()
        {
            const string tradeId      = "TEST_TRADE";
            const string t0MarketName = "Market2017-11-15";
            const string t1MarketName = "Market2017-11-16";

            var curveName        = "BondCurve";
            var curveDefinitions = GetTestBondPnLCurveDefinition(curveName);

            //var t0MarketInfo = new MarketInfo(t0MarketName,
            //    bondDataDefinitions: new[] { new BondMktData(tradeId, "Dirty", 97.0) })
            //{
            //    ReferenceDate = "2017-11-15",
            //    YieldCurveDefinitions = curveDefinitions.ToArray(),
            //    HistoricalIndexRates = HistoricalDataLoadHelper.HistoricalIndexRates
            //};

            //var t1MarketInfo = new MarketInfo(t1MarketName)
            //{
            //    ReferenceDate = "2017-11-16",
            //    YieldCurveDefinitions = curveDefinitions.ToArray(),
            //    HistoricalIndexRates = HistoricalDataLoadHelper.HistoricalIndexRates
            //};

            //XlManager.LoadMarket(t0MarketInfo);
            //XlManager.LoadMarket(t1MarketInfo);

            //XlManager.AddTrades(new TradeInfoBase[] { GetTestBondTrade(tradeId, curveName: curveName) });

            //var result = XlManager.xl_PnL(new string[] { tradeId }, t0MarketName, t1MarketName);
            //var curvePnL = result[tradeId].YieldCurvePnL[curveName].Sum(x=> x.Risk);
            //var curveRisk = result[tradeId].YieldCurvePnL[curveName + "KeyRateDv01"].Sum(x => x.Risk);

            //Assert.AreEqual(0.0, curvePnL, double.Epsilon);
            //Assert.AreEqual(-5.30227200201989, curveRisk, 1e-8);
            XlManager.AddHistoricalIndexRates(HistoricalDataLoadHelper.HistoricalIndexRatesMarket);
            XlManager.CreatePrebuiltMarket(t0MarketName, "2017-11-15");
            XlManager.AddBondPrice(tradeId, t0MarketName, "Dirty", 97.0);
            foreach (var curveDefinition in curveDefinitions)
            {
                XlManager.AddYieldCurve(curveDefinition.Name, t0MarketName, "2017-11-15", curveDefinition);
            }

            XlManager.CreatePrebuiltMarket(t1MarketName, "2017-11-16");
            foreach (var curveDefinition in curveDefinitions)
            {
                XlManager.AddYieldCurve(curveDefinition.Name, t1MarketName, "2017-11-16", curveDefinition);
            }

            XlManager.AddTrades(new TradeInfoBase[] { GetTestBondTrade(tradeId, curveName: curveName) });

            var result    = XlManager.xl_PnLWithPreBuiltMarket(new string[] { tradeId }, t0MarketName, t1MarketName);
            var curvePnL  = result[tradeId].YieldCurvePnL[curveName].Sum(x => x.Risk);
            var curveRisk = result[tradeId].YieldCurvePnL[curveName + "KeyRateDv01"].Sum(x => x.Risk);

            Assert.AreEqual(0.0, curvePnL, double.Epsilon);
            Assert.AreEqual(-5.30227200201989, curveRisk, 1e-8);
        }
Exemplo n.º 2
0
        public void TestIrsCurveZeroPnLFromUnChangedMkt()
        {
            const string tradeId      = "TEST_TRADE";
            const string t0MarketName = "Market2017-11-15";
            const string t1MarketName = "Market2017-11-16";

            var curveName        = "Fr007SwapCurve";
            var curveDefinitions = GetTestIrsCurveDefinition(curveName);

            //var t0MarketInfo = new MarketInfo(t0MarketName)
            //{
            //    ReferenceDate = "2017-11-15",
            //    YieldCurveDefinitions = curveDefinitions.ToArray(),
            //    HistoricalIndexRates = HistoricalDataLoadHelper.HistoricalIndexRates
            //};

            //var t1MarketInfo = new MarketInfo(t1MarketName)
            //{
            //    ReferenceDate = "2017-11-16",
            //    YieldCurveDefinitions = curveDefinitions.ToArray(),
            //    HistoricalIndexRates = HistoricalDataLoadHelper.HistoricalIndexRates
            //};

            //XlManager.LoadMarket(t0MarketInfo);
            //XlManager.LoadMarket(t1MarketInfo);
            //XlManager.AddTrades(new TradeInfoBase[] { GetTestIrsTrade(tradeId, curveName) });

            //var result = XlManager.xl_PnL(new string[] { tradeId }, t0MarketName, t1MarketName);
            //Assert.AreEqual(0.0, result[tradeId].YieldCurvePnL["Fr007SwapCurve"][2].Risk, double.Epsilon);

            XlManager.AddHistoricalIndexRates(HistoricalDataLoadHelper.HistoricalIndexRatesMarket);
            XlManager.CreatePrebuiltMarket(t0MarketName, "2017-11-15");
            foreach (var curveDefinition in curveDefinitions)
            {
                XlManager.AddYieldCurve(curveDefinition.Name, t0MarketName, "2017-11-15", curveDefinition);
            }

            XlManager.CreatePrebuiltMarket(t1MarketName, "2017-11-16");
            foreach (var curveDefinition in curveDefinitions)
            {
                XlManager.AddYieldCurve(curveDefinition.Name, t1MarketName, "2017-11-16", curveDefinition);
            }

            XlManager.AddTrades(new TradeInfoBase[] { GetTestIrsTrade(tradeId, curveName) });

            var result = XlManager.xl_PnLWithPreBuiltMarket(new string[] { tradeId }, t0MarketName, t1MarketName);

            Assert.AreEqual(0.0, result[tradeId].YieldCurvePnL["Fr007SwapCurve"][2].Risk, double.Epsilon);
        }