예제 #1
0
// [[Rcpp::export]]
bool setCalendarContext(std::string calendar, int fixingDays, QuantLib::Date settleDate) {

    // Rcpp Attribute cannot reflect complicated default arguments
    if (settleDate.serialNumber() == 0) {
        calendar = "TARGET";
        fixingDays = 2;
        settleDate = QuantLib::Date::todaysDate() + 2; 
    }
    // set fixingDays and settleDate
    RQLContext::instance().fixingDays = fixingDays;
    RQLContext::instance().settleDate = settleDate;

    boost::shared_ptr<QuantLib::Calendar> pcal(getCalendar(calendar));
    RQLContext::instance().calendar = *pcal; // set calendar in global singleton
    
    return true;
}
예제 #2
0
long libraryToScalar(const QuantLib::Date &d) {
    return d.serialNumber();
}
예제 #3
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  DDS::DomainParticipantFactory_var dpf = DDS::DomainParticipantFactory::_nil();
  DDS::DomainParticipant_var participant = DDS::DomainParticipant::_nil();

  try
  {
     QuantLibAddinCpp::initializeAddin();

     QuantLib::Calendar calendar = QuantLib::TARGET();

     QuantLib::Date settlementDate(22, QuantLib::September, 2004);

     settlementDate = calendar.adjust(settlementDate);

     QuantLib::Integer fixingDays = 2;

     QuantLib::Date todaysDate = calendar.advance(settlementDate, -fixingDays, QuantLib::Days);

     QuantLibAddinCpp::qlSettingsSetEvaluationDate( todaysDate.serialNumber(), OH_NULL );
     std::cout << "Today: " << todaysDate.weekday() << ", " << todaysDate << std::endl;
     std::cout << "Settlement date: " << settlementDate.weekday() << ", " << settlementDate << std::endl;

     // Initialize, and create a DomainParticipant
     dpf = TheParticipantFactoryWithArgs(argc, argv);


     qldds_utils::BasicDomainParticipant irs_participant( dpf, IRS_DOMAIN_ID );
     irs_participant.createPublisher();
     irs_participant.createSubscriber();

     std::string term_structure;

     std::vector<std::string> rate_helpers;

     ACE_Get_Opt cmd_opts( argc, argv, ":c:n:i:" );

     int option;

     while ( (option = cmd_opts()) != EOF )
     {
       switch( option )
       {
         case 'c' :
         { 
           std::istringstream f( cmd_opts.opt_arg() );
           std::string s;

           while (std::getline(f, s, '|')) {
             rate_helpers.push_back(s);
           }
           break;
         }
         case 'n' :
         {
           term_structure = cmd_opts.opt_arg();
           break;
         }
       }
     }

     QuantLibAddinCpp::qlLibor("Libor", "USD", "6M", "", false, false, true);
     
     // Topics for Swap Components
     // Setting up schedule topic
     DDS::Topic_var schedule_topic =
         irs_participant.createTopicAndRegisterType
         < schedule::qlScheduleTypeSupport_var, schedule::qlScheduleTypeSupportImpl >
         ( SCHEDULE_TOPIC_NAME );

     // setting up vanilla swap topic 
     DDS::Topic_var vanilla_swap_topic =
         irs_participant.createTopicAndRegisterType
         < vanillaswap::qlVanillaSwapTypeSupport_var, vanillaswap::qlVanillaSwapTypeSupportImpl >
         ( VANILLA_SWAP_TOPIC_NAME );

 
     // Topics for curve components
     // setting up deposit rate helper
     DDS::Topic_var deposit_rate_helper2_topic = irs_participant.createTopicAndRegisterType
         < ratehelpers::qlDepositRateHelper2TypeSupport_var, ratehelpers::qlDepositRateHelper2TypeSupportImpl >
          ( DEPOSIT_RATE_HELPER2_TOPIC_NAME );

     // setting up FRA Rate helper
     DDS::Topic_var fra_rate_helper2_topic = irs_participant.createTopicAndRegisterType
         < ratehelpers::qlFraRateHelper2TypeSupport_var, ratehelpers::qlFraRateHelper2TypeSupportImpl >
          ( FRA_RATE_HELPER2_TOPIC_NAME );

     // setting up Swap Rate helper
     DDS::Topic_var swap_rate_helper2_topic = irs_participant.createTopicAndRegisterType
       < ratehelpers::qlSwapRateHelper2TypeSupport_var, ratehelpers::qlSwapRateHelper2TypeSupportImpl >
        (  SWAP_RATE_HELPER2_TOPIC_NAME );


    irs_participant.createDataReaderListener< schedule::qlScheduleDataReaderListenerImpl> ( qldds_lock, schedule_topic );
    irs_participant.createDataReaderListener< VanillaSwapDataReaderListenerImpl > ( qldds_lock, vanilla_swap_topic );

    irs_participant.createDataReaderListener< DepositRateHelper2DataReaderListenerImpl > ( qldds_lock,deposit_rate_helper2_topic );
    irs_participant.createDataReaderListener< FraRateHelper2DataReaderListenerImpl > ( qldds_lock, fra_rate_helper2_topic );
    irs_participant.createDataReaderListener< SwapRateHelper2DataReaderListenerImpl > ( qldds_lock, swap_rate_helper2_topic );

    // setting up IRS Portfolio. Priced portfolios will be published on this topic
    DDS::Topic_var irs_portfolio_topic = irs_participant.createTopicAndRegisterType
       < IRS::PortfolioTypeSupport_var, IRS::PortfolioTypeSupportImpl >
        (  IRS_PORTFOLIO_TOPIC_NAME  );

    IRS::PortfolioDataWriter_var irs_portfolio_dw = irs_participant.createDataWriter
      < IRS::PortfolioDataWriter_var, IRS::PortfolioDataWriter >
       ( irs_portfolio_topic );

    curves.insert( std::pair < std::string, std::vector< std::string > > ( term_structure, rate_helpers ) );

    int calculation_performed = 0;

    while ( calculation_performed < 30 )
    {
      IRS::Portfolio irs_portfolio_out;

      if ( computeNPVs( term_structure,  irs_portfolio_out ) == false )
      {
        ACE_Time_Value sleep_100ms( 0, 100000 );
        ACE_OS::sleep( sleep_100ms );

        continue;
      } else {
        calculation_performed++;
        ACE_OS::sleep(1);
      } 

      std::cout << "Calculator ["<< term_structure << "] publishing NPVs for "<< irs_portfolio_out.swaps.length() << " interest rate swaps."<< std::endl; 

      int ret = irs_portfolio_dw->write( irs_portfolio_out, DDS::HANDLE_NIL );
      if (ret != DDS::RETCODE_OK) {
         ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: IRS Portfolio write returned %d.\n"), ret));
      }

    }

  } catch (CORBA::Exception& e)
  {
    cerr << "Exception caught in main.cpp:" << endl << e << endl;
    ACE_OS::exit(1);
  }

  TheServiceParticipant->shutdown();

  return 0;
}