public static ConvertibleBondInfo ToConvertibleBondInfo(BondInfoBase bondInfo, string conversionStartDate, string conversionEndDate, string conversionStockcode, double conversionPrice, string dividenCurveName, bool treatAsCommonBond = false, string[] ebcStrikeQuoteTypes = null, string[] ebpStrikeQuoteTypes = null) { var json = DataContractJsonObjectSerializer.Serialize(bondInfo); var bondPart = DataContractJsonObjectSerializer.Deserialize <BondInfoBase>(json); bondPart.OptionToAssPut = null; bondPart.OptionToCall = null; bondPart.OptionToPut = null; var hasPut = !(bondInfo.OptionToPut == null || !bondInfo.OptionToPut.Any()); var hasCall = !(bondInfo.OptionToCall == null || !bondInfo.OptionToCall.Any()); if (!hasPut) { bondInfo.OptionToPut = new Dictionary <string, double>(); } if (!hasCall) { bondInfo.OptionToCall = new Dictionary <string, double>(); } var ebos = bondInfo.OptionToPut.Select(x => new VanillaOptionInfo (tradeId: "", strike: x.Value, underlyingTicker: bondInfo.BondId, underlyingInstrumentType: "Bond", valuationParameter: null, startDate: bondInfo.StartDate, underlyingMaturityDate: bondInfo.MaturityDate, exerciseDates: x.Key, calendar: bondInfo.Calendar, dayCount: bondInfo.DayCount, exercise: "European", notional: 1.0, optionType: "Call" )).Union( bondInfo.OptionToCall.Select(x => new VanillaOptionInfo ("", strike: x.Value, underlyingTicker: bondInfo.BondId, underlyingInstrumentType: "Bond", valuationParameter: null, startDate: bondInfo.StartDate, underlyingMaturityDate: bondInfo.MaturityDate, exerciseDates: x.Key, calendar: bondInfo.Calendar, optionType: "Put", dayCount: bondInfo.DayCount, notional: 1.0) ) ).ToArray(); var eboStrikQuoteTypes = ebcStrikeQuoteTypes ?? new string[0] .Union(ebpStrikeQuoteTypes ?? new string[0]) .ToArray(); var conversion = new VanillaOptionInfo( tradeId: "", strike: conversionPrice, underlyingTicker: bondInfo.BondId, underlyingInstrumentType: "Stock", valuationParameter: null, startDate: conversionStartDate, underlyingMaturityDate: conversionEndDate, calendar: bondInfo.Calendar, optionType: "Call", exercise: "American", dayCount: bondInfo.DayCount, notional: 1.0, exerciseDates: bondInfo.OptionToCall.Keys.First() ); return(new ConvertibleBondInfo(bondPart.BondId) { BondPart = bondPart, ConversionOption = conversion, EmbeddedOptions = ebos.Any() ? ebos : null, EboStrikeQuoteTypes = eboStrikQuoteTypes.Any() ? eboStrikQuoteTypes : null, ValuationParameters = new OptionValuationParameters(discountCurveName: bondInfo.ValuationParamters.DiscountCurveName, dividendCurveName: dividenCurveName, volSurfName: conversionStockcode + "Vol", underlyingId: conversionStockcode), TreatAsCommonBond = treatAsCommonBond }); }
/// <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)); }