Re: QuantLib-SWIG: as_coupon() and friends in Python

Posted by Pascal Haakmat on
URL: http://quantlib.414.s1.nabble.com/QuantLib-SWIG-as-coupon-and-friends-in-Python-tp15935p15937.html

That does the trick. Many thanks,

Pascal

On 10/06/2014 02:46 PM, Luigi Ballabio wrote:

> The last cashflow is the redempion, which is not a coupon, and
> as_coupon(c) returns an empty shared_ptr to indicate a failed cast.
> Check for that case, or just loop over bond.cashflows()[:-1].
>
> Luigi
>
> On Mon, Oct 6, 2014 at 2:23 PM, Pascal Haakmat <[hidden email]> wrote:
>> Dear list,
>>
>> I seem to be having a problem using the as_coupon() SWIG function in
>> Python.
>>
>> I've tested this using QuantLib revision
>> 88aedbaf615de99143c71126dbd92827c3fff96f from May 27.
>>
>> Some pseudo-code for illustration:
>>
>> import QuantLib as QL
>>
>> ... create a FixedRateBond ...
>>
>> bond = QL.FixedRateBond(...)
>> for cashflow in bond.cashflows():
>>         coupon = QL.as_coupon(cashflow)
>>         print "Date: " + str(coupon.date()) + \
>>                 ", Amount: " + str(coupon.amount()) + \
>>                 ", Accrual period: " + str(coupon.accrualPeriod())
>>
>> This fails with:
>>
>>   File "/usr/local/lib/python2.7/dist-packages/QuantLib/QuantLib.py",
>> line 6271, in amount
>>     def amount(self): return _QuantLib.CashFlow_amount(self)
>> RuntimeError: Boost assertion failed: px != 0
>>
>> Other methods (like coupon.accrualPeriod()) fail in a similar manner.
>>
>> Thanks,
>> Pascal
>>
>> ------------------------------------------------------------------------------
>> Slashdot TV.  Videos for Nerds.  Stuff that Matters.
>> http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
>> _______________________________________________
>> QuantLib-users mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
>


------------------------------------------------------------------------------
Slashdot TV.  Videos for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users