QuantLib's soft call class constructor takes three inputs:
SoftCallability (const Bond::Price &price, const Date &date, Real trigger)
My expectation is that the trigger is in some way representing the stock price which must be equaled or exceeded in order for the call feature to be activated, however, I am unsure of the implementation.
The sample computation of the value of a convertible bond available in the QLAnnotatedSource implements the SoftCallability member function using a hardcoded 1.20:
ext::make_shared<SoftCallability>Bond::Price(
callPrices[i],
Bond::Price::Clean),
schedule.date(callLength[i]),
1.20));
However, the underlying (starting stock price) used in the example is 36.0. As such, my guess is that the 1.20 does not represent the stock price threshold directly (i.e. the stock price does not need to be above 1.20 for the call feature to be activated). Is it a multiple (the stock price must be greater than or equal to 1.20 * the starting stock price)? Or maybe some other implementation?
Thanks!
Related
Detailed business problem:
I'm trying to solve a production scheduling business problem as below:
I have two plants producing FG A and B respectively.
Both the products consume the same Raw Material x
I need to create a 30 day production schedule looking at the Raw Material availability.
FG A and B can be produced if there is sufficient raw material available on the day.
After every 6 days of production the plant has to undergo maintenance and the production on that day will be zero.
Objective is to maximize the margin looking at the day level Raw material available and adhere to the production constraint (i.e. shutdown after every 6th day)
I need to build a linear programming to address the below problem:
Variable y: (binary)
variable z: cumulative of y
When z > 6 then y = 0. I also need to reset the cumulation of z after this point.
Desired output:
How can I build the statement to MILP constraint. Are there any techniques for solving this problem. Thank you.
I think you can model your maintenance differently. Just forbid any sequences of 7 ones for y. I.e.
y[t-6]+y[t-5]+y[t-4]+y[t-3]+y[t-2]+y[t-1]+y[t] <= 6 for t=1,..,T
This is easier than using your accumulator. Note that the beginning needs some attention: you can use historic data for this. I.e., at t=1, the values for t=0,-1,-2,.. are known.
Your accumulator approach is not inherently wrong. We often use it to model inventory. An inventory capacity is a restriction on how large the accumulated inventory can be.
Firstly apologies if this has been answered elsewhere.
I am using QuantLib (via Excel) to build a "standard" bond pricing sheet: prices, yields, spline AND matched-maturity ASW.
I can price the bonds, and have successfully built a forecast (Euribor) and discount (EONIA) curve. I can use qlMakeVanillaSwap() to define a spot-start swap by tenor (eg "1y","2Y" etc) and it works fine. However I am struggling to define a "broken date" swap, ie one which starts T+2 and ends on a given date (and so usually has a short stub on the first payment), to match the bond maturity. All the examples I can find have integer year tenors.
I would be grateful if someone could point me to the right method (can be in python, C++ or Excel). Or do I have to go down the route of creating explicit fixed and floating rate schedules for the swaps?
The answer seems to be: Yes, I do have to create explicit fixed and floating rate schedules, using qlSchedule(), but it turns out to be not too onerous. NB. I am pricing a vanilla EUR ABB vs 6m Euribor swap.
As for pricing, it seems the qlMakeVanillaSwap() is doing a few helpful things in one call, but only IF your swap has a whole-period tenor (eg "1y"). I found the answer for what I wanted to do in the example sheet that came with the QuantLibXL download package.
The other thing that qlMakeVanillaSwap() is doing (in addition to creating the schedules) is setting the Pricing Engine (which is used to discount the cashflows). In the longer version you have to (a) set it yourself using qlInstrumentSetPricingEngine() and (b) pass the result of that call to the Trigger parameter of qlVanillaSwapFairRate(), to establish the calculation order.
I have looked "everywhere" but I cannot find one. Is there an example of how to use c++ Quantlib on how to interpolate for options prices with synthetic strikes/expiry dates?
So for example, if "today" is February 6, 2017, and I get mass quote of the INTC option chain for the expiry's of February 17 2017, March 17 2017, April 14 2017 (etc), and for the sake of argument say the strikes in the mass quote are in $5 wide increments from 15 to 45, and I compute the IV surface for that mass quote for the market given expiry dates/strikes/prices (using some model), how do interpolate for a __synthetic__ expiry date and/or strike, say I want the IV and price for the "April 5, 2017, 39.33 strike call" option?
I see that QL support these interpolation methods, but I am unsure which to use or how to set up the problem to run the solver(s).
LinearInterpolation (1-D)
LogLinearInterpolation and LogCubicInterpolation (1-D)
BackwardFlatInterpolation (1-D)
ConvexMonotone (1-D)
CubicInterpolation (1-D)
ForwardFlatInterpolation (1-D)
SABRInterpolation (1-D)
BilinearInterpolation (2-D)
BicubicSpline (2-D)
[I probably don't want to use weekly's to interpolate in between. Probably only the monthly and quarterly expiration since I believe those prices especially the further out the expiry is.]
This is a similar problem as bootstraping a yield curve, except we are bootstraping on the dimension of strike/tenor between known values on the vol surface, to some given granularity. It is also interesting that we can see new values of NPV changes to an option by simulating changes the underlying value with no extra work [since the market data are stored in Quote instances and thus can notify the option when any of the parameters changes] and holding everything else constant. That the library does not support the same kind of "simulation" by turning the dial on strikes/tenor seems an omission. It is also an inverse problem, using different dimensions.
I need both American and European with/without dividends.
You create a Black volatility surface and let it interpolate.
At this time, the only class you have available to do this is the BlackVarianceSurface class. Its constructor takes a vector of exercise dates, a vector of strikes, and a matrix of corresponding volatilities. The matrix must be full, so you'll need to quote a volatility for each combination of exercise and strike. By default, it uses bilinear interpolation on variances; the method can be changed by calling
volSurface.setInterpolation<Bicubic>();
after construction.
Once you have built the surface, you can use it to get volatilities and prices. To get the volatility, ask the surface:
Volatility v = volSurface.blackVol(exerciseDate, strike);
will interpolate on the exercise date and strike and return the volatility. To get the price, pass the whole surface to an instance of a Black-Scholes process, pass the process to an engine and use the latter to price the option; the engine will pick the correct volatility for the given exercise and strike.
I would like to construct a spot curve from supplied bond prices. I know that the curve has to be constructed from dirty prices (i.e. the ones that include accrued interest). However, from FittedBondCurve.cpp example posted on quantlib.org, it appears that FixedRateBondHelper class is initialized with clean prices.
So, my question is: does it mean that FixedRateBondHelper takes care of computing accrued interest and converting clean price to dirty price? Or is it something that a user should do? I believe it's the former but wanted to make sure.
The helper doesn't, but the fitting algorithm does. If you look at the FittedBondDiscountCurve::FittingMethod::FittingCost::value method, you'll cringe a bit at the nested inner classes, but then you'll see that the model price is calculated by adding the discounted future cash flows and subtracting the accrued amount.
A further note: in recent releases, the bond helpers have been given the possibility to work with quoted dirty prices when bootstrapping a curve (see the last parameter of their constructors, useCleanPrice, which defaults to true but can be set to false to use dirty prices. However, the FittedBondDiscountCurve class is not yet aware of this change, and thus setting useCleanPrice to false would break the algorithm. I'll try to fix this in a future release.
I am trying to price a floating rate bond and I already have the discount curve built with quantlib on C++. Now what I would like to do is to use the FloatingRateBond class and create a set of cash flows where the first cash flow is known (given that the index associated to this cash flow was known at the last reset date) and forecasting the remaining cash flows using the current index.
To make it more graphical assume annual payments and that the index at the last reset date was 1% and that the reset margin is 1%. Then the first cash flow will be 2% roughly speaking. Now assume that today's index is 2%, then I want all the remaining cash flows to be 3% (with the proper adjustments from the Day Count convention and Business Day convention).
How can I create such a cash flow structure for an instance of the FloatingRateBond class?
First I'll go quickly through building the bond, copying some code from the bonds example in the QuantLib release (also, disclaimer: I haven't tried compiling the code below). For more details on the classes involved, see the QuantLib documentation.
Let's assume annual payments as you said:
Schedule schedule(startDate, maturityDate, Period(Annual),
calendar, convention, convention,
DateGeneration::Backward, true);
and for illustration, let's assume we'll use an USD Libor index. Its future fixing are forecast based on an interest-rate term structure we'll set later.
RelinkableHandle<YieldTermStructure> liborTermStructure;
boost::shared_ptr<IborIndex> libor(
new USDLibor(Period(1,Years),liborTermStructure));
Now build the bond, adding the margin as a spread on the LIBOR rate:
FloatingRateBond bond(settlementDays, faceAmount,
schedule, libor, dayCounter,
convention, fixingDays,
// gearings
std::vector<Real>(1, 1.0),
// spreads
std::vector<Rate>(1, 0.001));
Now to get the coupons you want, you'll just set the corresponding market data. To set the rate of the first cash flow, store the past fixing of the Libor index:
libor->addFixing(resetDate, 0.01);
And to set the future cash flows, create a flat interest-rate curve with the desired rate (minding the conventions so that they match those of the Libor index):
boost::shared_ptr<YieldTermStructure> flatRate(
new FlatForward(today, 0.01, dayCounter, Simple, Annual));
liborTermStructure.linkTo(flatRate);
(You're not necessarily limited to a flat rate; if you can bootstrap a Libor curve, you can use that one to get realistic estimates for future coupons.)
At this point, you should be able to extract the bond coupons and check that they're as expected:
std::vector<boost::shared_ptr<CashFlow> > cashflows = bond.cashflows();
for (std::size_t i=0; i < cashflows.size(); ++i)
std::cout << cashflows[i]->date() << " "
<< cashflows[i]->amount() << "\n";
If you also want to call methods such as bond.cleanPrice(), you'll need to tell the bond how to discount the cash flows:
RelinkableHandle<YieldTermStructure> discountingTermStructure;
boost::shared_ptr<PricingEngine> bondEngine(
new DiscountingBondEngine(discountingTermStructure));
bond.setPricingEngine(bondEngine);
You can use for discounting the same curve you're using for forecasting...
discountingTermStructure.linkTo(flatRate);
...or create and use a different one.