Hi, I’m looking at extending the definitions in the
short-rate models for credit (or inflation) purposes. Problems arise with the TermStructureConsistentModel,
TermStructureFittingParameters etc. There are two possible approaches: 1) Specialise using
templates for the short-rate models. 2) Specialise
by adding to the TermStructure class. The first method requires rewriting of many classes within a
template structure – and specialising some of the class functions to
return the survival probability instead of the discount factor. The second
requires adding a function named oneFactorPrimitive() (or similar) to
TermStructure which specialises using the standard C++ inheritance. I’m leaning towards the second method as it is much
simpler. Any advice? Simon
This email is not intended to nor should it be taken to create any legal relations or contractual relationships. This email has originated from ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Is the problem that TSCM refers to a YTS rather than a TS?
Arguably ugly but could it help defaulting to the type used now: TSCM<TS_T=YTS> and the typedefs? it saves the existing code..... except for the T_ syntax to add, maybe thats what you meant. And somthing similar for TermStructureFittingParameter. Regards Pepe ----- "Simon Ibbotson" <[hidden email]> a écrit : > Hi, > > > > I’m looking at extending the definitions in the short-rate models for > credit (or inflation) purposes. > > Problems arise with the TermStructureConsistentModel, > TermStructureFittingParameters etc. > > There are two possible approaches: > > > > 1) Specialise using templates for the short-rate models. > > 2) Specialise by adding to the TermStructure class. > > > > The first method requires rewriting of many classes within a template > structure – and specialising some of the class functions to return the > survival probability instead of the discount factor. The second > requires adding a function named oneFactorPrimitive() (or similar) to > TermStructure which specialises using the standard C++ inheritance. > > > > I’m leaning towards the second method as it is much simpler. > > > > Any advice? > > > > Simon > > > > > > > > This communication and any attachments contains information which is > confidential and may be subject to legal privilege. It is for intended > recipients only. If you are not the intended recipient you must not > copy, distribute, publish, rely on or otherwise use it without our > consent. Some of our communications may contain confidential > information which it could be a criminal offence for you to disclose > or use without authority. If you have received this email in error > please notify [hidden email] immediately and delete the email > from your computer. > > The FSA reserves the right to monitor all email communications for > compliance with legal, regulatory and professional standards. > > This email is not intended to nor should it be taken to create any > legal relations or contractual relationships. This email has > originated from > > The Financial Services Authority (FSA) > 25 The North Colonnade, > Canary Wharf, > London > E14 5HS > United Kingdom > > Registered as a Limited Company in England and Wales No.1920623. > Registered Office as above > > Switchboard: 020 7066 1000 > Web Site: http://www.fsa.gov.uk > ***************************************************************** > > ------------------------------------------------------------------------------ > Nokia and AT&T present the 2010 Calling All Innovators-North America > contest > Create new apps & games for the Nokia N8 for consumers in U.S. and > Canada > $10 million total in prizes - $4M cash, 500 devices, nearly $6M in > marketing > Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi > Store > http://p.sf.net/sfu/nokia-dev2dev > _______________________________________________ > QuantLib-dev mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-dev ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
That was what I meant (making the classes into template classes ) - but it would affect many classes, not just the TSCM and the TSFP. Also, any classes that derive from those (e.g. Hull-White, CIR++) and that use them (Grids etc.).
However, there is already an inheritance (specialisation) structure in place for TermStructure. I don't see that it would make any sense to add a template based specialisation in the short-rate models to replicate this. Extending the TermStructure definition would be much simpler - or adding another layer (e.g. RateBasedTermStructure) which would derive from TermStructure and be the base class for YieldTermStructure, DefaultProbabilityTermStructure, InflationTermStructure etc. I dare say one of the administrators would have to comment. Simon -----Original Message----- From: [hidden email] [mailto:[hidden email]] Sent: 25 October 2010 13:08 To: Simon Ibbotson Cc: [hidden email] Subject: Re: [Quantlib-dev] Extending short-rate models for credit / inflation. Is the problem that TSCM refers to a YTS rather than a TS? Arguably ugly but could it help defaulting to the type used now: TSCM<TS_T=YTS> and the typedefs? it saves the existing code..... except for the T_ syntax to add, maybe thats what you meant. And somthing similar for TermStructureFittingParameter. Regards Pepe ----- "Simon Ibbotson" <[hidden email]> a écrit : > Hi, > > > > I'm looking at extending the definitions in the short-rate models for > credit (or inflation) purposes. > > Problems arise with the TermStructureConsistentModel, > TermStructureFittingParameters etc. > > There are two possible approaches: > > > > 1) Specialise using templates for the short-rate models. > > 2) Specialise by adding to the TermStructure class. > > > > The first method requires rewriting of many classes within a template > structure - and specialising some of the class functions to return the > survival probability instead of the discount factor. The second > requires adding a function named oneFactorPrimitive() (or similar) to > TermStructure which specialises using the standard C++ inheritance. > > > > I'm leaning towards the second method as it is much simpler. > > > > Any advice? > > > > Simon > > > > > > > > This communication and any attachments contains information which is > confidential and may be subject to legal privilege. It is for intended > recipients only. If you are not the intended recipient you must not > copy, distribute, publish, rely on or otherwise use it without our > consent. Some of our communications may contain confidential > information which it could be a criminal offence for you to disclose > or use without authority. If you have received this email in error > please notify [hidden email] immediately and delete the email > from your computer. > > The FSA reserves the right to monitor all email communications for > compliance with legal, regulatory and professional standards. > > This email is not intended to nor should it be taken to create any > legal relations or contractual relationships. This email has > originated from > > The Financial Services Authority (FSA) > 25 The North Colonnade, > Canary Wharf, > London > E14 5HS > United Kingdom > > Registered as a Limited Company in England and Wales No.1920623. > Registered Office as above > > Switchboard: 020 7066 1000 > Web Site: http://www.fsa.gov.uk > ***************************************************************** > > ------------------------------------------------------------------------------ > Nokia and AT&T present the 2010 Calling All Innovators-North America > contest > Create new apps & games for the Nokia N8 for consumers in U.S. and > Canada > $10 million total in prizes - $4M cash, 500 devices, nearly $6M in > marketing > Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi > Store > http://p.sf.net/sfu/nokia-dev2dev > _______________________________________________ > QuantLib-dev mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-dev ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
On Mon, 2010-10-25 at 13:20 +0100, Simon Ibbotson wrote:
> That was what I meant (making the classes into template classes ) - > but it would affect many classes, not just the TSCM and the TSFP. > Also, any classes that derive from those (e.g. Hull-White, CIR++) and > that use them (Grids etc.). > > [...] > > Extending the TermStructure definition would be much simpler - or > adding another layer (e.g. RateBasedTermStructure) which would derive > from TermStructure and be the base class for YieldTermStructure, > DefaultProbabilityTermStructure, InflationTermStructure etc. I'm not sure. On the one hand, you'd have to modify all the classes anyway so that they take a RateBasedTermStructure instead of a YieldTermStructure. Once you're doing that, you might as well make them into templates. On the other hand, RateBasedTermStructure has no particular concept associated besides "a term structure returning some kind of rate" or something like that (is default probability a rate?) which is a bit too generic. It looks to me it would be just an implementation thing with no actual financial concept behind. Since the problem you're trying to solve is to unify different interfaces in some way, have you thought about doing it explicitly and using an Adapter pattern instead? Off the top of my head (so I haven't tested the design to see if there's any showstoppers) you might define inside the model an inner class like: class TermStructureConsistentModel { ... private: class OneFactorThingamabob { // the name is your call public: virtual ~OneFactorThingamabob() {} virtual Real discountOrSomething(Time t) const = 0; } Handle<OneFactorThingamabob> bob_; ... }; then an adapter like: template <class T> class ThingamabobAdapter; and specializations such as: template <> class ThingamabobAdapter<YieldTermStructure> : public OneFactorThingamabob { public: // take and store a YieldTermStructure Real discountOrSomething(Time t) const { return storedYTS_->discount(t); } }; template <> class ThingamabobAdapter<DefaultProbabilityTermStructure> : public OneFactorThingamabob { public: // take and store a DefaultProbabilityTermStructure Real discountOrSomething(Time t) const { return storedYTS_->defaultProbability(t); } }; and finally a template constructor for TSCM: template <class T> TermStructureConsistentModel(const Handle<T>& h, ...) { bob_ = new ThingamabobAdapter<T>(h); ... } This should adapt the several interfaces and do the right thing for each. It might even remove the need of turning the classes into templates, since adding templates constructors might suffice. The problem would be backward compatibility. But it might (emphasis on might) be saved by keeping the old constructors as special cases. Later, Luigi -- Brady's First Law of Problem Solving: When confronted by a difficult problem, you can solve it more easily by reducing it to the question, "How would the Lone Ranger have handled this?" ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Hi Luigi,
Thanks for the advice, it works. I'll be submitting a patch in the next week. Simon -----Original Message----- From: Luigi Ballabio [mailto:[hidden email]] Sent: 26 October 2010 15:19 To: Simon Ibbotson Cc: [hidden email]; [hidden email] Subject: Re: [Quantlib-dev] Extending short-rate models for credit / inflation. On Mon, 2010-10-25 at 13:20 +0100, Simon Ibbotson wrote: > That was what I meant (making the classes into template classes ) - > but it would affect many classes, not just the TSCM and the TSFP. > Also, any classes that derive from those (e.g. Hull-White, CIR++) and > that use them (Grids etc.). > > [...] > > Extending the TermStructure definition would be much simpler - or > adding another layer (e.g. RateBasedTermStructure) which would derive > from TermStructure and be the base class for YieldTermStructure, > DefaultProbabilityTermStructure, InflationTermStructure etc. I'm not sure. On the one hand, you'd have to modify all the classes anyway so that they take a RateBasedTermStructure instead of a YieldTermStructure. Once you're doing that, you might as well make them into templates. On the other hand, RateBasedTermStructure has no particular concept associated besides "a term structure returning some kind of rate" or something like that (is default probability a rate?) which is a bit too generic. It looks to me it would be just an implementation thing with no actual financial concept behind. Since the problem you're trying to solve is to unify different interfaces in some way, have you thought about doing it explicitly and using an Adapter pattern instead? Off the top of my head (so I haven't tested the design to see if there's any showstoppers) you might define inside the model an inner class like: class TermStructureConsistentModel { ... private: class OneFactorThingamabob { // the name is your call public: virtual ~OneFactorThingamabob() {} virtual Real discountOrSomething(Time t) const = 0; } Handle<OneFactorThingamabob> bob_; ... }; then an adapter like: template <class T> class ThingamabobAdapter; and specializations such as: template <> class ThingamabobAdapter<YieldTermStructure> : public OneFactorThingamabob { public: // take and store a YieldTermStructure Real discountOrSomething(Time t) const { return storedYTS_->discount(t); } }; template <> class ThingamabobAdapter<DefaultProbabilityTermStructure> : public OneFactorThingamabob { public: // take and store a DefaultProbabilityTermStructure Real discountOrSomething(Time t) const { return storedYTS_->defaultProbability(t); } }; and finally a template constructor for TSCM: template <class T> TermStructureConsistentModel(const Handle<T>& h, ...) { bob_ = new ThingamabobAdapter<T>(h); ... } This should adapt the several interfaces and do the right thing for each. It might even remove the need of turning the classes into templates, since adding templates constructors might suffice. The problem would be backward compatibility. But it might (emphasis on might) be saved by keeping the old constructors as special cases. Later, Luigi -- Brady's First Law of Problem Solving: When confronted by a difficult problem, you can solve it more easily by reducing it to the question, "How would the Lone Ranger have handled this?" This communication and any attachments contains information which is confidential and may be subject to legal privilege. It is for intended recipients only. If you are not the intended recipient you must not copy, distribute, publish, rely on or otherwise use it without our consent. Some of our communications may contain confidential information which it could be a criminal offence for you to disclose or use without authority. If you have received this email in error please notify [hidden email] immediately and delete the email from your computer. The FSA reserves the right to monitor all email communications for compliance with legal, regulatory and professional standards. This email is not intended to nor should it be taken to create any legal relations or contractual relationships. This email has originated from The Financial Services Authority (FSA) 25 The North Colonnade, Canary Wharf, London E14 5HS United Kingdom Registered as a Limited Company in England and Wales No.1920623. Registered Office as above Switchboard: 020 7066 1000 Web Site: http://www.fsa.gov.uk ***************************************************************** ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Free forum by Nabble | Edit this page |