Posted by
SourceForge.net on
Sep 12, 2003; 4:37am
URL: http://quantlib.414.s1.nabble.com/quantlib-Feature-Requests-804600-Getting-maturity-date-for-a-swap-tp10350.html
Feature Requests item #804600, was opened at 2003-09-11 17:49
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=362740&aid=804600&group_id=12740Category: None
Group: None
Status: Open
Priority: 5
Submitted By: navin mehta (navin_mehta)
Assigned to: Nobody/Anonymous (nobody)
Summary: Getting maturity date for a swap
Initial Comment:
There is not an easy way to get the start date of a
swap,given a swap object.
It will be highly appreciated if you can please provide a
public method for the same in the Swap/Simpleswap
object.
Thanks!
BTW, I use a temporary workaround macro for this:
#define SWAPSTARTDATE(swap) ((const
CashFlows::Coupon*)&(*(swap->fixedLeg())[0]))-
>accrualStartDate()
where swap is a Swap object.
Other method as suggested by Luigi:
--------------------------------
#include <ql/Instruments/swap.hpp>
#include <ql/CashFlows/coupon.hpp>
namespace QuantLib {
namespace Instruments {
/* This class below inherits from Swap in order to
gain access
to its protected members.
Don't try this kind of hacks at home.
Oh, and did I mention this isn't tested?
*/
class SwapInspector : public Swap {
private:
// we don't really want to instantiate this
SwapInspector()
: Swap(std::vector<Handle<CashFlow> >(),
std::vector<Handle<CashFlow> >(),
RelinkableHandle<TermStructure>()) {}
public:
// return the start date of the first coupon
static Date startDate(const Swap& swap) {
// get the first cash flow
Handle<CashFlow> firstCF =
swap.firstLeg_.front();
try {
// is this a coupon?
Handle<CashFlows::Coupon> coupon =
firstCF;
// ok, return its start date
return coupon.accrualStartDate();
} catch (Error&) {
// it was not a coupon. We'll doctor the
// error message to make it more
readable.
throw Error("The swap coupons did not
provide "
"enough information");
}
}
// return the end date of the last coupon
static Date endDate(const Swap& swap) {
Handle<CashFlow> lastCF =
swap.firstLeg_.back();
try {
Handle<CashFlows::Coupon> coupon =
lastCF;
return coupon.accrualEndDate();
} catch (Error&) {
throw Error("The swap coupons did not
provide "
"enough information");
}
}
};
}
}
Given a swap object, how can I get the start date and
length
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=362740&aid=804600&group_id=12740