Hi all,
Pretty new to QuantLib and have been playing with the Example sources. I have a question regarding the PiecewiseYieldCurve object. If I want to make the first two parameters (traitid and interpolatorid) an input variable how can I do this? Specifically, I'm looking at the swapvaluation.cpp example where it is using "Discount" and "LogLinear". I want to make it a user input so the interpolation method can be changed. Sorry it's probably more of a C++ question as I'm a bit weak on templates. Thank you, Jon |
Hello,
template arguments have to be specified at compile time, so I'm afraid there's no way except a big if (traits == "Discount" && interpolation == "Linear") return make_shared<PiecewiseYieldCurve<Discount,Linear> >(...); else if (traits == "Discount" && interpolation == "LogLinear") return make_shared<PiecewiseYieldCurve<Discount,LogLinear> >(...); To minimize inconvenience, I'd put the above inside a function so that I'd only write it once. Then in client code I'd just write shared_ptr<YieldTermStructure> curve = make_piecewise(traits, interpolation, helpers, ...); Luigi On Wed, Jan 29, 2014 at 2:49 PM, jlee <[hidden email]> wrote: > Hi all, > Pretty new to QuantLib and have been playing with the Example sources. I > have a question regarding the PiecewiseYieldCurve object. If I want to make > the first two parameters (traitid and interpolatorid) an input variable how > can I do this? Specifically, I'm looking at the swapvaluation.cpp example > where it is using "Discount" and "LogLinear". I want to make it a user input > so the interpolation method can be changed. Sorry it's probably more of a > C++ question as I'm a bit weak on templates. > > Thank you, > Jon > > > > -- > View this message in context: http://quantlib.10058.n7.nabble.com/PiecewiseYieldCurve-question-tp14918.html > Sent from the quantlib-dev mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > WatchGuard Dimension instantly turns raw network data into actionable > security intelligence. It gives you real-time visual feedback on key > security issues and trends. Skip the complicated setup - simply import > a virtual appliance and go from zero to informed in seconds. > http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk > _______________________________________________ > QuantLib-dev mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-dev -- <https://implementingquantlib.blogspot.com> <https://twitter.com/lballabio> ------------------------------------------------------------------------------ WatchGuard Dimension instantly turns raw network data into actionable security intelligence. It gives you real-time visual feedback on key security issues and trends. Skip the complicated setup - simply import a virtual appliance and go from zero to informed in seconds. http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Thanks for the quick reply. Let me give this a way and see. Thanks for your help! On 29 January 2014 15:57, Luigi Ballabio [via QuantLib] <[hidden email]> wrote:
|
In reply to this post by Luigi Ballabio
Got it to work your with suggestion. But have a related question. Is there a list of available interpolation classes? I was able to get working:
Discount, BackwardFlat Discount, ForwardFlat Discount, Linear Discount, LogLinear but when i tried: CubicNaturalSpline LogCubicNaturalSpline MonotonicCubicNaturalSpline KrugerCubic FritschButlandCubic Parabolic LogParabolic MonotonicParabolic MonotonicLogParabolic Abcd Bilinear Bicubic I get compile a error saying no default constructor. Are these valid methods as these seems to be ones I've search around in the code. Thanks, Jon |
Those are valid interpolations, but PiecewiseYieldCurve needs the
corresponding traits class (i.e., the one that defines an interpolate() method that returns an Interpolation instance). For the various cubic interpolations, that would be the Cubic class. It maps to the various kinds of cubic depending on the parameters you use to create it. If you use, say, PiecewiseYieldCurve<Discount,Cubic> and just build it with the curve information (helpers etc), it will use the default parameters (which, I think, give you a Kruger cubic). If you create an instance of Cubic explicitly and pass it to the constructor of PiecewiseYieldCurve<Discount,Cubic> as the last, optional parameter, you'll get the corresponding cubic. You can see the parameters to use for each interpolation by looking at its constructor and checking what parameters it passes to the base CubicInterpolation class. Luigi On Wed, Jan 29, 2014 at 6:31 PM, jlee <[hidden email]> wrote: > Got it to work your with suggestion. But have a related question. Is there a > list of available interpolation classes? I was able to get working: > > Discount, BackwardFlat > Discount, ForwardFlat > Discount, Linear > Discount, LogLinear > > but when i tried: > > CubicNaturalSpline > LogCubicNaturalSpline > MonotonicCubicNaturalSpline > KrugerCubic > FritschButlandCubic > Parabolic > LogParabolic > MonotonicParabolic > MonotonicLogParabolic > Abcd > Bilinear > Bicubic > > I get compile a error saying no default constructor. Are these valid methods > as these seems to be ones I've search around in the code. > > Thanks, > Jon > > > > -- > View this message in context: http://quantlib.10058.n7.nabble.com/PiecewiseYieldCurve-question-tp14918p14923.html > Sent from the quantlib-dev mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > WatchGuard Dimension instantly turns raw network data into actionable > security intelligence. It gives you real-time visual feedback on key > security issues and trends. Skip the complicated setup - simply import > a virtual appliance and go from zero to informed in seconds. > http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk > _______________________________________________ > QuantLib-dev mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-dev -- <https://implementingquantlib.blogspot.com> <https://twitter.com/lballabio> ------------------------------------------------------------------------------ WatchGuard Dimension instantly turns raw network data into actionable security intelligence. It gives you real-time visual feedback on key security issues and trends. Skip the complicated setup - simply import a virtual appliance and go from zero to informed in seconds. http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Free forum by Nabble | Edit this page |