Python QuantLib BondFunctions

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

Python QuantLib BondFunctions

Dagur Gunnarsson-3
hello,

Does anyone know how to calculate Duration for say, a fixedrate bond in Python-QuantLib, I am not able to find the BondFunctions class in the python bindings.

regards
Dagur G

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Python QuantLib BondFunctions

Dagur Gunnarsson-3
hello,

I am trying to calculate Duration for a fixedrate bond in Python-QuantLib, but I am not able to find the BondFunctions class in the python bindings.

Does anyone here have experience with this binding?  Is the function-set missing from the Python Module?

regards
Dagur G


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Python QuantLib BondFunctions

Luigi Ballabio
In reply to this post by Dagur Gunnarsson-3
Dagur,
    you're correct, BondFunctions is not exported.  You can try adding
it to the SWIG interfaces and rebuilding the bindings; you can use the
CashFlows class as a model (it's in SWIG/cashflows.i).  If it works,
send me a patch and I'll add it to the repository.  And of course,
write back if you get stuck.

Luigi


On Thu, Jun 7, 2012 at 6:21 PM, Dagur Gunnarsson <[hidden email]> wrote:

> hello,
>
> Does anyone know how to calculate Duration for say, a fixedrate bond in
> Python-QuantLib, I am not able to find the BondFunctions class in the python
> bindings.
>
> regards
> Dagur G
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Python QuantLib BondFunctions

Lluis Pujol Bajador
In reply to this post by Dagur Gunnarsson-3

Hi,

Some time ago I exported some of BondFunctions I needed in the following way. I don't know if it is the best approach though.

 Spread zSpread(const BondPtr& bond,
                   Real cleanPrice,
                   const boost::shared_ptr<YieldTermStructure>& d,
                   const DayCounter& dayCounter,
                   Compounding compounding,
                   Frequency frequency,
                   Date settlement,
                   Real accuracy,
                   Size maxIterations,
                   Rate guess) {
                  
                  return QuantLib::BondFunctions::zSpread(
                  *(boost::dynamic_pointer_cast<Bond>(bond)),
                                  cleanPrice,
                                  d,
                                  dayCounter,
                                  compounding,
                                  frequency,
                                  settlement,
                                  accuracy,
                                  maxIterations,
                                  guess);      
    }

 Time duration(const BondPtr& bond,
                     const InterestRate& yield,
                     Duration::Type type,
                     Date settlement) {


        if (settlement == Date())
        settlement = boost::dynamic_pointer_cast<Bond>(bond)->settlementDate();

        return CashFlows::duration(boost::dynamic_pointer_cast<Bond>(bond)->cashflows(), yield,
                                   type,
                                   false, settlement);
    }
 
 Real bps(const BondPtr& bond,
                        const InterestRate& yield,
                        Date settlement){
 
        if (settlement == Date())
       settlement = boost::dynamic_pointer_cast<Bond>(bond)->settlementDate();
   

        return CashFlows::bps(boost::dynamic_pointer_cast<Bond>(bond)->cashflows(), yield,
                              false, settlement) * 100.0 / boost::dynamic_pointer_cast<Bond>(bond)->notional(settlement);
   }

Lluís

On Tue 12/06/12 11:58 , Luigi Ballabio <[hidden email]> wrote:

Dagur,
you're correct, BondFunctions is not exported. You can try adding
it to the SWIG interfaces and rebuilding the bindings; you can use the
CashFlows class as a model (it's in SWIG/cashflows.i). If it works,
send me a patch and I'll add it to the repository. And of course,
write back if you get stuck.

Luigi


On Thu, Jun 7, 2012 at 6:21 PM, Dagur Gunnarsson <<A href="javascript:top.opencompose('dagur@kodi.is','','','1')">javascript:top.opencompose('dagur@...','','','1')> wrote:
> hello,
>
> Does anyone know how to calculate Duration for say, a fixedrate bond in
> Python-QuantLib, I am not able to find the BondFunctions class in the python
> bindings.
>
> regards
> Dagur G
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> QuantLib-users mailing list
> <A href="javascript:top.opencompose('QuantLib-users@lists.sourceforge.net','','','1')">javascript:top.opencompose('QuantLib-users@...','','','1')
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
<A href="javascript:top.opencompose('QuantLib-users@lists.sourceforge.net','','','1')">javascript:top.opencompose('QuantLib-users@...','','','1')
https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users