Fixing QuantLib Cap Construction by Setting Leg Notionals
Summary
This troubleshooting exchange concerns constructing an interest-rate cap in QuantLib C++. The example builds a floating leg from an Ibor index and attempts to create a cap, but runtime initialization fails because the leg has no notional. The author notes that the cap strike vector is intended to make the instrument at the money; that choice does not supply the missing leg notional.
The resolution is to set the notional when building the Ibor leg, using its notional-setting method, before passing the leg into the cap constructor. This is a narrow implementation fix rather than a guide to cap valuation: it does not cover curve setup, volatility handles, schedules, strike selection, or pricing engines. The exchange’s practical lesson is that a valid cap requires a floating leg configured with notionals, in addition to the strike information passed to the cap.
Key ideas
- A QuantLib cap requires its underlying floating leg to have a notional.
- Set the notional on the Ibor leg with its notional-setting method before constructing the cap.
- Providing a strike vector, even one chosen for an at-the-money cap, does not replace the leg notional.
- The example addresses object initialization and does not explain the full cap pricing setup.
Tags
Full text
# Quantlib error initializing CapFloor C++ Class
# Quantlib error initializing CapFloor C++ Class
I'd like to use QuantLib as a C++ library to price interest rate derivatives, in particular Cap&Floors. To semplify things a little, let's say I have a vector of EURLibor1Y rates for different maturities, which I called r, and a constant caplet volatility which I called vol. When ever I try to set up a Cap/Floor object using the following code
```
Volatility vol = 0.180253;
boost::shared_ptr<OptionletVolatilityStructure> vol_ptr = boost::make_shared<ConstantOptionletVolatility>(settlement,cal,ModifiedFollowing,vol,Actual360());
RelinkableHandle<OptionletVolatilityStructure> vol_handle(vol_ptr);
boost::shared_ptr<YieldTermStructure> curve = boost::make_shared<InterpolatedForwardCurve<LogLinear>>(dates,r,Actual360());
RelinkableHandle<YieldTermStructure> ts_handle(curve);
boost::shared_ptr<IborIndex> index = boost::make_shared<EURLibor1Y>(ts_handle);
IborLeg floatingLeg(schd,index);
Cap cap(floatingLeg,r);
```
I get a runtime error saying "terminate called after throwing an instance of 'QuantLib::Error' what(): no notional given", any idea how to fix this?
EDIT: In initializing the Cap I use the vector r because I want it to be ATM.
## Answer by Matteo Campagnoli (score 1, accepted)
https://quant.stackexchange.com/a/61199
Never mind, just found out the issue. The IborLeg class has a method called "withNotionals(Real)" used to set the notional value.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.