Hello everybody,
I'm a new user of the QuantLib library and new to finance as well. After having read the examples and the documentation, I have tried to test my understanding of the libraryin reproducing a zero-rate curve I previously built my own, starting from deposits, futures and IRSs data. I cannot reproduce the zero-rate: rates are not correct from the beginning, so I will focus on deposits. Neither the dates of the curve (using the PieacewiseYieldCurve::dates() method) correspond to what I expected from the instruments I gave, for example there is one more date (28/11/2007) I don't know where it comes from (see the output I report below). I am also confused in how to describe the 1D 2D and 3D deposit in the DepositRateHelper constructor. Which are the correct settlement and fixing days? For a 1D deposit I expect settlement to be 0, fixing 1 and tenor 1*Day, for a 2D deposit I expect settlement to be 1, fixing 2 and tenor 1*Day. Why are settlement and fixing days both equal to 2 in 1W deposit? Can you help me in understanding what I did wrong? Here is what I have done, based on the swapvaluation example. Thank you all in advance, luca lferraro (luca _dot_ ferraro _at_ caspur _dot_ it) ############################### todaysDate: 22/11/2007 deposit: 1D 3.96 2D 4.06 3D 4.095 1W 4.15 ... ... futures: DEC07 95-363 MAR08 95-365 ... ... After having constructed the Handles to deposit rates, here's what I have done in describing the DepositRateHelpers: // deposits DayCounter depositDayCounter = Actual360(); // 1D deposit: // start today (settlement=0), last 1 day, payment tomorrow boost::shared_ptr<RateHelper> d1d(new DepositRateHelper( Handle<Quote>(d1dRate), 1*Days, 1, calendar, ModifiedFollowing, true, 0, depositDayCounter)); // 2D deposit: // start tomorrow(settlement=1), last 1 day, payment after tomorrow boost::shared_ptr<RateHelper> d2d(new DepositRateHelper( Handle<Quote>(d2dRate), 1*Days, 2, calendar, ModifiedFollowing, true, 1, depositDayCounter)); // 3D deposit: // start after tomorrow(settlement=2), last 1 day, payment after 3 day boost::shared_ptr<RateHelper> d3d(new DepositRateHelper( Handle<Quote>(d3dRate), 1*Days, 3, calendar, ModifiedFollowing, true, 2, depositDayCounter)); fixingDays = 2; // 1W deposit: from the swapvaluation example // why are settlement and fixing days both equal two ??? <-- question boost::shared_ptr<RateHelper> d1w(new DepositRateHelper( Handle<Quote>(d1wRate), 1*Weeks, fixingDays, calendar, ModifiedFollowing, true, fixingDays, depositDayCounter)); ... ... // Prepare the vector of depo-futures-swap to build the YieldCurve std::vector<boost::shared_ptr<RateHelper> > depoFutSwapInstruments; depoFutSwapInstruments.push_back(d1d); depoFutSwapInstruments.push_back(d2d); depoFutSwapInstruments.push_back(d3d); depoFutSwapInstruments.push_back(d1w); ... ... Date todaysDate = Date(22, November, 2007); Settings::instance().evaluationDate() = todaysDate; Integer fixingDays = 1; Date settlementDate=calendar.advance(todaysDate,fixingDays,Days); // creating the YieldCurve boost::shared_ptr<PieacewiseYieldCurve<Discount,LogLinear> > depoFutSwapTermStructure( new PiecewiseYieldCurve<Discount,LogLinear>( settlementDate, depoFutSwapInstruments, termStructureDayCounter, tolerance)); std::vector<Date> v = depoFutSwapTermStructure->dates(); for (unsigned i=0; i < v.size();i++) { std::cout << "Date: " << v[i].weekday() << ", " << v[i] << " rate: " << depoFutSwapTermStructure-> zeroRate(v[i],termStructureDayCounter,Continuous) << std::endl; } ################### OUTPUT OF THE CODE: Today: Thursday, November 22nd, 2007 Settlement date: Friday, November 23rd, 2007 Date: Friday, November 23rd, 2007 rate: 4.014338 % Date: Monday, November 26th, 2007 rate: 4.014338 % <-- the same rate? Date: Tuesday, November 27th, 2007 rate: 4.039792 % Date: Wednesday, November 28th, 2007 rate: 4.062162 % <-- hum !?! Date: Monday, December 3rd, 2007 rate: 4.148461 % ################## What I expected: Date: Days: Rate: 23/11/2007 1 4.01478 26/11/2007 4 4.09046 27/11/2007 5 4.10270 03/12/2007 11 4.16395 These values comes out from considering that: starting date: 22/11/2007 November 2007 December 2007 Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 1 2 5 6 7 8 9 10 11 3 4 5 6 7 8 9 12 13 14 15 16 17 18 10 11 12 13 14 15 16 19 20 21 22 23 24 25 17 18 19 20 21 22 23 26 27 28 29 30 24 25 26 27 28 29 30 31 1D 22/11/2007 -> 23/11/2007 2D 22/11/2007 -> (24,25) -> 26/11/2007 3D 22/11/2007 -> (24,25) -> -> 27/11/2007 1W 22/11/2007 -> (24,25) -> -> -> -> -> (1,2) -> 03/12/2007 and that I have built the zero rates considering that: 1D: exp^{Z_{1d}*(1/365)} = {1+R_{1D}*(1/360)} 2D: exp^{Z_{4d}*(4/365)} = {1+R_{2D}*(3/360)}*exp^{Z_{1d}*(1/365)} ... and so on ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi Luca
as far as I know there in no 3D deposit traded on the market, at least not in the EUR market. In the EUR market you can have SN (spot next: fixes today, starts in 2 working days, lasts 1 day), SW (spot week: fixes today, starts in 2 working days, lasts 1 week), 2W (2 weeks: fixes today, starts in 2 working days, lasts 2 weeks), 1M (1 month: fixes today, starts in 2 working days, lasts 1 months), nM (n month: fixes today, starts in 2 working days, lasts n months). You might also have ON (overnight: fixes today, starts today, lasts 1 day) and TN (tom-next: starts tomorrow, lasts 1 day). The star/end dates must be calculated taking into account holidays and market convention (end-of-month, modified following, etc) Details change for different currencies, e-g- for GBP spot=today, etc but the global picture is not altered. hope it helps ciao -- Nando On Tue, Mar 11, 2008 at 3:12 PM, luca ferraro <[hidden email]> wrote: > Hello everybody, > > I'm a new user of the QuantLib library and new to finance as well. > > After having read the examples and the documentation, I have tried to > test my understanding of the libraryin reproducing a zero-rate curve I > previously built my own, starting from deposits, futures and IRSs data. > > I cannot reproduce the zero-rate: rates are not correct from the > beginning, so I will focus on deposits. Neither the dates of the curve > (using the PieacewiseYieldCurve::dates() method) correspond to what I > expected from the instruments I gave, for example there is one more date > (28/11/2007) I don't know where it comes from (see the output I report > below). > > I am also confused in how to describe the 1D 2D and 3D deposit in the > DepositRateHelper constructor. Which are the correct settlement and > fixing days? For a 1D deposit I expect settlement to be 0, fixing 1 and > tenor 1*Day, for a 2D deposit I expect settlement to be 1, fixing 2 and > tenor 1*Day. Why are settlement and fixing days both equal to 2 in 1W > deposit? > > Can you help me in understanding what I did wrong? Here is what I > have done, based on the swapvaluation example. > > Thank you all in advance, > > luca lferraro > (luca _dot_ ferraro _at_ caspur _dot_ it) > > ############################### > todaysDate: 22/11/2007 > > deposit: > 1D 3.96 > 2D 4.06 > 3D 4.095 > 1W 4.15 > ... > ... > futures: > DEC07 95-363 > MAR08 95-365 > ... > ... > > > > After having constructed the Handles to deposit rates, here's what I > have done in describing the DepositRateHelpers: > > // deposits > DayCounter depositDayCounter = Actual360(); > > // 1D deposit: > // start today (settlement=0), last 1 day, payment tomorrow > boost::shared_ptr<RateHelper> d1d(new DepositRateHelper( > Handle<Quote>(d1dRate), 1*Days, 1, > calendar, ModifiedFollowing, > true, 0, depositDayCounter)); > > // 2D deposit: > // start tomorrow(settlement=1), last 1 day, payment after tomorrow > boost::shared_ptr<RateHelper> d2d(new DepositRateHelper( > Handle<Quote>(d2dRate), 1*Days, 2, > calendar, ModifiedFollowing, > true, 1, depositDayCounter)); > > // 3D deposit: > // start after tomorrow(settlement=2), last 1 day, payment after 3 day > boost::shared_ptr<RateHelper> d3d(new DepositRateHelper( > Handle<Quote>(d3dRate), 1*Days, 3, > calendar, ModifiedFollowing, > true, 2, depositDayCounter)); > > fixingDays = 2; > // 1W deposit: from the swapvaluation example > // why are settlement and fixing days both equal two ??? <-- question > boost::shared_ptr<RateHelper> d1w(new DepositRateHelper( > Handle<Quote>(d1wRate), 1*Weeks, fixingDays, > calendar, ModifiedFollowing, > true, fixingDays, depositDayCounter)); > > ... > ... > // Prepare the vector of depo-futures-swap to build the YieldCurve > std::vector<boost::shared_ptr<RateHelper> > depoFutSwapInstruments; > depoFutSwapInstruments.push_back(d1d); > depoFutSwapInstruments.push_back(d2d); > depoFutSwapInstruments.push_back(d3d); > depoFutSwapInstruments.push_back(d1w); > ... > ... > > Date todaysDate = Date(22, November, 2007); > Settings::instance().evaluationDate() = todaysDate; > > Integer fixingDays = 1; > Date settlementDate=calendar.advance(todaysDate,fixingDays,Days); > > // creating the YieldCurve > boost::shared_ptr<PieacewiseYieldCurve<Discount,LogLinear> > > depoFutSwapTermStructure( > new PiecewiseYieldCurve<Discount,LogLinear>( > settlementDate, depoFutSwapInstruments, > termStructureDayCounter, tolerance)); > > std::vector<Date> v = depoFutSwapTermStructure->dates(); > for (unsigned i=0; i < v.size();i++) { > std::cout << "Date: " << v[i].weekday() << ", " << v[i] > << " rate: " << depoFutSwapTermStructure-> > zeroRate(v[i],termStructureDayCounter,Continuous) > << std::endl; > } > > ################### > OUTPUT OF THE CODE: > Today: Thursday, November 22nd, 2007 > Settlement date: Friday, November 23rd, 2007 > > Date: Friday, November 23rd, 2007 rate: 4.014338 % > Date: Monday, November 26th, 2007 rate: 4.014338 % <-- the same rate? > Date: Tuesday, November 27th, 2007 rate: 4.039792 % > Date: Wednesday, November 28th, 2007 rate: 4.062162 % <-- hum !?! > Date: Monday, December 3rd, 2007 rate: 4.148461 % > > ################## > What I expected: > Date: Days: Rate: > 23/11/2007 1 4.01478 > 26/11/2007 4 4.09046 > 27/11/2007 5 4.10270 > 03/12/2007 11 4.16395 > > These values comes out from considering that: > > starting date: 22/11/2007 > > November 2007 December 2007 > Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su > 1 2 3 4 1 2 > 5 6 7 8 9 10 11 3 4 5 6 7 8 9 > 12 13 14 15 16 17 18 10 11 12 13 14 15 16 > 19 20 21 22 23 24 25 17 18 19 20 21 22 23 > 26 27 28 29 30 24 25 26 27 28 29 30 > 31 > > 1D 22/11/2007 -> 23/11/2007 > > 2D 22/11/2007 -> (24,25) -> 26/11/2007 > > 3D 22/11/2007 -> (24,25) -> -> 27/11/2007 > > 1W 22/11/2007 -> (24,25) -> -> -> -> -> (1,2) > -> 03/12/2007 > > and that I have built the zero rates considering that: > 1D: exp^{Z_{1d}*(1/365)} = {1+R_{1D}*(1/360)} > 2D: exp^{Z_{4d}*(4/365)} = {1+R_{2D}*(3/360)}*exp^{Z_{1d}*(1/365)} > ... > and so on > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > QuantLib-users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-users > ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Thanks Ferdinando, now I know a little bit more on finance conventions
and symbology :-) and I also do reproduce at least the first part of the zero-curve (I still have some problem in the dates corresponding to futures instruments). Taking this "rosetta's legend" in my previous message: 1D = overnight 2D = tomorrow-next 3D = spot next I should describe in QuantLib these deposit (1D, 2D, 3D) as: // 1D=overnight (fix today, start today, last 1 day) boost::shared_ptr<RateHelper> d1d(new DepositRateHelper( Handle<Quote>(d1dRate), 1*Days, 0, calendar, ModifiedFollowing, true, 0, depositDayCounter)); // 2D=tomorrow-next (fix today, start tomorrow, last 1 day) boost::shared_ptr<RateHelper> d2d(new DepositRateHelper( Handle<Quote>(d2dRate), 1*Days, 1, calendar, ModifiedFollowing, true, 0, depositDayCounter)); // 3D=spot-next (fix today, start after-tomorrow, last 1 day) boost::shared_ptr<RateHelper> d3d(new DepositRateHelper( Handle<Quote>(d3dRate), 1*Days, 2, calendar, ModifiedFollowing, true, 0, depositDayCounter)); Am I correct? Anyway, if today is 22/11/2007 and I want to obtain the zero-rate curve starting from tomorrow, should I write the following code ??? Calendar calendar = Italy(); Date todaysDate = Date(22, November, 2007); Settings::instance().evaluationDate() = todaysDate; Integer fixingDays = 1; Date settlementDate = calendar.advance(todaysDate, fixingDays, Days); boost::shared_ptr<PiecewiseYieldCurve<Discount,LogLinear> > depoFutSwapTermStructure( new PiecewiseYieldCurve<Discount,LogLinear>( settlementDate, depoFutSwapInstruments, termStructureDayCounter, tolerance)); std::vector<Date> v = depoFutSwapTermStructure->dates(); for (unsigned i=0; i < v.size();i++) { std::cout << "Date: " << v[i].weekday() << ", " << v[i] << " rate: " << depoFutSwapTermStructure-> zeroRate(v[i],termStructureDayCounter,Continuous) << std::endl; } Setting settlementDate as referenceDate in the PieacewiseYieldCurve, this code fails to evaluate the first deposit, because says that it has a date in the past. I should initialize PieacewiseYieldCurve with todaysDate as referenceDate and obtain the correct dates. So, what's the point of setting a settlementDate as: Date settlementDate = calendar.advance(todaysDate, fixingDays, Days); ??? Thank you again for the help. luca Ferdinando Ametrano wrote: > Hi Luca > > as far as I know there in no 3D deposit traded on the market, at least > not in the EUR market. > > In the EUR market you can have SN (spot next: fixes today, starts in 2 > working days, lasts 1 day), SW (spot week: fixes today, starts in 2 > working days, lasts 1 week), 2W (2 weeks: fixes today, starts in 2 > working days, lasts 2 weeks), 1M (1 month: fixes today, starts in 2 > working days, lasts 1 months), nM (n month: fixes today, starts in 2 > working days, lasts n months). > > You might also have ON (overnight: fixes today, starts today, lasts 1 > day) and TN (tom-next: starts tomorrow, lasts 1 day). > > The star/end dates must be calculated taking into account holidays and > market convention (end-of-month, modified following, etc) > > Details change for different currencies, e-g- for GBP spot=today, etc > but the global picture is not altered. > > hope it helps > > ciao -- Nando ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi Luca
> Taking this "rosetta's legend" in my previous message: > > 1D = overnight > 2D = tomorrow-next > 3D = spot next I would suggest you to abandon your 1D, 2D, 3D dialect and conform to market jargon: ON, TN, SN > // 1D=overnight (fix today, start today, last 1 day) > > boost::shared_ptr<RateHelper> d1d(new DepositRateHelper( > Handle<Quote>(d1dRate), > 1*Days, 0, > calendar, ModifiedFollowing, > true, 0, depositDayCounter)); > [...] the market convention for deposits under 1 Month is Following, not ModifiedFollowing. Besides that your code looks ok to me > if today is 22/11/2007 and I want to obtain the zero-rate curve > starting from tomorrow [..] why should you? You probably want to have discount = 1.0 at today's date. The only reasonable alternative (which I would NOT suggest) is to have discount = 1.0 at spot date, i.e. two business days from today. In the former case you can include ON, TN, and SN; in the latter you would only include SN, as nothing before spot makes sense in that case. You must have some really contrived reason to require discount = 1.0 tomorrow... > should I write the following code ??? > > Calendar calendar = Italy(); the reference holiday calendar for EUR is TARGET, not Italy > Date todaysDate = Date(22, November, 2007); > Settings::instance().evaluationDate() = todaysDate; > > Integer fixingDays = 1; > Date settlementDate = calendar.advance(todaysDate, fixingDays, Days); fixing date should be 2, or even better fix settlementDate = todaysDate and get rid of fixingDays > Setting settlementDate as referenceDate in the PieacewiseYieldCurve, > this code fails to evaluate the first deposit, because says that it has > a date in the past. This makes sense: if you fix discount = 1.0 at tomorrow's date nothing exists before tomorow's date, i.e. the SN depo is in the past Hope it helps... and also hope you have less trouble with futures and swaps ;-) ciao -- Nando ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |