/// <summary> /// Return QDP bond futures qdp object. /// </summary> /// <param name="tradeId"></param> /// <param name="startDate"></param> /// <param name="settlementDate"></param> /// <param name="deliverableBondIds"></param> /// <param name="notional"></param> /// <param name="calendar"></param> /// <param name="dayCount"></param> /// <param name="nominalCoupon"></param> /// <param name="currency"></param> /// <returns></returns> public static object xl_CustomizedBondFutures(string tradeId, string startDate = null, string settlementDate = null, string[] deliverableBondIds = null, double notional = 1000000, string calendar = "chn", string dayCount = "Act365", double nominalCoupon = 0.03, string currency = "CNY") { var trade = XlManager.GetTrade(tradeId); if (!(trade is BondFuturesInfo)) { startDate = startDate ?? DateTime.Now.ToString("yyyy-MM-dd"); settlementDate = settlementDate ?? new Term("3M").Next(startDate.ToDate()).ToString(); trade = new BondFuturesInfo(tradeId) { StartDate = startDate, MaturityDate = settlementDate, Calendar = calendar, Currency = currency, DayCount = dayCount, DeliverableBondInfos = deliverableBondIds == null ? null : deliverableBondIds.Select(x => (FixedRateBondInfo)XlManager.GetTrade(x)).ToArray(), InstrumentType = "BondFutures", NominalCoupon = nominalCoupon, Notional = notional, ValuationParamters = new SimpleCfValuationParameters("FundingCurve", "", "FundingCurve") }; XlManager.AddTrades(new[] { trade }); } return(trade.ToTradeInfoInLabelData(null)); }
/// <summary> /// Return a interest rate swap. /// </summary> /// <param name="tradeId"></param> /// <param name="startDate"></param> /// <param name="maturityDate"></param> /// <param name="tenor"></param> /// <param name="notional"></param> /// <param name="currency"></param> /// <param name="swapDirection"></param> /// <param name="calendar"></param> /// <param name="fixedLegDayCount"></param> /// <param name="fixedLegFrequency"></param> /// <param name="fixedLegBusinessDayConvention"></param> /// <param name="fixedLegStub"></param> /// <param name="fixedLegCoupon"></param> /// <param name="floatingLegDayCount"></param> /// <param name="floatingLegFrequency"></param> /// <param name="floatingLegBusinessDayConvention"></param> /// <param name="floatingLegStub"></param> /// <param name="index"></param> /// <param name="resetTerm"></param> /// <param name="resetStub"></param> /// <param name="resetBusinessDayConvention"></param> /// <param name="resetToFixingGap"></param> /// <param name="resetCompound"></param> /// <returns></returns> public static object xl_InterestRateSwap(string tradeId , string startDate = null , string maturityDate = null , string tenor = "1Y" , double notional = 100.0 , string currency = "CNY" , string swapDirection = "Payer" , string calendar = "chn_ib" , string fixedLegDayCount = "Act365" , string fixedLegFrequency = "Quarterly" , string fixedLegBusinessDayConvention = "ModifiedFollowing" , string fixedLegStub = "ShortEnd" , double fixedLegCoupon = 0.03 , string floatingLegDayCount = "Act365" , string floatingLegFrequency = "Quarterly" , string floatingLegBusinessDayConvention = "ModifiedFollowing" , string floatingLegStub = "ShortEnd" , string index = "Fr007" , string resetTerm = "1W" , string resetStub = "ShortEnd" , string resetBusinessDayConvention = "None" , string resetToFixingGap = "+1BD" , string resetCompound = "Compounded" ) { var interestRateSwapInfo = XlManager.GetTrade(tradeId); if (!(interestRateSwapInfo is InterestRateSwapInfo)) { startDate = startDate ?? DateTime.Now.ToString("yyyy-MM-dd"); if (maturityDate == null && tenor != null) { maturityDate = new Term(tenor).Next(startDate.ToDate()).ToString(); } else { maturityDate = maturityDate ?? new Term("1Y").Next(startDate.ToDate()).ToString(); } string curveName = ""; switch (index) { case "Fr007": curveName = "Fr007SwapCurve"; break; case "Shibor3M": curveName = "Shibor3MSwapCurve"; break; case "Shibor1D": curveName = "ShiborONSwapCurve"; break; case "Depo1Y": curveName = "Depo1YSwapCurve"; break; } interestRateSwapInfo = new InterestRateSwapInfo(tradeId) { StartDate = startDate, MaturityDate = maturityDate, Tenor = tenor, Notional = notional, Currency = currency, SwapDirection = swapDirection, Calendar = calendar, FixedLegDC = fixedLegDayCount, FixedLegFreq = fixedLegFrequency, FixedLegBD = fixedLegBusinessDayConvention, FixedLegStub = fixedLegStub, FixedLegCoupon = fixedLegCoupon, FloatingLegDC = floatingLegDayCount, FloatingLegFreq = floatingLegFrequency, FloatingLegBD = floatingLegBusinessDayConvention, FloatingLegStub = floatingLegStub, Index = index, ResetTerm = resetTerm, ResetStub = resetStub, ResetBD = resetBusinessDayConvention, ResetToFixingGap = resetToFixingGap, ResetCompound = resetCompound, ValuationParamters = new SimpleCfValuationParameters(curveName, curveName, null) }; XlManager.AddTrades(new[] { interestRateSwapInfo }); } return(interestRateSwapInfo.ToTradeInfoInLabelData(null)); }
/// <summary> /// Return QDP bond qdp object. /// </summary> /// <param name="tradeId"></param> /// <param name="startDate"></param> /// <param name="maturityDate"></param> /// <param name="notional"></param> /// <param name="calendar"></param> /// <param name="currency"></param> /// <param name="accrualDayCount"></param> /// <param name="accrualBusinessDayConvention"></param> /// <param name="paymentDayCount"></param> /// <param name="paymentFrequency"></param> /// <param name="paymentStub"></param> /// <param name="paymentBusinessDayConvention"></param> /// <param name="settlement"></param> /// <param name="settlementCoupon"></param> /// <param name="issuePrice"></param> /// <param name="firstPaymentDate"></param> /// <param name="issueRate"></param> /// <param name="amoritzationInIndex"></param> /// <param name="renormalizeAfterAmoritzation"></param> /// <param name="compensationRate"></param> /// <param name="optionToCall"></param> /// <param name="optionToPut"></param> /// <param name="optionToAssPut"></param> /// <param name="fixedCoupon"></param> /// <param name="index"></param> /// <param name="resetDayCount"></param> /// <param name="resetCompound"></param> /// <param name="resetStub"></param> /// <param name="resetBusinessDayConvention"></param> /// <param name="resetToFixingGap"></param> /// <param name="resetTerm"></param> /// <param name="resetAverageDays"></param> /// <param name="resetRateDigits"></param> /// <param name="spread"></param> /// <param name="floatingRateMultiplier"></param> /// <param name="stickToEom"></param> /// <returns></returns> private static object xl_Bond( string tradeId, string startDate = null, string maturityDate = null, double notional = 100, string calendar = "chn_ib", string currency = "CNY", string accrualDayCount = "Act365", string accrualBusinessDayConvention = "ModifiedFollowing", string paymentDayCount = "Act365", string paymentFrequency = "SemiAnnual", string paymentStub = "ShortStart", string paymentBusinessDayConvention = "ModifiedFollowing", string settlement = "+0D", double settlementCoupon = double.NaN, double issuePrice = double.NaN, string firstPaymentDate = null, double issueRate = double.NaN, Dictionary <int, double> amoritzationInIndex = null, bool renormalizeAfterAmoritzation = false, Dictionary <int, double> compensationRate = null, Dictionary <string, double> optionToCall = null, Dictionary <string, double> optionToPut = null, Dictionary <string, double> optionToAssPut = null, double fixedCoupon = double.NaN, string index = null, string resetDayCount = null, string resetCompound = null, string resetStub = null, string resetBusinessDayConvention = null, string resetToFixingGap = null, string resetTerm = null, int resetAverageDays = 1, int resetRateDigits = 12, double spread = double.NaN, double floatingRateMultiplier = double.NaN, bool stickToEom = false) { var tradeInfo = XlManager.GetTrade(tradeId); if (!(tradeInfo is BondInfoBase)) { startDate = startDate ?? DateTime.Now.ToString("yyyy-MM-dd"); maturityDate = maturityDate ?? new Term("1Y").Next(startDate.ToDate()).ToString(); BondInfoBase bondInfo = null; if (string.IsNullOrWhiteSpace(index)) { bondInfo = new FixedRateBondInfo(tradeId) { FixedCoupon = double.IsNaN(fixedCoupon) ? 0.03 : fixedCoupon }; } else { bondInfo = new FloatingRateBondInfo(tradeId) { Index = index ?? "Shibor3M", ResetDC = resetDayCount ?? "Act365", ResetCompound = resetCompound ?? "Simple", ResetStub = resetStub ?? "ShortStart", ResetBD = resetBusinessDayConvention ?? "ModifiedFollowing", ResetToFixingGap = resetToFixingGap ?? "-1BD", ResetTerm = resetTerm ?? "3M", Spread = double.IsNaN(spread) ? 0.0 : spread, ResetAverageDays = resetAverageDays, ResetRateDigits = resetRateDigits, FloatingRateMultiplier = double.IsNaN(floatingRateMultiplier) ? 1.0 : floatingRateMultiplier, FloatingCalc = "ZzFrn", CapRate = 100, FloorRate = -100 }; } bondInfo.StartDate = startDate; bondInfo.MaturityDate = maturityDate; bondInfo.Calendar = calendar; bondInfo.PaymentFreq = paymentFrequency; bondInfo.StickToEom = stickToEom; bondInfo.PaymentStub = paymentStub; bondInfo.Notional = notional; bondInfo.Currency = currency; bondInfo.AccrualDC = accrualDayCount; bondInfo.DayCount = paymentDayCount; bondInfo.AccrualBD = accrualBusinessDayConvention; bondInfo.PaymentBD = paymentBusinessDayConvention; bondInfo.Settlement = settlement; bondInfo.SettlementCoupon = settlementCoupon; bondInfo.TradingMarket = calendar == "chn_ib" ? TradingMarket.ChinaInterBank.ToString() : TradingMarket.ChinaExShe.ToString(); bondInfo.IsZeroCouponBond = !double.IsNaN(issuePrice); bondInfo.IssuePrice = issuePrice; bondInfo.FirstPaymentDate = firstPaymentDate; bondInfo.AmortizationType = "None"; bondInfo.AmoritzationInIndex = amoritzationInIndex; bondInfo.RenormAmortization = renormalizeAfterAmoritzation; bondInfo.CompensationRate = compensationRate; bondInfo.IssueRate = issueRate; bondInfo.OptionToCall = optionToCall; bondInfo.OptionToPut = optionToPut; bondInfo.OptionToAssPut = optionToAssPut; bondInfo.ValuationParamters = new SimpleCfValuationParameters("中债国债收益率曲线", "", "中债国债收益率曲线"); XlManager.AddTrades(new[] { bondInfo }); tradeInfo = bondInfo; } return(tradeInfo.ToTradeInfoInLabelData(null)); }