|
From: Luigi B. <lui...@gm...> - 2008-03-14 15:11:45
|
On Thu, 2008-03-06 at 18:10 +0000, a akpitidis wrote: > I tried to add to 8.0 the CAD vanilla swaps for the curve building and > i came across with some design issues, mainlly because i don't want to > change existing modules of the library. However, i want to reuse most > of the core code. > > In my mind someone who wants to extend a library shouldn't have to > change existing files, but the library needs to provide the > appropriate hooks (i.e. interfaces, template classes/functions and so > on). We all agree here. However... > At the same time, as we all know, that takes time and effort, and in > the main time the DIY solution fits most clients :). It's not just that. Generalization can be applied if one knows in what direction to generalize. For instance, until you wrote about your problem, I wasn't aware of the CAD convention, not could I have imagined it. Since early generalization risks going in the wrong direction and burdening the code with unused abstractions, I prefer waiting for use cases such as yours and generalize based on actual need. > Here are some sugestions for the future: > > 1. Create a template class VanillaSwapG ( G for generic), the > coupontype should be the template parameters and they should be > propagated down to the construction of the floating leg. > > 3. Those template arguments should be propagated upwards to > MakeVanillaSwap and SwapRateHelper. Does your coupon's constructor take the same number of arguments as the existing IborCoupon? Otherwise, one would also have to generalize coupon creation so that it has a common interface (we'd probably need some kind of factory.) > 4. Finally, i need to be able to hook my own code into the > SwapRateHelper::initializeDates as i need to set the custom floating > leg tenor, which is different from the index tenor. Then again that > extra information needs to come from somewhere, but then i need to > have my new SwapRateHelper class, but i don't want to copy existing > code. This kind of hook is already provided by the language. You can inherit from SwapRatehelper and override SwapRateHelper::initializeDates (you don't need to copy any code; you can call the parent-class method after executing the CAD-specific code.) The extra data can go in the derived class. Luigi -- It is always the best policy to tell the truth, unless, of course, you are an exceptionally good liar. -- Jerome K. Jerome |