1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
   | SyntheticCDO::SyntheticCDO(const char* filename){
	CreditdefaultSwap cds;
	// Parametres d'un cds
	double nominal;
	double cours;
	double recovery_rate;
	string line;
	size_t size;
	char* line_tmp;
 
	char* token;
	vector<char*> v_tokens;
	ifstream file;
	file.open(filename, ifstream::in);
 
	if (!file.is_open()){
		cout <<"Impossible de lire dans le fichier " 
                               << filename <<endl;
	                 }
	     else{
	cin.getline(file, line.size()); // Enleve la ligne des noms des colonnes
		      while(!file.eof()){
			  v_tokens.clear();
			  getline(file, line);
			  if(line.size() !=0){
			// Conversion en char* pour utiliser strtok
				size = line.size() +1;
				line_tmp = new char[size];
				strncpy(line_tmp, line.c_str(), size);
 
				// Tokenizer
				token = strtok(line_tmp, "\t");
				v_tokens.push_back(token);
 
				while (token != NULL){
					token = strtok (NULL, "\t%");
					v_tokens.push_back(token);
				}
				nominal = atof(v_tokens[0]);
				cours = atof(v_tokens[1]);
				recovery_rate = atof(v_tokens[2]);
				cds.setNominal(nominal);
				cds.setCours(cours);
				cds.setRecoveryRate(recovery_rate);
				cds.setHazardRate();
				addCDS(cds);
			}
		}
		file.close();
	}
	int n = (int)v.size();
	correl = (double**) malloc(n*sizeof(double*));
	for(int i=0;i<n;i++){
		correl[i] = (double*) malloc(n*sizeof(double));
		for(int j=0;j<n;j++){
			correl[i][j] = 0.0;
		}
	}
	maturity = 0;
} | 
Partager