1 /***********START***************/
2 void forexSimulator(void){
3 void forexSimulator(void){
4 setJobID("forexYahoo");
5
6 //1 Identify Data Files
7 unsigned short int forexCounterDB(0), i{ 0 }, j{ 0 }, k{ 0 };
8 string forexCoin;
9 string dbFile = "...forexFiles.txt";
10 fstream fdb;
11 string* aryFx = new string[11];
12 fdb.open(dbFile, ios::in);
13 if (!fdb) {//donde esta la data que se lee de los distintos archivos
14 printf("Error! cant find this file");
15 cout << "This file does not exist " << dbFile;
16 return;
17 exit(1);
18 }
19 do {
20 fdb >> forexCoin;
21 ++forexCounterDB;
22 aryFx[forexCounterDB] = forexCoin;
23 cout << "\t" << forexCounterDB << "\t" << forexCoin << endl;
24 } while (!fdb.eof());
25 fdb.close();
26
27 cout << "\t\tForexCounterDB - Number of files: "
28 << forexCounterDB << endl; // << "\t" << stock << endl;
29
30 fstream* fDB = new fstream[forexCounterDB+1];
31
32 for (i = 1; i <= forexCounterDB; i++)
33 fout << "\n\tAryFx i: " << i << " " << aryFx[i];
34
35 string corePath = "...\\\\ExSan\\\\";
36 string* fileID = new string[forexCounterDB + 1];
37
38 for (i = 1; i <= forexCounterDB; i++) {
39 fileID[i] = corePath + aryFx[i] + ".txt";
40 cout << "\n\t:56: forexFile[" << i << "]\t" << fileID[i];
41 fDB[i].open(fileID[i], ios::in);
42 if (!fDB[i]) {
43 printf(":244: Error! Data File not found");
44 fout.flush() << "\n\t:245: This file does not exist " << fileID[i];
45 fDB[i].close();
46 exit(1);
47 }
48 fDB[i].close();
49 }
50
51 //2 Random scenario
52 unsigned short shift(0);
53 unsigned seed = chrono::system_clock::now().time_since_epoch().count();
54 default_random_engine generator(seed);
55 double datum(0);
56 boost::random::uniform_int_distribution<> dist{ 0, 10 };
57 for (i = 1; i <= forexCounterDB; i++) {
58 fDB[i].open(fileID[i], ios::in);
59 if (!fDB[i]) {
60 printf("Error!");
61 fout.flush() << "\n\tThis file does not exist " << fileID[i];
62 exit(1);
63 }
64 shift = dist(generator); //much better randomness
65 while (shift--)
66 fDB[i] >> datum; /// shift in this file i
67 }
68
69 for (i = 1; i <= forexCounterDB; i++){
70 fDB[i] >> datum;
71 cout << "\n\tAryFx i: " << i << " "
72 << aryFx[i] << "\tdatum: ---> " << datum;
73 }
74
75
76 enum FLOAT { pp_float = 1};
77 enum BOOL { pp_bool};
78 enum USHORT { pp_us };
79 enum STRING { pp_string };
80 enum CHAR { pp_char };
81
82 NETPTR net(nullptr);//
83 CELLPTR ptr(nullptr); // , auxPtrLast(nullptr);
84 ROWPTR rowPtr(nullptr);
85
86 unsigned short rows{ forexCounterDB }, cols{ forexCounterDB };
87 ntNodes = 0;
88
89 net = net->exsan(rows, cols, pp_float, pp_bool, pp_us, pp_string, pp_char);
90 for (i = pp_float; i > 0; i--) {
91 net->set_work_sheet(net, i, forexCounterDB, forexCounterDB); //page i, (i * i)
92 net->show_page(net, i, 'f', 0, 2, 5, 2);
93 }
94 unsigned short k = 3;
95 do{
96 //5 Populate BuySellMatrix[n, n]
97 for (i = 1; i <= forexCounterDB; i++) {
98 fDB[i] >> datum;
99 switch (i) {
100 case 1:
101 ptr = net->point_to(net, pp_float, 1, 2, 'f');
102 ptr->set_data(pp_float, datum);
103 break;
104
105 case 2:
106 ptr = net->point_to(net, pp_float, 1, 3, 'f');
107 ptr->set_data(pp_float, datum);
108 break;
109
110 case 3:
111 ptr = net->point_to(net, pp_float, 2, 3, 'f');
112 ptr->set_data(pp_float, datum);
113 break;
114 }
115 }
116 net->show_page(net, pp_float, 'f', 0, 2, 5, 2);
117
118 rateExPtr = net->point_to(net, 0, 2, 1, 'f');// track exchange
119 tracptr = net->point_to(net, 0, 1, 1, 'f'); //
120 ptr = net->point_to(net, ppdata, 1, 1, 'f');//
121 aux_max = net->point_to(net, ppdata, 1, 1, 'f');
122
123 for (i = 1; i <= forexCounterDB - 1; i++) {// row traversal
124 net->DiscarDB(net, crptr, rootRowHolDB, db_root, 'f');
125 tracptr->set_data(0, ptr->get_row());
126 checkptr = tracptr->get_previous_ptr();
127 tracptr = tracptr->get_next_ptr();
128 while (checkptr && tracptr->get_col() != 1) {
129 if (checkptr->get_data(0) == 1) {
130 //cout << "\n\tOK TRADING SEQUENCE";
131 //break;
132 }
133 else if (ptr->get_row() == checkptr->get_data(0)) {
134 cout << "\n\tno !!! -TRADING SEQUENCE- !!! no";
135 done = 1;
136 //break;
137 }
138 checkptr = checkptr->get_previous_ptr();
139 }
140 if (done) goto sequence;
141 cout << "\n\tRow: " << ptr->get_row();
142 //if (i == ppdata + 1) break;
143 for (j = 1 + 1; j <= forexCounterDB; j++) {
144 //cout << "\n\tpoint to(" << i << ", " << j << ")";
145 ptr = net->point_to(net, ppdata, aux_max->get_col(), j, 'f');
146 if (ptr->get_data(ppdata) <= 0 ||
147 ptr->get_row() == ptr->get_col() ||
148 ptr->get_col() < ptr->get_row()) { //
149 continue;
150 }
151 net->RB_Insert_data(net, rootRowHolDB, db_root, ptr, 'f', pp_float);
152 }
153 aux_max = net->RB_data_maximun(net, rootRowHolDB, crptr, db_root);
154 rateExPtr->set_data(0, aux_max->get_data(ppdata));
155 rateExPtr = rateExPtr->get_next_ptr();
156
157 if (!aux_max) {
158 cout << "\n\tNO CYCLE - !!!";
159 i = ppdata + 1;
160 }
161 else {
162 ptr = net->point_to(net, ppdata, aux_max->get_col(), 1, 'f');
163 }
164 }
165 }while(--k);
166
167 sequence:
168 cout << "\n\tRow 1: Forex Trading Sequence";
169 cout << "\n\tRow 2: Forex Trading Exchange";
170 net->set_work_sheet(net, 0, 2, tracptr->get_col()); //page i, (i * i)
171 net->show_page(net, 0, 'f', 0, 2, 8, 4);
172 for (i = 1; i <= forexCounterDB; i++)
173 fDB[i].close();
174 return;
175 }
176 /******END forexSimulator(void)******/
177
178 ===========output========================
179 AryFx i: 1 EU-GBP datum: ---> 0.6578
180 AryFx i: 2 USD-BP datum: ---> 0.5283
181 AryFx i: 3 USD-EU datum: ---> 0.7874
182 WORKSHEET 1 A[3, 3] FLOAT
183 A B C
184 >---------------------<
185 1: 0 0.6578 0.5283
186 2: 0 0 0.7874
187 3: 0 0 0
188 <--------------------->
189
190 AryFx i: 1 EU-GBP datum: ---> 0.6558
191 AryFx i: 2 USD-BP datum: ---> 0.5304
192 AryFx i: 3 USD-EU datum: ---> 0.7878
193 WORKSHEET 1 A[3, 3] FLOAT
194 A B C
195 >---------------------<
196 1: 0 0.6558 0.5304
197 2: 0 0 0.7878
198 3: 0 0 0
199 <--------------------->
200
201 AryFx i: 1 EU-GBP datum: ---> 0.66
202 AryFx i: 2 USD-BP datum: ---> 0.5294
203 AryFx i: 3 USD-EU datum: ---> 0.7883
204 WORKSHEET 1 A[3, 3] FLOAT
205 A B C
206 >---------------------<
207 1: 0 0.66 0.5294
208 2: 0 0 0.7883
209 3: 0 0 0
210 <--------------------->
211
212 Row 1: Forex Trading Sequence
213 Row 2: Forex Trading Exchange
214 WORKSHEET 0 @[2, 3] FLOAT
215 A B C
216 >---------------------------<
217 1: 1 2 0
218 2:2.114e-307 4.451e-308 0
219 <--------------------------->
220
221 ENDS forexSim2334 Elapsed Time: 0.075 sec
222 Boost version: 1.59.0
223 EXIT FROM EXSAN
224
225
Comments
Post a Comment