C++ Quantlib Vanilla Swap: setting future fixing dates and gearing for floating leg - c++

Is it possible for user to change the future fixing dates and gearing of the floating leg in Quantlib?
First, when Quantlib calculate the NPV for floating leg, it will go into couponpricer.hpp to call inline function BlackIborCouponPricer::swapletPrice(). Inside this function, there is a parameter called gearing_. This parameter is automatically setting to 1 in my case. If I need to change this to other value, say 0.8, where shall I make this change?
Second, all my future fixing dates are the same as the date vector generated in floating leg schedule. i.e. fixing dates are the same as accrual period starting dates. Is it possible to change these fixing dates to be different from the accrual period starting dates, say 2 business days before accrual starting dates subject to normal business day convention adjustment? Alternatively, is it possible for me to pass a date vector to store these fixing dates?
Many thanks.

VanillaSwap doesn't take gearings as a constructor argument (I guess the idea was to keep it simple). Instead, you can create the fixed and floating legs separately using the FixedLeg and IborLeg classes and pass them to a Swap instance. You can see an example of that in SwapTest::testInArrears(), in the test-suite/swap.cpp file.
As for the fixing dates: when you build the IborIndex instance to be passed to IborLeg, you can pass a number of fixing days to its constructor. If you're using the available indexes such as Euribor or USDLibor, though, they already use 2 fixing days (as well as the correct calendar and business-day convention).

Related

How to automatically feed a cell value from a range of values, based on its matching condition with other cell value

I'm making a time-spending tracker based on the work I do every hour of the day.
Now, suppose I have 28 types of work listed in my tracker (which I also have to increase from time to time), and I have about 8 significance values that I have decided to relate to these 28 types of work, predefined.
I want that, as soon as I enter a type of work in cell 1 - I want the adjacent cell 2 to get automatically populated with a significance value (from a range of 8 values) that is pre-definitely set by me.
Every time I input a new or old occurrence of a type of work, the adjacent cell should automatically get matched with its relevant significance value & automatically get populated in real-time.
I know how to do it using IF, IFS, and IF_OR conditions, but I feel that based on the ever-expanding types of work & significance values, the above formulas will be very big, complicated, and repetitive in the future. I feel there's a more efficient way to achieve it. Also, I don't want it to be selected from a drop-down list.
Guys, please help me out with the most efficient way to handle this. TUIA :)
Also, I've added a snapshot and a sample sheet describing the problem.
Sample sheet
XLOOKUP() may work. Try-
=XLOOKUP(D2,A2:A,B2:B)
Or FILTER() function like-
=FILTER(B2:B,A2:A=D2)
You can use this formula for a whole column:
=INDEX(IFERROR(VLOOKUP(C14:C,A2:B9,2,0)))
Adapt the ranges to your actual tables in order to include in the second argument all the potential values and their significances
This is the formula, that worked for me (for anybody's reference):
I created another reference sheet, stating the types of work & their significance. From that sheet, I'm using either vlookup, filter, xlookup.Using gforms for inputting my data.
=ARRAYFORMULA(IFS(ROW(D:D)=1,"Significance",A:A="","",TRUE,VLOOKUP(D:D,Reference!$A:$B,2,0)))

Matched-maturity vanilla swap in Quantlib

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.

clean or dirty price for FixedRateBondHelper

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.

Quantlib USDLibor, how does it knows which is the correct fixing date?

When pricing floating rate bonds, one needs to work with instances of the USDLibor class and adding new fixings given a date (which is equivalent to the last reset date minus two business days). However, sometimes it complaints on runtime telling the user that the fixing for a specified date is not available (meaning that one has provided the fixing for a wrong date).
How do instances of USDLibor know which is correct date? I ask this because maybe I can sort this problem by retrieving the correct date directly as USDLibor gets it working around the problem of figuring out the correct date.
The fixing date is two business days before the reset date, as you said (the implementation of the logic is in the FloatingRateCoupon::fixingDate() method, if you want to check it).
However, you might be using the wrong business days. USD LIBOR is fixed in London, so holidays are determined according to the UK calendar, not the US calendar.
In any case, once you have built the bond, you can ask the cashflows themselves for their fixings dates with something like this (which I haven't tested, so it might not even compile, but you should get the idea):
using namespace QuantLib;
Leg cashflows = bond.cashflows();
std::vector<Date> fixingDates;
for (Size i=0; i<cashflows.size(); ++i) {
boost::shared_ptr<FloatingRateCoupon> coupon =
boost::dynamic_pointer_cast<FloatingRateCoupon>(cashflows[i]);
if (coupon)
fixingDates.append(coupon->fixingDate());
}
after which the fixingDates vector will contain (not surprisingly) the fixing dates.

c++ function -- which date is first / last?

One of my c++ function does some calculations based off of the values of other variables. The program asks for a bunch of information including start date and end date for 2 separate events.
p1.start_date and p2.start_date; p1.end_date and p2.end_date each of which have a day, month and year stored inside.
I need to set combined.start_date to which happens earlier (p1.start_date or p2.start_date) and I need to set combined.end_date to which happens later.
Could I please have some help in getting this started? Here is what I have now: http://pastebin.com/huJprtHj.
At least assuming the dates involved are reasonably current1, stuff the month/day/year into a struct tm and use mktime to convert to a timt_t, then you can compare the two time_ts directly.
If you need/want to support a wider range of dates, you might consider Ray Gardner's Julian Date routines.
At least in a typical case, dates from 1970 to at least 2038 will work.
Generally, calculations based on dates can be done in two ways.
Convert the date into a "number of days since some fixed date (e.g. 1 Jan 1970)".
Use the date components (year, month, day).
If this is all you need to do, just comparing each part (with the "highest first") will work just fine - you just need a compare function that can tell you if date1 is less than date2.
The rest of your question should be really simple programming.
Edit: to clarify: For DATE calculations, days from a set date is fine. The system library functions have functions that use seconds [and in some systems, fractions of a second] for a complete time down to seconds. This is not required for comparing dates where a the time of day is not involved.
Make this function. I'm guessing that your dates are stored in an object named Date, since you don't specify.
bool operator< ( const Date& left, const Date &right )
{
// ...
}
Then you can compare your date objects the same as if they were built-in types like int.