Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.17 KB | None | 0 0
  1. #include "BondCalculator.h"
  2.  
  3. Result BondCalculator::calculate( BondCalculator::Changed ch, double num, const std::string& dateString )
  4. {
  5.   ql::Date date = ql::DateParser::parse( dateString, "dd/MM/yyyy" );
  6.  
  7.   switch ( ch ) {
  8.   case Changed::SimpleYield:
  9.     return simpleYieldChanged( num, date );
  10.  
  11.   case Changed::CompoundedYield:
  12.     return compoundedYieldChanged( num, date );
  13.  
  14.   case Changed::CleanPrice:
  15.     return cleanPriceChanged( num, date );
  16.  
  17.   case Changed::DirtyPrice:
  18.     return dirtyPriceChanged( num, date );
  19.   }
  20. }
  21.  
  22. Result BondCalculator::simpleYieldChanged( double num, const ql::Date& date )
  23. {
  24.   Result res;
  25.   res.simpleyield = num;
  26.   res.cleanPrice = this->m_bond->cleanPrice( num, this->m_params->dayCounter, ql::Compounding::Simple,
  27.                                              ql::Frequency::Annual,
  28.                                              date );
  29.   res.dirtyPrice = this->m_bond->dirtyPrice( num, this->m_params->dayCounter, ql::Compounding::Simple,
  30.                                              ql::Frequency::Annual,
  31.                                              date );
  32.   res.compoundedYield = this->m_bond->yield( res.cleanPrice, this->m_params->dayCounter, ql::Compounding::Compounded,
  33.                                              ql::Frequency::Annual,
  34.                                              date );
  35.   return res;
  36. }
  37.  
  38. Result BondCalculator::compoundedYieldChanged( double num, const ql::Date& date )
  39. {
  40.   Result res;
  41.   res.compoundedYield = num;
  42.   res.cleanPrice = this->m_bond->cleanPrice( num, this->m_params->dayCounter, ql::Compounding::Compounded,
  43.                                              ql::Frequency::Annual,
  44.                                              date );
  45.   res.dirtyPrice = this->m_bond->dirtyPrice( num, this->m_params->dayCounter, ql::Compounding::Compounded,
  46.                                              ql::Frequency::Annual,
  47.                                              date );
  48.   res.simpleyield = this->m_bond->yield( res.cleanPrice, this->m_params->dayCounter, ql::Simple, ql::Annual,
  49.                                          date );
  50.   return res;
  51. }
  52.  
  53. Result BondCalculator::cleanPriceChanged( double num, const ql::Date& date )
  54. {
  55.   Result res;
  56.   res.cleanPrice = num;
  57.   res.simpleyield = this->m_bond->yield( num, this->m_params->dayCounter, ql::Simple, ql::Annual, date );
  58.   res.compoundedYield = this->m_bond->yield( num, this->m_params->dayCounter, ql::Compounded, ql::Annual,
  59.                                              date );
  60.  
  61.   res.dirtyPrice = this->m_bond->dirtyPrice( res.compoundedYield, this->m_params->dayCounter, ql::Compounded, ql::Annual,
  62.                                              date );
  63.   return res;
  64. }
  65.  
  66. Result BondCalculator::dirtyPriceChanged( double num, const ql::Date& date )
  67. {
  68.   Result res;
  69.  
  70.   res.dirtyPrice = num;
  71.   res.cleanPrice = num - this->m_bond->accruedAmount( date );
  72.   res.simpleyield = this->m_bond->yield( res.cleanPrice, this->m_params->dayCounter, ql::Simple, ql::Annual, date );
  73.   res.compoundedYield = this->m_bond->yield( res.cleanPrice, this->m_params->dayCounter, ql::Compounded, ql::Annual,
  74.                                              date );
  75.  
  76.   return res;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement