662
1 //C++ Code
2 int main(){
3 unsigned short i;
4 printf("Hello World A\n");
5 i = 0;
6 for(; i < 3; i++)
7 printf( "i -> %d\n", i);
8 //--------------------
9 printf("Hello World B\n");
10 i = 0;
11 for(; i < 3; i++);
12 printf( "i -> %d\n", i);
13 return 0;
14 }
15
16 OUTPUT>
17 Hello World A
18 i -> 0
19 i -> 1
20 i -> 2
21 Hello World B
22 i -> 3
1 2 1
no trading sequence exists
3
1.2 .89
.88 5.1
1.1 0.15
4
3.1 0.0023 0.35
0.21 0.00353 8.13
200 180.559 10.339
2.11 0.089 0.06111
2
2.0
0.45
1 2 1
1 2 4 1
no trading sequence exists
3
1.004987562112089 1.004987562112089
0.99503719020999 1.004987562112089
1.004987562112089 0.99503719020999
| USD | MXN | EUR
----------------------------------------------
USD | 0 | 1.01^(1/2) | 1.01^(1/2)
MXN | 1.01^(-1/2) | 0 | 1.01^(1/2)
EUR | 1.01^(1/2) | 1.01^(-1/2) | 0
USD USD EUR USD
USD EUR USD
USD -> MXN -> EUR -> USD
CYCLE : RATE
USD -> MXN -> USD : 1
USD -> EUR -> USD : 1.01
EUR -> MXN -> EUR : 1
USD -> MXN -> EUR -> USD : 1.01^(3/2)
USD -> EUR -> MXN -> USD : 1.01^(-1/2)
USD -> EUR -> USD
USD -> MXN -> EUR -> USD
USD -> EUR -> USD
4
1 0 0
1.005 0 0
0 0 0
0 0 0
CYCLE : RATE
1 2 1 : 1.005
1 2 1 2 1 : 1.010025
1 2 1 2 1
1 2 1
5
1.001992047666533 0 0 1.001992047666533
1.001992047666533 0 0 0
1.001992047666533 0 0 0
0 0 0 0
0 0 1.001992047666533 0
CYCLE : RATE
1 2 1 : 1.01^(2/5)
1 5 3 1 : 1.01^(3/5)
1 2 1 5 3 1 : 1.01
1 2 1 5 3 1
1 2 1
1 5 3 1
K2: 1
K3: 5
K4: 42
K5: 384
K6: 4,665
K7: 69,537
K8: 1,230,124
K9: 25,140,552
K10: 582,508,305
K11: 15,084,077,381
K12: 431,646,196,806
K13: 13,525,545,361,080
K14: 460,576,563,322,057
K15: 16,935,036,272,292,001
K16: 668,691,718,661,091,000
K17: 28,220,125,532,003,984,176
K18: 1,267,597,789,008,779,578,401
K19: 60,381,304,029,673,985,693,205
K20: 3,040,239,935,992,309,703,757,730
1
2
2
1
2 -> 1 -> 2
1
2
1 -> 2 -> 1
i -> j
j -> k -> i
1
2
1 -> 2
1
2
2 -> 3 -> 1
2
1
2
1
p = i -> k -> ... -> j
------------------
|
m edges
i -> k
k -> ... -> j
k
j
p
p
i
j
k
j
B'[i,j]
p
W[i,k]
B[k,j]
B'[i,j] = W[i,k] * B[k,j]
i
j
B[m][i,j]
m
m - 1
B[m][i,j] = max { W[i,k] * B[m - 1][k,j] | k in 1 ... n }
W
B[1]
W
NUMBER OF CYCLES NUMBER OF PATHS WE CONSIDER
K2: 1 < 16
K3: 5 < 81
K4: 42 < 256
K5: 384 < 625
K6: 4,665 > 1296
K7: 69,537 > 2401
K8: 1,230,124 > 4096
K9: 25,140,552 > 6561
K10: 582,508,305 > 10000
K11: 15,084,077,381 > 14641
K12: 431,646,196,806 > 20736
K13: 13,525,545,361,080 > 28561
K14: 460,576,563,322,057 > 38416
K15: 16,935,036,272,292,001 > 50625
K16: 668,691,718,661,091,000 > 65536
K17: 28,220,125,532,003,984,176 > 83521
K18: 1,267,597,789,008,779,578,401 > 104976
K19: 60,381,304,029,673,985,693,205 > 130321
K20: 3,040,239,935,992,309,703,757,730 > 160000
1 -> 2
2
1
2 1 2 1
1 2 1 2 1
ExSan at Work
#Download intraday data
import yfinance as yf
import mplfinance as mpf
asset1 = "CGEMY"
data1 = yf.download(asset1, period = "7d", interval = "1m", show_nontrading=True)
dataDownloaded = 'C:.....\\'+asset1 + '.csv'
data1['Close'].to_csv(dataDownloaded, index=False)
Author [email protected]
1 /***********START***************/
2 // C++ code
3 #include Python.h
4 void xsnCallsPython(void) {
5 setJobID("xsnCallsPython_");
6 //REQUEST PYTHON SERVICE
7 Py_Initialize();
8
14
15 CELLPTR ptr(nullptr);
16 NETPTR net(nullptr);
18 unsigned short dim{ 7 };
19 unsigned short netRows{ dim }, netCols{ dim };
20 net = net->exsan(dim, dim, );
21
22 for (unsigned short row = dim - 4; row <= dim; row++) {
23 for (unsigned short col = dim - 3; col <= dim; col++) {
24 fout << "---------Call Python Service for each Matrix ------------";
27
28 string usedByExSanToTransmitData = "tx.txt";
29 fstream ftx;
30 ftx.open(usedByExSanToTransmitData, ios::out);
31 ftx << row << " " << col << endl;
32 for (unsigned short roww = 1; roww <= row; roww++) {
33 for (unsigned short coll = 1; coll <= col; coll++) {
34 ptr = net->point_to(net, pp_us, roww, coll, 'u');
35 ptr->set_ushort(pp_us, 10 * roww + coll);
36 ftx << ptr->get_ushort(pp_us) << " ";
37 }
38 ftx << endl;
39 }
40 ftx.close()//The original Matrix is created in C++ and ready to be send to Python
41 net->show_page(net, pp_us);
42
43 //---CallPython Service Begin-----
48
49 PyObject* obj = Py_BuildValue("s", "XsnCallsPython.py");
50 FILE* filePyScript = _Py_fopen_obj(obj, "r+");
51 if (filePyScript != NULL) {
52 PyRun_SimpleFile(filePyScript, "XsnCallsPython.py");
53 }
54
55 //--------Python Service Done ------------------------
57 fout.open(out_txt_file_name, ios::out | fstream::app); // open the output file
59 string usedByExSanToReceiveData = "rx.txt";
60 fstream frx;
61 frx.open(usedByExSanToReceiveData, ios::in);
62 //capture returned data and upload to exsan
63 unsigned short frxRow{ 0 }, frxCol{ 0 };
64 frx >> frxRow;
65 frx >> frxCol;
66 fout << "\n\tData Ary received, Rows: " << frxRow << " Cols: " << frxCol << endl;
67 net->set_work_sheet(net, pp_float, frxRow, frxCol);
68 double data(0);
69 double dt(0);
70 for (unsigned short roww = 1; roww <= frxRow; roww++) {
71 for (unsigned short coll = 1; coll <= frxCol; coll++) {
72 frx >> data;
73 ptr = net->point_to(net, pp_float, roww, coll, 'f');
74 ptr->set_data(pp_float, data);
75 }
76 }
77 net->show_page(net, pp_float);
78 frx.close();
79 fout << endl;
80 //---------Python Service Done - Close----------
81 }
82 }
83
84 Py_Finalize();
85 net->kill_exsan(net);
86 return;
87 } //Author [email protected]
88 /***********xsnCallsPython END*****************/
89
90
91
92 ---PYTHON SCRIPT FILE XsnCallsPython.py--------
93 foutFile = "exsan_out.txt"
94 fout = open(foutFile, "a")
95
96 finFile = "tx.txt" # data from Exsan
97 foutFile = "rx.txt" # data send to Exsan
98
99 pin = open(finFile, "r")
100 pout = open(foutFile, "w") #each call a new one
101
102 from contextlib import redirect_stdout
103 import numpy as np
107
108 with redirect_stdout(fout) :
109 print("\n\t\tPython Script Begins Data read from: ", finFile)
110 def readMatrixFile(FileName) :
111 rows, cols = np.fromfile(FileName, dtype = int, count = 2, sep = " ")
112 a = np.fromfile(FileName, dtype = float, count = rows * cols, sep = " ").reshape((rows, cols))
113 return a
114
115 a = readMatrixFile(pin)
116 #Python does the division and returns modified matrix to C++
117 b = a / a.shape[0]
118
119 with redirect_stdout(fout) :
120 print("\n\t\tData from ExSan is divided by the number of rows ", a.shape[0])
121
122
123 with redirect_stdout(pout) :
124 print(b.shape[0], " ", b.shape[1])
125
126 x = '\n'.join([''.join(['{:4}'.format(item) for item in row]) for row in b])
127
128 with redirect_stdout(pout) :
129 print(x)
130
131 with redirect_stdout(fout) :
132 print("\n\t\tPython Script Ends")
133 #-------------------------
134 pin.close()
135 pout.close()
136 fout.close()
----------ENDS PYTHON SCRIPT-------------------
138
OUTPUT
140
141 WORKSHEET 1 A[4, 5]
142 A B C D E
143 > -------------- - <
144 1 : 11 12 13 14 15
145 2 : 21 22 23 24 25
146 3 : 31 32 33 34 35
147 4 : 41 42 43 44 45
148 < --------------->
149 Python Script Begins Data read from : tx.txt
150 Data from ExSan is divided by the number of rows 4
151 Python Script Ends
152 Data Ary received, Rows: 4 Cols : 5
153
154 WORKSHEET 0 @[4, 5] FLOAT
155 A B C D E
156 > ------------------------ - <
157 1 : 2.75 3 3.25 3.5 3.75
158 2 : 5.25 5.5 5.75 6 6.25
159 3 : 7.75 8 8.25 8.5 8.75
160 4 : 10.2 10.5 10.8 11 11.2
161 < ------------------------->
162
163 -------- - Call Python Service for each Matrix------------
164 WORKSHEET 1 A[4, 6]
165 A B C D E F
166 > ------------------<
167 1 : 11 12 13 14 15 16
168 2 : 21 22 23 24 25 26
169 3 : 31 32 33 34 35 36
170 4 : 41 42 43 44 45 46
171 < ------------------ >
172
173 Python Script Begins Data read from : tx.txt
174 Data from ExSan is divided by the number of rows 4
175 Python Script Ends
176 Data Ary received, Rows: 4 Cols : 6
177
178 WORKSHEET 0 @[4, 6] FLOAT
179 A B C D E F
180 >------------------------------<
181 1: 2.75 3 3.25 3.5 3.75 4
182 2 : 5.25 5.5 5.75 6 6.25 6.5
183 3 : 7.75 8 8.25 8.5 8.75 9
184 4 : 10.2 10.5 10.8 11 11.2 11.5
185 < ------------------------------ >
186 Author [email protected]
187 -------- - Call Python Service for each Matrix------------
188 WORKSHEET 1 A[5, 5]
189 A B C D E
190 >-------------- - <
191 1 : 11 12 13 14 15
192 2 : 21 22 23 24 25
193 3 : 31 32 33 34 35
194 4 : 41 42 43 44 45
195 5 : 51 52 53 54 55
196 < --------------->
197
198 Python Script Begins Data read from : tx.txt
199 Data from ExSan is divided by the number of rows 5
200 Python Script Ends
201 Data Ary received, Rows: 5 Cols : 5
202
203 WORKSHEET 0 @[5, 5] FLOAT
204 A B C D E
205 > ------------------------ - <
206 1: 2.2 2.4 2.6 2.8 3
207 2 : 4.2 4.4 4.6 4.8 5
208 3 : 6.2 6.4 6.6 6.8 7
209 4 : 8.2 8.4 8.6 8.8 9
210 5 : 10.2 10.4 10.6 10.8 11
211 < ------------------------->
212 Author [email protected]