Advertisement
Guest User

Untitled

a guest
Sep 5th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. void testYieldFromIRSwap()
  2. {
  3. Settings::instance().evaluationDate() = Date(1, Jan, 2015);
  4.  
  5. auto dc = Actual360();
  6.  
  7. auto h1 = boost::shared_ptr<RateHelper>(new DepositRateHelper
  8. (0.03, Period(1, Years), 0.0, UnitedStates(), Following, false, Actual360()));
  9. auto h2 = boost::shared_ptr<RateHelper>(new DepositRateHelper
  10. (0.04, Period(2, Years), 0.0, UnitedStates(), Following, false, Actual360()));
  11.  
  12. auto index = boost::shared_ptr<IborIndex>(new EURLibor1Y());
  13. auto h3 = boost::shared_ptr<RateHelper>(
  14. new SwapRateHelper(0.05, Period(3, Years), UnitedStates(), Annual,
  15. Following, Actual360(), index));
  16.  
  17. std::vector<boost::shared_ptr<RateHelper>> helpers;
  18. helpers.push_back(h1);
  19. helpers.push_back(h2);
  20. helpers.push_back(h3);
  21.  
  22. boost::shared_ptr<YieldTermStructure> yield(
  23. new PiecewiseYieldCurve<Discount,LogLinear>(
  24. Settings::instance().evaluationDate(), helpers,
  25. Actual360()));
  26.  
  27. const auto t1 = dc.yearFraction(Date(1, Jan, 2015), Date(1, Jan, 2016)); // 1.014
  28. const auto t2 = dc.yearFraction(Date(1, Jan, 2015), Date(1, Jan, 2017)); // 2.031
  29. const auto t3 = dc.yearFraction(Date(1, Jan, 2015), Date(1, Jan, 2018)); // 3.044
  30.  
  31. std::cout << yield->discount(0) << std::endl; // Must be 1
  32. std::cout << yield->discount(t1) << std::endl; // 1/((1+0.03) ^ 1.014) = 0.9704721
  33. std::cout << yield->discount(t2) << std::endl; // 1/(1+0.04) ^ 2.031 = 0.9234328
  34. std::cout << yield->discount(t3) << std::endl;
  35. }
  36.  
  37. Real SwapRateHelper::impliedQuote() const {
  38. QL_REQUIRE(termStructure_ != 0, "term structure not set");
  39. // we didn't register as observers - force calculation
  40. swap_->recalculate();
  41. // weak implementation... to be improved
  42. static const Spread basisPoint = 1.0e-4;
  43. Real floatingLegNPV = swap_->floatingLegNPV();
  44. Spread spread = spread_.empty() ? 0.0 : spread_->value();
  45. Real spreadNPV = swap_->floatingLegBPS()/basisPoint*spread;
  46. Real totNPV = - (floatingLegNPV+spreadNPV);
  47. Real result = totNPV/(swap_->fixedLegBPS()/basisPoint);
  48. return result;
  49. }
  50.  
  51. Real result = totNPV/(swap_->fixedLegBPS()/basisPoint);
  52.  
  53. bps += cp->nominal() * cp->accrualPeriod() * df;
  54.  
  55. targetNPV : fixedRate = BPS : 1 basis point
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement