public void TestLoanPayment3() { var loanInfo = new LoanInfo() { Amortization = "EqualPrincipalAndInterest", Coupon = 0.05, Currency = "CNY", DayCount = "B30360", FirstPaymentDate = "20141209", FloatingRateMultiplier = 1, Frequency = "Monthly", IndexType = "Gjj5YAbove", IsFloatingRate = false, MaturityDate = "20441109", Notional = 10000000.00, NumOfPayment = 360, ResetDate = "20150101", StartDate = "20141109", MortgageCalcMethod = "Simple", AbsPrepaymentModel = "Psa", AbsDefaultModel = "Sda", SdaMultiplier = 1, PsaMultiplier = 0 }; var market = new MarketInfo("testMarket", "20160202") { HistoricalIndexRates = new Dictionary <string, Dictionary <string, double> > { { "Gjj5YAbove", new Dictionary <string, double> { { "20140101", 0.0425 } } }, { "Gjj5Y", new Dictionary <string, double> { { "20150825", 0.0275 } } } } }; QdpMarket qdpMarket; MarketFunctions.BuildMarket(market, out qdpMarket); var loanVf = new LoanVf(loanInfo); var result = loanVf.ValueTrade(qdpMarket, PricingRequest.Cashflow); var cfs = result.Cashflows; var p = cfs.Where(x => x.CashflowType == CashflowType.Principal || x.CashflowType == CashflowType.PrincipalLossOnDefault) .Sum(x => x.PaymentAmount); Assert.AreEqual(p, loanInfo.Notional, 1e-4); //Assert.AreEqual(Math.Round(cfs[8].PaymentAmount, 2), 12115.23); //Assert.AreEqual(Math.Round(cfs[9].PaymentAmount, 2), 41564.25); //Assert.AreEqual(Math.Round(cfs[11].PaymentAmount, 2), 498.30); //Assert.AreEqual(Math.Round(cfs[1435].PaymentAmount, 2), 1.28); //Assert.AreEqual(Math.Round(cfs[1436].PaymentAmount, 2), 51141.30); //Assert.AreEqual(Math.Round(cfs[1437].PaymentAmount, 2), 213.09); }
public static IValuationFunction ToVf(TradeInfoBase tradeInfo) { IValuationFunction vf; // sean todo // tradeInfo.GetValuationFunction if (tradeInfo is BondInfoBase) { vf = new BondVf((BondInfoBase)tradeInfo); } else if (tradeInfo is VanillaOptionInfo) { vf = new VanillaOptionVf((VanillaOptionInfo)tradeInfo); } else if (tradeInfo is BarrierOptionInfo) { vf = new BarrierOptionVf((BarrierOptionInfo)tradeInfo); } else if (tradeInfo is BinaryOptionInfo) { vf = new BinaryOptionVf((BinaryOptionInfo)tradeInfo); } else if (tradeInfo is AsianOptionInfo) { vf = new AsianOptionVf((AsianOptionInfo)tradeInfo); } else if (tradeInfo is RainbowOptionInfo) { vf = new RainbowOptionVf((RainbowOptionInfo)tradeInfo); } else if (tradeInfo is SpreadOptionInfo) { vf = new SpreadOptionVf((SpreadOptionInfo)tradeInfo); } else if (tradeInfo is InterestRateSwapInfo) { vf = new InterestRateSwapVf((InterestRateSwapInfo)tradeInfo); } else if (tradeInfo is FixedLegInfo) { vf = new FixedLegVf((FixedLegInfo)tradeInfo); } else if (tradeInfo is FloatingLegInfo) { vf = new FloatingLegVf((FloatingLegInfo)tradeInfo); } else if (tradeInfo is BondFuturesInfo) { vf = new BondFuturesVf((BondFuturesInfo)tradeInfo); } else if (tradeInfo is LoanInfo) { vf = new LoanVf((LoanInfo)tradeInfo); } else if (tradeInfo is HoldingPeriodInfo) { vf = new HoldingPeriodVf((HoldingPeriodInfo)tradeInfo); } else if (tradeInfo is AbsWithRepurchaseInfo) { vf = new AbsWithRepurchaseVf((AbsWithRepurchaseInfo)tradeInfo); } else if (tradeInfo is ConvertibleBondInfo) { vf = new ConvertibleBondVf((ConvertibleBondInfo)tradeInfo); } else { throw new PricingLibraryException("Unknowy trade info type"); } return(vf); }
public void TestLoanPayment() { var loanInfo = new LoanInfo() { Amortization = "EqualPrincipalAndInterest", Coupon = 0.045, Currency = "CNY", DayCount = "Act360", FirstPaymentDate = "20141209", FloatingRateMultiplier = 1, Frequency = "Monthly", IndexType = "Gjj5YAbove", IsFloatingRate = true, MaturityDate = "20320409", Notional = 294150.32, NumOfPayment = 209, ResetDate = "20150101", StartDate = "20141109", MortgageCalcMethod = "Simple", AbsPrepaymentModel = "Psa", AbsDefaultModel = "Sda", PsaMultiplier = 0.0, SdaMultiplier = 0.0, }; var market = new MarketInfo("testMarket", "20160202") { HistoricalIndexRates = new Dictionary <string, Dictionary <string, double> > { { "Gjj5YAbove", new Dictionary <string, double> { { "20140101", 0.0425 } } }, { "Gjj5Y", new Dictionary <string, double> { { "20150825", 0.0275 } } } } }; QdpMarket qdpMarket; MarketFunctions.BuildMarket(market, out qdpMarket); var loanVf = new LoanVf(loanInfo); var result = loanVf.ValueTrade(qdpMarket, PricingRequest.Cashflow); var cfs = result.Cashflows; Assert.AreEqual(Math.Round(cfs.Where(c => c.PaymentDate == new Date(2014, 12, 09) && c.CashflowType == CashflowType.Principal).ToArray()[0].PaymentAmount, 2), 929.71); Assert.AreEqual(Math.Round(cfs.Where(c => c.PaymentDate == new Date(2014, 12, 09) && c.CashflowType == CashflowType.Coupon).ToArray()[0].PaymentAmount, 2), 1103.06); Assert.AreEqual(Math.Round(cfs.Where(c => c.PaymentDate == new Date(2015, 01, 09) && c.CashflowType == CashflowType.Principal).ToArray()[0].PaymentAmount, 2), 956.04); Assert.AreEqual(Math.Round(cfs.Where(c => c.PaymentDate == new Date(2015, 01, 09) && c.CashflowType == CashflowType.Coupon).ToArray()[0].PaymentAmount, 2), 1119.94); Assert.AreEqual(Math.Round(cfs.Where(c => c.PaymentDate == new Date(2015, 02, 09) && c.CashflowType == CashflowType.Principal).ToArray()[0].PaymentAmount, 2), 959.42); Assert.AreEqual(Math.Round(cfs.Where(c => c.PaymentDate == new Date(2015, 02, 09) && c.CashflowType == CashflowType.Coupon).ToArray()[0].PaymentAmount, 2), 1035.10); var netCf = cfs.GroupBy(x => x.PaymentDate) .Select(x => Tuple.Create(x.Key, x.Sum(entry => entry.PaymentAmount))) .OrderBy(x => x.Item1) .ToArray(); foreach (var tuple in netCf) { if (tuple.Item1 > new Date(2015, 02, 09)) { Assert.AreEqual(Math.Round(tuple.Item2, 2), 1994.53); } } }