Ejemplo n.º 1
0
void AbstractFileSource::display(const CSVDatabase& db) {
	if(!db.size())
		return;
	CSVDatabaseCI i=db.begin();
	for(; i != db.end(); ++i){
		display(*i);
		std::cout<<std::endl;
	}	
};
Ejemplo n.º 2
0
void BondFutureFileSource::retrieveRecord(){
	if (!_enabled) return;
	
	CSVDatabase db = readCSV(_persistDir+_fileName);
	int numOfRows=db.size();
	RecordHelper::BondFutureMap* bondRateMap = RecordHelper::getInstance()->getBondFutureMap();

	for (int i=1;i<numOfRows;i++) {
		BondFuture* tempBondFuture = createBondFutureObject(db, i);
		insertBondFutureIntoCache(tempBondFuture, bondRateMap);
	}
}
Ejemplo n.º 3
0
void CcyPairFileSource::retrieveRecord(){
	if (!_enabled) return;
	
	CSVDatabase db = readCSV(_persistDir+_fileName);
	int numOfRows=db.size();
	int numOfCols=db.at(0).size();

	RecordHelper::CcyPairMap* CcyPairMap = RecordHelper::getInstance()->getCcyPairMap();

	for (int i=1;i<numOfRows;i++) {
		CcyPair* tempCcyPair = createCcyPairObject(db, i);
		insertCcyPairIntoCache(tempCcyPair, CcyPairMap);
	}
}
Ejemplo n.º 4
0
void BondPriceFileSource::retrieveRecord(){
	if (!_enabled) return;
	
	CSVDatabase db = readCSV(_persistDir+_fileName);
	int numOfRows=db.size();
	int numOfCols=db.at(0).size();
	int bondTenorNumOfMonths=0;

	RecordHelper::BondRateMap* bondRateMap = RecordHelper::getInstance()->getBondRateMap();

	for (int i=1;i<numOfRows;i++) {
		Bond* tempBond = createBondObject(db, i);
		insertBondIntoCache(tempBond, bondRateMap);
	}
}
Ejemplo n.º 5
0
void DepositFileSource::retrieveRecord(){
	if (!_enabled) return;	

	CSVDatabase db = readCSV(_persistDir+_fileName);
	int numOfRows=db.size();
	int numOfCols=db.at(0).size();

	RecordHelper::DepositRateMap* depositRateMap = RecordHelper::getInstance()->getDepositRateMap();

	for (int i=1;i<numOfRows;i++) {
		Deposit* tempDeposit = createDepositObject(db, i);
		tempDeposit->deriveAccrualStartDate();
		insertDepositIntoCache(tempDeposit, depositRateMap);
	}
}
Ejemplo n.º 6
0
void BondFutureFileSource::retrieveRecord(){
	if (!_enabled) return;
	
	AbstractFileSource::retrieveRecord();
	CSVDatabase db;
	readCSV(_inFile, db);
	int numOfRows=db.size();
	RecordHelper::BondFutureMap* bondRateMap = RecordHelper::getInstance()->getBondFutureMap();

	for (int i=1;i<numOfRows;i++) {
		BondFuture* tempBondFuture = createBondFutureObject(db, i);
		insertBondFutureIntoCache(tempBondFuture, bondRateMap);
	}

	_inFile.close();
}
Ejemplo n.º 7
0
void FXForwardFileSource::retrieveRecord(){
	if (!_enabled) return;
	
	AbstractFileSource::retrieveRecord();
	CSVDatabase db;
	readCSV(_inFile, db);

	int numOfRows=db.size();
	int numOfCols=db.at(0).size();

	RecordHelper::FXForwardMap* FXForwardMap = RecordHelper::getInstance()->getFXForwardMap();

	for (int i=1;i<numOfRows;i++) {
		FXForward* tempForward = createForwardObject(db, i);
		insertForwardIntoCache(tempForward, FXForwardMap);
	}
	deriveSpotForwardRate(FXForwardMap);

	_inFile.close();
}
Ejemplo n.º 8
0
void DepositFileSource::retrieveRecord(){
	AbstractFileSource::retrieveRecord();

	enums::MarketEnum marketEnum;

	CSVDatabase db;
	readCSV(_inFile, db);

	int numOfRows=db.size();
	int numOfCols=db.at(0).size();

	RecordHelper::RateMap tempDepositMap;
	RecordHelper::RateMap tempOvernightMap;

	for (int i=1;i<numOfCols;i++) {

		marketEnum=EnumHelper::getCcyEnum(db.at(0).at(i));
		Market market = Market(marketEnum);

		map<long, double>* depositRateMap = new map<long, double>;
		map<long, double>* overnightRateMap = new map<long, double>;

		for (int j = 1; j<numOfRows; j++)
		{
			string tenorStr = db.at(j).at(0);
			double liborRate = std::stod(db.at(j).at(i))/100.0;
			insertRateIntoMap(tenorStr, liborRate, market, depositRateMap, overnightRateMap);
		}
		tempDepositMap.insert(pair<enums::MarketEnum, map<long, double>>(marketEnum,*depositRateMap));
		tempOvernightMap.insert(pair<enums::MarketEnum, map<long, double>>(marketEnum,*overnightRateMap));
	}
	RecordHelper::getInstance()->setDepositRateMap(tempDepositMap);
	RecordHelper::getInstance()->setOverNightRateMap(tempOvernightMap);
	_inFile.close();
}
Ejemplo n.º 9
0
void MarketFileSource::retrieveRecord(){
	if (!_enabled) return;

	AbstractFileSource::retrieveRecord();
	CSVDatabase db;
	readCSV(_inFile, db);

	int numOfRows=db.size();
	int numOfCols=db.at(0).size();
	RecordHelper::MarketMap marketMap;

	for (int j=1;j<numOfCols;j++) {

		String marketStr = db.at(0).at(j);
		enums::CurrencyEnum CurrencyEnum = EnumHelper::getCcyEnum(marketStr);
		Market* market = new Market();

		for (int i=0;i<numOfRows;i++){
			String fieldName=db.at(i).at(0);
			String fieldVal=db.at(i).at(j);
			updateMarketObjectField(fieldName, fieldVal, market);
		}
		market->display();
		marketMap.insert(std::make_pair(CurrencyEnum,*market));
	}
	RecordHelper::getInstance()->setMarketMap(marketMap);
	_inFile.close();
}
Ejemplo n.º 10
0
void AbstractFileSource::readCSV(std::ifstream &input, CSVDatabase &db) {
	String csvLine;
	// read every line from the stream
	while( std::getline(input, csvLine) ){
		std::istringstream csvStream(csvLine);
		CSVRow csvRow;
		String csvCol;
		// read every element from the line that is seperated by commas
		// and put it into the vector or strings
		while( std::getline(csvStream, csvCol, ','))
			csvRow.push_back(csvCol);
		db.push_back(csvRow);
	}

};
void SwaptionVolFileSource::retrieveRecord(){
	AbstractFileSource::retrieveRecord();

	CSVDatabase db;
	readCSV(_inFile, db);

	int numOfRows=db.size();
	int numOfCols=db.at(0).size();
	int strikeDiffATM=0;
	
	RecordHelper::SwaptionCubeMap tempSwaptionCubeMap;
	RecordHelper::SwaptionATMStrikeMap tempSwaptionATMStrikeMap;
	RecordHelper::SwaptionSurfaceMap volSurfaceMap;
	std::regex ATM ("ATM(.*)");

	for (int i=0;i<=numOfRows-1;i++) {

		String aCell=db.at(i).at(0);

		if (std::regex_match (aCell,ATM)) {
			if (i!=0){				
				tempSwaptionCubeMap.insert(std::make_pair(strikeDiffATM,volSurfaceMap));
				//<double,std::map<tuple<double,double>,double>>
				volSurfaceMap.clear();
			}
			strikeDiffATM = getStrikeDiffATM(aCell);
			enums::MarketEnum market = EnumHelper::getCcyEnum(db.at(i).at(1));
			Market mkt(market);
			continue;
		}

		for (int j=2;j<=numOfCols-1;j++) {

			String topRowCell=db.at(0).at(j);
			String tagCell=db.at(i).at(1);

			if (tagCell.compare("Vol")==0) {
				int optionExpiryInMonth=std::stoi(aCell.substr(0,aCell.find(" ")));
				if (string::npos != aCell.find("YR")) {
					optionExpiryInMonth=std::stoi(aCell.substr(0,aCell.find(" ")))*12;
				}

				double vol=db.at(i).at(j).compare("")==0?NaN:std::stod(db.at(i).at(j))/100;
				double strike=db.at(i+1).at(j).compare("")==0?NaN:std::stod(db.at(i+1).at(j));
				int fSwapTenorInMonth=std::stoi(topRowCell.substr(0,topRowCell.find(" ")))*12;

				auto aTuple=std::make_tuple(fSwapTenorInMonth,optionExpiryInMonth);
				insertPointVolSurfaceMap(volSurfaceMap,fSwapTenorInMonth,optionExpiryInMonth,vol);
				if (strikeDiffATM==0)
					tempSwaptionATMStrikeMap.insert(std::make_pair(aTuple,strike));

			}
			else {
				continue;
			}
		}
	}

	/*cout <<"numofRows="<<db.size()<<endl;
	cout <<"numOfCols="<<db.at(0).size()<<endl;*/

	tempSwaptionCubeMap.insert(std::make_pair(strikeDiffATM,volSurfaceMap));
	RecordHelper::getInstance()->setSwaptionATMStrikeMap(tempSwaptionATMStrikeMap);
	RecordHelper::getInstance()->setSwaptionVolMap(tempSwaptionCubeMap);
	_inFile.close();
	//DAO::SwaptionVolFileSource::swaptionTest();
}