Serving the Quantitative Finance Community

 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

February 24th, 2022, 3:48 pm

662
°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

February 28th, 2022, 3:23 pm

°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

March 3rd, 2022, 12:57 pm

°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

March 10th, 2022, 2:34 pm

223230

°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

March 14th, 2022, 1:32 pm

Image
   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
°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

April 12th, 2022, 4:53 pm

4370
Exsan with +100K lines of source code, is a dynamic console-oriented spreadsheet software I have conceived, created and developed. It is capable of handling extremely large data sets and performing complex calculations and analysis. In plain words, ExSan is my C++ version of Excel! (Matlab)

ExSan does Real Time Data (RTD -worth to say NO HISTORICAL DATA-) tick-by-tick live(instant) data analysis using Interactive Brokers C++ API.

IB allows to zoom up to 30 seconds candle graph, ExSan scrutinizes data behavior beyond that limit, it is suitable for Low Latency Trading and in general for High Frequency Quant
ExSan is already plugged to Interactive Brokers C++ API.
This is forex activity in the stated lapse of time (33 seconds) Gbp vs Usd Fx Eastern Time from 2022-Apr-12 07:13:30.940771 to 07:14:04.319069  


The following graphs depict the same data though expressed in groups of n-ticks



Interactive Brokers C++ API & ExSan xsn 898772
°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

May 11th, 2022, 5:27 pm

5440
E x S a n ++  
From a Double Link List and a Red Black Tree to ExSan
Forex 001

"Man invented language to satisfy his deep need to complain."-- Lily Tomlin

Exsan High Performance C++ [email protected]
 iTwit   Mon May 9 13:24:34 2022         x: 18.10.25     
FOREX TRADING  
°°°°-ExSan at Work -Current Project-°°°
[font={defaultattr}]Trading of one currency for another with the hopes of taking advantage of small differences in conversion rates among several currencies in order to achieve a profit. For example, if 1.00 in U.S. currency buys 0.7 British pounds currency, 1.00 in British currency buys 9.5 French francs, and 1 French franc buys 0.16 in U.S. dollars, then a forex trader can start with 1.00 USD and earn 1 * 0.7 * 9.5 * 0.16 = 1.064 dollars thus earning a profit of 6.4 percent.
The problem consist to write a program that determines whether a sequence of currency exchanges can yield a profit as described above.
To result in successful trade, a sequence of exchanges must begin and end with the same currency, but any starting currency may be considered.
The input file consists of one or more conversion tables. You must solve the trading problem for each of the tables in the input file. Each table is preceded by an integer n on a line by itself giving the dimensions of the table. The maximum dimension is 20. The minimum dimension is 2.
The table then follows in row major order but with the diagonal elements of the table missing (these are assumed to have value 1.0). Thus the first row of the table represents the conversion rates between country 1 and n - 1 other countries, i.e. the amount of currency of country i constrained to 2 eq i eq n that can be purchased with one unit of the currency of country 1.
Thus each table consists of n + 1 lines in the input file: 1 line containing n and n lines representing the conversion table.[/font]

Output
[font={defaultattr}]For each table in the input file, you must determine whether a sequence of exchanges exists that results in a profit of more than 1 percent (0.01). If a sequence exists you must print the sequence of exchanges that results in a profit. If there is more than one sequence that results in a profit of more than 1 percent you must print a sequence of minimal length, i.e. one of the sequences that uses the fewest exchanges of currencies to yield a profit.
Because the IRS (United States Internal Revenue Service) taxes long transaction sequences with a high rate, all profitable sequences must consist of n or fewer transactions where n is the dimension of the table giving conversion rates. The sequence [/font]
1 2 1
[font={defaultattr}]
 represents two conversions.
If a profitable sequence exists you must print the sequence of exchanges that results in a profit. The sequence is printed as a sequence of integers with the integer i representing the i_th line of the conversion table (country i. The first integer in the sequence is the country from which the profitable sequence starts. This integer also ends the sequence.
If no profiting sequence of n or fewer transactions exists, then the line[/font]
no trading sequence exists
[font={defaultattr}]
should be printed.[/font]

Sample Input
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
Sample Output
1 2 1
1 2 4 1
no trading sequence exists
Analysis
[font={defaultattr}]
For a given problem, the conversion table corresponds to a graph and the solution corresponds to a shortest profitable cycle in that graph. Consider the following conversion table over USD, MXN, and EUR.[/font]
3
1.004987562112089 1.004987562112089
0.99503719020999 1.004987562112089
1.004987562112089 0.99503719020999
[font={defaultattr}]
The table corresponds to the following interpretation.[/font]
    | 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
[font={defaultattr}]
The corresponding graph is the following.[/font]

Image
[font={defaultattr}]
When we interpret the conversion table, we write 0 for the rates in the diagonal to indicate that we do not consider edges that start and end in the same vertex. The reason is that those edges are redundant. A lasso is an edge that starts and ends in the same vertex. Lassos are redundant because from a given sequence that includes a lasso you obtain a shorter sequence with the same rate by removing the lasso. For example, sequence [/font]
USD USD EUR USD
[font={defaultattr}]
 yields profit 1.01, the same profit that the shorter sequence [/font]
USD EUR USD
[font={defaultattr}]
 yields.

A sequence of exchanges may yield a profit only if the sequence is a cycle. For example, the cycle [/font]
USD -> MXN -> EUR -> USD
[font={defaultattr}]
 yields profit of [email protected]^{3/2}@$. Given that the number of vertices in the graph is 3, we do not consider cycles longer than 3. Consider the cycles of length 3 or less.[/font]
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)
[font={defaultattr}]

A cycle is profitable when its rate is greater or equal to 1.01. Out of the five cycles, only the following two are profitable.[/font]
USD -> EUR -> USD
USD -> MXN -> EUR -> USD
[font={defaultattr}]
Out of the two profitable cycles, [/font]
USD -> EUR -> USD
[font={defaultattr}]
 is the only solution because it is the shortest cycle.

A solution may not be a simple cycle like in the previous example. For example, consider the following conversion table and its corresponding graph.[/font]
4
1 0 0
1.005 0 0
0 0 0
0 0 0
Image
[font={defaultattr}]
For the graph, the cycles of length 4 or less are the following[/font]
CYCLE     : RATE
1 2 1     : 1.005
1 2 1 2 1 : 1.010025
[font={defaultattr}]
The only profitable cycle is [/font]
1 2 1 2 1
[font={defaultattr}]
 and therefore it is the only solution. The cycle is a solution regardless of the fact that it consists of the repetition of simple cycle [/font]
1 2 1
[font={defaultattr}]
.

A solution that is not a simple cycle is not necessarily the repetition of a simple cycle like in the previous example. For example, consider the following conversion table and its corresponding graph.[/font]
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
Image
[font={defaultattr}]
For the graph, the cycles of length 5 or less are the following.[/font]
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
[font={defaultattr}]
The only profitable cycle is [/font]
1 2 1 5 3 1
[font={defaultattr}]
 and therefore it is the only solution. The cycle consists of simple cycles [/font]
1 2 1
[font={defaultattr}]
 and [/font]
1 5 3 1
[font={defaultattr}]
.

Searching for a solution is difficult because there may be many cycles for a given problem. The reason is that a conversion table of length n corresponds to complete graph _n. Even if there are edges with weight 0, we consider them because considering a complete graph makes for a simpler solution. The exception are lassos, which we do not consider because they are redundant. For complete graphs of size 2 eq n eq 20, the number of cycles of length n or less is the following.[/font]
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
Approach
[font={defaultattr}]
We approach the problem by searching for a shortest profitable cycle amongst a limited number of candidates. We guarantee that the profitable cycle we find is shortest by considering candidates in order of length.

Consider the following input graph.[/font]

Image
[font={defaultattr}]
The candidates of length 2 are the cycles of length 2. Thus, we consider the cycles of length 2 from each one of the vertices as illustrated in the following diagram. These are all the cycles of length 2 because we consider all paths that start and end in each given vertex.[/font]

Image
[font={defaultattr}]
We search for a profitable candidate of length 2 by considering each root and each corresponding child. For example, for root [/font]
1
[font={defaultattr}]
 and child [/font]
2
[font={defaultattr}]
, we consider the following candidate.[/font]

Image
[font={defaultattr}]
The rate of the candidate is 1.005 which is not profitable and therefore not a solution. We search the rest of the candidates by repeating the process for each root and child. We find no profitable candidate of length 2.
Half of the candidates of length 2 are repeated but we consider them anyway. For example, candidate for root [/font]
2
[font={defaultattr}]
 and child [/font]
1
[font={defaultattr}]
 ([/font]
2 -> 1 -> 2
[font={defaultattr}]
) is the same cycle and candidate for root [/font]
1
[font={defaultattr}]
 and child [/font]
2
[font={defaultattr}]
 ([/font]
1 -> 2 -> 1
[font={defaultattr}]
). The reason we consider repetitions is that when we apply the process to longer candidates, the number of candidates we consider for each length remains 12 while the number of cycles for the length increases. For example, when we consider candidates of length 4 for the input graph, we consider 12 candidates instead of the 28 cycles of length 4 that exist.

Given that there is no solution of length 2, we search for a profitable candidate of length 3. The candidates of length 3 are most beneficial cycles of length 3. The structure of each candidate consists of a prefix edge [/font]
i -> j
[font={defaultattr}]
 and a suffix path [/font]
j -> k -> i
[font={defaultattr}]
. For example, the candidate for root [/font]
1
[font={defaultattr}]
 and child [/font]
2
[font={defaultattr}]
 is the following.[/font]

Image
[font={defaultattr}]
The prefix edge [/font]
1 -> 2
[font={defaultattr}]
 is the edge from [/font]
1
[font={defaultattr}]
 to [/font]
2
[font={defaultattr}]
 given by the input graph. The suffix path [/font]
2 -> 3 -> 1
[font={defaultattr}]
 is a most beneficial path of length 2 from [/font]
2
[font={defaultattr}]
 to [/font]
1
[font={defaultattr}]
. In this case the suffix is the most beneficial path of length 2 from [/font]
2
[font={defaultattr}]
 to [/font]
1
[font={defaultattr}]
. The rate of the candidate is 1 which is not profitable and therefore not a solution. Given that there is a candidate for each root and child, we search the rest of the candidates by repeating the process for each root and child. We find no profitable candidate of length 3.

Candidates are most beneficial paths, for that reason we construct candidates by constructing most beneficial paths.

The construction of most beneficial paths is determined by their structure. Consider the structure a most beneficial path.[/font]
p = i -> k -> ... -> j
    ------------------
             |
          m edges
[font={defaultattr}]
The candidate consists of a prefix edge [/font]
i -> k
[font={defaultattr}]
 and a suffix path [/font]
k -> ... -> j
[font={defaultattr}]
. The suffix path is a most beneficial path of length 2 from [/font]
k
[font={defaultattr}]
 to [/font]
j
[font={defaultattr}]
 because [/font]
p
[font={defaultattr}]
 is a most beneficial path. If the suffix were not most beneficial, [/font]
p
[font={defaultattr}]
 would not be a most beneficial path from [/font]
i
[font={defaultattr}]
 to [/font]
j
[font={defaultattr}]
 because there would be a suffix from [/font]
k
[font={defaultattr}]
 to [/font]
j
[font={defaultattr}]
 with a higher rate. The rate [/font]
B'[i,j]
[font={defaultattr}]
 of path [/font]
p
[font={defaultattr}]
 is determined by the rate of its edge [/font]
W[i,k]
[font={defaultattr}]
 and the rate of its suffix [/font]
B[k,j]
[font={defaultattr}]
 as follows.[/font]
B'[i,j] = W[i,k] * B[k,j]
[font={defaultattr}]

The construction of a most beneficial path corresponds to the calculation of its rate. For given origin [/font]
i
[font={defaultattr}]
 and destination [/font]
j
[font={defaultattr}]
 vertices, we obtain the rate [/font]
B[m][i,j]
[font={defaultattr}]
 of most beneficial path of length [/font]
m
[font={defaultattr}]
 from the rates of most beneficial paths of length [/font]
m - 1
[font={defaultattr}]
 as follows.[/font]
B[m][i,j] = max { W[i,k] * B[m - 1][k,j] | k in 1 ... n }
[font={defaultattr}]
For the matrix of weights [/font]
W
[font={defaultattr}]
 corresponding to the input graph, the rate of most beneficial paths of length 1 [/font]
B[1]
[font={defaultattr}]
 is [/font]
W
[font={defaultattr}]
.

It is possible to construct most beneficial paths on demand instead of upfront together with candidates. We do not explain that approach because the time complexity of the end-to-end algorithm is the same either way. We do provide an implementation of the approach for reference.

When we construct most beneficial paths, we consider many more paths than the count of candidates. While we consider 12 candidates for each length, we consider 48 paths when we compute most beneficial paths (4 roots times 3 children times 4 destination vertices). We do so because for a given input graph, the number of candidates is constant for each length and thus the total count of paths that we consider is much less than the count of cycles in the graph. Compare the over approximation n^4$ of count of paths we consider to the number of cycles in the input graph.[/font]
               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
[font={defaultattr}]
The overapproximation corresponds to our nested iteration of $@n@$ lengths, $@n@$ roots, $@n@$ children, and $@n@$ destination vertices.
Given that there is no solution of length 3, we search for a profitable candidate of length 4. For root 1 and child 2, the candidate is the following.[/font]

Image
[font={defaultattr}]
The prefix edge [/font]
1 -> 2
[font={defaultattr}]
 is given by the input graph. The suffix path is the most beneficial path of length 3 from [/font]
2
[font={defaultattr}]
 to [/font]
1
[font={defaultattr}]
. In this case there is only one most beneficial path, [/font]
2 1 2 1
[font={defaultattr}]
. The rate of the candidate is 1.010025 which is profitable and thus a solution. We stop and return the solution. If we repeated the process for the other candidates, we would find no other solution. Thus, [/font]
1 2 1 2 1
[font={defaultattr}]
 is the only solution.[/font]

Implementation
[font={defaultattr}]
The following C program is the ExSan implementation of my own algorithm. For a given weight matrix [/font]
ExSan at Work
EXIT FROM EXSAN
[font={defaultattr}]
Boost version: 1.59.0© Registered TRADEMARK ExSan[/font]

ExSan Blog
[font={defaultattr}]https://exsan-pixsan.blogspot.com/2022/05/forex-001.html[/font]
°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

May 14th, 2022, 2:25 pm

5588
M  e  n         a t         W  o  r  k
Systematic Forex Trading
Interactive Brokers C++ API + ExSan  
Forex Algorithm ExSan Solution
Forex State Diagram
Two Matrices are needed  [ buy/sell ]  They must be updated(refreshed) constantly.  Double Layer Matrix  [ buy/sell ]
Forex Market is the trading of currencies for a profit. Forex is a very real problem that promises a lot of money, if it were not for fees, taxes, and other imposed bounds.  The challenge in Forex is finding an optimal solution despite the size of the search space.
The problem consist to write a program that determines whether a sequence of currency exchanges can yield a profit as described above. To result in successful trade, a sequence of exchanges must begin and end with the same currency, but any starting currency may be considered.
For example, for a set of 20 currencies, the search space consists of  
3×10243×1024   (read “three septillion” in the short scale
It sounds complicated, it is indeed! 
However an appropriate algorithm and the correct tool can beat it ! 


Image
°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

May 18th, 2022, 2:07 pm

5760 / Updated Blog Entry

Systematic Forex Trading
°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

July 26th, 2022, 2:49 pm

°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

July 28th, 2022, 12:26 pm




Image
°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

July 30th, 2022, 12:34 pm

#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)
PySan
°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

August 2nd, 2022, 5:28 pm

8825

°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

August 18th, 2022, 10:59 am

°31200
Integrating C++ and Python // Simplest Way
Today's Bilingual Code  C++ and Python
Ref:  LinkedIn1   LinkedIn2
-----
Ref Personal1  Personal2
----
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]

Image
°°° About ExSan bit.ly/3U5bIdq °°°
 
User avatar
ExSan
Topic Author
Posts: 493
Joined: April 12th, 2003, 10:40 am

Re: Fractals - Patterns and Chaos

October 20th, 2022, 1:28 pm

Image
°°° About ExSan bit.ly/3U5bIdq °°°