Hi all, First of all, I found some classes of Quantlib have no default constructor. This mean users have to create object on the heap. Is this intentional, as I tentatively want to add default constructor for the class I am using. Anyway in the case of no default constructor, we use boost::shared_ptr. I read appendixA.pdf of Quantlib doc: Handle is designed to replace pointer to pointer. But I think passing reference of boost::shared_ptr in a function call will have same effect. I could be wrong, any comments? Thanks, Yan Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
On Thu, 2009-08-27 at 17:14 +1000, Yan Kuang wrote:
> First of all, I found some classes of Quantlib have no default > constructor. This mean users have to create object on the heap. How are the two things related? You can create objects on the stack just the same. You'll just have to pass arguments to the constructor instead of just declaring the object. > Is this intentional, as I tentatively want to add default constructor > for the class I am using. If there's no default constructor, it probably makes no sense to have one. The default-constructed object wouldn't have enough information to work anyway. > Anyway in the case of no default constructor, we use > boost::shared_ptr. I read appendixA.pdf of Quantlib doc: Handle is > designed > to replace pointer to pointer. But I think passing reference of > boost::shared_ptr in a function call will have same effect. I could be > wrong, > any comments? I'm not sure I understand. If the function takes a Handle, you'll have to use one since there's no automatic conversion from boost::shared_ptr. Or do you want to write the function instead? Luigi -- If you can't convince them, confuse them. -- Harry S. Truman ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Luigi Ballabio <[hidden email]> wrote on 27/08/2009 06:30:35 PM: > On Thu, 2009-08-27 at 17:14 +1000, Yan Kuang wrote: > > First of all, I found some classes of Quantlib have no default > > constructor. This mean users have to create object on the heap. > > How are the two things related? You can create objects on the stack just > the same. You'll just have to pass arguments to the constructor instead > of just declaring the object. > Sorry I make the confusion. I mean without default constructor, you can't declare an object without passing argument, but you can declare a pointer. > > Is this intentional, as I tentatively want to add default constructor > > for the class I am using. > > If there's no default constructor, it probably makes no sense to have > one. The default-constructed object wouldn't have enough information to > work anyway. > It's just during development, sometimes I like to declare an object without passing the argument first, write follow on routine and test the compilation. I change the default constructor to a specialised constructor a little late on. > > > Anyway in the case of no default constructor, we use > > boost::shared_ptr. I read appendixA.pdf of Quantlib doc: Handle is > > designed > > to replace pointer to pointer. But I think passing reference of > > boost::shared_ptr in a function call will have same effect. I could be > > wrong, > > any comments? > > I'm not sure I understand. If the function takes a Handle, you'll have > to use one since there's no automatic conversion from boost::shared_ptr. > Or do you want to write the function instead? > > Luigi > Take an example: class adtLGM { public: adtLGM(); adtLGM(int rollNum, std::vector<double> Roll, std::vector<double> exBool, std::vector<double> notional, std::vector<double> FixedSched,std::vector<double> Rmax, std::vector<double> Rmin, int pay1_rec0, string liborTerm, int rollRule, string Hol, int daycount, boost::shared_ptr<SwaptionVolCube2>& swopVolCube, boost::shared_ptr<CapFloorTermVolSurface>& cpflVolSurf); virtual ~adtLGM(); double LGM_CpflrLetPDE(int call_put, int expIdx, int N, int M); private: .......................... deleted ........ boost::shared_ptr<SwaptionVolCube2> m_swopVolCube; boost::shared_ptr<CapFloorTermVolSurface> m_cpflVolSurf; .......................... deleted ....... }; adtLGM::adtLGM(int rollNum, std::vector<double> Roll, std::vector<double> exBool, std::vector<double> notional, std::vector<double> FixedSched,std::vector<double> Rmax, std::vector<double> Rmin, int pay1_rec0, string liborTerm, int rollRule, string Hol, int daycount, boost::shared_ptr<SwaptionVolCube2>& swopVolCube, boost::shared_ptr<CapFloorTermVolSurface>& cpflVolSurf) { .......................... deleted ........ m_swopVolCube = swopVolCube; m_cpflVolSurf = cpflVolSurf; .......................... deleted ........ } .................... Suppose suppose I create SwaptionVolCube2 object, then I pass the shared_ptr (as reference) to adtLGM constructor. If I purtube SwaptionVolCube2 object after an adtLGM object construction, I expect m_swopVolCube reflect the pertubation. Am I right? (I haven't tested). In Quantlib doucument appendixA.pdf, it is stated: I thought this paragraph implies Handle class is designed to replace smart pointer to smart pointer. While I thought we never needed a smart pointer to smart pointer, we should use the reference passing instead. I never used boost::shared_ptr before, so I could be wrong. Or I misunderstood the document? Thanks, Yan Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Maybe passing reference or not doesn't matter in this case (apart from memory saving)? I guess the copy constructor just increase reference count of shared_ptr: m_swopVolCube = swopVolCube; In another word, m_swopVolCube and swopVolCube should point to the same vol cube object? What if the vol cube being modified, would an new copy of vol cube object be created?
Luigi Ballabio <[hidden email]> wrote on 27/08/2009 06:30:35 PM: > On Thu, 2009-08-27 at 17:14 +1000, Yan Kuang wrote: > > First of all, I found some classes of Quantlib have no default > > constructor. This mean users have to create object on the heap. > > How are the two things related? You can create objects on the stack just > the same. You'll just have to pass arguments to the constructor instead > of just declaring the object. > Sorry I make the confusion. I mean without default constructor, you can't declare an object without passing argument, but you can declare a pointer. > > Is this intentional, as I tentatively want to add default constructor > > for the class I am using. > > If there's no default constructor, it probably makes no sense to have > one. The default-constructed object wouldn't have enough information to > work anyway. > It's just during development, sometimes I like to declare an object without passing the argument first, write follow on routine and test the compilation. I change the default constructor to a specialised constructor a little late on. > > > Anyway in the case of no default constructor, we use > > boost::shared_ptr. I read appendixA.pdf of Quantlib doc: Handle is > > designed > > to replace pointer to pointer. But I think passing reference of > > boost::shared_ptr in a function call will have same effect. I could be > > wrong, > > any comments? > > I'm not sure I understand. If the function takes a Handle, you'll have > to use one since there's no automatic conversion from boost::shared_ptr. > Or do you want to write the function instead? > > Luigi > Take an example: class adtLGM { public: adtLGM(); adtLGM(int rollNum, std::vector<double> Roll, std::vector<double> exBool, std::vector<double> notional, std::vector<double> FixedSched,std::vector<double> Rmax, std::vector<double> Rmin, int pay1_rec0, string liborTerm, int rollRule, string Hol, int daycount, boost::shared_ptr<SwaptionVolCube2>& swopVolCube, boost::shared_ptr<CapFloorTermVolSurface>& cpflVolSurf); virtual ~adtLGM(); double LGM_CpflrLetPDE(int call_put, int expIdx, int N, int M); private: .......................... deleted ........ boost::shared_ptr<SwaptionVolCube2> m_swopVolCube; boost::shared_ptr<CapFloorTermVolSurface> m_cpflVolSurf; .......................... deleted ....... }; adtLGM::adtLGM(int rollNum, std::vector<double> Roll, std::vector<double> exBool, std::vector<double> notional, std::vector<double> FixedSched,std::vector<double> Rmax, std::vector<double> Rmin, int pay1_rec0, string liborTerm, int rollRule, string Hol, int daycount, boost::shared_ptr<SwaptionVolCube2>& swopVolCube, boost::shared_ptr<CapFloorTermVolSurface>& cpflVolSurf) { .......................... deleted ........ m_swopVolCube = swopVolCube; m_cpflVolSurf = cpflVolSurf; .......................... deleted ........ } .................... Suppose suppose I create SwaptionVolCube2 object, then I pass the shared_ptr (as reference) to adtLGM constructor. If I purtube SwaptionVolCube2 object after an adtLGM object construction, I expect m_swopVolCube reflect the pertubation. Am I right? (I haven't tested). In Quantlib doucument appendixA.pdf, it is stated: I thought this paragraph implies Handle class is designed to replace smart pointer to smart pointer. While I thought we never needed a smart pointer to smart pointer, we should use the reference passing instead. I never used boost::shared_ptr before, so I could be wrong. Or I misunderstood the document? Thanks, Yan Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by Yan Kuang
On Fri, 2009-08-28 at 14:06 +1000, Yan Kuang wrote:
> I thought this paragraph implies Handle class is designed to replace > smart pointer to smart pointer. > While I thought we never needed a smart pointer to smart pointer, we > should use the reference passing instead. If you just want to be able to perturb an object and have the containing object see the change, the shared_ptr is enough. Classes in the library use a Handle so that, beside modifying it, one can also replace the contained object altogether and have the containing object see the new one. Luigi -- Skinner's Constant (or Flannagan's Finagling Factor): That quantity which, when multiplied by, divided by, added to, or subtracted from the answer you got, gives you the answer you should have gotten. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Luigi Ballabio <[hidden email]> wrote on 31/08/2009 07:52:01 PM: > On Fri, 2009-08-28 at 14:06 +1000, Yan Kuang wrote: > > I thought this paragraph implies Handle class is designed to replace > > smart pointer to smart pointer. > > While I thought we never needed a smart pointer to smart pointer, we > > should use the reference passing instead. > > If you just want to be able to perturb an object and have the containing > object see the change, the shared_ptr is enough. Classes in the library > use a Handle so that, beside modifying it, one can also replace the > contained object altogether and have the containing object see the new > one. > I am not sure I understand, do you mean point to a different object. Shared pointer can do too: void f (boost::shared_ptr<T> & pA) { boost::shared_ptr<T> pB(new T); pA = pB; } Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
On Wed, 2009-09-02 at 14:31 +1000, Yan Kuang wrote:
> I am not sure I understand, do you mean point to a different object. > Shared pointer > can do too: > > void f (boost::shared_ptr<T> & pA) > { > boost::shared_ptr<T> pB(new T); > > pA = pB; > } Yes, but try this: #include <iostream> class T { int i_; public: T(int i) : i_(i) {} int i() const { return i_; } }; class Foo { shared_ptr<T> p_; public: Foo(const shared_ptr<T>& p) : p_(p) {} void check() const { std::cout << p_->i() << std::endl; } }; int main() { boost::shared_ptr<T> pA(new T(1)); Foo f(pA); f.check(); // prints 1 boost::shared_ptr<T> pB(new T(2)); pA = pB; // you're changing pA, but not the copy // stored by the Foo object f.check(); // in fact, this still prints 1 } With Handles instead, when you relink the handle the Foo instance sees the new T object. Luigi -- Skinner's Constant (or Flannagan's Finagling Factor): That quantity which, when multiplied by, divided by, added to, or subtracted from the answer you got, gives you the answer you should have gotten. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Luigi, just to clarify this fundamental issue, look at follow constructor.
template <class T> inline Handle<T>::Handle(T* ptr_h, bool registerAsObserver) : link_(new Link(boost::shared_ptr<T> (ptr_h),registerAsObserver)) {} Is it possible to add such constructor in new QL version, cause i guess it's more easy-to-use (and i use it successfully)? Pay attention, that this declaration doesn't run counter to purpose of handles, moreover it won't create problem with allocation of T* pointer.
|
In reply to this post by Luigi Ballabio
Luigi Ballabio <[hidden email]> wrote on 02/09/2009 07:33:35 PM: > On Wed, 2009-09-02 at 14:31 +1000, Yan Kuang wrote: > > I am not sure I understand, do you mean point to a different object. > > Shared pointer > > can do too: > > > > void f (boost::shared_ptr<T> & pA) > > { > > boost::shared_ptr<T> pB(new T); > > > > pA = pB; > > } > > Yes, but try this: > > #include <iostream> > > class T { > int i_; > public: > T(int i) : i_(i) {} > int i() const { return i_; } > }; > > class Foo { > shared_ptr<T> p_; > public: > Foo(const shared_ptr<T>& p) : p_(p) {} > void check() const { > std::cout << p_->i() << std::endl; > } > }; > > int main() { > boost::shared_ptr<T> pA(new T(1)); > Foo f(pA); > f.check(); // prints 1 > > boost::shared_ptr<T> pB(new T(2)); > pA = pB; // you're changing pA, but not the copy > // stored by the Foo object > f.check(); // in fact, this still prints 1 > } > This because constructor of Foo called copy constructor of boost::shared_ptr. f.p_ is just a copy of pA. So Handle behaves like a raw pointer. I can see YieldTermStructure, Quote etc using handle in Quantlib code, I can see the reason now. Thanks, Yan Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
On Thu, 2009-09-03 at 09:41 +1000, Yan Kuang wrote:
> Luigi Ballabio <[hidden email]> wrote on 02/09/2009 07:33:35 > PM: > > Yes, but try this: > > > This because constructor of Foo called copy constructor of > boost::shared_ptr. That's the same with raw pointers. Look at the following, and forget about the fact that I'm leaking memory: #include <iostream> class T { int i_; public: T(int i) : i_(i) {} int i() const { return i_; } }; class Foo { T* p_; public: Foo(T* p) : p_(p) {} void check() const { std::cout << p_->i() << std::endl; } }; int main() { T* pA = new T(1); Foo f(pA); f.check(); // prints 1 T* pB = new T(2); pA = pB; // you're changing pA, but not the copy // stored by the Foo object f.check(); // in fact, this still prints 1 } > So Handle behaves like a raw pointer. Handle behaves like a pointer to pointer. If you're reading appendix A of my drafts, look at the aside on pointer semantics. Luigi -- Never mistake motion for action. -- Ernest Hemingway ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In this example, I can use reference so that the second f.check() print 2. The only thing to notice is p_ is an alias, can not be change to something else. #include <boost/shared_ptr.hpp> #include <iostream> class T { int i_; public: T(int i) : i_(i) {} int i() const { return i_; } }; class Foo { boost::shared_ptr<T> & p_; public: Foo(boost::shared_ptr<T>& p) : p_(p) {} void check() const { std::cout << p_->i() << std::endl; } }; int _tmain(int argc, _TCHAR* argv[]) { boost::shared_ptr<T> pA(new T(1)); Foo f(pA); f.check(); // prints 1 boost::shared_ptr<T> pB(new T(2)); pA = pB; // you're changing pA, but not the copy // stored by the Foo object f.check(); // now print 2. }
On Thu, 2009-09-03 at 09:41 +1000, Yan Kuang wrote: > Luigi Ballabio <[hidden email]> wrote on 02/09/2009 07:33:35 > PM: > > Yes, but try this: > > > This because constructor of Foo called copy constructor of > boost::shared_ptr. That's the same with raw pointers. Look at the following, and forget about the fact that I'm leaking memory: #include <iostream> class T { int i_; public: T(int i) : i_(i) {} int i() const { return i_; } }; class Foo { T* p_; public: Foo(T* p) : p_(p) {} void check() const { std::cout << p_->i() << std::endl; } }; int main() { T* pA = new T(1); Foo f(pA); f.check(); // prints 1 T* pB = new T(2); pA = pB; // you're changing pA, but not the copy // stored by the Foo object f.check(); // in fact, this still prints 1 } > So Handle behaves like a raw pointer. Handle behaves like a pointer to pointer. If you're reading appendix A of my drafts, look at the aside on pointer semantics. Luigi -- Never mistake motion for action. -- Ernest Hemingway Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
On Fri, 2009-09-04 at 10:19 +1000, Yan Kuang wrote:
> In this example, I can use reference so that the second f.check() > print 2. Yes, but storing references is dangerous, because you can't control lifetime (which is kind of the whole point of smart pointers, anyway.) #include <boost/shared_ptr.hpp> #include <iostream> class T { int i_; public: T(int i) : i_(i) {} int i() const { return i_; } }; class Foo { boost::shared_ptr<T> & p_; public: Foo(boost::shared_ptr<T>& p) : p_(p) {} void check() const { std::cout << p_->i() << std::endl; } }; Foo make_foo() { boost::shared_ptr<T> p(new T(1)); // local to the function Foo f(p); // stores a reference to the local variable... return f; // ...but here, the local variable is destroyed. } int main() { Foo f = make_foo(); // now f is storing a reference to a deleted object. f.check(); // all bets are off. This might crash the program, // print garbage (it prints 0 on my Linux box), // or even print the right value. But it's unreliable. return 0; } -- All generalizations are false, including this one. -- Mark Twain ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi All, In the constructor of SwaptionVolCube2, there are two swap index: const boost::shared_ptr<SwapIndex>& swapIndexBase, const boost::shared_ptr<SwapIndex>& shortSwapIndexBase, I can't understand why we need two swap indices. I can only guess different swap tenor may require different index. However one can always fix the issue in the index definition. For example I defined aud BBSW swap index as: (if swap tenor longer thant 3 years, 6 months tenor for fixed an floating side.) namespace QuantLib { AudBbswSwapAfma::AudBbswSwapAfma(const Period& tenor, const Handle<YieldTermStructure>& h) : SwapIndex("AudBbswSwapAfma", // familyName tenor, 1, // settlementDays AUDCurrency(), Australia(), tenor > 3*Years ? 6*Months : 3*Months, // fixedLegTenor ModifiedFollowing, // fixedLegConvention Actual365Fixed(), // fixedLegDaycounter boost::shared_ptr<IborIndex> (new AudBbsw(tenor > 3*Years ? 6*Months : 3*Months, h))) {} } To make my SwaptionVolCube2 usage code compiled, I did the following (4 year for longer, 3 years for shorter :)) swapIndexBase = boost::shared_ptr<SwapIndex>(new AudBbswSwapAfma(4*Years, termStructure)); shortSwapIndexBase = boost::shared_ptr<SwapIndex>(new AudBbswSwapAfma(3*Years, termStructure)); boost::shared_ptr<SwaptionVolCube2> pSwopVolCube(new SwaptionVolCube2(atmVolMatrix, tenors.options, tenors.swaps, strikeSpreads, volSpreadsHandle, swapIndexBase, shortSwapIndexBase, vegaWeighedSmileFit)); Please tell me if I missunderstood the issue. Help will be greatly appreciated, as I am trying to achieve the target using quantlib under time pressure. Many thanks, Yan Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by Andrew Kolesnikov
On Wed, 2009-09-02 at 05:23 -0700, Andrew Kolesnikov wrote:
> template <class T> > inline Handle<T>::Handle(T* ptr_h, > bool registerAsObserver) > : link_(new Link(boost::shared_ptr<T> (ptr_h),registerAsObserver)) {} > > Is it possible to add such constructor in new QL version, cause i guess it's > more easy-to-use (and i use it successfully)? Done, thanks. Luigi -- Present to inform, not to impress; if you inform, you will impress. -- Fred Brooks ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by Yan Kuang
On Thu, Sep 10, 2009 at 2:54 AM, Yan Kuang <[hidden email]> wrote:
> In the constructor of SwaptionVolCube2, there are two swap index: > > const boost::shared_ptr<SwapIndex>& swapIndexBase, > const boost::shared_ptr<SwapIndex>& shortSwapIndexBase, > > I can't understand why we need two swap indices. I can only guess different > swap tenor may require different index. the input swapIndexBase is used to convey all the convention details for options' underlying swaps (the only unused info it's its tenor). Since in the EUR swap market the conventions are different for the (short tenor) 1Y swap, here's the need for a second shortSwapIndexBase. I own you a couple of answer about optionletvol and swaptionvol: sorry for being late, I'll catch up soon... stay tuned ciao -- Nando ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by Luigi Ballabio
Hi All, I am build an AUD depo-future-swap curve. I have defined nessary interest rate index such as BBSW etc. I implemeted AUD Bank Bill Future last trading date function: Date bbf = AUDBBF_nextDate(dtValDate); boost::shared_ptr<RateHelper> fut1(new FuturesRateHelper( fut1Quote,bbf,BBSW3m)); However, the the constructor required the future's last trading date as an IMM date, I have commented the QL_REQUIRE. Also the the earliestDate shoule be: earliestDate_ = cal.advance(immDate, i->fixingDays(), Days); Instead of //earliestDate_ = immDate; Hence I changed latestDate as well. latestDate_=cal.advance(earliestDate_,i->tenor(),i->businessDayConvention()); instead of //latestDate_=cal.advance(immDate,i->tenor(),i->businessDayConvention()); In the long run, probably we should create a generic class to handle last trading date of future. Cheers, Yan >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FuturesRateHelper::FuturesRateHelper(Real price, const Date& immDate, const shared_ptr<IborIndex>& i, Rate convAdj) : RateHelper(price), convAdj_(Handle<Quote>(shared_ptr<Quote>(new SimpleQuote(convAdj)))) { //QL_REQUIRE(IMM::isIMMdate(immDate, false), // immDate << "is not a valid IMM date"); //earliestDate_ = immDate; const Calendar& cal = i->fixingCalendar(); earliestDate_ = cal.advance(immDate, i->fixingDays(), Days); //latestDate_=cal.advance(immDate,i->tenor(),i->businessDayConvention()); latestDate_=cal.advance(earliestDate_,i->tenor(),i->businessDayConvention()); yearFraction_=i->dayCounter().yearFraction(earliestDate_, latestDate_); } Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by Ferdinando Ametrano-4
[hidden email] wrote on 10/09/2009 06:36:08 PM: > On Thu, Sep 10, 2009 at 2:54 AM, Yan Kuang <[hidden email]> wrote: > > In the constructor of SwaptionVolCube2, there are two swap index: > > > > const boost::shared_ptr<SwapIndex>& swapIndexBase, > > const boost::shared_ptr<SwapIndex>& shortSwapIndexBase, > > > > I can't understand why we need two swap indices. I can only guessdifferent > > swap tenor may require different index. > > the input swapIndexBase is used to convey all the convention details > for options' underlying swaps (the only unused info it's its tenor). > Since in the EUR swap market the conventions are different for the > (short tenor) 1Y swap, here's the need for a second > shortSwapIndexBase. > > I own you a couple of answer about optionletvol and swaptionvol: sorry > for being late, I'll catch up soon... stay tuned > > ciao -- Nando As I pointed in the last email, Aussie market has similar situation (under 3 year swaps are different from 4 years and plus). But that has been handle in the swap index. A general way to handle this is to passing a vector of swap index for each swap tenor, the dimension of the vector should be same as that of swaps vector. There are may be a clever way of doing this, e.g., passing in a generic swap index. The generic swap index should be able to tell you the market conventions for each tenor. Thanks, Yan Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
On Fri, 2009-09-11 at 14:28 +1000, Yan Kuang wrote:
> As I pointed in the last email, Aussie market has similar situation > (under 3 year swaps are different from 4 years and plus). But that has > been handle in the swap index. > > [...] > > There are may be a clever way of doing this, e.g., passing in a > generic swap index. > The generic swap index should be able to tell you the market > conventions for each tenor. We need some kind of factory. We could use a factory class, but it's probably overkill. We could just add a factory method to SwapRate that returns a correctly-instantiated rate of the same family but with the given tenor. Yan, do you want to give it a try? Luigi -- There is no likelihood man can ever tap the power of the atom. -- Robert Millikan, Nobel Prize in Physics, 1923 ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by Yan Kuang
Hi Yan,
On Fri, 2009-09-11 at 14:04 +1000, Yan Kuang wrote: > I am build an AUD depo-future-swap curve. I have defined nessary > interest rate index such as BBSW etc. Would you like to share them? If you're in a position to contribute them, I'll add them to a future release. > I implemeted AUD Bank Bill Future last trading date function: > > However, the [FuturesRateHelper] constructor required the future's > last trading date as an IMM date, I have commented the > QL_REQUIRE. I see. Yes, that might have been too specific. > Also the the earliestDate shoule be: > > earliestDate_ = cal.advance(immDate, i->fixingDays(), Days); > > Instead of > //earliestDate_ = immDate; That depends on how one defines the relevant date, doesn't it? You're currently passing the fixing date for the rate, meaning that the start of your accrual period is 2 days later. The convention currently implemented seems to be that the IMM date is the value date, and the fixing date is 2 days before that (Nando, you probably wrote the code: is this correct?) However, the two conventions could be made to agree---for instance, if your function or another similar one returned the value date of the last trading date. Luigi -- Olmstead's Law: After all is said and done, a hell of a lot more is said than done. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by Luigi Ballabio
Luigi Ballabio <[hidden email]> wrote on 12/09/2009 12:14:31 AM: > On Fri, 2009-09-11 at 14:28 +1000, Yan Kuang wrote: > > As I pointed in the last email, Aussie market has similar situation > > (under 3 year swaps are different from 4 years and plus). But that has > > been handle in the swap index. > > > > [...] > > > > There are may be a clever way of doing this, e.g., passing in a > > generic swap index. > > The generic swap index should be able to tell you the market > > conventions for each tenor. > > We need some kind of factory. We could use a factory class, but it's > probably overkill. We could just add a factory method to SwapRate that > returns a correctly-instantiated rate of the same family but with the > given tenor. Yan, do you want to give it a try? > Luigi, Thanks for the encouragement. I haven't done serious C++ programming for quite a few years. I will certainly give it a go. However, I need to finish a validation project in two weeks times with quantlib, I then will take a two weeks leaves. I plan to use quantlib quite extensively to assist some exotic ir models validation in the next six months. Certainly I hope to contribute. Cheers, Yan Please consider our environment before printing this email. WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately. It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments. This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision. Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency. Westpac Banking Corporation ABN 33 007 457 141. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |