Esempio n. 1
0
        public void VerifyFr007SwapCashflow()
        {
            var irsInfo = new InterestRateSwapInfo
            {
                StartDate    = "20150828",
                MaturityDate = "20160828",

                Notional      = 50000000,
                Calendar      = "chn_ib",
                Currency      = "CNY",
                SwapDirection = "Payer",

                FixedLegDC     = "Act365",
                FixedLegBD     = "ModifiedFollowing",
                FixedLegCoupon = 0.02395,
                FixedLegFreq   = "Quarterly",
                FixedLegStub   = "ShortEnd",

                FloatingLegDC      = "Act365",
                FloatingLegFreq    = "Quarterly",
                FloatingLegBD      = "ModifiedFollowing",
                FloatingLegStub    = "ShortEnd",
                Index              = "Fr007",
                ResetTerm          = "1W",
                ResetBD            = "None",
                ResetToFixingGap   = "-1BD",
                ResetStub          = "ShortEnd",
                ResetCompound      = "Compounded",
                ValuationParamters = new SimpleCfValuationParameters("Fr007", "Fr007")
            };

            var qdpMarket = VerifyCurveConstructionMarket("2015-10-23");
            var irsVf     = new InterestRateSwapVf(irsInfo);
            var result    = irsVf.ValueTrade(qdpMarket, PricingRequest.All);

            Assert.AreEqual(result.Pv, -4184.93417566339, 1e-4);
            foreach (var d in result.KeyRateDv01)
            {
                Console.WriteLine("{0},{1}", d.Key, d.Value);
            }
            Console.WriteLine("Total Dv01 {0}", result.Dv01);
            Console.WriteLine("Summed Dv01 {0}", result.KeyRateDv01.Sum(x => x.Value.Sum(e => e.Risk)));
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        protected ICalibrationSupportedInstrument CreateIrsInstrument(RateMktData rateMktData,
                                                                      out MktInstrumentCalibMethod calibMethod)
        {
            MktIrsJson irsJson = null;
            ICalibrationSupportedInstrument irs = null;

            if (rateMktData.TradeInfo != null)
            {
                var irsInfo = (InterestRateSwapInfo)rateMktData.TradeInfo;
                var vf      = new InterestRateSwapVf(irsInfo);
                irs     = vf.GenerateInstrument();
                irsJson = MktInstrumentIrsRule.MktIrsRule[irsInfo.Index.ToIndexType()];
            }
            else
            {
                irsJson = MktInstrumentIrsRule.MktIrsRule[rateMktData.IndexType.ToIndexType()];
                var irsInfo  = irsJson.InterestRateSwapInfo;
                var calendar = irsInfo.Calendar.ToCalendarImpl();

                var startDate    = calendar.NextBizDay(Market.ReferenceDate);
                var isTernor     = rateMktData.IsTerm();
                var tenor        = isTernor ? rateMktData.Tenor : null;
                var maturityDate = isTernor ? new Term(tenor).Next(startDate) : new Date(DateTime.Parse(rateMktData.Tenor));

                var fixedLeg = new SwapLeg(startDate,
                                           maturityDate,
                                           -1.0,
                                           false,
                                           irsInfo.Currency.ToCurrencyCode(),
                                           new FixedCoupon(rateMktData.Rate),
                                           calendar,
                                           irsInfo.FixedLegFreq.ToFrequency(),
                                           irsInfo.FixedLegStub.ToStub(),
                                           irsInfo.FixedLegDC.ToDayCountImpl(),
                                           irsInfo.FixedLegBD.ToBda()
                                           );

                var floatingLegFrequency    = irsInfo.FloatingLegFreq.ToFrequency();
                var floatingCouponResetTerm = new Term(irsInfo.ResetTerm);
                if (floatingCouponResetTerm.Equals(floatingLegFrequency.GetTerm()))
                {
                    floatingCouponResetTerm = null;
                }
                var floatingCoupon =
                    new FloatingCoupon(
                        new Index(rateMktData.IndexType.ToIndexType(), 1, irsInfo.ResetCompound.ToCouponCompound()),
                        calendar,
                        irsInfo.FloatingLegDC.ToDayCountImpl(),
                        0.0,
                        floatingCouponResetTerm,
                        irsInfo.ResetStub.ToStub(),
                        irsInfo.ResetBD.ToBda(),
                        new DayGap(irsInfo.ResetToFixingGap));
                var floatingLeg = new SwapLeg(startDate,
                                              maturityDate,
                                              1.0,
                                              false,
                                              irsInfo.Currency.ToCurrencyCode(),
                                              floatingCoupon,
                                              calendar,
                                              irsInfo.FloatingLegFreq.ToFrequency(),
                                              irsInfo.FloatingLegStub.ToStub(),
                                              irsInfo.FloatingLegDC.ToDayCountImpl(),
                                              irsInfo.FloatingLegBD.ToBda()
                                              );
                irs = new InterestRateSwap(fixedLeg, floatingLeg, SwapDirection.Payer, tenor);
            }

            calibMethod = irsJson.CalibrationMethod.ToCalibMethod();
            return(irs);
        }