void EventFunctionMFactory::parseXml(TiXmlNode* node)
	{
		boost::shared_ptr<EventFunction> ptr;
		
		//bool equality = getElementBool(node,"equality");
		bool equality = node->FirstChild("checkValue").Attribute("equality");
		double checkValue = d_xpath_double(node,"//checkValue/text()");
		std::string functionType = getElementValue(node,"functionType");

		if(to_upper_copy(functionType)=="UPEVENTCHECK"){ptr = boost::shared_ptr<EventFunction>(new UpEventCheck(checkValue,equality));}
		else if(to_upper_copy(functionType)=="DOWNEVENTCHECK"){ptr = boost::shared_ptr<EventFunction>(new DownEventCheck(checkValue,equality));}
		else if(to_upper_copy(functionType)=="UPDOWNEVENTCHECK"){ptr = boost::shared_ptr<EventFunction>(
					new UpDownEventCheck(checkValue,equality,checkValue,equality));}
		//else if(functionType=="RangeCheck"){ptr = boost::shared_ptr<EventFunction>(new IdentityEventCheck(checkValue,equality));}
		else{ptr = boost::shared_ptr<EventFunction>(new IdentityEventCheck(equality));}

		//std::string value = node->FirstChildElement()->GetText();

		std::string functionSymbol = getElementValue(node,"functionSymbol");
		std::string indexSymbol = getElementValue(node,"indexSymbol");

		eventFunctionM_ = boost::shared_ptr<EventFunctionManager>(
									new EventFunctionManager(functionSymbol,
															 indexSymbol,
															 ptr));



		
		
	}
    double* IndexSymbolManager::setSymbol(const string& name) const {
		if(this->hasSymbol(name)){
	        return &(data_[to_upper_copy(name)]);
		}else{
			data_[to_upper_copy(name)]=0.0; //ÃʱâÈ­ÇÔ.
			return &(data_[to_upper_copy(name)]);
		}
    }
예제 #3
0
bool case_insensitive_cmp::operator () (const std::string &left, const std::string &right) const
{

	if (strcmp(to_upper_copy(left).c_str(), to_upper_copy(right).c_str()) < 0)
		return true;
	else
		return false;
	
}
	void IDManager::setVID(const string& name,const std::vector<boost::shared_ptr<ISerialized>>& id) const {
		#ifdef ConsolePrint
			FileManager::instance().outFile_ << FileManager::instance().tap_ << "setVID : " << name.c_str() << std::endl;
		#endif

		if(this->hasID(to_upper_copy(name))){
	        QL_FAIL("already exist id : " << name.c_str());
		}else{
			vdata_[to_upper_copy(name)]=id; //초기화함.
		}
    }
void PathInformation::addIndexName(const std::string& name)
{
	bool hasIndexFlag = false;

	for(Size i = 0 ; i < indexName_.size() ; ++i){
		if(to_upper_copy(indexName_[i]) == to_upper_copy(name))
			hasIndexFlag = true;
	}
	if(!hasIndexFlag)
		this->indexName_.push_back(name);

}
	std::vector<boost::shared_ptr<ISerialized>> IDManager::getVID(const string& name) const {
		#ifdef ConsolePrint
			FileManager::instance().outFile_ << FileManager::instance().tap_ << "getVID : " << name.c_str() << std::endl;
		#endif

		if(this->hasID(to_upper_copy(name))){
			return vdata_[to_upper_copy(name)];
		}else
		{
			QL_FAIL("id doesn't exist : " << name.c_str());
		}
	}
		bool getElementBool(TiXmlNode* xmlNode , const std::string& elementName){
			//element이름 getText()하는 부분에서 오류남.

			if((xmlNode->FirstChildElement(elementName.c_str())) != 0){
				std::string str = xmlNode->FirstChildElement(elementName.c_str())->GetText();
				if( to_upper_copy(str) == "TRUE" || to_upper_copy(str) == "T")	{
					return true;
				}else{
					return false;
				}
			}
			return false;
		}
예제 #8
0
    bool ECB::isECBcode(const std::string& ecbCode) {

        if (ecbCode.length() != 5)
            return false;

        string code = to_upper_copy(ecbCode);

        string str1("0123456789");
        string::size_type loc = str1.find(code.substr(3, 1), 0);
        if (loc == string::npos)
            return false;
        loc = str1.find(code.substr(4, 1), 0);
        if (loc == string::npos)
            return false;

        string monthString = code.substr(0, 3);
        if (monthString=="JAN")      return true;
        else if (monthString=="FEB") return true;
        else if (monthString=="MAR") return true;
        else if (monthString=="APR") return true;
        else if (monthString=="MAY") return true;
        else if (monthString=="JUN") return true;
        else if (monthString=="JUL") return true;
        else if (monthString=="AUG") return true;
        else if (monthString=="SEP") return true;
        else if (monthString=="OCT") return true;
        else if (monthString=="NOV") return true;
        else if (monthString=="DEC") return true;
        else return false;
    }
예제 #9
0
    string ECB::nextCode(const std::string& ecbCode) {
        QL_REQUIRE(isECBcode(ecbCode),
                   ecbCode << " is not a valid ECB code");

        string code = to_upper_copy(ecbCode);
        std::ostringstream result;

        string monthString = code.substr(0, 3);
        if (monthString=="JAN")      result << "FEB" << code.substr(3, 2);
        else if (monthString=="FEB") result << "MAR" << code.substr(3, 2);
        else if (monthString=="MAR") result << "APR" << code.substr(3, 2);
        else if (monthString=="APR") result << "MAY" << code.substr(3, 2);
        else if (monthString=="MAY") result << "JUN" << code.substr(3, 2);
        else if (monthString=="JUN") result << "JUL" << code.substr(3, 2);
        else if (monthString=="JUL") result << "AUG" << code.substr(3, 2);
        else if (monthString=="AUG") result << "SEP" << code.substr(3, 2);
        else if (monthString=="SEP") result << "OCT" << code.substr(3, 2);
        else if (monthString=="OCT") result << "NOV" << code.substr(3, 2);
        else if (monthString=="NOV") result << "DEC" << code.substr(3, 2);
        else if (monthString=="DEC") {
            // lexical_cast causes compilation errors with x64
            //Year y = boost::lexical_cast<Year>(code.substr(3, 2));
            unsigned int y = (io::to_integer(code.substr(3, 2)) + 1) % 100;
            string padding;
            if (y < 10)
                padding = "0";

            result << "JAN" << padding << y;
        } else QL_FAIL("not an ECB month (and it should have been)");


        #if defined(QL_EXTRA_SAFETY_CHECKS)
        QL_ENSURE(isECBcode(result.str()),
                  "the result " << result.str() <<
                  " is an invalid ECB code");
        #endif
        return result.str();
    }
예제 #10
0
    Date ECB::date(const string& ecbCode,
                   const Date& refDate) {

        QL_REQUIRE(isECBcode(ecbCode),
                   ecbCode << " is not a valid ECB code");

        string code = to_upper_copy(ecbCode);
        string monthString = code.substr(0, 3);
        Month m;
        if (monthString=="JAN")      m = January;
        else if (monthString=="FEB") m = February;
        else if (monthString=="MAR") m = March;
        else if (monthString=="APR") m = April;
        else if (monthString=="MAY") m = May;
        else if (monthString=="JUN") m = June;
        else if (monthString=="JUL") m = July;
        else if (monthString=="AUG") m = August;
        else if (monthString=="SEP") m = September;
        else if (monthString=="OCT") m = October;
        else if (monthString=="NOV") m = November;
        else if (monthString=="DEC") m = December;
        else QL_FAIL("not an ECB month (and it should have been)");

        // lexical_cast causes compilation errors with x64
        //Year y = boost::lexical_cast<Year>(code.substr(3, 2));

        Year y = io::to_integer(code.substr(3, 2));
        Date referenceDate = (refDate != Date() ?
                              refDate :
                              Date(Settings::instance().evaluationDate()));
        Year referenceYear = (referenceDate.year() % 100);
        y += referenceDate.year() - referenceYear;
        if (y<Date::minDate().year())
            return ECB::nextDate(Date::minDate());

        return ECB::nextDate(Date(1, m, y));
    }
예제 #11
0
 void IndexManager::clearHistory(const string& name) {
     data_.erase(to_upper_copy(name));
 }
	boost::shared_ptr<IEventCheck> EventSymbolManager::getSymbol(const std::string& name) const {
	    return data_[to_upper_copy(name)];
    }
예제 #13
0
 void IndexManager::clearHistory(const string& name) {
     data_[to_upper_copy(name)] = TimeSeries<Real>();
 }
예제 #14
0
파일: libor.cpp 프로젝트: AAthresh/quantlib
 Libor::Libor(const shared_ptr<ValueObject>& properties,
              const QuantLib::Currency& currency,
              const std::string& p,
              const QuantLib::Handle<QuantLib::YieldTermStructure>& h,
              bool permanent) : IborIndex(properties, permanent)
 {
     switch (currency.numericCode()) {
       case 978: // EUR
         if (to_upper_copy(p)=="ON")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorEURLibor(0, h));
         else if (to_upper_copy(p)=="1D")
             QL_FAIL("1D is ambigous: please specify ON, TN, or SN");
         else if (to_upper_copy(p)=="TN")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorEURLibor(1, h));
         else if (to_upper_copy(p)=="SN")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorEURLibor(2, h));
         else if (to_upper_copy(p)=="SW")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::EURLibor(1*QuantLib::Weeks, h));
         else {
             QuantLib::Period pp = QuantLib::PeriodParser::parse(p);
             pp.normalize();
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::EURLibor(pp, h));
         }
         break;
       case 840: // USD
         if (to_upper_copy(p)=="ON")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorUSDLibor(0, h));
         else if (to_upper_copy(p)=="1D")
             QL_FAIL("1D is ambigous: please specify ON, TN, or SN");
         else if (to_upper_copy(p)=="TN")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorUSDLibor(1, h));
         else if (to_upper_copy(p)=="SN")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorUSDLibor(2, h));
         else if (to_upper_copy(p)=="SW")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::USDLibor(1*QuantLib::Weeks, h));
         else {
             QuantLib::Period pp = QuantLib::PeriodParser::parse(p);
             pp.normalize();
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::USDLibor(pp, h));
         }
         break;
       case 826: // GBP
         if (to_upper_copy(p)=="ON")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorGBPLibor(0, h));
         else if (to_upper_copy(p)=="1D")
             QL_FAIL("1D is ambigous: please specify ON, TN, or SN");
         else if (to_upper_copy(p)=="TN")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorGBPLibor(1, h));
         else if (to_upper_copy(p)=="SN")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorGBPLibor(2, h));
         else if (to_upper_copy(p)=="SW")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::GBPLibor(1*QuantLib::Weeks, h));
         else {
             QuantLib::Period pp = QuantLib::PeriodParser::parse(p);
             pp.normalize();
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::GBPLibor(pp, h));
         }
         break;
       case 756: // CHF
         if (to_upper_copy(p)=="ON")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorCHFLibor(0, h));
         else if (to_upper_copy(p)=="1D")
             QL_FAIL("1D is ambigous: please specify ON, TN, or SN");
         else if (to_upper_copy(p)=="TN")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorCHFLibor(1, h));
         else if (to_upper_copy(p)=="SN")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorCHFLibor(2, h));
         else if (to_upper_copy(p)=="SW")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::CHFLibor(1*QuantLib::Weeks, h));
         else {
             QuantLib::Period pp = QuantLib::PeriodParser::parse(p);
             pp.normalize();
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::CHFLibor(pp, h));
         }
         break;
       case 392: // JPY
         if (to_upper_copy(p)=="ON")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorJPYLibor(0, h));
         else if (to_upper_copy(p)=="1D")
             QL_FAIL("1D is ambigous: please specify ON, TN, or SN");
         else if (to_upper_copy(p)=="TN")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorJPYLibor(1, h));
         else if (to_upper_copy(p)=="SN")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::DailyTenorJPYLibor(2, h));
         else if (to_upper_copy(p)=="SW")
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::JPYLibor(1*QuantLib::Weeks, h));
         else {
             QuantLib::Period pp = QuantLib::PeriodParser::parse(p);
             pp.normalize();
             libraryObject_ = shared_ptr<QuantLib::IborIndex>(new
                 QuantLib::JPYLibor(pp, h));
         }
         break;
       default:
           QL_FAIL("Unhandled currency " << currency);
     }
 }
예제 #15
0
 void IndexManager::setHistory(const string& name,
                               const TimeSeries<Real>& history) {
     data_[to_upper_copy(name)] = history;
 }
예제 #16
0
 boost::shared_ptr<Observable>
 IndexManager::notifier(const string& name) const {
     return data_[to_upper_copy(name)];
 }
예제 #17
0
 bool IndexManager::hasHistory(const string& name) const {
     return data_.find(to_upper_copy(name)) != data_.end();
 }
예제 #18
0
 const TimeSeries<Real>&
 IndexManager::getHistory(const string& name) const {
     return data_[to_upper_copy(name)].value();
 }
 bool IDManager::hasID(const string& name) const {
     return data_.find(to_upper_copy(name)) != data_.end();
 }
 void IndexSymbolManager::clearSymbol(const string& name) {
     data_.erase(to_upper_copy(name));
 }
 bool IndexSymbolManager::hasSymbol(const string& name) const {
     return data_.find(to_upper_copy(name)) != data_.end();
 }
	void EventSymbolManager::setSymbol(const string& name , const boost::shared_ptr<IEventCheck>& ptr) const {
			data_[to_upper_copy(name)] = ptr; //µ¤À½.
    }
//! returns whether historical fixings were stored for the index
bool PathInformation::hasPath(const std::string& name) const
{
	return data_.find(to_upper_copy(name)) != data_.end();
}
예제 #24
0
//------------------------------------------------------------------------------
int main(int argc, char * const argv[])
{
  Options opt = GetOptions(argc, argv);

  // Log in
  SpreadsheetService service(opt.user, opt.password,
                             "xeckollc-thirteen-" + VERSION);

  // Get the spreadsheet we are interested in
  Spreadsheet spreadsheet;
  if(opt.spreadsheet_id.size()) {
    spreadsheet = service.GetSpreadsheet(opt.spreadsheet_id);
  } else {
    vector<Spreadsheet> sheets = service.GetSpreadsheets();
    int report_index = -1;
    for (int i=0; i < sheets.size(); ++i) {
      if(sheets[i].GetTitle() == opt.spreadsheet_name) {
        report_index = i;
        break;
      }
    }
    if(report_index < 0) {
      cerr << format("No spreadsheet named [%1%] found") %
           opt.spreadsheet_name << endl;
      return 1;
    }
    spreadsheet = sheets[report_index];
  }

  // Get the worksheet we are interested in. If we didn't specify one,
  // use the first one in the spreadsheet
  Worksheet worksheet;
  if(opt.worksheet_id.size()) {
    worksheet = spreadsheet.GetWorksheet(opt.worksheet_id);
  } else {
    vector<Worksheet> sheets = spreadsheet.GetWorksheets();
    if(opt.worksheet_name.size()) {
      int report_index = -1;
      for (int i=0; i < sheets.size(); ++i) {
        if(sheets[i].GetTitle() == opt.worksheet_name) {
          report_index = i;
          break;
        }
      }
      if(report_index < 0) {
        cerr << format("No worksheet named [%1%] found") %
             opt.worksheet_name << endl;
        return 1;
      }
      worksheet = sheets[report_index];
    } else {
      worksheet = sheets[0];
    }
  }

  // Get 2 columns of Cells from selected worksheet
  CellRange cells = worksheet.GetColumns(1, 2);

  // Parse the cells for the data
  map<string, int> on_air, off_air;
  State state = NONE;
  for (int row=cells.GetFirstRow(); row <= cells.GetLastRow(); ++row) {
    Cell *label_cell = cells.GetCell(row, 1);
    if(label_cell == NULL) {
      state = NONE;
      continue;
    }
    string label = label_cell->GetContent();
    if(!label.size()) {
      state = NONE;
      continue;
    }
    if(label == ON_AIR_HEADER) {
      state = ONAIR;
      continue;
    }
    if(label == OFF_AIR_HEADER) {
      state = OFFAIR;
      continue;
    }

    Cell *value_cell = cells.GetCell(row, 2);
    if(value_cell == NULL) {
      continue;
    }
    string value = value_cell->GetContent();
    int ivalue;
    try {
      ivalue = lexical_cast<int>(value.c_str());
    } catch(bad_lexical_cast &) {
      ivalue = 0;
    }
    switch (state) {
    case ONAIR:
      if(ivalue) {
        on_air[label] = ivalue;
      }
      break;

    case OFFAIR:
      if(ivalue) {
        off_air[label] = ivalue;
      }
      break;

    case NONE:
      break;
    }
  }

  // Figure the start and stop dates from the worksheet name
  string name = worksheet.GetTitle();
  re::sregex rex = re::sregex::compile("(.+) +(.+)");
  re::smatch matches;
  if(!re::regex_match(name, matches, rex)) {
    cerr << format("Worksheet name [%1%] does not look like a month and year") %
         name << endl;
    return 1;
  }

  string mon, yr;
  int month, year;
  mon = matches[1];
  yr  = matches[2];
  year = lexical_cast<int>(yr.c_str());
  if(year < 2000) {
    year += 2000;
  }
  month = 0;
  string months[] = {
    "jan", "feb", "mar", "apr", "may", "jun",
    "jul", "aug", "sep", "oct", "nov", "dec"
  };
  for (int i=0; i<12; ++i) {
    if (iequals(mon, months[i])) {
      month=i+1;
      break;
    }
  }
  if(month < 1) {
    cerr << format("Worksheet name [%1%] does not contain a valid month") %
         name << endl;
    return 1;
  }
  date start_date(year, month, 1);
  date stop_date = start_date.end_of_month();

  stringstream start, stop;
  date_facet *facet = new date_facet("%d %b");
  start.imbue(locale(cout.getloc(), facet));
  start << start_date;
  opt.start_date = to_upper_copy(start.str());

  facet = new date_facet("%d %b %Y");
  stop.imbue(locale(cout.getloc(), facet));
  stop << stop_date;
  opt.stop_date = to_upper_copy(stop.str());

  // Print the report
  PrintReport(cout, opt, on_air, off_air);
  return 0;
}
 void IDManager::clearID(const string& name) {
     data_.erase(to_upper_copy(name));
 }