LogLinear interpolation

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

LogLinear interpolation

Andre Louw-2
Nando,

I just checked out loglinearinterpolation and noted the change you
implemented. I have a comment.

Correct me if i'm wrong, but I see you are using linear interpolation on
cont. compounded rates to get to the resulting discount factor i.o.w:

        cf1 = ln(df1), cf2 = ln(df2)
        dfx = exp(cf1+((tx-t1)/(t2-t1))*(cf2-cf1)))

I implemented loglinear interpolation to get to the result i.o.w:

        dfx = (df1^(tx/t1*(t2-tx)/(t2-t1)))*(df2^(tx/t2*(tx-t1)/(t2-t1)))

Not quite the same thing.

If that is your institution's standard, fine, but could I then rename your
implementation as contcomplinearinterpolation.hpp (or some such name), as I
see the original implementation being log-linear interpolation? We could the
implement a mechanism in DiscountCurve to distinguish which to use?

I had a problem with the original implementation between t1 = 0 and some tx
which I solved by testing for this condition and calculating dfx:
        dfx = 1/1+((1/df2-1)/t2)*tx

Comments?

Andre


 
-------------------------------------------------------------------------
This e-mail is intended only for the use of the individual or entity named
above and may contain information that is confidential and privileged,
proprietary to the company and protected by law. If you are not the intended
recipient, you are hereby notified that any dissemination, distribution or
copying of this e-mail is strictly prohibited. Opinions, conclusions and
other information in this message that do not relate to the official
business of our company shall be understood as neither given nor endorsed by
it.


Reply | Threaded
Open this post in threaded view
|

Re: LogLinear interpolation

Luigi Ballabio-4
Hi Andre,
         forget me for jumping in, but I got interested...

At 01:25 PM 6/26/02 +0200, Andre Louw wrote:
>Correct me if i'm wrong, but I see you are using linear interpolation on
>cont. compounded rates to get to the resulting discount factor i.o.w:
>
>         cf1 = ln(df1), cf2 = ln(df2)
>         dfx = exp(cf1+((tx-t1)/(t2-t1))*(cf2-cf1)))

Personally, I didn't see the above as cont. compounded rates (shouldn't
they be ln(df1)/t1 anyway?)
I had figured it as "linear interpolation on the logarithms of the discounts"
which, I assumed, was the definition Nando took of "loglinear".


>I implemented loglinear interpolation to get to the result i.o.w:
>
>         dfx = (df1^(tx/t1*(t2-tx)/(t2-t1)))*(df2^(tx/t2*(tx-t1)/(t2-t1)))
>
>Not quite the same thing.

Well, almost :)
Nando's formula can be transformed to

         dfx = (df1^((t2-tx)/(t2-t1)))*(df2^((tx-t1)/(t2-t1)))

Moreover, it can be transformed to

         dfx = df1*(df2/df1)^((tx-t1)/(t2-t1))

or

         ln(dfx)-ln(df1)   ln(df2)-ln(df1)
         --------------- = ---------------
              tx-t1             t2-t1

which is not a direct one but best expresses the intent...


>If that is your institution's standard, fine, but could I then rename your
>implementation as contcomplinearinterpolation.hpp (or some such name), as I
>see the original implementation being log-linear interpolation?

I think it's just a matter of deciding what's what.
<asking just out of ignorance>
What is your definition of "loglinear"? In plain english, I mean?
</asking just out of ignorance>


>We could the implement a mechanism in DiscountCurve to distinguish which
>to use?

Sure:

template <class Interpolation>
class DiscountCurve {
    ...
};

Bye,
         Luigi



Reply | Threaded
Open this post in threaded view
|

Re: LogLinear Interpolation

Andre Louw-2
In reply to this post by Andre Louw-2
Luigi,

Disregard my previous rant. I got my facts a bit mixed up.

Nando's implementation of log-linear interpolation is quite correct. What
had me confused is that I remember it (parrot wise) as:
        dfx = df1*((df2/df1)^((t3-t1)/(t2-t1))), which, alas, as you pointed
out matches Nando's!

Sorry for the confusion, I will in any case implement a linear interpolation
on continuos compounding.

Could you give me a bit more on how one would go about giving DiscountCurve
the ability to distinguish which to use?

Andre



 
-------------------------------------------------------------------------
This e-mail is intended only for the use of the individual or entity named
above and may contain information that is confidential and privileged,
proprietary to the company and protected by law. If you are not the intended
recipient, you are hereby notified that any dissemination, distribution or
copying of this e-mail is strictly prohibited. Opinions, conclusions and
other information in this message that do not relate to the official
business of our company shall be understood as neither given nor endorsed by
it.


Reply | Threaded
Open this post in threaded view
|

Re: LogLinear interpolation

Ferdinando M. Ametrano-2
In reply to this post by Andre Louw-2
Hi all

Andre Louw wrote:
>Correct me if i'm wrong, but I see you are using linear interpolation on
>cont. compounded rates to get to the resulting discount factor
As Luigi pointed out I implemented a linear interpolation on the logarithm
of the discounts. The logarithm of a discount is not the continuos
compounded rate r, but -r*t.

Anyway for sake of clarity let's talk before about interpolation in
general, with no reference to discount and rates. So the LogLinear
interpolation I implemented is a linear interpolation on {Xi}, {LOG(Yi(Xi))}

>I implemented loglinear interpolation to get to the result i.o.w:
>
>         dfx = (df1^(tx/t1*(t2-tx)/(t2-t1)))*(df2^(tx/t2*(tx-t1)/(t2-t1)))
>
>Not quite the same thing.
Not quite the same thing indeed. I might be wrong but your formula is quite
similar to "geometric interpolation" dfx =
(df1^((t2-tx)/(t2-t1)))*(df2^((tx-t1)/(t2-t1))).
The problem with your original formula is that is undefined at t1==0.0 and
t2==0.0
We could add to the CVS your original code as XXXinterpolation.hpp, but I
would require to handle the t==0.0 case. When I decided to rewrite
LogLinear interpolation I didn't got it was geometric interpolation, I just
noticed that as interpolation it had problem at t=0.0

>>We could the implement a mechanism in DiscountCurve to distinguish which
>>to use?
>
>Sure:
>
>template <class Interpolation>
>class DiscountCurve {
>    ...
>};
I'm not happy about this approach since it will allow some really bad
interpolation choice, anyway since QuantLib users are supposed to be smart
... it's OK for me.
If we go this way it should be clear here that it's a must for
geometricinterpolation to handle t==0.0, or the discount near t=0.0 will be
screwed up.

Andre, I'm sorry if my changes broke some functionality you were relying
upon, but in a previous email last week-end I asked about it:
>3) I fixed 2 bugs in DiscountCurve, but I still have problems with
>calculations between settlementDate and the first knot date, probably due
>to some problem in LogLinearInterpolation. Have someone ever used this
>classes? Do they work for you?
The bugs were pointed object lifetime issues, while I realized now that the
problem with the LogLinearInterpolation was just that geometric
interpolation was undefined at t=0.0

ciao -- Nando




Reply | Threaded
Open this post in threaded view
|

RE: LogLinear interpolation

Andre Louw-2
In reply to this post by Andre Louw-2
Nando,

> I might be wrong but your formula is quite similar to "geometric
interpolation"
dfx = (df1^((t2-tx)/(t2-t1)))*(df2^((tx-t1)/(t2-t1))).
I think you're right, I actually got this from some existing code and
implemented it as is. Will delve a bit deeper to get to it's origin!

> We could add to the CVS your original code as
> XXXinterpolation.hpp, but I
> would require to handle the t==0.0 case.
Don't bother, I would prefer to use loglinear.

> I'm not happy about this approach since it will allow some really bad
> interpolation choice, anyway since QuantLib users are
> supposed to be smart
> ... it's OK for me.
> If we go this way it should be clear here that it's a must for
> geometricinterpolation to handle t==0.0, or the discount near
> t=0.0 will be
> screwed up.
O.K

> Andre, I'm sorry if my changes broke some functionality you
> were relying
> upon, but in a previous email last week-end I asked about it:

That's actually what sparked me to check out the latest version from CVS.

Sorry again for the confusion, check my other e-mail.

Andre
 
-------------------------------------------------------------------------
This e-mail is intended only for the use of the individual or entity named
above and may contain information that is confidential and privileged,
proprietary to the company and protected by law. If you are not the intended
recipient, you are hereby notified that any dissemination, distribution or
copying of this e-mail is strictly prohibited. Opinions, conclusions and
other information in this message that do not relate to the official
business of our company shall be understood as neither given nor endorsed by
it.


Reply | Threaded
Open this post in threaded view
|

Re: LogLinear Interpolation

Luigi Ballabio-4
In reply to this post by Andre Louw-2
At 01:05 PM 6/27/02 +0200, Andre Louw wrote:
>Disregard my previous rant. I got my facts a bit mixed up.

I know the feeling. And vacations are still sooo far away...


>Could you give me a bit more on how one would go about giving DiscountCurve
>the ability to distinguish which to use?

Sure. Modifying DiscountCurve so that it can use different interpolations
in easy enough: you just have to declare it as:

     template <class DfInterpolation>
     class DiscountCurve : public DiscountStructure {
         ... blah blah ...
         // typedef Math::LogLinearInterpolation <     remove this typedef!!
         // std::vector < Time >::const_iterator,
         // std::vector < double >::const_iterator > DfInterpolation;
         Handle < DfInterpolation > interpolation_;
     };

on the other hand, the instantiation would be kind of clumsy as one would
be forced to write:

     DiscountCurve<LogLinearInterpolation <
         std::vector<Time>::const_iterator,
         std::vector<double>::const_iterator > > curve(...);

Then again, we could provide a few typedefs such as:

     typedef DiscountCurve<LogLinearInterpolation <
         std::vector<Time>::const_iterator,
         std::vector<double>::const_iterator > > LogLinearDiscountCurve;

so that the instantiation would be written as:

     LogLinearDiscountCurve curve(...);


Also, I'm sure that there's some other syntax one could use so that one
could instantiate the curve as

     DiscountCurve<LogLinearInterpolation> curve(...);

but a) I don't remember it so I have to dig it out and b) I'm not sure that
all compiler will allow it.

I'll do my homework and come back.

Later,
         Luigi



Reply | Threaded
Open this post in threaded view
|

RE: LogLinear interpolation

Luigi Ballabio-4
In reply to this post by Andre Louw-2
At 3:12 PM +0200 6/27/02, Andre Louw wrote:
>Nando,
>
>>  I might be wrong but your formula is quite similar to "geometric
>interpolation"
>dfx = (df1^((t2-tx)/(t2-t1)))*(df2^((tx-t1)/(t2-t1))).
>I think you're right, I actually got this from some existing code and
>implemented it as is. Will delve a bit deeper to get to it's origin!

(posting it again since the mail didn't seem to go through...)

Nando, you can call the above "geometric interpolation" if you want,
but it's actually the same formula you used for loglinear
interpolation :)

(not very surprising, actually. I think "geometric" means
interpolating y vs exp(x), while "loglinear" means interpolating
log(y) vs x...)

Bye,
        Luigi (which doesn't feel like reusing the closing quip he
already put into the mail that sourceforge is holding. Computers. Bah)



Reply | Threaded
Open this post in threaded view
|

Re: Re: LogLinear interpolation

Luigi Ballabio-4
In reply to this post by Ferdinando M. Ametrano-2
At 01:29 PM 6/27/02 +0200, Ferdinando Ametrano wrote:
>Not quite the same thing indeed. I might be wrong but your formula is
>quite similar to "geometric interpolation"
>     dfx = (df1^((t2-tx)/(t2-t1)))*(df2^((tx-t1)/(t2-t1))).

Which is exactly the same as your loglinear formula.


Playing the devil's advocate and loving it,

                 Luigi