Example #1
0
        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);
        }
Example #2
0
        public void TestLoanWithRepurchase()
        {
            #region

            var loanInfo = new LoanInfo
            {
                Amortization       = "EqualPrincipal",
                Coupon             = 0.18,
                Currency           = "CNY",
                DayCount           = "Act360",
                FirstPaymentDate   = "20150712",
                Frequency          = "Monthly",
                IsFloatingRate     = false,
                MaturityDate       = "20160612",
                Notional           = 500000000,
                NumOfPayment       = 12,
                StartDate          = "20150612",
                MortgageCalcMethod = "Simple",
                AbsPrepaymentModel = "Cpr",
                AbsDefaultModel    = "Cdr",
                AnnualCprRate      = 0.0,
                AnnualCdrRate      = 0.03,
                TaxRate            = 0.056
            };

            #endregion

            var maturityDates = new[] { "20150912", "20151212", "20160312", "20160612" };
            var coupons       = new[] { 0.05, 0.052, 0.054, 0.055 };
            var notionals     = new[] { 115000000, 113000000, 110000000, 112000000 };
            var bondInfos     =
                maturityDates.Select((x, i) =>
                                     new FixedRateBondInfo("bond" + x)
            {
                StartDate          = "20150612",
                MaturityDate       = x,
                Notional           = notionals[i],
                Currency           = "CNY",
                FixedCoupon        = coupons[i],
                Calendar           = "chn",
                PaymentFreq        = "Quarterly",
                PaymentStub        = "ShortEnd",
                AccrualDC          = "Act365NoLeap",
                DayCount           = "Act360",
                AccrualBD          = "None",
                PaymentBD          = "None",
                TradingMarket      = "ChinaInterBank",
                Settlement         = "+0D",
                ValuationParamters = new SimpleCfValuationParameters("Fr007", null, "Fr007")
            }).ToArray();

            var loanWithRepurchaseInfo = new AbsWithRepurchaseInfo("test1")
            {
                Tranches           = bondInfos,
                LoanInfo           = loanInfo,
                RepurchaseRatio    = 0.8,
                MaintenanceFeeRate = 0.004,
                ProtectionFeeRate  = 0.0015
            };
            var marketInfo = new MarketInfo("testMarket", "20160202");

            QdpMarket qdpMarket;
            MarketFunctions.BuildMarket(marketInfo, out qdpMarket);

            var loanVf = new AbsWithRepurchaseVf(loanWithRepurchaseInfo);
            var market = loanVf.GenerateMarketCondition(qdpMarket);

            var loanWithRepurchase = loanVf.GenerateInstrument();
            var engine             = loanVf.GenerateEngine();
            var result             = engine.Calculate(loanWithRepurchase, market, PricingRequest.Cashflow);
            foreach (var cashflow in result.Cashflows)
            {
                Console.WriteLine("{0},{1},{2}", cashflow.PaymentDate, cashflow.CashflowType, cashflow.PaymentAmount);
            }
        }