question on YieldTermStructure::forwardRate

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

question on YieldTermStructure::forwardRate

Whit Armstrong
I have a question on the forwardRate function of YieldTermStructure.

When I bootstrap a yield curve and calc the 5yr5yr forward rate using
the forwardRate function, it does not match the 'fairRate' calculated
from an actual VanillaSwap object using the same forward dates.

Is this expected, and if so, is there something I can do to my
forwardRate call to adjust the rate to match the par swap rate of the
forward dates?

See this link for an example which prints both rates.

The rate calculated from the forwardRate function is consistently
higher over historical dates (by about 1.5 bpts) than the rate
calculated by the fairRate function.

Any insight would be much appreciated.

-Whit


https://gist.github.com/armstrtw/8940881

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: question on YieldTermStructure::forwardRate

Nils Tobias Kramer
Hi Whit,

Maybe I'm misunderstanding you and I didn't look at the code.

FRA is a single forward rate calculated by two discount factors on the same curve and a swap par rate is a bit more complex to calculate. You have two curves to calculate, the first to get the forward rates and then a second to discount your cashflows. You can check wikipedia to see how the fair rate of a swap is calculated.

Toby

> On 11.02.2014, at 19:29, Whit Armstrong <[hidden email]> wrote:
>
> I have a question on the forwardRate function of YieldTermStructure.
>
> When I bootstrap a yield curve and calc the 5yr5yr forward rate using
> the forwardRate function, it does not match the 'fairRate' calculated
> from an actual VanillaSwap object using the same forward dates.
>
> Is this expected, and if so, is there something I can do to my
> forwardRate call to adjust the rate to match the par swap rate of the
> forward dates?
>
> See this link for an example which prints both rates.
>
> The rate calculated from the forwardRate function is consistently
> higher over historical dates (by about 1.5 bpts) than the rate
> calculated by the fairRate function.
>
> Any insight would be much appreciated.
>
> -Whit
>
>
> https://gist.github.com/armstrtw/8940881
>
> ------------------------------------------------------------------------------
> Android apps run on BlackBerry 10
> Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
> Now with support for Jelly Bean, Bluetooth, Mapview and more.
> Get your Android app in front of a whole new audience.  Start now.
> http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: question on YieldTermStructure::forwardRate

Whit Armstrong
Thanks, Toby.

What I really want to know is whether there is a more elegant way to
calculate the fairRate for the swap without having to build the whole
swap object (fixed schedule, float schedule, fakeNotional,
fakeCoupon).

All I really want to do is ask QL,
given this discount curve, and these conventions (Semi, vs 3mL) what
is the fair rate of the swap?

I realize that building out the swap is in fact giving QL the
definitive conventions, but it all seems a bit cumbersome to build a
swap w/ a fake coupon, just to pull the 'fairRate' back out of it.

-Whit


On Tue, Feb 11, 2014 at 2:08 PM, Nils Tobias Kramer
<[hidden email]> wrote:

> Hi Whit,
>
> Maybe I'm misunderstanding you and I didn't look at the code.
>
> FRA is a single forward rate calculated by two discount factors on the same curve and a swap par rate is a bit more complex to calculate. You have two curves to calculate, the first to get the forward rates and then a second to discount your cashflows. You can check wikipedia to see how the fair rate of a swap is calculated.
>
> Toby
>
>> On 11.02.2014, at 19:29, Whit Armstrong <[hidden email]> wrote:
>>
>> I have a question on the forwardRate function of YieldTermStructure.
>>
>> When I bootstrap a yield curve and calc the 5yr5yr forward rate using
>> the forwardRate function, it does not match the 'fairRate' calculated
>> from an actual VanillaSwap object using the same forward dates.
>>
>> Is this expected, and if so, is there something I can do to my
>> forwardRate call to adjust the rate to match the par swap rate of the
>> forward dates?
>>
>> See this link for an example which prints both rates.
>>
>> The rate calculated from the forwardRate function is consistently
>> higher over historical dates (by about 1.5 bpts) than the rate
>> calculated by the fairRate function.
>>
>> Any insight would be much appreciated.
>>
>> -Whit
>>
>>
>> https://gist.github.com/armstrtw/8940881
>>
>> ------------------------------------------------------------------------------
>> Android apps run on BlackBerry 10
>> Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
>> Now with support for Jelly Bean, Bluetooth, Mapview and more.
>> Get your Android app in front of a whole new audience.  Start now.
>> http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
>> _______________________________________________
>> QuantLib-users mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: question on YieldTermStructure::forwardRate

Peter Caspers-4
Hi,
   I think you can use SwapIndex::fixing(...) for this.
best regards, Peter

On 11 February 2014 20:27, Whit Armstrong <[hidden email]> wrote:

> Thanks, Toby.
>
> What I really want to know is whether there is a more elegant way to
> calculate the fairRate for the swap without having to build the whole
> swap object (fixed schedule, float schedule, fakeNotional,
> fakeCoupon).
>
> All I really want to do is ask QL,
> given this discount curve, and these conventions (Semi, vs 3mL) what
> is the fair rate of the swap?
>
> I realize that building out the swap is in fact giving QL the
> definitive conventions, but it all seems a bit cumbersome to build a
> swap w/ a fake coupon, just to pull the 'fairRate' back out of it.
>
> -Whit
>
>
> On Tue, Feb 11, 2014 at 2:08 PM, Nils Tobias Kramer
> <[hidden email]> wrote:
>> Hi Whit,
>>
>> Maybe I'm misunderstanding you and I didn't look at the code.
>>
>> FRA is a single forward rate calculated by two discount factors on the same curve and a swap par rate is a bit more complex to calculate. You have two curves to calculate, the first to get the forward rates and then a second to discount your cashflows. You can check wikipedia to see how the fair rate of a swap is calculated.
>>
>> Toby
>>
>>> On 11.02.2014, at 19:29, Whit Armstrong <[hidden email]> wrote:
>>>
>>> I have a question on the forwardRate function of YieldTermStructure.
>>>
>>> When I bootstrap a yield curve and calc the 5yr5yr forward rate using
>>> the forwardRate function, it does not match the 'fairRate' calculated
>>> from an actual VanillaSwap object using the same forward dates.
>>>
>>> Is this expected, and if so, is there something I can do to my
>>> forwardRate call to adjust the rate to match the par swap rate of the
>>> forward dates?
>>>
>>> See this link for an example which prints both rates.
>>>
>>> The rate calculated from the forwardRate function is consistently
>>> higher over historical dates (by about 1.5 bpts) than the rate
>>> calculated by the fairRate function.
>>>
>>> Any insight would be much appreciated.
>>>
>>> -Whit
>>>
>>>
>>> https://gist.github.com/armstrtw/8940881
>>>
>>> ------------------------------------------------------------------------------
>>> Android apps run on BlackBerry 10
>>> Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
>>> Now with support for Jelly Bean, Bluetooth, Mapview and more.
>>> Get your Android app in front of a whole new audience.  Start now.
>>> http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
>>> _______________________________________________
>>> QuantLib-users mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
> ------------------------------------------------------------------------------
> Android apps run on BlackBerry 10
> Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
> Now with support for Jelly Bean, Bluetooth, Mapview and more.
> Get your Android app in front of a whole new audience.  Start now.
> http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: question on YieldTermStructure::forwardRate

Whit Armstrong
Peter,

Thanks for the post.

It is interesting.

'fixing' is implemented in InterestRateIndex:
https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/indexes/interestrateindex.cpp#L61

which actually calls the method 'forecastFixing,' which is defined here:
https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/indexes/swapindex.cpp#L78

'forecastFixing' is simply: return underlyingSwap(fixingDate)->fairRate();

and the 'underlyingSwap' method (defined here):
https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/indexes/swapindex.cpp#L83

is just a call to the helper class: MakeVanillaSwap
https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/makevanillaswap.cpp#L31

which does just what one would expect, it makes a swap.

So, in the end it looks like SwapIndex is just doing the swap
construction for us and returning the fixing which is what I was doing
in my code already.

One thing I don't understand about MakeVanillaSwap, why does it need
to make assumptions about the fixedDayCount based on the currency of
the IborIndex?
https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/makevanillaswap.cpp#L112

Lastly, can someone point me to where the actual code for the
'fairRate' calculation is defined?

In VanillaSwap, it's just a call to 'calculate' and return the member
variable (which presumably the caculate function has populated):
https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/vanillaswap.cpp#L138

However, at this point I get lost trying to find how the 'calculate'
from LazyObject relates to the swap object.

Again, thanks for your help.

-Whit

On Wed, Feb 12, 2014 at 4:12 AM, Peter Caspers <[hidden email]> wrote:

> Hi,
>    I think you can use SwapIndex::fixing(...) for this.
> best regards, Peter
>
> On 11 February 2014 20:27, Whit Armstrong <[hidden email]> wrote:
>> Thanks, Toby.
>>
>> What I really want to know is whether there is a more elegant way to
>> calculate the fairRate for the swap without having to build the whole
>> swap object (fixed schedule, float schedule, fakeNotional,
>> fakeCoupon).
>>
>> All I really want to do is ask QL,
>> given this discount curve, and these conventions (Semi, vs 3mL) what
>> is the fair rate of the swap?
>>
>> I realize that building out the swap is in fact giving QL the
>> definitive conventions, but it all seems a bit cumbersome to build a
>> swap w/ a fake coupon, just to pull the 'fairRate' back out of it.
>>
>> -Whit
>>
>>
>> On Tue, Feb 11, 2014 at 2:08 PM, Nils Tobias Kramer
>> <[hidden email]> wrote:
>>> Hi Whit,
>>>
>>> Maybe I'm misunderstanding you and I didn't look at the code.
>>>
>>> FRA is a single forward rate calculated by two discount factors on the same curve and a swap par rate is a bit more complex to calculate. You have two curves to calculate, the first to get the forward rates and then a second to discount your cashflows. You can check wikipedia to see how the fair rate of a swap is calculated.
>>>
>>> Toby
>>>
>>>> On 11.02.2014, at 19:29, Whit Armstrong <[hidden email]> wrote:
>>>>
>>>> I have a question on the forwardRate function of YieldTermStructure.
>>>>
>>>> When I bootstrap a yield curve and calc the 5yr5yr forward rate using
>>>> the forwardRate function, it does not match the 'fairRate' calculated
>>>> from an actual VanillaSwap object using the same forward dates.
>>>>
>>>> Is this expected, and if so, is there something I can do to my
>>>> forwardRate call to adjust the rate to match the par swap rate of the
>>>> forward dates?
>>>>
>>>> See this link for an example which prints both rates.
>>>>
>>>> The rate calculated from the forwardRate function is consistently
>>>> higher over historical dates (by about 1.5 bpts) than the rate
>>>> calculated by the fairRate function.
>>>>
>>>> Any insight would be much appreciated.
>>>>
>>>> -Whit
>>>>
>>>>
>>>> https://gist.github.com/armstrtw/8940881
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Android apps run on BlackBerry 10
>>>> Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
>>>> Now with support for Jelly Bean, Bluetooth, Mapview and more.
>>>> Get your Android app in front of a whole new audience.  Start now.
>>>> http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
>>>> _______________________________________________
>>>> QuantLib-users mailing list
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>>
>> ------------------------------------------------------------------------------
>> Android apps run on BlackBerry 10
>> Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
>> Now with support for Jelly Bean, Bluetooth, Mapview and more.
>> Get your Android app in front of a whole new audience.  Start now.
>> http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
>> _______________________________________________
>> QuantLib-users mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: question on YieldTermStructure::forwardRate

Peter Caspers-4
Hi Whit,

> One thing I don't understand about MakeVanillaSwap, why does it need
> to make assumptions about the fixedDayCount based on the currency of
> the IborIndex?
> https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/instruments/makevanillaswap.cpp#L112

If you do not provide a fixed leg day counter, it is guessed from the
currency. That's all I think, just some
intelligence built into the library.

> Lastly, can someone point me to where the actual code for the
> 'fairRate' calculation is defined?

In the end it is in vanillaswap.cpp, line 196 where it is derived from
results provided by the
DiscountingSwapEngine associated to the VanillaSwap created before.

Best regards
Peter

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users