Hi Nando,
suggested changes below & attached.
in /instruments/capfloor.hpp
after line 104:
//! Returns the i'th optionlet as a new CapFloor with only one cash flow.
boost::shared_ptr<CapFloor> optionlet(const Size i) const;
in /instruments/capfloor.cpp
after line 160:
boost::shared_ptr<CapFloor> CapFloor::optionlet(const Size i) const {
QL_REQUIRE(i < leg().size(), "optionlet " << i << " does not exist, only " << leg().size());
Leg
cashflowi;
cashflowi.push_back(leg()[i]);
boost::shared_ptr<CapFloor> optionleti;
if (type() == Cap) {
std::vector<Rate> capRatei;
capRatei.push_back(capRates()[i]);
optionleti = boost::shared_ptr<CapFloor>(new CapFloor(type(), cashflowi, capRatei) );
} else if (type() == Floor) {
std::vector<Rate> floorRatei;
floorRatei.push_back(floorRates()[i]);
optionleti = boost::shared_ptr<CapFloor>(new CapFloor(type(), cashflowi, floorRatei) );
} else {
std::vector<Rate> capRatei;
capRatei.push_back(capRates()[i]);
std::vector<Rate> floorRatei;
floorRatei.push_back(floorRates()[i]);
optionleti = boost::shared_ptr<CapFloor>(new CapFloor(type(), cashflowi,
capRatei,
floorRatei) );
}
return optionleti;
}
I've added to testConsistency() as well (checks that sum of optionlet NPV's is the same as the original NPV). This is a bit longer so I've attached the file.
Regards,
Chris
-----
Original Message ----
From: Chris Kenyon <
[hidden email]>
To: Ferdinando Ametrano <
[hidden email]>
Cc:
[hidden email]Sent: Friday, March 7, 2008 11:37:39 AM
Subject: Re: [Quantlib-dev] add .asOptionlet() to MakeCapFloor ?
Hi Nando,
I like your second suggestion - simple and addresses an equivalent issue directly (getting the n-th caplet), avoids market convention issues, and avoids doing something awkward (forward starts). The output should still be a capfloor, but with just one cashflow. I can put a patch together or would you like to?
Regards,
Chris
----- Original Message ----
From: Ferdinando Ametrano <
[hidden email]>
To: Chris Kenyon <
[hidden email]>
Cc:
[hidden email]Sent: Friday, March 7, 2008 11:15:12 AM
Subject: Re: [Quantlib-dev] add .asOptionlet() to
MakeCapFloor ?
Hi Chris,not sure I get your point.
Couldn't you obtain the same result just using the standard constructor: MakeCapFloor(CapFloor::Type capFloorType,
const Period& capFloorTenor, const boost::shared_ptr<IborIndex>& iborIndex,
Rate strike = Null<Rate>(), const Period& forwardStart = 0*Days);
E.g. let's assume you want the last caplet in a 3Y cap on 6M ibor rate:
MakeCapFloor(Cap, 6*Months, my6mIborIndex, myStrike, 30*Months);
If this is not equivalent because of market conventions used in the 30M fwd start swap calculation, then I still have another point.
To obtain the sequence of distinct caplets contained in a standard cap, we could have something like CapFloor::optionlet(Size i) instead: this would allow to create just one single cap and to extract all caplets from it, avoiding multiple redundant cap creations
I look forward to your feedback
ciao -- NandoOn Fri, Mar 7, 2008 at 11:35 AM, Chris Kenyon <[hidden email]> wrote:
> > Hi,
> > this would make life easier. Effect: only the last cashflow is returned.
> The extra code could be something like:>
> In .hpp after line 66>
> //! Only get last coupon, i.e. get caplet version of cap > //! or floorlet version of floor, etc.
> MakeCapFloor& asOptionlet();>
> Also before closing };>
> bool asOptionlet_;>
> In .cpp after line 38 in constructor (and before {}):>
> asOptionlet_(false) >
> after new line 53>
> //! only leaves the last coupon> if (asOptionlet_ && leg.size()>1)
> leg.erase(leg.begin(), --leg.end());>
> Best regards,> Chris
> > > -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________> QuantLib-dev mailing list
> [hidden email]> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
> >