Hi,
This question relates to my current project RQuantLib. Is it possible to reconstruct a YieldTermStructure object from the following data > data.frame(curves$time, curves$zero) curves.time curves.zero 1 0.0 0.03907353 2 0.1 0.03763962 3 0.2 0.03792946 4 0.3 0.03772951 5 0.4 0.03688215 6 0.5 0.03595016 7 0.6 0.03518703 8 0.7 0.03446887 9 0.8 0.03394159 10 0.9 0.03374615 11 1.0 0.03372845 12 1.1 0.03378364 13 1.2 0.03390000 14 1.3 0.03404539 15 1.4 0.03418891 .... 90 8.9 0.05042988 91 9.0 0.05056532 92 9.1 0.05069762 93 9.2 0.05082671 94 9.3 0.05095246 95 9.4 0.05107479 96 9.5 0.05119360 97 9.6 0.05130878 98 9.7 0.05142024 99 9.8 0.05152787 100 9.9 0.05163158 101 10.0 0.05173125 the 'curves' object is built from this data using quantlib tsQuotes <- list(d1w =0.0382, d1m =0.0372, fut1=96.2875, fut2=96.7875, fut3=96.9875, fut4=96.6875, fut5=96.4875, fut6=96.3875, fut7=96.2875, fut8=96.0875, s3y =0.0398, s5y =0.0443, s10y =0.05165, s15y =0.055175) Thanks. -k ------------------------------------------------------------------------------ Are you an open source citizen? Join us for the Open Source Bridge conference! Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250. Need another reason to go? 24-hour hacker lounge. Register today! http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi Khanh. Actually, I'm not sure what the question is. So, do you get future + swap quotes and you'd like to build a curve? 2009/6/21 Khanh Nguyen <[hidden email]> Hi, ------------------------------------------------------------------------------ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by Khanh Nguyen
On Sun, 2009-06-21 at 09:58 -0400, Khanh Nguyen wrote:
> This question relates to my current project RQuantLib. Is it possible > to reconstruct a YieldTermStructure object from the following data > > > data.frame(curves$time, curves$zero) > curves.time curves.zero > 1 0.0 0.03907353 > 2 0.1 0.03763962 > 3 0.2 0.03792946 > .... > 100 9.9 0.05163158 > 101 10.0 0.05173125 > > the 'curves' object is built from this data using quantlib > > tsQuotes <- list(d1w =0.0382, > d1m =0.0372, > fut1=96.2875, > fut2=96.7875, > fut3=96.9875, > fut4=96.6875, > fut5=96.4875, > fut6=96.3875, > fut7=96.2875, > fut8=96.0875, > s3y =0.0398, > s5y =0.0443, > s10y =0.05165, > s15y =0.055175) I'm not familiar with RQuantLib, so I'll have to make some guesses. Since you list a set of deposits, futures, and swaps, I assume that you built a piecewise yield curve. If you want to store it and reconstruct it later, your best choice would be to store the nodes of the curve (for instance, with your set of inputs you'd have a node at 1 week, one at 1 month etc.) From here though, I can only guess. For instance, when you build the piecewise curve you can interpolate on discount factors, zero yields, or forwards. Depending on what you chose, the nodes will contain different values and you'll need to know what you have stored in order to rebuild the curve (using an InterpolatedDiscountCurve, or an InterpolatedZeroCurve...) Also, the data you're listing above are at t=0.1, 0.2 etc, and seem to be some kind of regular sampling of the curve rather than the values at the nodes. With those data, you won't be able to reconstruct the curve exactly. Luigi -- This gubblick contains many nonsklarkish English flutzpahs, but the overall pluggandisp can be glorked from context. -- David Moser ------------------------------------------------------------------------------ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi Luigi,
I have another question regarding this. I am following Example\CallableBond\CallableBond.cpp to implement a callable bond function for rquantlib. My problem is this If I built the term structure directly like this Date today = Date(16,October,2007); boost::shared_ptr<SimpleQuote> rRate(new SimpleQuote(0.055)); Handle<YieldTermStructure> termStructure(flatRate(today,rRate,Actual360())); then my codes work fine. However, if I built the term structure curve from discrete date using InterpolateZeroCurve, calling bond-NPV() returns an 'year outside valid range' exception. In particular, the codes are Handle<YieldTermStructure> termStructure(rebuildCurveFromZeroRates( hwTermDateSexp, hwTermZeroSexp)); with hwTermDateSexp and hwTermZeroSexp are date and zero rates vectors. They are generated by int n = termStructure->maxDate() - settlementDate; for (int i = 0; i<n;i++){ std::vector<ColDatum> row(numCol); Date d = current; row[0].setDateValue(RcppDate(d.month(), d.dayOfMonth(), d.year())); double zrate = termStructure->zeroRate(current, ActualActual(), Continuous); row[1].setDoubleValue(zrate); frame.addRow(row); current++; } The rebuiltCurveFromZeroRates is implemented as boost::shared_ptr<YieldTermStructure> rebuildCurveFromZeroRates( SEXP dateSexp, SEXP zeroSexp){ RcppDateVector rcppdates = RcppDateVector(dateSexp); int n = rcppdates.size(); std::vector<QuantLib::Date> dates(rcppdates.size()); for (int i = 0;i<n;i++){ QuantLib::Date day(dateFromR(rcppdates(i)) ); dates[i] = day; } //extract coupon rates vector RcppVector<double> RcppVec(zeroSexp); std::vector<double> zeros(RcppVec.stlVector()); boost::shared_ptr<YieldTermStructure> rebuilt_curve(new InterpolatedZeroCurve<LogLinear>( dates, zeros, ActualActual())); return rebuilt_curve; } Any ideas? This has been bugging me for a few days. Thanks -k On Mon, Jun 29, 2009 at 10:35 PM, Luigi Ballabio<[hidden email]> wrote: > On Sun, 2009-06-21 at 09:58 -0400, Khanh Nguyen wrote: >> This question relates to my current project RQuantLib. Is it possible >> to reconstruct a YieldTermStructure object from the following data >> >> > data.frame(curves$time, curves$zero) >> curves.time curves.zero >> 1 0.0 0.03907353 >> 2 0.1 0.03763962 >> 3 0.2 0.03792946 >> .... >> 100 9.9 0.05163158 >> 101 10.0 0.05173125 >> >> the 'curves' object is built from this data using quantlib >> >> tsQuotes <- list(d1w =0.0382, >> d1m =0.0372, >> fut1=96.2875, >> fut2=96.7875, >> fut3=96.9875, >> fut4=96.6875, >> fut5=96.4875, >> fut6=96.3875, >> fut7=96.2875, >> fut8=96.0875, >> s3y =0.0398, >> s5y =0.0443, >> s10y =0.05165, >> s15y =0.055175) > > I'm not familiar with RQuantLib, so I'll have to make some guesses. > Since you list a set of deposits, futures, and swaps, I assume that you > built a piecewise yield curve. If you want to store it and reconstruct > it later, your best choice would be to store the nodes of the curve (for > instance, with your set of inputs you'd have a node at 1 week, one at 1 > month etc.) From here though, I can only guess. For instance, when you > build the piecewise curve you can interpolate on discount factors, zero > yields, or forwards. Depending on what you chose, the nodes will > contain different values and you'll need to know what you have stored in > order to rebuild the curve (using an InterpolatedDiscountCurve, or an > InterpolatedZeroCurve...) Also, the data you're listing above are at > t=0.1, 0.2 etc, and seem to be some kind of regular sampling of the > curve rather than the values at the nodes. With those data, you won't be > able to reconstruct the curve exactly. > > Luigi > > > -- > > This gubblick contains many nonsklarkish English flutzpahs, but the > overall pluggandisp can be glorked from context. > -- David Moser > > > ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |