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();
}
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();
}
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);
	}
}
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);
	}
}
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);
	}
}
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();
}
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();
}