Übergabe stimmt nicht
-
Hi Leute!
Ich hänge jetzt schon eine Weile über meinem Programm und bekomme nicht die gewünschten Ergebnisse raus. Ich lese eine csv Datei ein und verarbeite die gewonnenen Daten in einem Algorithmus. Dann werden die Ergebnisse wieder in eine csv Datei ausgegeben. Es kommen aber nur Nullen raus und das kann nicht sein, denn wenn ich die ersten Zeilen per Hand rechne, ist dies nicht der Fall.Ich habe dann den Algorihtmus alleine getestet und ihm Werte vorgegeben und er funktioniert einwandfrei. Es muß scheinbar an der Übergabe liegen. Ich finde aber nicht den Fehler.
Vielleicht findet ihr ihn ja:
#include <fstream> #include <string> #include <iostream> #include <math.h> using namespace std; int main(int argc, char **argv) { double av_price = 40.1475; long int quote = 50000; long int limit = 250000; struct zeile{ double posit; string time; double stk; double orderVol; bool traderID; bool market; bool buy; bool agent; double MXBVol; double MXVol; double GVol; double GXBVol; double GMXBVol; double GMXVol; bool glatt; }; /******************************************************************************/ struct zeile n[2]; { // Initialisierung des Startwertes der Iteration: n[0].posit = 0; n[0].stk = 0; n[0].orderVol= n[0].stk * av_price; n[0].traderID = false; n[0].market=false; n[0].buy = false; n[0].agent = false; n[0].MXBVol = 0.0; n[0].MXVol = 0.0; n[0].GVol = 0.0; n[0].GXBVol = 0.0; n[0].GMXBVol = 0.0; n[0].GMXVol = 0.0; n[0].glatt = false; } string ids[] = {"BVMMU", "CITDU", "CBKFR", "COSNU", "DABMU", "BFGFR", "PLUHH", "DBKFR", "DRBFR", "TUBDU", "QUENU"}; ifstream inFile("SAP1611.txt"); if (!inFile.good()) { cerr << "Error opening input-file" << endl; exit(1); } // das ist die Ausgabedatei: fstream f; f.open("ausgabe.csv", ios::out); //erste Zeile: f << "time;pos;MXBVol;MXVol;GMXVol;GMXBVol;GXBVol;GVol;glatt" << endl; string line; string tmpString; string time; string traderID; double price; double number; string market_limit; string buy_sell; string agent_prop; int pos; int dec_pos; int j = 0; // zählt die Schleifendurchläufe int offset; // reading header information ... //getline(inFile,line); /***************************************************************************/ /* Hier fängt die Hauptschleife an, bearbeitet pro Durchlauf eine Zeile: */ while (inFile.good()) { /* n[0] ist immer die Vorgängerzeile, n[1] die aktuelle!*/ /*Die Zuweisung erfolgt hier: */ if (j>0){ n[0].posit=n[1].posit; n[0].orderVol=n[1].orderVol; n[0].GVol=n[1].GVol; n[0].GXBVol=n[1].GXBVol; n[0].GMXBVol=n[1].GMXBVol; n[0].GMXVol=n[1].GMXVol; n[0].MXBVol=n[1].MXBVol; n[0].MXVol=n[1].MXVol; } // hier muss n[1] für jeden Schleifendurchlauf neu initialisiert werden... n[1].posit = 0; n[1].stk = 0; n[1].orderVol=n[1].stk * av_price; n[1].traderID = false; n[1].market=false; n[1].buy = false; n[1].agent = false; n[1].MXBVol = 0.0; n[1].MXVol = 0.0; n[1].GVol = 0.0; n[1].GXBVol = 0.0; n[1].GMXBVol = 0.0; n[1].GMXVol = 0.0; n[1].glatt = false; getline(inFile,line); if (line.empty()){ break; } // buy_sell offset = 56; line = line.substr(offset,((int)line.length()-offset)); pos = line.find('"'); if (pos != 0){ buy_sell = line.substr(0,pos); } if(buy_sell=="B"){ n[1].buy = true; } //time offset = 2; line=line.substr(offset+pos,((int)line.length()-offset-pos)); pos=line.find(';'); time=line.substr(0,pos); n[1].time=time; //number offset = 8; line = line.substr(pos+offset,((int)line.length()-pos-offset)); pos = line.find(','); if (pos != 0){ tmpString = line.substr(0,pos); number = atof(tmpString.c_str()); } n[1].stk=number; n[1].orderVol= n[1].stk * av_price; /* kann erst hier initialisiert werden... */ // trader ID offset = 5; line = line.substr(pos+offset,((int)line.length()-pos-offset)); pos = line.find('"'); traderID = line.substr(0,pos); for( int x=0; x<=10; x++){ if(traderID==ids[x]){ n[1].traderID=true; } } //market limit offset = 2; line = line.substr(pos+offset,((int)line.length()-pos-offset)); pos = line.find('"'); if(pos!=0){ market_limit=line.substr(0,pos); } if(market_limit == "M" || market_limit == "L"){ n[1].market = true; } //agent offset=3; line=line.substr(pos+offset,((int)line.length()-pos-offset)); pos=line.find('"'); if (pos != 0){ agent_prop = line.substr(0,pos); } if(agent_prop == "A"){ n[1].agent = true; } //market_limit offset=3; line=line.substr(pos+offset,((int)line.length()-pos-offset)); pos=line.find('"'); if (pos != 0){ market_limit = line.substr(0,pos); } if (market_limit == "M"){ n[1].market = true; } /**************************************************************************/ //hier jetzt mein Algorithmus: for(int i=1; i < 2; i++) // nur ein Durchlauf { if((n[i].orderVol)<=quote){ // Abschnitt 1 if(n[i].traderID == true && n[i].agent == true && n[i].market == true){ // Abschnitt 2a n[i].orderVol = (n[i].buy == true) ? (n[i].orderVol * (-1)) : n[i].orderVol; // Abschnitt 3a n[i].posit=n[i-1].posit + n[i].orderVol; // Abschnitt 4a if(((n[i-1].posit>0) && (n[i].posit<0))||((n[i-1].posit<0) && (n[i].posit>0)) // Abschnitt 5a || ((n[i-1].posit!=0) && (n[i].posit==0))){ n[i].MXBVol = 2*fabs(n[i-1].posit); n[i].GXBVol= fabs(n[i].orderVol)+n[i-1].GXBVol; n[i].GVol= fabs(n[i].orderVol)+n[i-1].GVol; n[i].GMXBVol=n[i-1].GMXBVol+(2*fabs(n[i-1].posit)); n[i].GMXVol=n[i-1].GMXVol; n[i].glatt = false; continue; } if(((n[i-1].posit>0) && (n[i].posit>0) && ((fabs(n[i-1].posit)-fabs(n[i].posit))>0)) || // Abschnitt 6a ((n[i-1].posit<0) && (n[i].posit<0) && ((fabs(n[i-1].posit)-fabs(n[i].posit))>0))){ n[i].MXBVol = 2*(fabs(n[i-1].posit)-fabs(n[i].posit)); n[i].GXBVol= fabs(n[i].orderVol)+n[i-1].GXBVol; n[i].GVol= fabs(n[i].orderVol)+n[i-1].GVol; n[i].GMXBVol=n[i-1].GMXBVol+(2*(fabs(n[i-1].posit)-fabs(n[i].posit))); n[i].GMXVol=n[i-1].GMXVol; n[i].glatt = false; continue; } else{ // Abschnitt 7a n[i].GXBVol= fabs(n[i].orderVol)+n[i-1].GXBVol; n[i].GVol= fabs(n[i].orderVol)+n[i-1].GVol; n[i].GMXVol=n[i-1].GMXVol; n[i].GMXBVol=n[i-1].GMXBVol; if(n[i].posit>=limit){ n[i].posit=limit/2; n[i].glatt=true; continue; } continue; } } //================================================================================= else{ // ab hier 2b // hier wird die andere Seite reingeparsed.... Überflüssig, oder? } //================================================================================== }//===================================================================================== if(n[i-1].posit==0){ // Abschnitt 2b n[i].posit=n[i-1].posit; n[i].GVol=n[i-1].GVol; n[i].GXBVol=n[i-1].GXBVol; n[i].GMXBVol=n[i-1].GMXBVol; n[i].GMXVol=n[i-1].GMXVol; continue; } else{ if(((n[i-1].posit<0) && (n[i].buy == true))||((n[i-1].posit>0) && (n[i].buy == false))){ n[i].posit=n[i-1].posit; n[i].GVol=n[i-1].GVol; n[i].GXBVol=n[i-1].GXBVol; n[i].GMXBVol=n[i-1].GMXBVol; n[i].GMXVol=n[i-1].GMXVol; continue; } else{ // Abschnitt 4b if(fabs(n[i-1].posit)>fabs(n[i].orderVol)){ n[i].orderVol = (n[i].buy == true) ? (n[i].orderVol * (-1)) : n[i].orderVol; n[i].posit=n[i-1].posit + n[i].orderVol; } } n[i].MXVol = 2*(fabs(n[i-1].posit)-fabs(n[i].posit)); n[i].GXBVol= n[i-1].GXBVol; n[i].GVol= (fabs(n[i-1].posit)-fabs(n[i].posit))+n[i-1].GVol; n[i].GMXBVol=n[i-1].GMXBVol; n[i].GMXVol=n[i-1].GMXVol+(2*(fabs(n[i-1].posit)-fabs(n[i].posit))); } } // Hier ist die Ausgabe der jeweiligen Zeile in die Datei f << n[1].time << ";" << n[1].posit << ";" << n[1].MXBVol << ";" << n[1].MXVol << ";" << n[1].GMXVol << ";" << n[1].GMXBVol <<";"<< n[1].GXBVol << ";" << n[1].GVol << ";" << n[1].glatt << endl; j++; } /* Hier hört die Hauptschleife auf!*/ /******************************************************************************/ cout << "\nread " << j << " lines of input " << endl; inFile.close(); f.close(); string userInput; cout << "any key to continue ..." << endl; cin >> userInput; }Ich weiß es ist nicht die schönste Programmierung....ist erst eine meiner ersten. Ich muß noch üben:)
Vielen Dank für jeden Versuch!!
zehnsim