Hi All,
I have question regarding the YieldTermStructure instance in QuantLib. Basically, I would like to construct a YieldTermStructure instance by feeding in a vector of discount factors and corresponding dates. What is the simplest way to do that? Currently I am doing is by constructing an InterpolatedDiscountCurve but that has to come with interpolation, and since my inputs are already daily discount factors I would like to avoid this step and thus save some calculation. The code looks like this: boost::shared_ptr<YieldTermStructure> discountingCrv(new InterpolatedDiscountCurve<Linear>(dates, discounts, Actual365Fixed())); where dates and discounts are vector of type Date and DiscountFactors respectively. Thank you, Teejayu |
Hi Teejayu,
you could implement a new class doing that. Note that the YieldTermStructure interface requires the implementation of a time-based discount factor implementation, so you have to convert a time back to a date in every case. Also be aware of instantaneous forward rate calculations that are implemented by a finite difference logic, so if you return the same discount factor throughout a day you would get zero as the instantaneous forward. I once implemented a similar kind of class (with a different objective though) here https://github.com/pcaspers/quantlib/blob/master/QuantLib/ql/experimental/yield/clonedyieldtermstructure.hpp if you are interested to have a look. In the end I wouldn't expect too much performance gain from such a specialized class. Even if you feed like 10,000 days the linear interpolation lookup would have a complexity of around 10 double - comparisons, so not that bad. The memory footprint seems a more serious issue for such a representation. Best regards Peter On 21 October 2015 at 22:54, teejayu <[hidden email]> wrote: > Hi All, > > I have question regarding the YieldTermStructure instance in QuantLib. > Basically, I would like to construct a YieldTermStructure instance by > feeding in a vector of discount factors and corresponding dates. What is the > simplest way to do that? > > Currently I am doing is by constructing an InterpolatedDiscountCurve but > that has to come with interpolation, and since my inputs are already daily > discount factors I would like to avoid this step and thus save some > calculation. > > The code looks like this: > *boost::shared_ptr<YieldTermStructure> discountingCrv(new > InterpolatedDiscountCurve<Linear>(dates, discounts, Actual365Fixed()));* > > where dates and discounts are vector of type Date and DiscountFactors > respectively. > > Thank you, > Teejayu > > > > -- > View this message in context: http://quantlib.10058.n7.nabble.com/Passing-on-a-discount-curve-without-interpolating-tp16956.html > Sent from the quantlib-users mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > _______________________________________________ > QuantLib-users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-users ------------------------------------------------------------------------------ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi Peter,
Thanks for your reply. I am indeed feeding in a long vector of days (daily for 30yrs)...but I agree that it's prb not going to be saving too much speed there. I will implement a similar class (of your example) and see if it's worth it. At the same time, could you elaborate on what you meant by "memory footprint"? What exactly is the concern about memory in using such a cloned class? Thanks, TJ |
Hi Teejayu,
in the cloned yield term structure class I have two double vectors with one entry per day each. If you clone a term structure with maximum date 31-12-2199 (which is the maximum date allowed in ql), the instance is already consuming over 1 MB of main memory. I grew up with computers that had 4 KB and later 64 KB of main memory. This is also why I am not using a linear interpolation object, since this would create two more vectors (s_ and primitiveConst_) of the same size, so 3 MB already (for one curve with maximum length). Best regards Peter On 26 October 2015 at 17:50, teejayu <[hidden email]> wrote: > Hi Peter, > > Thanks for your reply. > > I am indeed feeding in a long vector of days (daily for 30yrs)...but I agree > that it's prb not going to be saving too much speed there. I will implement > a similar class (of your example) and see if it's worth it. > > At the same time, could you elaborate on what you meant by "memory > footprint"? What exactly is the concern about memory in using such a cloned > class? > > Thanks, > TJ > > > > -- > View this message in context: http://quantlib.10058.n7.nabble.com/Passing-on-a-discount-curve-without-interpolating-tp16956p16964.html > Sent from the quantlib-users mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > _______________________________________________ > QuantLib-users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-users ------------------------------------------------------------------------------ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |