public void TestConvertibleBondWhenCallOnMaturity() { var bond = new FixedRateBondInfo("110030.SH") { StartDate = "2014-12-25", MaturityDate = "2019-12-25", Notional = 100.0, Currency = "CNY", FixedCoupon = 0.006, Calendar = "chn", PaymentFreq = "Annual", PaymentStub = "ShortStart", AccrualDC = "Act365NoLeap", DayCount = "ModifiedAfb", AccrualBD = "None", PaymentBD = "None", TradingMarket = "ChinaExShg", Settlement = "+0BD", CompensationRate = new Dictionary <int, double>() { { 2, 0.002 }, { 3, 0.002 }, { 4, 0.005 }, { 5, 0.005 } }, ValuationParamters = new SimpleCfValuationParameters("Fr007", null, "Fr007"), RedemptionRate = 1.06, RedemptionIncludeLastCoupon = true }; var bondVf = new BondVf(bond); var market = TestMarket("2017-10-20", new BondMktData(bond.TradeId, "Dirty", 95.90891)); //var result = bondVf.ValueTrade(market, PricingRequest.Ytm); XlManager.AddTrades(new TradeInfoBase[] { bond }); var ytm = XlUdf.xl_YieldFromPrice("110030.SH", "2017-10-20", 95.90891); }
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); }
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); }