Re: Accrued Amount for Vanilla Swaps

Posted by John Orford on
URL: http://quantlib.414.s1.nabble.com/Accrued-Amount-for-Vanilla-Swaps-tp15068p15223.html

Hey Luigi,

I tried to add the fixedLeg() and floatingLeg() vanilla swap methods, without much success (failed to build the Debian package each time).

Instead, I put some effort into exporting another function, which I got further with.

From the Debian source code directory, I inserted the following code.

Everything compiles, but see this error:

AttributeError: 'module' object had no attribute 'VanillaSwap_floatingLegNPV'

Any pointers would be fantastic.

Hope once am up and running i can add more to the package.

Thanks,

John




File SWIG/swap.i

Real fixedLegNPV() {
            return boost::dynamic_pointer_cast<VanillaSwap>(*self)
                 ->fixedLegNPV();
        }


File: Python/QuantLib.py

def fixedLegNPV(self): return _QuantLib.VanillaSwap_fixedLegNPV(self)


File: Python/quantlib_wrap.cpp

SWIGINTERN Real VanillaSwapPtr_fixedLegNPV(VanillaSwapPtr *self){
            return boost::dynamic_pointer_cast<VanillaSwap>(*self)
                 ->fixedLegNPV();
        }


On 14 April 2014 21:48, Luigi Ballabio <[hidden email]> wrote:
The SWIG site itself has extensive docs at <http://swig.org/doc.html> (we're still using version 2.0, since 3.0 wasn't available at the time of our last release).

The definitions of our bindings are in the .i files in the SWIG folder of our QuantLib-SWIG release. There are a few tricks that we're using to hide the use of shared_ptr from the target language, and I'll have to write about those when I have some time. However, the classes you're interested in are already exported, so you should be able to look at those and add the relevant methods by copying the structure of the existing ones. And of course I'll be here to help.

Later,
    Luigi




On Thu, Apr 10, 2014 at 1:16 PM, John Orford <[hidden email]> wrote:
Luigi,

I have never looked into the mechanics of the SWIG bindings before.

If you can recommend a site showing me where to start learning about SWIG I'll give it a shot.

John


On 9 April 2014 21:51, Luigi Ballabio <[hidden email]> wrote:
Hello,
    I'm afraid that's not possible at this time. You'll have to extend the SWIG bindings and recompile them; specifically, you'll have to:
1) extend the VanillaSwap bindings so that they export the fixedLeg and floatingLeg methods.
2) extend the CashFlows bindings so that they export the accruedAmount method.
Once you have these, you can extract the legs from the swap and get the accrued amount of either.
Both the additions should not be difficult, given that the classes are already exported and you have other methods that you can use as models. However, let me know if you get stuck. Also, I'll be glad to merge your changes to the main repository if you want.

Luigi




On Tue, Mar 18, 2014 at 11:07 AM, John Orford <[hidden email]> wrote:
Hi All,

I am trying to figure out how to calculate the accrued amount for vanilla swaps using the Python bindings.

Could anyone give me some pointers?

As an aside, are there any clean / dirty conventions around swap pricing?  I have seen many cases of both, but perhaps there's some logic to it which'd be useful to know for future reference.

Thanks!

John

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users




--
<https://implementingquantlib.blogspot.com>
<https://twitter.com/lballabio>




--
<https://implementingquantlib.blogspot.com>
<https://twitter.com/lballabio>


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.  Get
unparalleled scalability from the best Selenium testing platform available.
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users