Accrued Amount for Vanilla Swaps

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

Accrued Amount for Vanilla Swaps

John Orford
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
Reply | Threaded
Open this post in threaded view
|

Re: Accrued Amount for Vanilla Swaps

Luigi Ballabio
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>

------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Accrued Amount for Vanilla Swaps

John Orford
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>


------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Accrued Amount for Vanilla Swaps

Luigi Ballabio
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>

------------------------------------------------------------------------------
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/NeoTech
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Accrued Amount for Vanilla Swaps

John Orford
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
Reply | Threaded
Open this post in threaded view
|

Re: Accrued Amount for Vanilla Swaps

Luigi Ballabio
Hi John,
    first of all: are you modifying all of SWIG/swap.i,
Python/QuantLib.py and Python/quantlib_wrap.cpp? The last two are
generated, so you have to modify only swap.i and then run SWIG to add
the needed code to all files.

(Note: the call to SWIG is maybe not included in the Debian recipe,
since it works on a released tarball. It should be enough to run
"./configure" from the QuantLib-SWIG directory and "make" from
QuantLib-SWIG/Python to build everything, including the call to SWIG
when needed.)
(Also, I suggest you clone the git repository and work from there
instead of the Debian source. It will also make much easier to
contribute your changes.)

As for your error, it looks like a leftover from a previous attempt of
yours. Do you have a call to VanillaSwap_floatingLegNPV anywhere in
QuantLib.py? But anyway, I suggest you regenerate the files as above
and see if the error disappears.

Later,
    Luigi


On Thu, May 1, 2014 at 2:08 PM, John Orford <[hidden email]> wrote:

> 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>
>
>



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

------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users