protected CallableBond(int settlementDays, Schedule schedule, DayCounter paymentDayCounter, Date issueDate = null, CallabilitySchedule putCallSchedule = null) : base(settlementDays, schedule.calendar(), issueDate) { if (putCallSchedule == null) { putCallSchedule = new CallabilitySchedule(); } paymentDayCounter_ = paymentDayCounter; putCallSchedule_ = putCallSchedule; maturityDate_ = schedule.dates().Last(); if (!putCallSchedule_.empty()) { Date finalOptionDate = Date.minDate(); for (int i = 0; i < putCallSchedule_.Count; ++i) { finalOptionDate = Date.Max(finalOptionDate, putCallSchedule_[i].date()); } Utils.QL_REQUIRE(finalOptionDate <= maturityDate_, () => "Bond cannot mature before last call/put date"); } // derived classes must set cashflows_ and frequency_ }
public ConvertibleFixedCouponBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, Handle <Quote> creditSpread, Date issueDate, int settlementDays, List <double> coupons, DayCounter dayCounter, Schedule schedule, double redemption = 100) : base( exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, schedule, redemption) { // !!! notional forcibly set to 100 cashflows_ = new FixedRateLeg(schedule) .withCouponRates(coupons, dayCounter) .withNotionals(100.0) .withPaymentAdjustment(schedule.businessDayConvention()); addRedemptionsToCashflows(new List <double>() { redemption }); Utils.QL_REQUIRE(redemptions_.Count == 1, () => "multiple redemptions created"); option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_, dayCounter, schedule, issueDate, settlementDays, redemption); }
public CallabilitySchedule(CallabilitySchedule other) : this(NQuantLibcPINVOKE.new_CallabilitySchedule__SWIG_1(CallabilitySchedule.getCPtr(other)), true) { if (NQuantLibcPINVOKE.SWIGPendingException.Pending) { throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); } }
public CallabilityScheduleEnumerator(CallabilitySchedule collection) { collectionRef = collection; currentIndex = -1; currentObject = null; currentSize = collectionRef.Count; }
public option(ConvertibleBond bond, Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, Handle <Quote> creditSpread, List <CashFlow> cashflows, DayCounter dayCounter, Schedule schedule, Date issueDate, int settlementDays, double redemption) : base(new PlainVanillaPayoff(Option.Type.Call, (bond.notionals()[0]) / 100.0 * redemption / conversionRatio), exercise) { bond_ = bond; conversionRatio_ = conversionRatio; callability_ = callability; dividends_ = dividends; creditSpread_ = creditSpread; cashflows_ = cashflows; dayCounter_ = dayCounter; issueDate_ = issueDate; schedule_ = schedule; settlementDays_ = settlementDays; redemption_ = redemption; }
protected ConvertibleBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, Handle <Quote> creditSpread, Date issueDate, int settlementDays, Schedule schedule, double redemption) : base(settlementDays, schedule.calendar(), issueDate) { conversionRatio_ = conversionRatio; callability_ = callability; dividends_ = dividends; creditSpread_ = creditSpread; maturityDate_ = schedule.endDate(); if (!callability.empty()) { Utils.QL_REQUIRE(callability.Last().date() <= maturityDate_, () => "last callability date (" + callability.Last().date() + ") later than maturity (" + maturityDate_.ToShortDateString() + ")"); } creditSpread.registerWith(update); }
public ConvertibleFloatingRateBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, Handle <Quote> creditSpread, Date issueDate, int settlementDays, IborIndex index, int fixingDays, List <double> spreads, DayCounter dayCounter, Schedule schedule, double redemption = 100) : base(exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, schedule, redemption) { // !!! notional forcibly set to 100 cashflows_ = new IborLeg(schedule, index) .withPaymentDayCounter(dayCounter) .withFixingDays(fixingDays) .withSpreads(spreads) .withNotionals(100.0) .withPaymentAdjustment(schedule.businessDayConvention()); addRedemptionsToCashflows(new List <double> { redemption }); Utils.QL_REQUIRE(redemptions_.Count == 1, "multiple redemptions created"); option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_, dayCounter, schedule, issueDate, settlementDays, redemption); }
protected ConvertibleBond( Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, Handle<Quote> creditSpread, Date issueDate, int settlementDays, Schedule schedule, double redemption) : base(settlementDays, schedule.calendar(), issueDate) { conversionRatio_ = conversionRatio; callability_ = callability; dividends_ = dividends; creditSpread_ = creditSpread; maturityDate_ = schedule.endDate(); if (!callability.empty()) { Utils.QL_REQUIRE( callability.Last().date() <= maturityDate_, () => "last callability date (" + callability.Last().date() + ") later than maturity (" + maturityDate_.ToShortDateString() + ")"); } creditSpread.registerWith(update); }
public void SetRange(int index, CallabilitySchedule values) { NQuantLibcPINVOKE.CallabilitySchedule_SetRange(swigCPtr, index, CallabilitySchedule.getCPtr(values)); if (NQuantLibcPINVOKE.SWIGPendingException.Pending) { throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); } }
public CallabilitySchedule GetRange(int index, int count) { global::System.IntPtr cPtr = NQuantLibcPINVOKE.CallabilitySchedule_GetRange(swigCPtr, index, count); CallabilitySchedule ret = (cPtr == global::System.IntPtr.Zero) ? null : new CallabilitySchedule(cPtr, true); if (NQuantLibcPINVOKE.SWIGPendingException.Pending) { throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public static CallabilitySchedule Repeat(Callability value, int count) { global::System.IntPtr cPtr = NQuantLibcPINVOKE.CallabilitySchedule_Repeat(Callability.getCPtr(value), count); CallabilitySchedule ret = (cPtr == global::System.IntPtr.Zero) ? null : new CallabilitySchedule(cPtr, true); if (NQuantLibcPINVOKE.SWIGPendingException.Pending) { throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public CallableFixedRateBond(int settlementDays, double faceAmount, Schedule schedule, List <double> coupons, DayCounter accrualDayCounter, BusinessDayConvention paymentConvention = BusinessDayConvention.Following, double redemption = 100.0, Date issueDate = null, CallabilitySchedule putCallSchedule = null) : base(settlementDays, schedule, accrualDayCounter, issueDate, putCallSchedule) { if (putCallSchedule == null) { putCallSchedule = new CallabilitySchedule(); } frequency_ = schedule.tenor().frequency(); bool isZeroCouponBond = (coupons.Count == 1 && Utils.close(coupons[0], 0.0)); if (!isZeroCouponBond) { cashflows_ = new FixedRateLeg(schedule) .withCouponRates(coupons, accrualDayCounter) .withNotionals(faceAmount) .withPaymentAdjustment(paymentConvention); addRedemptionsToCashflows(new List <double>() { redemption }); } else { Date redemptionDate = calendar_.adjust(maturityDate_, paymentConvention); setSingleRedemption(faceAmount, redemption, redemptionDate); } // used for impliedVolatility() calculation SimpleQuote dummyVolQuote = new SimpleQuote(0.0); blackVolQuote_.linkTo(dummyVolQuote); blackEngine_ = new BlackCallableFixedRateBondEngine(blackVolQuote_, blackDiscountCurve_); }
public CallableZeroCouponBond(int settlementDays, double faceAmount, Calendar calendar, Date maturityDate, DayCounter dayCounter, BusinessDayConvention paymentConvention = BusinessDayConvention.Following, double redemption = 100.0, Date issueDate = null, CallabilitySchedule putCallSchedule = null) : base(settlementDays, faceAmount, new Schedule(issueDate, maturityDate, new Period(Frequency.Once), calendar, paymentConvention, paymentConvention, DateGeneration.Rule.Backward, false), new List <double>() { 0.0 }, dayCounter, paymentConvention, redemption, issueDate, putCallSchedule) { }
public ConvertibleZeroCouponBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, Handle <Quote> creditSpread, Date issueDate, int settlementDays, DayCounter dayCounter, Schedule schedule, double redemption = 100) : base(exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, schedule, redemption) { cashflows_ = new List <CashFlow>(); // !!! notional forcibly set to 100 setSingleRedemption(100.0, redemption, maturityDate_); option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_, dayCounter, schedule, issueDate, settlementDays, redemption); }
public ConvertibleFixedCouponBond( Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, Handle<Quote> creditSpread, Date issueDate, int settlementDays, List<double> coupons, DayCounter dayCounter, Schedule schedule, double redemption = 100) : base(exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, schedule, redemption) { // !!! notional forcibly set to 100 cashflows_ = new FixedRateLeg(schedule) .withCouponRates(coupons, dayCounter) .withNotionals(100.0) .withPaymentAdjustment(schedule.businessDayConvention()); addRedemptionsToCashflows(new List<double>(){redemption}); Utils.QL_REQUIRE(redemptions_.Count == 1, "multiple redemptions created"); option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_, dayCounter, schedule, issueDate, settlementDays, redemption); }
public ConvertibleZeroCouponBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, Handle<Quote> creditSpread, Date issueDate, int settlementDays, DayCounter dayCounter, Schedule schedule, double redemption = 100) : base(exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays,schedule, redemption) { cashflows_ = new List<CashFlow>(); // !!! notional forcibly set to 100 setSingleRedemption(100.0, redemption, maturityDate_); option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_, dayCounter, schedule, issueDate, settlementDays, redemption); }
public ConvertibleFloatingRateBond( Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, Handle<Quote> creditSpread, Date issueDate, int settlementDays, IborIndex index, int fixingDays, List<double> spreads, DayCounter dayCounter, Schedule schedule, double redemption = 100) : base(exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, schedule, redemption) { // !!! notional forcibly set to 100 cashflows_ = new IborLeg(schedule, index) .withPaymentDayCounter(dayCounter) .withFixingDays(fixingDays) .withSpreads(spreads) .withNotionals(100.0) .withPaymentAdjustment(schedule.businessDayConvention()); addRedemptionsToCashflows(new List<double>{redemption}); Utils.QL_REQUIRE( redemptions_.Count == 1, () => "multiple redemptions created" ); option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_, dayCounter, schedule, issueDate, settlementDays, redemption); }
//public class engine; public option( ConvertibleBond bond, Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, Handle<Quote> creditSpread, List<CashFlow> cashflows, DayCounter dayCounter, Schedule schedule, Date issueDate, int settlementDays, double redemption) :base(new PlainVanillaPayoff(Option.Type.Call, (bond.notionals()[0])/100.0 *redemption/conversionRatio), exercise) { bond_ = bond; conversionRatio_ = conversionRatio; callability_ = callability; dividends_ = dividends; creditSpread_ = creditSpread; cashflows_ = cashflows; dayCounter_ = dayCounter; issueDate_ = issueDate; schedule_ = schedule; settlementDays_ = settlementDays; redemption_ = redemption; }
static void Main(string[] args) { try { Option.Type type = Option.Type.Put; double underlying = 36.0; double spreadRate = 0.005; double dividendYield = 0.02; double riskFreeRate = 0.06; double volatility = 0.2; int settlementDays = 3; int length = 5; double redemption = 100.0; double conversionRatio = redemption / underlying; // at the money // set up dates/schedules Calendar calendar = new TARGET(); Date today = calendar.adjust(Date.Today); Settings.setEvaluationDate(today); Date settlementDate = calendar.advance(today, settlementDays, TimeUnit.Days); Date exerciseDate = calendar.advance(settlementDate, length, TimeUnit.Years); Date issueDate = calendar.advance(exerciseDate, -length, TimeUnit.Years); BusinessDayConvention convention = BusinessDayConvention.ModifiedFollowing; Frequency frequency = Frequency.Annual; Schedule schedule = new Schedule(issueDate, exerciseDate, new Period(frequency), calendar, convention, convention, DateGeneration.Rule.Backward, false); DividendSchedule dividends = new DividendSchedule(); CallabilitySchedule callability = new CallabilitySchedule(); List <double> coupons = new InitializedList <double>(1, 0.05); DayCounter bondDayCount = new Thirty360(); int[] callLength = { 2, 4 }; // Call dates, years 2,4. int[] putLength = { 3 }; // Put dates year 3. double[] callPrices = { 101.5, 100.85 }; double[] putPrices = { 105.0 }; // Load call schedules for (int i = 0; i < callLength.Length; i++) { SoftCallability s = new SoftCallability( new Callability.Price(callPrices[i], Callability.Price.Type.Clean), schedule.date(callLength[i]), 1.20); callability.Add(s); } for (int j = 0; j < putLength.Length; j++) { Callability s = new Callability(new Callability.Price(putPrices[j], Callability.Price.Type.Clean), Callability.Type.Put, schedule.date(putLength[j])); callability.Add(s); } // Assume dividends are paid every 6 months . for (Date d = today + new Period(6, TimeUnit.Months); d < exerciseDate; d += new Period(6, TimeUnit.Months)) { Dividend div = new FixedDividend(1.0, d); dividends.Add(div); } DayCounter dayCounter = new Actual365Fixed(); double maturity = dayCounter.yearFraction(settlementDate, exerciseDate); Console.WriteLine("option type = " + type); Console.WriteLine("Time to maturity = " + maturity); Console.WriteLine("Underlying price = " + underlying); Console.WriteLine("Risk-free interest rate = {0:0.0%}", riskFreeRate); Console.WriteLine("Dividend yield = {0:0.0%}%", dividendYield); Console.WriteLine("Volatility = {0:0.0%}%", volatility); Console.WriteLine(""); // write column headings int[] widths = { 35, 14, 14 }; int totalWidth = widths[0] + widths[1] + widths[2]; string rule = new string('-', totalWidth); string dblrule = new string('=', totalWidth); Console.WriteLine(dblrule); Console.WriteLine("Tsiveriotis-Fernandes method"); Console.WriteLine(dblrule); Console.WriteLine("Tree Type European American "); Console.WriteLine(rule); Exercise exercise = new EuropeanExercise(exerciseDate); Exercise amexercise = new AmericanExercise(settlementDate, exerciseDate); Handle <Quote> underlyingH = new Handle <Quote>(new SimpleQuote(underlying)); Handle <YieldTermStructure> flatTermStructure = new Handle <YieldTermStructure>(new FlatForward(settlementDate, riskFreeRate, dayCounter)); Handle <YieldTermStructure> flatDividendTS = new Handle <YieldTermStructure>(new FlatForward(settlementDate, dividendYield, dayCounter)); Handle <BlackVolTermStructure> flatVolTS = new Handle <BlackVolTermStructure>(new BlackConstantVol(settlementDate, calendar, volatility, dayCounter)); BlackScholesMertonProcess stochasticProcess = new BlackScholesMertonProcess(underlyingH, flatDividendTS, flatTermStructure, flatVolTS); int timeSteps = 801; Handle <Quote> creditSpread = new Handle <Quote>(new SimpleQuote(spreadRate)); Quote rate = new SimpleQuote(riskFreeRate); Handle <YieldTermStructure> discountCurve = new Handle <YieldTermStructure>(new FlatForward(today, new Handle <Quote>(rate), dayCounter)); IPricingEngine engine = new BinomialConvertibleEngine <JarrowRudd>(stochasticProcess, timeSteps); ConvertibleFixedCouponBond europeanBond = new ConvertibleFixedCouponBond(exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, coupons, bondDayCount, schedule, redemption); europeanBond.setPricingEngine(engine); ConvertibleFixedCouponBond americanBond = new ConvertibleFixedCouponBond(amexercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, coupons, bondDayCount, schedule, redemption); americanBond.setPricingEngine(engine); Console.WriteLine("Jarrow-Rudd {0:0.000000} {1:0.000000}", europeanBond.NPV(), americanBond.NPV()); americanBond.setPricingEngine(new BinomialConvertibleEngine <CoxRossRubinstein>(stochasticProcess, timeSteps)); europeanBond.setPricingEngine(new BinomialConvertibleEngine <CoxRossRubinstein>(stochasticProcess, timeSteps)); Console.WriteLine("CoxRossRubinstein {0:0.000000} {1:0.000000}", europeanBond.NPV(), americanBond.NPV()); americanBond.setPricingEngine(new BinomialConvertibleEngine <AdditiveEQPBinomialTree>(stochasticProcess, timeSteps)); europeanBond.setPricingEngine(new BinomialConvertibleEngine <AdditiveEQPBinomialTree>(stochasticProcess, timeSteps)); Console.WriteLine("AdditiveEQPBinomialTree {0:0.000000} {1:0.000000}", europeanBond.NPV(), americanBond.NPV()); americanBond.setPricingEngine(new BinomialConvertibleEngine <Trigeorgis>(stochasticProcess, timeSteps)); europeanBond.setPricingEngine(new BinomialConvertibleEngine <Trigeorgis>(stochasticProcess, timeSteps)); Console.WriteLine("Trigeorgis {0:0.000000} {1:0.000000}", europeanBond.NPV(), americanBond.NPV()); americanBond.setPricingEngine(new BinomialConvertibleEngine <Tian>(stochasticProcess, timeSteps)); europeanBond.setPricingEngine(new BinomialConvertibleEngine <Tian>(stochasticProcess, timeSteps)); Console.WriteLine("Tian {0:0.000000} {1:0.000000}", europeanBond.NPV(), americanBond.NPV()); americanBond.setPricingEngine(new BinomialConvertibleEngine <LeisenReimer>(stochasticProcess, timeSteps)); europeanBond.setPricingEngine(new BinomialConvertibleEngine <LeisenReimer>(stochasticProcess, timeSteps)); Console.WriteLine("LeisenReimer {0:0.000000} {1:0.000000}", europeanBond.NPV(), americanBond.NPV()); americanBond.setPricingEngine(new BinomialConvertibleEngine <Joshi4>(stochasticProcess, timeSteps)); europeanBond.setPricingEngine(new BinomialConvertibleEngine <Joshi4>(stochasticProcess, timeSteps)); Console.WriteLine("Joshi4 {0:0.000000} {1:0.000000}", europeanBond.NPV(), americanBond.NPV()); Console.WriteLine("==========================================================================="); } catch (Exception e) { Console.WriteLine(e.ToString()); } Console.ReadKey(); }
static void Main(string[] args) { // boost::timer timer; Date today = new Date(16,Month.October,2007); Settings.setEvaluationDate(today); Console.WriteLine(); Console.WriteLine("Pricing a callable fixed rate bond using"); Console.WriteLine("Hull White model w/ reversion parameter = 0.03"); Console.WriteLine("BAC4.65 09/15/12 ISIN: US06060WBJ36"); Console.WriteLine("roughly five year tenor, "); Console.WriteLine("quarterly coupon and call dates"); Console.WriteLine("reference date is : " + today ); /* Bloomberg OAS1: "N" model (Hull White) varying volatility parameter The curve entered into Bloomberg OAS1 is a flat curve, at constant yield = 5.5%, semiannual compounding. Assume here OAS1 curve uses an ACT/ACT day counter, as documented in PFC1 as a "default" in the latter case. */ // set up a flat curve corresponding to Bloomberg flat curve double bbCurveRate = 0.055; DayCounter bbDayCounter = new ActualActual(ActualActual.Convention.Bond); InterestRate bbIR = new InterestRate(bbCurveRate,bbDayCounter,Compounding.Compounded ,Frequency.Semiannual); Handle<YieldTermStructure> termStructure = new Handle<YieldTermStructure>(flatRate( today, bbIR.rate(), bbIR.dayCounter(), bbIR.compounding(), bbIR.frequency())); // set up the call schedule CallabilitySchedule callSchedule = new CallabilitySchedule(); double callPrice = 100.0; int numberOfCallDates = 24; Date callDate = new Date(15,Month.September,2006); for (int i=0; i< numberOfCallDates; i++) { Calendar nullCalendar = new NullCalendar(); Callability.Price myPrice = new Callability.Price(callPrice, Callability.Price.Type.Clean); callSchedule.Add( new Callability(myPrice,Callability.Type.Call, callDate )); callDate = nullCalendar.advance(callDate, 3, TimeUnit.Months); } // set up the callable bond Date dated = new Date(16,Month.September,2004); Date issue = dated; Date maturity = new Date(15,Month.September,2012); int settlementDays = 3; // Bloomberg OAS1 settle is Oct 19, 2007 Calendar bondCalendar = new UnitedStates(UnitedStates.Market.GovernmentBond); double coupon = .0465; Frequency frequency = Frequency.Quarterly; double redemption = 100.0; double faceAmount = 100.0; /* The 30/360 day counter Bloomberg uses for this bond cannot reproduce the US Bond/ISMA (constant) cashflows used in PFC1. Therefore use ActAct(Bond) */ DayCounter bondDayCounter = new ActualActual(ActualActual.Convention.Bond); // PFC1 shows no indication dates are being adjusted // for weekends/holidays for vanilla bonds BusinessDayConvention accrualConvention = BusinessDayConvention.Unadjusted; BusinessDayConvention paymentConvention = BusinessDayConvention.Unadjusted; Schedule sch = new Schedule( dated, maturity, new Period(frequency), bondCalendar, accrualConvention, accrualConvention, DateGeneration.Rule.Backward, false); int maxIterations = 1000; double accuracy = 1e-8; int gridIntervals = 40; double reversionParameter = .03; // output price/yield results for varying volatility parameter double sigma = Const.QL_Epsilon; // core dumps if zero on Cygwin ShortRateModel hw0 = new HullWhite(termStructure,reversionParameter,sigma); IPricingEngine engine0 = new TreeCallableFixedRateBondEngine(hw0, gridIntervals, termStructure); CallableFixedRateBond callableBond = new CallableFixedRateBond( settlementDays, faceAmount, sch, new InitializedList<double>(1, coupon), bondDayCounter, paymentConvention, redemption, issue, callSchedule); callableBond.setPricingEngine(engine0); Console.WriteLine("sigma/vol (%) = {0:0.00}", (100.0 * sigma)); Console.WriteLine("QuantLib price/yld (%) "); Console.WriteLine( "{0:0.00} / {1:0.00} ", callableBond.cleanPrice() , 100.0 * callableBond.yield(bondDayCounter, Compounding.Compounded, frequency, accuracy, maxIterations)); Console.WriteLine("Bloomberg price/yld (%) "); Console.WriteLine("96.50 / 5.47"); // sigma = .01; Console.WriteLine("sigma/vol (%) = {0:0.00}", (100.0 * sigma)); ShortRateModel hw1 = new HullWhite(termStructure,reversionParameter,sigma); IPricingEngine engine1 = new TreeCallableFixedRateBondEngine(hw1,gridIntervals,termStructure); callableBond.setPricingEngine(engine1); Console.WriteLine("QuantLib price/yld (%) "); Console.WriteLine( "{0:0.00} / {1:0.00} ", callableBond.cleanPrice() , 100.0 * callableBond.yield(bondDayCounter, Compounding.Compounded, frequency, accuracy, maxIterations)); Console.WriteLine("Bloomberg price/yld (%) "); Console.WriteLine("95.68 / 5.66"); // sigma = .03; Console.WriteLine("sigma/vol (%) = {0:0.00}", (100.0 * sigma)); ShortRateModel hw2 = new HullWhite(termStructure, reversionParameter, sigma); IPricingEngine engine2 = new TreeCallableFixedRateBondEngine(hw2, gridIntervals, termStructure); callableBond.setPricingEngine(engine2); Console.WriteLine("QuantLib price/yld (%) "); Console.WriteLine("{0:0.00} / {1:0.00} ", callableBond.cleanPrice(), 100.0 * callableBond.yield(bondDayCounter, Compounding.Compounded, frequency, accuracy, maxIterations)); Console.WriteLine("Bloomberg price/yld (%) "); Console.WriteLine("92.34 / 6.49"); // sigma = .06; Console.WriteLine("sigma/vol (%) = {0:0.00}", (100.0 * sigma)); ShortRateModel hw3 = new HullWhite(termStructure, reversionParameter, sigma); IPricingEngine engine3 = new TreeCallableFixedRateBondEngine(hw3, gridIntervals, termStructure); callableBond.setPricingEngine(engine3); Console.WriteLine("QuantLib price/yld (%) "); Console.WriteLine("{0:0.00} / {1:0.00} ", callableBond.cleanPrice(), 100.0 * callableBond.yield(bondDayCounter, Compounding.Compounded, frequency, accuracy, maxIterations)); Console.WriteLine("Bloomberg price/yld (%) "); Console.WriteLine("87.16 / 7.83"); // sigma = .12; Console.WriteLine("sigma/vol (%) = {0:0.00}", (100.0 * sigma)); ShortRateModel hw4 = new HullWhite(termStructure, reversionParameter, sigma); IPricingEngine engine4 = new TreeCallableFixedRateBondEngine(hw4, gridIntervals, termStructure); callableBond.setPricingEngine(engine4); Console.WriteLine("QuantLib price/yld (%) "); Console.WriteLine("{0:0.00} / {1:0.00} ", callableBond.cleanPrice(), 100.0 * callableBond.yield(bondDayCounter, Compounding.Compounded, frequency, accuracy, maxIterations)); Console.WriteLine("Bloomberg price/yld (%) "); Console.WriteLine("77.31 / 10.65"); }
public ConvertibleFloatingRateBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, QuoteHandle creditSpread, Date issueDate, int settlementDays, IborIndex index, int fixingDays, DoubleVector spreads, DayCounter dayCounter, Schedule schedule) : this(NQuantLibcPINVOKE.new_ConvertibleFloatingRateBond__SWIG_1(Exercise.getCPtr(exercise), conversionRatio, DividendSchedule.getCPtr(dividends), CallabilitySchedule.getCPtr(callability), QuoteHandle.getCPtr(creditSpread), Date.getCPtr(issueDate), settlementDays, IborIndex.getCPtr(index), fixingDays, DoubleVector.getCPtr(spreads), DayCounter.getCPtr(dayCounter), Schedule.getCPtr(schedule)), true) { if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(CallabilitySchedule obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
static void Main(string[] args) { // boost::timer timer; Date today = new Date(16, Month.October, 2007); Settings.setEvaluationDate(today); Console.WriteLine(); Console.WriteLine("Pricing a callable fixed rate bond using"); Console.WriteLine("Hull White model w/ reversion parameter = 0.03"); Console.WriteLine("BAC4.65 09/15/12 ISIN: US06060WBJ36"); Console.WriteLine("roughly five year tenor, quarterly coupon and call dates"); Console.WriteLine("reference date is : " + today.ToLongDateString()); Console.WriteLine(""); /* Bloomberg OAS1: "N" model (Hull White) * varying volatility parameter * * The curve entered into Bloomberg OAS1 is a flat curve, * at constant yield = 5.5%, semiannual compounding. * Assume here OAS1 curve uses an ACT/ACT day counter, * as documented in PFC1 as a "default" in the latter case. */ // set up a flat curve corresponding to Bloomberg flat curve double bbCurveRate = 0.055; DayCounter bbDayCounter = new ActualActual(ActualActual.Convention.Bond); InterestRate bbIR = new InterestRate(bbCurveRate, bbDayCounter, Compounding.Compounded, Frequency.Semiannual); Handle <YieldTermStructure> termStructure = new Handle <YieldTermStructure>(flatRate(today, bbIR.rate(), bbIR.dayCounter(), bbIR.compounding(), bbIR.frequency())); // set up the call schedule CallabilitySchedule callSchedule = new CallabilitySchedule(); double callPrice = 100.0; int numberOfCallDates = 24; Date callDate = new Date(15, Month.September, 2006); for (int i = 0; i < numberOfCallDates; i++) { Calendar nullCalendar = new NullCalendar(); Callability.Price myPrice = new Callability.Price(callPrice, Callability.Price.Type.Clean); callSchedule.Add(new Callability(myPrice, Callability.Type.Call, callDate)); callDate = nullCalendar.advance(callDate, 3, TimeUnit.Months); } // set up the callable bond Date dated = new Date(16, Month.September, 2004); Date issue = dated; Date maturity = new Date(15, Month.September, 2012); int settlementDays = 3; // Bloomberg OAS1 settle is Oct 19, 2007 Calendar bondCalendar = new UnitedStates(UnitedStates.Market.GovernmentBond); double coupon = .0465; Frequency frequency = Frequency.Quarterly; double redemption = 100.0; double faceAmount = 100.0; /* The 30/360 day counter Bloomberg uses for this bond cannot * reproduce the US Bond/ISMA (constant) cashflows used in PFC1. * Therefore use ActAct(Bond) */ DayCounter bondDayCounter = new ActualActual(ActualActual.Convention.Bond); // PFC1 shows no indication dates are being adjusted // for weekends/holidays for vanilla bonds BusinessDayConvention accrualConvention = BusinessDayConvention.Unadjusted; BusinessDayConvention paymentConvention = BusinessDayConvention.Unadjusted; Schedule sch = new Schedule(dated, maturity, new Period(frequency), bondCalendar, accrualConvention, accrualConvention, DateGeneration.Rule.Backward, false); int maxIterations = 1000; double accuracy = 1e-8; int gridIntervals = 40; double reversionParameter = .03; // output price/yield results for varying volatility parameter double sigma = Const.QL_EPSILON; // core dumps if zero on Cygwin ShortRateModel hw0 = new HullWhite(termStructure, reversionParameter, sigma); IPricingEngine engine0 = new TreeCallableFixedRateBondEngine(hw0, gridIntervals, termStructure); CallableFixedRateBond callableBond = new CallableFixedRateBond(settlementDays, faceAmount, sch, new InitializedList <double>(1, coupon), bondDayCounter, paymentConvention, redemption, issue, callSchedule); callableBond.setPricingEngine(engine0); Console.WriteLine("sigma/vol (%) = {0:0.00}", (100.0 * sigma)); Console.WriteLine("QLNet price/yld (%) {0:0.00} / {1:0.00} ", callableBond.cleanPrice(), 100.0 * callableBond.yield(bondDayCounter, Compounding.Compounded, frequency, accuracy, maxIterations)); Console.WriteLine("Bloomberg price/yld (%) 96,50 / 5,47"); Console.WriteLine(""); // sigma = .01; Console.WriteLine("sigma/vol (%) = {0:0.00}", (100.0 * sigma)); ShortRateModel hw1 = new HullWhite(termStructure, reversionParameter, sigma); IPricingEngine engine1 = new TreeCallableFixedRateBondEngine(hw1, gridIntervals, termStructure); callableBond.setPricingEngine(engine1); Console.WriteLine("QLNet price/yld (%) {0:0.00} / {1:0.00} ", callableBond.cleanPrice(), 100.0 * callableBond.yield(bondDayCounter, Compounding.Compounded, frequency, accuracy, maxIterations)); Console.WriteLine("Bloomberg price/yld (%) 95,68 / 5,66"); Console.WriteLine(""); // sigma = .03; Console.WriteLine("sigma/vol (%) = {0:0.00}", (100.0 * sigma)); ShortRateModel hw2 = new HullWhite(termStructure, reversionParameter, sigma); IPricingEngine engine2 = new TreeCallableFixedRateBondEngine(hw2, gridIntervals, termStructure); callableBond.setPricingEngine(engine2); Console.WriteLine("QLNet price/yld (%) {0:0.00} / {1:0.00} ", callableBond.cleanPrice(), 100.0 * callableBond.yield(bondDayCounter, Compounding.Compounded, frequency, accuracy, maxIterations)); Console.WriteLine("Bloomberg price/yld (%) 92,34 / 6,49"); Console.WriteLine(""); // sigma = .06; Console.WriteLine("sigma/vol (%) = {0:0.00}", (100.0 * sigma)); ShortRateModel hw3 = new HullWhite(termStructure, reversionParameter, sigma); IPricingEngine engine3 = new TreeCallableFixedRateBondEngine(hw3, gridIntervals, termStructure); callableBond.setPricingEngine(engine3); Console.WriteLine("QLNet price/yld (%) {0:0.00} / {1:0.00} ", callableBond.cleanPrice(), 100.0 * callableBond.yield(bondDayCounter, Compounding.Compounded, frequency, accuracy, maxIterations)); Console.WriteLine("Bloomberg price/yld (%) 87,16 / 7,83"); Console.WriteLine(""); // sigma = .12; Console.WriteLine("sigma/vol (%) = {0:0.00}", (100.0 * sigma)); ShortRateModel hw4 = new HullWhite(termStructure, reversionParameter, sigma); IPricingEngine engine4 = new TreeCallableFixedRateBondEngine(hw4, gridIntervals, termStructure); callableBond.setPricingEngine(engine4); Console.WriteLine("QLNet price/yld (%) {0:0.00} / {1:0.00} ", callableBond.cleanPrice(), 100.0 * callableBond.yield(bondDayCounter, Compounding.Compounded, frequency, accuracy, maxIterations)); Console.WriteLine("Bloomberg price/yld (%) 77,31 / 10,65"); }
public ConvertibleFixedCouponBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, QuoteHandle creditSpread, Date issueDate, int settlementDays, DoubleVector coupons, DayCounter dayCounter, Schedule schedule) : this(NQuantLibcPINVOKE.new_ConvertibleFixedCouponBond__SWIG_1(Exercise.getCPtr(exercise), conversionRatio, DividendSchedule.getCPtr(dividends), CallabilitySchedule.getCPtr(callability), QuoteHandle.getCPtr(creditSpread), Date.getCPtr(issueDate), settlementDays, DoubleVector.getCPtr(coupons), DayCounter.getCPtr(dayCounter), Schedule.getCPtr(schedule)), true) { if (NQuantLibcPINVOKE.SWIGPendingException.Pending) { throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); } }
public ConvertibleFloatingRateBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, QuoteHandle creditSpread, Date issueDate, int settlementDays, IborIndex index, int fixingDays, DoubleVector spreads, DayCounter dayCounter, Schedule schedule, double redemption) : this(NQuantLibcPINVOKE.new_ConvertibleFloatingRateBond__SWIG_0(Exercise.getCPtr(exercise), conversionRatio, DividendSchedule.getCPtr(dividends), CallabilitySchedule.getCPtr(callability), QuoteHandle.getCPtr(creditSpread), Date.getCPtr(issueDate), settlementDays, IborIndex.getCPtr(index), fixingDays, DoubleVector.getCPtr(spreads), DayCounter.getCPtr(dayCounter), Schedule.getCPtr(schedule), redemption), true) { if (NQuantLibcPINVOKE.SWIGPendingException.Pending) { throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); } }
public ConvertibleFixedCouponBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, QuoteHandle creditSpread, Date issueDate, int settlementDays, DoubleVector coupons, DayCounter dayCounter, Schedule schedule, double redemption) : this(NQuantLibcPINVOKE.new_ConvertibleFixedCouponBond__SWIG_0(Exercise.getCPtr(exercise), conversionRatio, DividendSchedule.getCPtr(dividends), CallabilitySchedule.getCPtr(callability), QuoteHandle.getCPtr(creditSpread), Date.getCPtr(issueDate), settlementDays, DoubleVector.getCPtr(coupons), DayCounter.getCPtr(dayCounter), Schedule.getCPtr(schedule), redemption), true) { if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); }
public void testRegression() { // Testing fixed-coupon convertible bond in known regression case Date today = new Date(23, Month.December, 2008); Date tomorrow = today + 1; Settings.Instance.setEvaluationDate(tomorrow); Handle <Quote> u = new Handle <Quote>(new SimpleQuote(2.9084382818797443)); List <Date> dates = new InitializedList <Date>(25); List <double> forwards = new InitializedList <double>(25); dates[0] = new Date(29, Month.December, 2008); forwards[0] = 0.0025999342800; dates[1] = new Date(5, Month.January, 2009); forwards[1] = 0.0025999342800; dates[2] = new Date(29, Month.January, 2009); forwards[2] = 0.0053123275500; dates[3] = new Date(27, Month.February, 2009); forwards[3] = 0.0197049598721; dates[4] = new Date(30, Month.March, 2009); forwards[4] = 0.0220524845296; dates[5] = new Date(29, Month.June, 2009); forwards[5] = 0.0217076395643; dates[6] = new Date(29, Month.December, 2009); forwards[6] = 0.0230349627478; dates[7] = new Date(29, Month.December, 2010); forwards[7] = 0.0087631647476; dates[8] = new Date(29, Month.December, 2011); forwards[8] = 0.0219084299499; dates[9] = new Date(31, Month.December, 2012); forwards[9] = 0.0244798766219; dates[10] = new Date(30, Month.December, 2013); forwards[10] = 0.0267885498456; dates[11] = new Date(29, Month.December, 2014); forwards[11] = 0.0266922867562; dates[12] = new Date(29, Month.December, 2015); forwards[12] = 0.0271052126386; dates[13] = new Date(29, Month.December, 2016); forwards[13] = 0.0268829891648; dates[14] = new Date(29, Month.December, 2017); forwards[14] = 0.0264594744498; dates[15] = new Date(31, Month.December, 2018); forwards[15] = 0.0273450367424; dates[16] = new Date(30, Month.December, 2019); forwards[16] = 0.0294852614749; dates[17] = new Date(29, Month.December, 2020); forwards[17] = 0.0285556119719; dates[18] = new Date(29, Month.December, 2021); forwards[18] = 0.0305557764659; dates[19] = new Date(29, Month.December, 2022); forwards[19] = 0.0292244738422; dates[20] = new Date(29, Month.December, 2023); forwards[20] = 0.0263917004194; dates[21] = new Date(29, Month.December, 2028); forwards[21] = 0.0239626970243; dates[22] = new Date(29, Month.December, 2033); forwards[22] = 0.0216417108090; dates[23] = new Date(29, Month.December, 2038); forwards[23] = 0.0228343838422; dates[24] = new Date(31, Month.December, 2199); forwards[24] = 0.0228343838422; Handle <YieldTermStructure> r = new Handle <YieldTermStructure>(new InterpolatedForwardCurve <BackwardFlat>(dates, forwards, new Actual360())); Handle <BlackVolTermStructure> sigma = new Handle <BlackVolTermStructure>(new BlackConstantVol(tomorrow, new NullCalendar(), 21.685235548092248, new Thirty360(Thirty360.Thirty360Convention.BondBasis))); BlackProcess process = new BlackProcess(u, r, sigma); Handle <Quote> spread = new Handle <Quote>(new SimpleQuote(0.11498700678012874)); Date issueDate = new Date(23, Month.July, 2008); Date maturityDate = new Date(1, Month.August, 2013); Calendar calendar = new UnitedStates(); Schedule schedule = new MakeSchedule().from(issueDate) .to(maturityDate) .withTenor(new Period(6, TimeUnit.Months)) .withCalendar(calendar) .withConvention(BusinessDayConvention.Unadjusted).value(); int settlementDays = 3; Exercise exercise = new EuropeanExercise(maturityDate); double conversionRatio = 100.0 / 20.3175; List <double> coupons = new InitializedList <double>(schedule.size() - 1, 0.05); DayCounter dayCounter = new Thirty360(Thirty360.Thirty360Convention.BondBasis); CallabilitySchedule no_callability = new CallabilitySchedule(); DividendSchedule no_dividends = new DividendSchedule(); double redemption = 100.0; ConvertibleFixedCouponBond bond = new ConvertibleFixedCouponBond(exercise, conversionRatio, no_dividends, no_callability, spread, issueDate, settlementDays, coupons, dayCounter, schedule, redemption); bond.setPricingEngine(new BinomialConvertibleEngine <CoxRossRubinstein> (process, 600)); try { double x = bond.NPV(); // should throw; if not, an INF was not detected. QAssert.Fail("INF result was not detected: " + x + " returned"); } catch (Exception) { // as expected. Do nothing. // Note: we're expecting an Error we threw, not just any // exception. If something else is thrown, then there's // another problem and the test must fail. } }
public CallableFixedRateBond(int settlementDays, double faceAmount, Schedule schedule, DoubleVector coupons, DayCounter accrualDayCounter, BusinessDayConvention paymentConvention, double redemption, Date issueDate, CallabilitySchedule putCallSchedule) : this(NQuantLibcPINVOKE.new_CallableFixedRateBond(settlementDays, faceAmount, Schedule.getCPtr(schedule), DoubleVector.getCPtr(coupons), DayCounter.getCPtr(accrualDayCounter), (int)paymentConvention, redemption, Date.getCPtr(issueDate), CallabilitySchedule.getCPtr(putCallSchedule)), true) { if (NQuantLibcPINVOKE.SWIGPendingException.Pending) { throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve(); } }