#include #include #include #include struct day { long date; long turnout; long year; char* month ; day () { turnout = date = year = 0; month = new char[3]; } }; struct tick { day den; long time; double index; }; void panic (char * str) { cerr << str << endl; exit (0); } void ReadData (const char *InName, tick* ticks, long &nticks); void MakeOutput (const char *OutName, tick* ticks, long nticks); main (int argc, char* argv[]) { if (argc < 3) panic ("bourse "); long nticks; tick ticks[5000]; ReadData (argv[1], ticks, nticks); MakeOutput (argv[2], ticks, nticks); } void ReadData (const char *InName, tick ticks[], long &nticks) { ifstream in (InName); char *datechar = new char[10]; long cnt = 0; long dummy = 0 ; while (!in.eof()) { if (!dummy) { in >> datechar; ticks[cnt].den.date = atoi(datechar); } else ticks[cnt].den.date = dummy; in >> ticks[cnt].den.month; in >> ticks[cnt].den.year; in >> ticks[cnt].time; in >> ticks[cnt].index; in >> dummy ; if (!dummy) in >> dummy ; if (dummy > 32) { ticks[cnt].den.turnout = dummy; dummy = 0 ; } else ticks[cnt].den.turnout = ticks[cnt-1].den.turnout; if ( ticks[cnt].den.year == 1995 && strcmp(ticks[cnt].den.month, "Oct") == 0 ) break; if (ticks[cnt].time - ticks[cnt].time/100 * 100 != 30) cnt++; // take 1 hour difference } nticks = cnt; } // output for years 1996-98, RTS. 1995 input used only as reference for // 1996. void MakeOutput (const char *OutName, tick ticks[], long nticks) { ofstream out(OutName) ; long cnt ; long cnt2 ; double last_close; long last_close_cnt; long id; long nchanged = 0; long currentdate; for (cnt = 0; cnt < nticks && ticks[cnt].den.year>=1996 ; cnt++) { // 1st variable - time out << ticks[cnt].time << " "; // 2nd variable - difference with previous tick, if tick is in the same // day, otherwise - 0 if (ticks[cnt].den.date == ticks[cnt+1].den.date) out << (ticks[cnt].index - ticks[cnt+1].index) / ticks[cnt+1].index << " "; else out << 0 << " " ; // 3rd variable - difference between opening at the same day and // previous close. for ( cnt2 = cnt ; ticks[cnt2].den.date == ticks[cnt].den.date ; cnt2 ++ ) ; last_close = ticks[cnt2].index; out << (ticks[cnt2-1].index-ticks[cnt2].index) / ticks[cnt2].index; out << " " ; last_close_cnt = cnt2; // 4th variable - change during the previous day (close of the day before // - close 2 days before for ( cnt2 = last_close_cnt ; ticks[cnt2].den.date == ticks[last_close_cnt].den.date ; cnt2 ++ ) ; out << (last_close-ticks[cnt2].index) / ticks[cnt2].index; out << " " ; // 5th variable - change during the previous week - close of the day // before - close 6 sessions before (5 working days in the week) cnt2 = last_close_cnt; nchanged = 0 ; currentdate = ticks[last_close_cnt].den.date; while ( nchanged++ < 22 ) { while (ticks[cnt2++].den.date == currentdate ) currentdate = ticks[cnt2-1].den.date ; } out << (ticks[last_close_cnt].index - ticks[cnt2].index) / ticks[cnt2].index << " " ; // 6th variable - change during the previous month - close 22 days ago cnt2 = last_close_cnt; nchanged = 0 ; currentdate = ticks[cnt].den.date; while ( nchanged++ < 22 ) { while (ticks[cnt2++].den.date == currentdate ) currentdate = ticks[cnt2-1].den.date ; } out << (ticks[last_close_cnt].index-ticks[cnt2].index) / ticks[cnt2].index << " " ; // 7th variable - turnout in the previous day for ( cnt2 = cnt ; ticks[cnt2].den.date == ticks[cnt].den.date ; cnt2 ++ ) ; out << ticks[cnt2].den.turnout << " " ; // id - percent change of the index to the next tick double perc_chang; if (cnt) perc_chang = (ticks[cnt-1].index - ticks[cnt].index) / ticks[cnt].index * 100 ; if (!cnt || ticks[cnt].time == 1800) id = 100 ; else { if (perc_chang < -0.5) id = 1; if (perc_chang >= -0.5 && perc_chang < -0.05 ) id = 2; if (perc_chang >= -0.05 && perc_chang < 0.05 ) id = 3; if (perc_chang >= 0.05 && perc_chang < 0.5 ) id = 4; if (perc_chang >= 0.5) id = 5; } if ( cnt && ticks[cnt].time == 1800 ) { if (perc_chang < -0.5) id = 10; if (perc_chang >= -0.5 && perc_chang < 0.5 ) id = 20; if (perc_chang > 0.5) id = 30; } out << id << endl; } out.close (); }