Which methods to expose to access Discount/FwdRate?

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

Which methods to expose to access Discount/FwdRate?

newbie73
I want to use the Short Rate models to generate spot curves / forward curves in discount factors and also in yields.  Currently I am unable to access the discount function that is a part of the ShortRateTree class and the OneFactorAffineModel class.

Am I looking in the wrong place for this?  I'm attempting to access this info by accessing some method that is a part of the ShortRateModel class.  I'd like to do this:  SwapRate(t) -> swap rate or Discount(t) -> discount factor

Any ideas on where to look to be able to do this?
Reply | Threaded
Open this post in threaded view
|

Re: Which methods to expose to access Discount/FwdRate?

Luigi Ballabio
On Fri, 2007-09-14 at 17:50 -0700, newbie73 wrote:
> I want to use the Short Rate models to generate spot curves / forward curves
> in discount factors and also in yields.  Currently I am unable to access the
> discount function that is a part of the ShortRateTree class and the
> OneFactorAffineModel class.

Hi,
        those methods are not exported in the C# bindings (is that what you're
using, right?) In order to export them, you'll have to add them to the
SWIG interface files and regenerate the wrappers. For instance, you'll
have to go to the definition of the Hull-White model in
shortratemodels.i and add inside the %extend block the following:

DiscountFactor discount(Time t) const {
    return boost::dynamic_pointer_cast<HullWhite>(*self)->discount(t);
}

Luigi


--

The wisdom of the wise and the experience of the ages are perpetuated
by quotations.
-- Benjamin Disraeli



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Which methods to expose to access Discount/FwdRate?

newbie73
I'm using the Python bindings.  I made the changes you suggested, yet after running the setup.py script again with the new version of the .i file, I still cannot view the discount method from an instance of the HullWhite model.

This is what I added to shortratemodels.i:

%rename(HullWhite) HullWhitePtr;
class HullWhitePtr : public boost::shared_ptr<ShortRateModel> {
  public:
    %extend
    {
        HullWhitePtr(const Handle<YieldTermStructure>& termStructure,
                     Real a = 0.1, Real sigma = 0.01)
                     {
                                                return new HullWhitePtr(new HullWhite(termStructure, a, sigma));                        
                                        }
                DiscountFactor discount(Time t) const
                {
                        return boost::dynamic_pointer_cast<HullWhite>(*self)->discount(t);
                }

    }
};



------------------------------------------------------------------------
Hi,
        those methods are not exported in the C# bindings (is that what you're
using, right?) In order to export them, you'll have to add them to the
SWIG interface files and regenerate the wrappers. For instance, you'll
have to go to the definition of the Hull-White model in
shortratemodels.i and add inside the %extend block the following:

DiscountFactor discount(Time t) const {
    return boost::dynamic_pointer_cast<HullWhite>(*self)->discount(t);
}

Luigi


--

The wisdom of the wise and the experience of the ages are perpetuated
by quotations.
-- Benjamin Disraeli



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
QuantLib-users mailing list
QuantLib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib-users


Reply | Threaded
Open this post in threaded view
|

Re: Which methods to expose to access Discount/FwdRate?

Luigi Ballabio

On Sep 17, 2007, at 8:36 PM, newbie73 wrote:
> I'm using the Python bindings.  I made the changes you suggested, yet
> after
> running the setup.py script again with the new version of the .i file,
> I
> still cannot view the discount method from an instance of the HullWhite
> model.

You have to regenerate the wrappers. You can do this by running

python setup.py wrap

after which running setup.py as usual should give you the new method
(as well as the Vasicek model you added.)

Luigi

P.S. Once you get it working, send me a patch and I'll include it in
next release.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Which methods to expose to access Discount/FwdRate?

newbie73
Thanks for the response.  When building the wrapper, what is the argument list expected by the "wrap" option?  I can't seem to get this command option to work.

Thanks!

Returned Error Message:

libs: ['c:\\Quantlib\\QuantLib-0.8.1\\lib', 'c:\\boost\\lib']
Traceback (most recent call last):
  File "setup2.py", line 209, in <module>
    'wrap': my_wrap}
  File "C:\Python25\lib\distutils\core.py", line 137, in setup
    ok = dist.parse_command_line()
  File "C:\Python25\lib\distutils\dist.py", line 459, in parse_command_line
    args = self._parse_command_opts(parser, args)
  File "C:\Python25\lib\distutils\dist.py", line 534, in _parse_command_opts
    cmd_class
distutils.errors.DistutilsClassError: command class __main__.my_wrap must provide 'user_options' att
ribute (a list of tuples)
C:\QuantLib\QuantLib-SWIG-0.8.0\Python>



- Luis


Luigi Ballabio wrote
On Sep 17, 2007, at 8:36 PM, newbie73 wrote:
> I'm using the Python bindings.  I made the changes you suggested, yet
> after
> running the setup.py script again with the new version of the .i file,
> I
> still cannot view the discount method from an instance of the HullWhite
> model.

You have to regenerate the wrappers. You can do this by running

python setup.py wrap

after which running setup.py as usual should give you the new method
(as well as the Vasicek model you added.)

Luigi

P.S. Once you get it working, send me a patch and I'll include it in
next release.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
QuantLib-users mailing list
QuantLib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Which methods to expose to access Discount/FwdRate?

Luigi Ballabio

On Sep 17, 2007, at 9:36 PM, newbie73 wrote:
> Thanks for the response.  When building the wrapper, what is the
> argument
> list expected by the "wrap" option?  I can't seem to get this command
> option
> to work.

Do you have the latest SWIG installed? What is the error exactly?

Luigi



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Which methods to expose to access Discount/FwdRate?

Luigi Ballabio
In reply to this post by newbie73

On Sep 17, 2007, at 9:41 PM, newbie73 wrote:

> Returned Error Message:
>
> libs: ['c:\\Quantlib\\QuantLib-0.8.1\\lib', 'c:\\boost\\lib']
> Traceback (most recent call last):
>   File "setup2.py", line 209, in <module>
>     'wrap': my_wrap}
>   File "C:\Python25\lib\distutils\core.py", line 137, in setup
>     ok = dist.parse_command_line()
>   File "C:\Python25\lib\distutils\dist.py", line 459, in
> parse_command_line
>     args = self._parse_command_opts(parser, args)
>   File "C:\Python25\lib\distutils\dist.py", line 534, in
> _parse_command_opts
>     cmd_class
> distutils.errors.DistutilsClassError: command class __main__.my_wrap
> must
> provide 'user_options' att
> ribute (a list of tuples)
> C:\QuantLib\QuantLib-SWIG-0.8.0\Python>

Ouch---it seems that there's a bug in there. Open setup.py, look for
the my_wrap class and add

user_options = []

as a class member.

Luigi


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Which methods to expose to access Discount/FwdRate?

newbie73
In reply to this post by Luigi Ballabio
Thanks - adding that variable worked.  I've included the shortratemodels.i file I am using to expose Vasicek and discount(...) for the AffineModels

Thanks!

- Luis
Reply | Threaded
Open this post in threaded view
|

Re: Which methods to expose to access Discount/FwdRate?

Luigi Ballabio

On Sep 17, 2007, at 9:56 PM, newbie73 wrote:
> Thanks - adding that variable worked.

Ok.

>   I've included the shortratemodels.i
> file I am using to expose Vasicek and discount(...) for the
> AffineModels

Er, not really.  Or maybe it didn't come through.

Luigi



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users