Login  Register

PiecewiseYieldCurve ZeroRate

Posted by George Cowie on May 07, 2014; 12:02pm
URL: http://quantlib.414.s1.nabble.com/PiecewiseYieldCurve-ZeroRate-tp15241.html


  I feel like this flavor of question has been asked before on this forum, but I can't seem to figure out what I'm doing wrong.  I would expect the following code to return pretty much the same rates I input into the RateHelpers, but that's not the case.  

  Am I incorrect about the expected functionality, or do I have something wrong with my code?

Thanks,
George

Output:

Period,Input Rate,Curve Rate
1W,0.0012075,0.00120749
1M,0.001515,0.00138513
2M,0.001935,0.00176613
3M,0.0022535,0.00209296
6M,0.00323,0.00306812
1Y,0.00549,0.005284

Code:

#include <ql/quantlib.hpp>

using namespace std ;
using namespace QuantLib ;

int main(int argc, char** argv)
{
  vector<Rate> liborRates ;
  liborRates.push_back(0.12075 / 100.0) ; //1W
  liborRates.push_back(0.1515 / 100.0) ; //1M
  liborRates.push_back(0.1935 / 100.0) ; //2M
  liborRates.push_back(0.22535 / 100.0) ; //3M
  liborRates.push_back(0.323 / 100.0) ; //6M
  liborRates.push_back(0.549 / 100.0) ; //12M

  vector<Period> periods ;
  periods.push_back(Period(1,Weeks)) ;
  periods.push_back(Period(1,Months)) ;
  periods.push_back(Period(2,Months)) ;
  periods.push_back(Period(3,Months)) ;
  periods.push_back(Period(6,Months)) ;
  periods.push_back(Period(12,Months)) ;

  vector<boost::shared_ptr<RateHelper> > instruments ;

  for (vector<int>::size_type i = 0 ; i < liborRates.size() ; i++)
    {
      boost::shared_ptr<Quote> liborQuote(new SimpleQuote(liborRates[i])) ;
      Handle<Quote> liborHandle(liborQuote) ;
      boost::shared_ptr<IborIndex> liborIndex(new USDLibor(periods[i])) ;
      boost::shared_ptr<RateHelper> rateHelper(new DepositRateHelper(liborHandle,liborIndex)) ;
      instruments.push_back(rateHelper) ;
    }

  Calendar calendar = TARGET ();
  Date today (29 , Apr ,2014);
  Natural settlementDays = 2;
  Date settlement = calendar.advance ( today , settlementDays , Days );
  DayCounter dc = Actual360 ();
  boost::shared_ptr <YieldTermStructure> yieldCurve ;
  yieldCurve = boost::shared_ptr <YieldTermStructure>(new
     PiecewiseYieldCurve < ZeroYield , Linear >( settlement , instruments , dc ));

  cout << "Period,Input Rate,Curve Rate" << endl ;
  for(vector<int>::size_type i = 0 ; i < periods.size() ; i++)
    {
      Rate curveRate = Rate(yieldCurve->zeroRate(settlement + periods[i], dc, Continuous)) ;
      cout << periods[i] << "," << liborRates[i] << "," << curveRate << endl ;
    }

  return 0 ;
}


------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users