FixedLeg duration of vanilla swap

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

FixedLeg duration of vanilla swap

suhasg
How does one go about calculating the modified duration of the fixed leg? Following the swapvaluation.cpp example, I can calculate the NPV by
 
NPV = spot5YearSwap.NPV();

I guess at this point I could get hold of the fixed leg as bunch of cashflows.

const std::vector<boost::shared_ptr<QuantLib::CashFlow> >& leg = spot5YearSwap.fixedLeg();

Now I am stumped, after looking at bind examples, I know I nned to use CashFlows::Duration here but I can not figure out how to "convert" my fixedleg to a fixedratebond, or what to pass for the yield parameter to duration.

It would have been nice if the fixedLeg contained methods to output analytics as well.
Thanks for your help.
Reply | Threaded
Open this post in threaded view
|

Re: FixedLeg duration of vanilla swap

Luigi Ballabio

On Jun 2, 2011, at 8:10 PM, Pointman wrote:

>
> How does one go about calculating the modified duration of the fixed  
> leg?
> Following the swapvaluation.cpp example, I can calculate the NPV by
>
> NPV = spot5YearSwap.NPV();
>
> I guess at this point I could get hold of the fixed leg as bunch of
> cashflows.
>
> const std::vector<boost::shared_ptr<QuantLib::CashFlow> >& leg =
> spot5YearSwap.fixedLeg();
>
> Now I am stumped, after looking at bind examples, I know I nned to use
> CashFlows::Duration here but I can not figure out how to "convert" my
> fixedleg to a fixedratebond, or what to pass for the yield parameter  
> to
> duration.

I think you can use CashFlows::yield to obtain a yield given the NPV  
you found.  Once you have that, you can call CashFlows::duration.

Luigi


------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users