I am trying to convert the example below from C++ to Python using SWIG.
LINK: http://quantlib.org/reference/_fitted_bond_curve_8cpp-example.html I am stuck on how to convert some of the lines such as the following to Python: 1) std::vector< boost::shared_ptr<SimpleQuote> > quote; 2) RelinkableHandle<Quote> quoteHandle[numberOfBonds] 3) Real coupons[] = { 0.0200, 0.0225, 0.0250, 0.0275, 0.0300, 0.0325, 0.0350, 0.0375, 0.0400, 0.0425, 0.0450, 0.0475, 0.0500, 0.0525, 0.0550 }; Are there any written documentation with examples that would be helpful on using Quantlib with Python? Glenn ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
On Sun, 2008-04-20 at 20:25 -0500, glenn andrews wrote:
> I am trying to convert the example below from C++ to Python using SWIG. > I am stuck on how to convert some of the lines such as the following to > Python: > > 1) std::vector< boost::shared_ptr<SimpleQuote> > quote; > > 2) RelinkableHandle<Quote> quoteHandle[numberOfBonds] > > 3) Real coupons[] = { 0.0200, 0.0225, 0.0250, 0.0275, 0.0300, > 0.0325, 0.0350, 0.0375, 0.0400, 0.0425, > 0.0450, 0.0475, 0.0500, 0.0525, 0.0550 }; In each case, you can use Python lists. For instance, the third case would be: coupons = [ 0.0200, 0.0225, 0.0250, 0.0275, 0.0300, 0.0325, 0.0350, 0.0375, 0.0400, 0.0425, 0.0450, 0.0475, 0.0500, 0.0525, 0.055 ] In the first two cases, you don't need separate initialization. You can create the list using list comprehension; for example, 1) would be: quote = [ SimpleQuote(cleanPrice[i]) for i in range(len(cleanPrice)) ] or better yet quote = [ SimpleQuote(p) for p in cleanPrice ] In general: - shared_ptr is hidden in the SWIG interfaces, so you can just omit it and use the pointed class directly; - for vectors, use Python lists. Luigi -- Weiler's Law: Nothing is impossible for the man who doesn't have to do it himself. ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |