Hi, Under Python I need to obtain the overall yield and casflow duration of a portfolio of bonds (plain vanilla either Fixed or FRN). I am already able to obtain the single duration and yield for each bond but in order to correctly obtain the real yield (and not a weigthed average yield) of the portfolio I should create a Leg object with all the cashflows of the portfolio. As far as I know the cashflows for a Leg object need to be sorted and thus I don't know how to easily proceed . Is there any builtin method to add cashflows from another Leg? Any hint of a way to achieve a single Leg object with all shorted cashflows under Python? Thanks in advance. Lluís.
------------------------------------------------------------------------------ What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
On Fri, 2011-03-04 at 14:27 +0100, Lluis Pujol Bajador wrote:
> Under Python I need to obtain the overall yield and casflow duration > of a portfolio of bonds (plain vanilla either Fixed or FRN). > > I am already able to obtain the single duration and yield for each > bond but in order to correctly obtain the real yield (and not a > weigthed average yield) of the portfolio I should create a Leg object > with all the cashflows of the portfolio. As far as I know the > cashflows for a Leg object need to be sorted and thus I don't know how > to easily proceed . As for adding them, all = [] for b in bonds: all += bonds.cashflows() Then, write a function to compare dates and let Python sort them: def cmp_cf(c1,c2): return cmp(c1.date(),c2.date()) all.sort(cmp = cmp_cf) Luigi P.S. Warning: I haven't tested the above, so there might be errors. But the idea is the correct one. -- Greenspun's Tenth Rule of Programming: Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp. ------------------------------------------------------------------------------ What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Thanks Luigi, it works perfect.
Lluís El 04/03/2011 15:05, Luigi Ballabio escribió: > On Fri, 2011-03-04 at 14:27 +0100, Lluis Pujol Bajador wrote: >> Under Python I need to obtain the overall yield and casflow duration >> of a portfolio of bonds (plain vanilla either Fixed or FRN). >> >> I am already able to obtain the single duration and yield for each >> bond but in order to correctly obtain the real yield (and not a >> weigthed average yield) of the portfolio I should create a Leg object >> with all the cashflows of the portfolio. As far as I know the >> cashflows for a Leg object need to be sorted and thus I don't know how >> to easily proceed . > As for adding them, > > all = [] > for b in bonds: > all += bonds.cashflows() > > Then, write a function to compare dates and let Python sort them: > > def cmp_cf(c1,c2): > return cmp(c1.date(),c2.date()) > > all.sort(cmp = cmp_cf) > > Luigi > > P.S. Warning: I haven't tested the above, so there might be errors. But > the idea is the correct one. > > ------------------------------------------------------------------------------ What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |