Back Testing Algorithmic Trading Modern Portfolio Simulator - Some Code

      Previous Post       Next Post 

This  module (5K lines of  source  C++ code) is based on ExSan a multipurpose master library, It is a console-oriented worksheet tool written in C++11 that is comparable in functionality to Excel or Matlab. Some Outputs  in the next entries of this blog. ExSan is already plugged into  Interactive Brokers C++ API to perform live market data analysis

This ALGORITHM is used in line 3231

 I am looking for a job as a C/C++ developer / programmer .  

My portfolio https://lnkd.in/dPC3ZuDr    Personal https://lnkd.in/dDuC9uMi  


    

  Some lines of code have been omitted to protect the author's copyright. 

    57 /***********START***************/

    58 void hft(void) {

    59    setJobID("hft");

    60 

   158    //fout << "Today is " << as::date << now << " and tomorrow is " << now + 24 * 3600 << endl;

   159    //time_t now = time(0);   

   160    //fout << "Today is "<< as::date << now << " and tomorrow is " << now+24*3600 << endl;

   161    //fout << "Current time is "<< as::time << now << endl;

   162    //fout << "The current weekday is "<< as::ftime("%A") << now << endl;   

   163    ////*/

   164    //fout << " 1 menos 99.9999998759799979797774747 =  " << setprecision(33) <

   165    ptime pt;

   166    string temporal;

   167 

   168    std::time_t now = std::time(0);

   169    boost::random::mt19937 gen{ static_cast(now) };

   170 

   171    string plot_smooth_data, plot_LS_data;

   172 

   173    unsigned seed = chrono::system_clock::now().time_since_epoch().count();

   174    default_random_engine generator(seed);

   175 

   177    unsigned short xsnFileOutID(0);

   178 

   222    }

   223    /*

   224    else {

   225       //printf("\tOPEN Balance Sheet File: ", balanceSheet);

   226       fout.flush() << "\tReady Balance Sheet File: " << balanceSheet ;

   227       //return;

   228    }

   229    //*/

   230    fstream f1db, fLS, fsos;

   231 

   241       "stockDB_2.txt",      // 2  half of stockDB

   242       "stockDB_4.txt",      // 3  84   quarter of stockDB

   243       "stockDB_8.txt",      // 4  43   1/8 of stockDB

   244       "stockDB_16.txt",      // 5 22   1/16 of stockDB

   245       "stockDB_base.txt",      // 6    7

   246       "stockDB15.txt",      // 7    15

   247       "stockOneDB.txt",      // 8

   248       "stockTwoDB.txt",      // 9

   249       "stocki.txt",           // 10

   250       "stocki2.txt",          // 11

   251    };

   252 

   253    unsigned short dbfileID = 4;      

   313    j = 0;

   314    fdb.open(dbFile, ios::in);  //scramble file

   315    do {

   316       fdb >> stock;

   317       //if (fdb.eof()) break;

   318       //cout << stock;

   319       stockID[j] = stock;   //new ary of scrambled file

   320       //fout << "\t" << j << "\t"<< stockID[j] << "  " << stock <<   endl;  //system("pause");

   321       j++;

   322    } while (j < stockCounterDB);

   323    fdb.close();

   324    //return;

   325 

   346    double sum1(0), sum2(0);

   347    gnuplot plot, endLess, pltCorr, pltCorrA, pltCorrB, pltCorrAB, pltInvCorr, pltInvCorrA, pltInvCorrB, pltInvCor

   348    gnuplot graph[5];

   349 

   350    //solo mostrar los 10 primeros  <= 9 

   351    //gnuplot pltCorr[10], pltCorrA[10], pltCorrB[10], pltCorrAB[10], pltInvCorr[10], pltInvCorrA[10], pltInvCorrB

   352    //nuplot pltCorr[10];

   353    //gnuplot* pltCorr = new gnuplot[10];

   354 //   RESET COUNTER Endless Macro Correlation : -3.193 Slope : 0.876315   Lineal Correlation : 0.656907

   355 //inebitable que el ultimo dato se lea dos veces....

   356 ///////////////////////

   357    //dummy variables

   358    double const transactionFee(0.), transactionFeeShort(0.);  // Transaction Fee

   359    bool hedging(1), validSign(0),  dummyExecutePortfolio(1), backFromDangerousBlock(0), flagSOS(1);  // portfolio

   360    ///hedge .33     minDB 12

   361    bool onlyOnce(0), goodReturn(0), linealCorrelatedOnly(1), inData(0), plotDenoisedData(0), hedge(1);   /// if d

   362    unsigned long int geNSTOCKS(999999), geNSTOCKSlimit(50);  // 99K ok sino demora mucho test 3              // m

   363    double thisRunInvestment(0), myInvestment(10000), minInvPerStock(15), stFrom(3.), stTo(10000.);   // stFrom(0)

   364    double mmu(0.1), ep(0.0001), counterBadTickLimit(3.), temp(0);

   365    unsigned short cols(10), minDB(4), maxDB(33), minDBsearchRHO(2), nRHOS(2), nTicksLineal(3), run(3);

   366    unsigned short bigRun(run);

   367    double stPrice(0), stDeltaPercent(60), carryInv(0);   // stFrom(0)  SI DIFERENTE DE CERO ALGO ESTA MAL range s

   368    if (stPrice && 50) {//range stock val around %

   369       stFrom = stPrice * (1. - stDeltaPercent / 100.);

   370       stTo = stPrice * (1. + stDeltaPercent / 100.);

   371    }

   372    double sumReturn(0), factoRun(2), toInvest(0), toSavings(0), toBank(0), timesLaspse(0), limitSavings(10000), t

   373    double expectedReturn(2.00), hedgeBand(0.2), factor_correlation(0.92345), factor_linear_correlation(.9456), sl

   374    //double expectedReturn(2.3300), hedgeBand(0.33), factor_correlation(0.7889012533), slope(.4155675678933), fac

   375    bool retakeData(1), onlyInteger(0), evenOdd(0);  // if hedging - program looks for negative macro correlation 

   376    //auxiliar data used during the program

   377    bool noEnd(1), changeInRecord(0), backUPcheck(1), plotSelected(0);

   378    double Invest_0(0), discarPercent(.05), meanTimer(0), currentBalanceTemp(0); // discarPercent(.05)   

   379    bool readyDB(0), portfolio(0), plotMacro(1), doneTime(0), change(0);

   380    double prePreviousFValStock(0), completeRecDB(0.33), acumReturn(0), retFactor(2.0); // % of completenss 

   381    bool justCounter(0), outOfRangeNoThisRow(0);//    

   382    unsigned short checkTrigger(minDB), minPortfolio(2);   //minDB data que entra al principio files que se leen

   383    unsigned short limitTicks(0), completeRec(0), ss, currentF(0), previousF(0), prePreviousF(0), colIndex(5);

   384    unsigned short  tickLimitToClear(33);

   385 

   386    ntNodesCols = cols; // ntTree solo en estas columnas

   387    ntNodes = 2; //how many nodes in each cell

   388    //*capture input unsigned short*/

   389    //ntNodes = capture_val(1, 20, "Numeber of NOdes; 1 min - 0 Exit ");

   390    //// input parameters using file    

   391    if (!ntNodes || nTicksLineal < 3) {

   392       if (!ntNodes)  fout << "\nntNodes should be at least 1";

   393       if (nTicksLineal < 3) fout << "\n\tTicksLineal should be at least 3";

   394       return;

   395    }

   396 

   397    ///-------------Read Parameters from File------------------------------

   404       fout.flush() << "\t:413: Couldn't open Parameter Sheet File: " << finpFile;

   405       exit(1);

   406    }

   407    else {  // MASTER FILE DATA READ TO EXECUTE EXSAN

   408       fout.flush() << "\n\t:408: Parameters File : " << finpFile;

   409       finp >> dbfileID;   fout << "\n\t:409: 1 dbfileID: " << dbfileID <<  " " << dbfiles[dbfileID];

   410       finp >> geNSTOCKS;  fout << "\n\t:410: 2 nTickRead: " << geNSTOCKS;

   411       finp >> cols;      fout << "\n\t:411: 3 cols: " << cols;  //10   

   412       finp >> ntNodes;      //1     3

   413       finp >> factor_correlation; //0.9699        4 

   414       finp >> factor_linear_correlation;//.877   5

   415       finp >> expectedReturn; //.2333         6

   416       finp >> minDB;    fout << "\n\t:416: 7 minDB: " << minDB;  //10    // 4     7

   417       finp >> hedgeBand; // .1   8

   418       finp >> retFactor;  //1.5  9

   419       finp >> limitWeightFactor;  //10

   420       finp >> noEnd;  //11

   421       finp.close();

   422    }

   423 

   424    if (factor_correlation > 0.93377 || factor_linear_correlation > 0.97733) {   // RHO/rho   

   425       fout.flush() << "\t:425: Incompatible parameters; ";

   426       if (factor_correlation >= 0.9677) fout.flush() << "\tRho is too high: " << factor_correlation;

   427       if (factor_linear_correlation >= 0.97733) fout.flush() << "\tLineal Correlation is too high: " << factor_line

   428       exit(1);

   429    }

   430    ///-------------Read Parameters from File   End --------------------------

   431    

   432    string thiStock = "NOLE"; //  NOLE, MSFT

   433    unsigned short copyntNodes(ntNodes);

   434    //factor_linear_correlation = factor_correlation + 0.1233 * (1. - factor_correlation);  // el factor en 0-1

   435 //el slope viene siendo cuanto en dolar sube en cada tick y esto 

   436 //   dependería del valor minimo de la accion y de como  varia ??? no tanto así   

   437    //al tener un numero menor hay un problema toma el registro incompleto com 

   438    bool trade(0);

   439    if (trade) {

   440       mu = .33;  // smooth factor for data, .33 parece razonable ligero smooth      

   441       mmu = 0.10;  //.10 SOFT FACTOR SOMOOTH DATA 

   442       expectedReturn = 3.33;   //3.0  expected Return 3.0% , si menor se asegura pronta ganancia

   443       cols = 12;   // number of ticks considered for calculating RHO

   444       stFrom = 10., stTo = 100.;   // Stock price RANGE

   445       ep = 0.0001;   //  percentage around pre and pre_previous 2 concecutives data epsilon ep*d 

   446       factor_correlation = 0.977;  // RHO .977 IDEAL  .96 Y LA CORRELACION es +/- 

   447       factor_linear_correlation = 0.967;   //

   448       slope = .6777;   //

   449       hedgeBand = .03;   // .033 percent around  1 for hedging   

   450       cols = 12;   //ok n ticksata considered for RHO

   451       nTicksLineal = 4;   //ok last n_ticks for Lineal Correlation      

   452       //timesLaspse               =      1;  // 1 normal val !!! no change

   453       timeZoomFactor = 1.;  //  1 normal valores muy altos, para visualizar subir a 200

   454       minDB = 12;  //# stocks in portfolio 7 lucky number

   455       minDBsearchRHO = 1 + minDB / 2;  //after capture the fastes, how many min for RHO      

   456       nRHOS = minDBsearchRHO;  //HAW MANY BIG RHOS BEFORE LOOK FOR LINEAL CORRELATION

   457 

   458       ///* CONSTANT DO NOT CHANGE

   459       linealCorrelatedOnly = hedging = 1;

   460       //*/

   461       /*

   462       bool noEnd(0), changeInRecord(0), backUPcheck(1);

   463       double stPrice(7), stDeltaPercent(50), stFrom(7.), stTo(777.);   // stFrom(0)  SI DIFERENTE DE CERO ALGO ESTA

   464       //double   stFrom(stPrice*(1. - stDeltaPercent/100.)), stTo(stPrice*(1. + stDeltaPercent / 100.));//range sto

   465       double slope(.3451655), factor_linear_correlation(0.67877543); //.977 IDEAL  .96 Y LA CORRELACION es +/-

   466       bool linealCorrelatedOnly(1), hedging(1), retakeData(1);  // if hedging - program looks for negative macro co

   467       double  myInvestment(10000), discarPercent(.02), meanTimer(0); // discarPercent(.05)

   468       double timesLaspse(12.0), timeZoomFactor(1); // zoom only 1000 for testing, normal val 1

   469       bool readyDB(0), portfolio(0), plotMacro(1), doneTime(0), change(0);

   470       double  hedgeBand(15.), completeRecDB(0.456789); // % of completenss

   471       bool justCounter(0), outOfRangeNoThisRow(0);//

   472       minDB(200)   minDBsearchRHO(100

   473       unsigned short checkTrigger(stockCounterDB/3), run(3), cols(7), nTicksLineal(4), minPortfolio(3), minDB(3), m

   474       unsigned short  completeRec(0); // 1.e5

   475       */

   476    }

   477 

   478    //capture input

   479    //cols = capture_val(3, 20, "0 Exit.cols");

   480    //timesLaspse = capture_float(1, 33, "0 Exit.TimeLapse"); //Ctrl g  goto 1333      

   481    

   482    //----begin macro graph 

   483    unsigned short idPlotG(0);

   484    gnuplot pltM;  // multiple graphs data / candle data

   485    unsigned short nStocksMg(1); // limite es 5 de gnuplot si es de un solo tipo  2 si es candle y linear

   486    unsigned short nPointers(nStocksMg);

   487    double superMin(10000), superMax(0);

   488    ROWPTR* aryStockPtr = new ROWPTR[nPointers];

   489    CELLPTR* aryPtr = new CELLPTR[nPointers];

   490 

   491    //pltM.set_titleMg("Snap Shot of the Market, sometime after 2000");

   492    //----end macro graph  

   493 ///////////////////////   

   494    unsigned short const dbRecSize(cols - nTicksLineal);

   495    //unsigned short const dbRecSize(cols - 1); // the last cluster is not included, always ntNodes greather than 

   496    const short nTL = nTicksLineal;

   497    unsigned short presCol(3), widthCol(8), checkCounter(0), countAsset(0), countAssetPlus(0), countAssetMinus(0);

   498    unsigned short rrows(stockCounterDB + 1);  // (stockCounterDB + 3) mayor posible para no perder datos,  a col 

   499    //SEARCH CONCENTRATION OF PRICES

   500    const int nstars = 100;     // maximum number of stars to distribute

   501    const int nintervals = 10; // number of intervals

   502    unsigned long int p[nintervals] = {};

   503    //int p1[nintervals] = {};

   504    unsigned short nrolls(0);  // number of experiments

   505    unsigned short  countRC(0), counterSt(0);

   506    int starsMax = 50;

   507 

   508    //hedgeband

   509    double lowHB(.5 - hedgeBand / 2.), upHB(.5 + hedgeBand / 2.), keepAbsRet(0);

   510    double sum(0), posSum(0), negSum(0), prevabSum(0), abSum(0), prevposSum(0), prevnegSum(0), AbsRet(0), deltaPri

   511    double prev_nt_Val(0), prev_nt_PreVal(0);

   512    double hdplus(0), hdminus(0), hdsum(0);

   513 

   514    bool firstReturn(1);

   515    double carryValStock(0);

   516    double returnVal(0); 

   517 

   518    if (expectedReturn > 3.33) {

   519       fout << "\nexpectedReturn > 3.33";

   520       return;

   521    }

   522    //widthCol = presCol + 2;  //  123.343   asume centenas y el punto

   529       exit(1);

   530    }

   531    //else fstat << "\n----------------------------------------- " << topic_id_job;

   532    else fstat << endl;

   533 

   534    //string invFile = "c: .....\\\invest.txt";

   535    string invFile = ExSan_Data_path +  "invest.txt";

   536    //fstream finv;

   537    //finv.open(invFile, ios::in | ios::out);

   538 

   539    double savings(0), initial(0), myInvestment0(0);

   540    fstream finv(invFile, ios::in);

   541    if (finv.is_open()) { /* ok, proceed with output */

   542       finv >> myInvestment;

   543       finv >> savings;

   544       finv >> initial;

   545       if (!myInvestment || myInvestment < .7777 * 1000.) {

   546          printf("Error! No funds to invest");

   547          fout.flush();

   548          exit(1);

   549       }

   550       finv.close();

   551       print("Read From File myInvestment: ", myInvestment, "  Savings: ", savings);

   552    }

   553    else {

   554       printf("Error! Couldn't Open Investment  File", invFile);

   555       exit(1);

   556    }

   557 

   558    //myInvestment = 1000;  // to test the program, uncommon for normal execution

   559    myInvestment0 = myInvestment;

   560    thisRunInvestment = myInvestment;

   561    //stTo = myInvestment;

   562    //stFrom = stTo / 20.;

   563 

   564    if (stFrom < 7.)  stFrom = 7.;

   565    //if (stFrom < 4.)  stFrom = 4.;

   566    minInvPerStock = 10;

   567    // investment in not direct proporcion to return but inverse   

   568    if(!xsn)fout << "\n\tstFrom : " << stFrom << " <---> ";// << stTo << "   ";

   569    double myInvestRange[7] = {1000., 2000., 3500., 5500., 9000. };

   570    

   571    if (myInvestment <= 1000.) {

   572       minDB = 7;

   573       stTo = .77 * myInvestment / minDB;

   574       if (!xsn)fout  << stTo << " stTo   =  .77 * myInvestment /  minDB : " << .5 * myInvestment << " / " << minDB 

   575    }

   576    else if (myInvestment > 1000. && myInvestment <= 2000.) {

   577       minDB = 8;

   578       minInvPerStock += 10;

   579       expectedReturn += .01;

   580       stTo = .66 * myInvestment / minDB;

   581       if (!xsn)fout  << stTo << " stTo   =  .66 * myInvestment /  minDB : " << .66 * myInvestment << " / " << minDB

   582    }

   583    else if (myInvestment > 2000. && myInvestment <= 3000.) {

   584       minDB = 9;

   585       minInvPerStock += 20;

   586       expectedReturn += .03;

   587       stTo = .55 * myInvestment / minDB;

   588       if (!xsn)fout  << stTo << " stTo   =  .55 * myInvestment /  minDB : " << .55 * myInvestment << " / " << minDB

   589    }

   590    else if (myInvestment > 3000. && myInvestment <= 4000.) {

   591       minDB = 10;

   592       minInvPerStock += 30;

   593       expectedReturn += .06;

   594       stTo = .50 * myInvestment / minDB;

   595       if (!xsn)fout  << stTo << " stTo   =  .50 * myInvestment /  minDB : " << .50 * myInvestment << " / " << minDB

   596    }

   597    else { // > 10000 

   598       minDB = 10;

   599       minInvPerStock += 40;

   600       expectedReturn += .04;

   601       stTo = 0.45 * myInvestment / minDB;

   602       if (!xsn)fout  << stTo << " stTo    =  0.45 * myInvestment /  minDB : " << 0.45 * myInvestment << " / " << mi

   603    }

   604 

   605    //myInvestment = 1000;   keep comented just for testing enable this

   606    //only one of this group must be enable 

   607    //limitSavings *= 1.33,                        minDB +=1, factoRun = 2;   //10K  reached / 2 run;

   608    //limitSavings *= (1.33*1.33),                  minDB +=2, factoRun = 3;   //13.k reched

   609    //limitSavings *= (1.33*1.33*1.33),               minDB +=3, factoRun = 4;   //13.k reched

   610    //limitSavings *= (1.33*1.33*1.33*1.33),         minDB +=4, factoRun = 5;   //13.k reched

   611    //limitSavings *= (1.33*1.33*1.33*1.33*1.33),      minDB +=5, factoRun = 3;   //13.k reched

   612    //limitSavings *= (1.33*1.33*1.33*1.33*1.33*1.33),   minDB +=6, factoRun = 3;   //13.k reched

   613 

   614    if (minDB > stockCounterDB) minDB = stockCounterDB; // 

   615    //minDB = 2;   // comment this to allow previous block

   616    //nRHOS = minDB / 2; // en un caso optimo, no se usa esta variable

   617    //geNSTOCKSlimit = minDB* tickLimitToClear;   // en siete ticks tiene que definirse  

   618    // when stock is done set the remaining of tick  minus the tick counter - 7

   619 

   620    double startInvestment = myInvestment;

   621    //string dbStatRHO = "c:...... n\\\\exsan_data\\\\statisticsRHO.txt";

   622    string dbStatRHO =  ExSan_Data_path +  "statistics.txt";

   623 

   624    fstream fstatR;

   625    unsigned short indexMaxRHO(0);

   626    bool setRHO(0);

   627    fstatR.open(dbStatRHO, ios::app);

   628    if (!fstatR) {

   629       printf("Error! Couldn't Statistics File", dbStat);

   630       exit(1);

   631    }

   632    //else fstatR << "\n------------------------------------------------------------------------------------ " << 

   633    //fstatR << "\n\tn\t";

   634    fstatR.width(2);

   635    //for (k = 99; k > 80; k--) fstatR << k << "\t";

   636    /*

   637    //fstat  << "\n"   << setw(7)   << "id" << " "

   638    fstat << "\n" <<  setw(4)   << "c"     // cols

   639          << setw(5)   << "cL"     // cols used for linear regre

   640          << setw(16) << "RHO"  // big RHO between stocks

   641          << setw(10) << "r1"   //

   642          << setw(10) << "s1"   //

   643          << setw(10) << "r2"  //

   644          << setw(10) << "s2"  //

   645          << setw(8)   << "nR"  // how many aprove linear reg selection

   646          << setw(5)   << "nS"  // Number Of Stocks

   647          << setw(5)  << "hd"  // hedge bande

   648          << setw(10) << "%RF" <<  endl;   // portfolio perfomance

   649    //*/

   650    token tok;

   651    unsigned short menuOpt(0);

   652    enum menumOpt { go, tLaspse, noend, st_o, st_f, macroCorr, slopeLineal, linealCorr, nTicks, checkTrig, linealN

   653    double param[linealNTicks + 1];

   654    string menuOPT[linealNTicks + 1];

   655 

   656    menuOPT[go] = "GO !";                     param[macroCorr] = 0;

   657    menuOPT[tLaspse] = "Time Lapse";            param[tLaspse] = timesLaspse;

   658    menuOPT[st_o] = "Stock Min Val";            param[st_o] = stFrom;

   659    menuOPT[st_f] = "Stock Max Val";            param[st_f] = stTo;

   660    menuOPT[macroCorr] = "Macro Correlation";      param[macroCorr] = factor_correlation;

   661    menuOPT[linealCorr] = "Lineal Correlation";      param[linealCorr] = factor_linear_correlation;

   662    menuOPT[nTicks] = "n ticks ";               param[nTicks] = cols;

   663    menuOPT[linealNTicks] = "n ticks for lineal correl"; param[linealNTicks] = nTicksLineal;

   664    menuOPT[slopeLineal] = "Slope";               param[slopeLineal] = slope;

   665    menuOPT[checkTrig] = "Trigger Counter";         param[checkTrig] = checkTrigger;

   666    menuOPT[noend] = "Endless";                  param[noend] = noEnd;

   667 

   668    do {

   669       //system("cls");

   670       for (unsigned o = go; o <= linealNTicks; o++)      cout << "\n\t" << o << " " << menuOPT[o] << " :-> " << param[o

   671       //cout << "\n\tWhich one";   //habilitar cuando menu???

   672       //menuOpt = capture_val(go, linealNTicks," menu opt");

   673       menuOpt = 0;

   674       switch (menuOpt) {

   675          case go:  break;

   676          case macroCorr: factor_correlation = capture_float(.5, .9, "0 Exit Macro Correlation factor "); param[macroC

   677          case linealCorr: factor_linear_correlation = capture_float(.5, .9, "0 Exit Lineal Correlation factor");  par

   678          case nTicks: cols = capture_val(10, 33, " nTicks"); break;

   679          case linealNTicks: nTicksLineal = capture_val(4, cols - 1, " nTicks Lineal Correlation"); param[linealNTicks

   680          case slopeLineal: slope = capture_float(0, 7., "Slope");   param[slopeLineal] = slope; break;

   681          case st_o: stFrom = capture_float(0, 1000, " Range of Stock MIN");   param[st_o] = stFrom; break;

   682          case st_f: stTo = capture_float(0, 1000, " Range of Stock MAX");   param[st_f] = stTo; break;

   683          case noend: cout << "\n\tEndless";   noEnd = tok.get_bool();                        param[noend] = noEnd; break;

   684          case tLaspse: timesLaspse = capture_float(1, 5000, "Range of Time Lapse");                 param[tLaspse] = 

   685             //case: break;

   686          default: cout << "\n\tnot in menu"; return;

   687       }

   688       menuOpt = go;

   689       //if (menuOpt == go) break;

   690       //cout << "\n\ttry again";   // habilitar cuando menu input?

   691 //   } while (tok.get_bool());

   692    } while (0);

   693    //if (hedging) fout << "\n\tONLY NEGATIVE CORRELATION";

   694    //if (linealCorrelatedOnly) fout << "\n\tPortfolio has extrictly lineal dependent & Correlated assets ";   

   695    //mostrar el circ previous and previous to previus of discarded

   696    if (nTicksLineal > cols)  nTicksLineal = cols - 1;

   697    //minDB = minPortfolio;

   698    bool abortPortfolio(0);

   699    bool testPCapacity(false);

   700    if (testPCapacity) { fout << "\tTest PC Suitability for handling size : "; rrows = 1500; }

   701    // 8Gb RAM  pueden con rows = 1500      

   702    //if (minPortfolio > minDB) minPortfolio = minDB - 3;     

   703    unsigned int grandTotal = geNSTOCKS;

   704    if (justCounter) rrows = 50;

   705    unsigned short  colss(0), tempCheckCounter(0), nCol(0), firstRow(0), lastRow(0), firstCol(0), lastCol(0), maxF

   706    bool firsTime(0), check(0), displayDB(1), found(0), oonlyOnce(0);

   707    unsigned short ccols(0);// = rrows + 1;  /// ahora si  estaba (2 *cols) + 1

   708    double delta(0), returnPortfolio(0), currentValueOfPortfolio(0), initialInvestment(0), retPortfolio(0), dprevi

   709    ////

   710    double min2(1e10);

   711    unsigned short kmin, previous_dbSize(0);

   712    bool doneSelect(0);

   713    double maxAllowed(0);

   714    unsigned short counterINdenoised(0), imin;

   715    unsigned long int sumUpFreqCounter(0), previous_sumUpFreqCounter(0);

   716    unsigned short counterIN(0);

   717 

   718    double bigRHO[100], prevbigRHO[100];

   719 

   720    CELLPTR cell_ptrmin(nullptr);

   721    NODEPTR node_ptr(nullptr);

   722 

   723    string time_series_data, ffile, twoStocks, tempSt;

   724    fstream fts;

   725    //

   726    const enum pages_nt { pp_lastIN, ppnt_time, ppnt_data, ppnt_medium };  // es necesario el elemento zero el ppn

   727    unsigned short* ary_ntPage = new unsigned short[ppnt_medium];

   728    //ary_ntPage = { pp_lastIN , ppnt_time, ppnt_data, ppnt_medium};

   729    // 

   730    

   731    //

   732    enum FLOAT  { ppAux, ppU, ppX, ppReturn, ppDB, ppTilda, ppCovMatrix, ppCorrBU, ppCorr, ppDataIn, ppTime, ppRTi

   733    enum BOOL   { pp_bscorr, pp_bool };/// dos paginas????

   734    enum USHORT { temp_us, pp_key_index, pp_us };

   735    enum STRING { pp_string };

   736    enum CHAR   { pp_char };

   737    //

   738 

   739    /*   PAGE DESCRIPTION

   740    fout << "\n\tPAGE ID & Function";

   741    fout << "\n\t" << setw(15) << "ppU: "      << setw(2) << ppU << "\tMean / Portfolio Final Value - Return Mean col 

   742    fout << "\n\t" << setw(15) << "ppX: "      << setw(2) << ppX << "   ";

   743    fout << "\n\t" << setw(15) << "ppReturn: "   << setw(2) << ppReturn << "\t (Vf-Vo)/Vo   ";

   744    fout << "\n\t" << setw(15) << "ppDB: "      << setw(2) << ppDB << "\tre-arranged data on time -talvez se podria ev

   745    fout << "\n\t" << setw(15) << "ppTilda: "   << setw(2) << ppTilda << "\t..   ";

   746    fout << "\n\t" << setw(15) << "ppCovMatrix: "<< setw(2) << ppCovMatrix << "\t..   ";

   747    fout << "\n\t" << setw(15) << "ppCorrBU: "   << setw(2) << ppCorrBU << "\t ..  ";

   748    fout << "\n\t" << setw(15) << "ppCorr: "   << setw(2) << ppCorr << "\t  ,.. ";

   749    fout << "\n\t" << setw(15) << "ppDataIn: "   << setw(2) << ppDataIn << " Main Storage for input data / Portfolio

   750    fout << "\n\t" << setw(15) << "ppTime: "   << setw(2) << ppTime << "\tTime Stamped in";

   751    fout << "\n\t" << setw(15) << "ppRTime: "   << setw(2) << ppRTime << "\tMean Time related to wall time, backup o

   752    fout << "\n\t" << setw(15) << "ppDB3: "      << setw(2) << ppDB3 << "\tSmoothed data to feed RHO  ";

   753    fout << "\n\t" << setw(15) << "matC2: "      << setw(2) << matC2 << "\t..   ";

   754    fout << "\n\t" << setw(15) << "ppRhist: "   << setw(2) << ppRhist << "\t..   ";

   755    fout << "\n\t" << setw(15) << "ppRcount: "   << setw(2) << ppRcount << "\t..   ";

   756    fout << "\n\t" << setw(15) << "ppSumR: "   << setw(2) << ppSumR << "\t..   ";

   757    fout << "\n\t" << setw(15) << "pp_float: "   << setw(2) << pp_float << "\t..   " ;

   758    fout << "\n\t-------files-----------------" << endl;

   759    fout << "\n\tfdb   " << setw(15) << dbFile        << " all the stock names" ;

   760    fout << "\n\tf1db  " << setw(15) << firstInDbFile << " ...";

   761    fout << "\n\tfstat " << setw(15) << dbStat << " ...";

   762    fout << "\n\tc:......n\\\\out_" + id_job + ".txt  crash file\n";

   763    ////*/

   764 

   765    fout << "\n\tpp_lastIN  " << pp_lastIN << "\tppnt_time  " << ppnt_time << "\tppnt_data  " << ppnt_data;

   766 

   767    if (rrows + 1 < (2 * cols) + 1) {

   768       fout << "\t ... -> prev 1, last 0\n";

   769       ccols = (2 * cols) + 1;  //se corrige el numero de cols y se hace matriz cuadrada

   770    }

   771    else ccols = rrows + 1;

   772 

   773    if (rrows + 1 < (2 * cols) + 1) {

   774       fout << "\t ... -> prev 1, last 0\n";

   775       rrows = (2 * cols) + 1;  //se corrige el numero de cols y se hace matriz cuadrada

   776    }

   777    //else  = rrows + 1;

   778    out("", "stockCounterDB: ", stockCounterDB, " mu: ", mu, "    Limit Trading / Savings: ", limitSavings, " Fact

   779    out("h2", "******************");

   780 

   781    short int rndRow(0);

   782    if (justCounter)  rrows -= 3;

   783 

   784    NETPTR net(nullptr);//

   785    NODEPTR previous_nt_Datum(nullptr), previous_nt_PreDatum(nullptr);

   786    CELLPTR previousDatum(nullptr), previousPreDatum(nullptr), ptr(nullptr), auxPtr(nullptr), ptrDB(nullptr), ptr2

   787    ROWPTR stockPtr(nullptr), auxRowPtr(nullptr), stPtr(nullptr), idStockPtr(nullptr);

   788    //test PC capacity

   789    fout << XSNfrom;

//ExSan Library

   790    net = net->exsan(rrows, ccols, pp_float, pp_bool, pp_us, pp_string, pp_char);   

   791    //cout << "\t ... ->   XSNET READY!!!\n";

   792    //fstat << "\n" << topic_id_job << setw(4) << cols << setw(3) <<  nTicksLineal;

   793    //statVector.back() << cols   

   794    statVector[0] = cols; // statVector.push_back(cols);

   795    statVector[1] = nTicksLineal; //statVector.at(1) = nTicksLineal;//statVector[1] = nTicksLineal;       //   sta

   796    if (testPCapacity) { net->kill_exsan(net);  f1db.close(); return; }

   797    //Mem Usage

   798    //net->thisNetRAM(net, pp_float, pp_bool, pp_us, pp_string, pp_char);

   799    ROWRECORDPTR rr_ptr(net->get_main_row_record());

   800    ROWPTR rootStocks;

   801    ROWPTR rowPtr(nullptr);

   802    //PLATFORM FOR CUBIC SMOOTHING

   803    double xMean(0);

   804    //fout << "\t ... ->   aqui\n";

   805    net->set_work_sheet(net, ppRcount, cols, 2 * cols - 1);

   806    //fout << "\t ... ->   aca!!!\n";

   807 

   808    ptr = net->point_to(net, ppRcount, 1, 1, 'f');

   809    for (unsigned short col = 1; col <= cols; col++) {

   810       //xMean += col;

   811       ptr->set_data(ppRcount, 1);

   812       ptr = ptr->get_se_ptr();

   813    }

   814    //if (cols < 10) {   fout << "\N\tPage ppRcount-> " << ppRcount;    net->show_page(net, ppRcount, 'f', 0, 3, 8, 5)

   815    ///double aryInitial[5] = { xMean, 1, 2, 3, 4 };   

   816    //net->set_work_sheet(net, ppAux2, cols, 2 * cols - 1);

   817    ptr = net->point_to(net, ppRcount, 1, cols + 1, 'f');

   818    for (unsigned short col = cols + 1; col <= 2 * cols - 1; col++) {

   819       ptr->set_data(ppRcount, -sqrt(mmu));

   820       ptr->get_s_ptr()->set_data(ppRcount, sqrt(mmu));

   821       ptr = ptr->get_se_ptr();

   822    }

   823    //if (cols <= 10)  net->show_page(net, ppRcount, 'f', 0, 3, 8, 5);

   824 

   825    //relative correlation on ppDB backward

   826    bool* aryColsRelativeVol = new bool[net->get_net_cols() + 1];

   827    for (k = net->get_net_cols(); k >= 1; k--){

   828       if(k >=  net->get_rows_in_page(ppDB, 'f')- net->get_cols_in_page(ppDB, 'f')) aryColsRelativeVol[k] = 1;

   829       else aryColsRelativeVol[k] = 0;

   830    }

   831 

   832    bool* aryRows2 = new bool[net->get_rows_in_page(ppRcount, 'f') + 1];

   833    bool* aryCols2 = new bool[net->get_cols_in_page(ppRcount, 'f') + 1];

   834    for (k = 1; k <= net->get_rows_in_page(ppRcount, 'f'); k++)    aryRows2[k] = 1;

   835    for (k = 1; k <= net->get_cols_in_page(ppRcount, 'f'); k++)    aryCols2[k] = 1;

   836    for (k = 0; k < 100; k++) prevbigRHO[k] = bigRHO[k] = 0;

   837    if (cols <= 10) {

   838       //fout << "Generate A_transpose * A";

   839       //print("MULTIPLY XXt");

   840       //net->show_page(net, ppAux2, 'f', 0, 3, 8, 5);

   841       //fout << "rows    ";  for (k = 1; k <= net->get_rows_in_page(ppAux2, 'f'); k++)    fout << aryRows2[k];

   842       //fout << "\ncols  ";  for (k = 1; k <= net->get_cols_in_page(ppAux2, 'f'); k++)    fout << aryCols2[k];

   843    }

   844    ///*   

   845    net->set_work_sheet(net, ppRhist, net->get_rows_in_page(ppRcount, 'f'), net->get_rows_in_page(ppRcount, 'f'));

   846    net->sparce_mat_multXXt(net, ppRhist, ppRcount, aryRows2, aryCols2);

   847    //if (cols <= 10)  net->show_page(net, ppRhist, 'f', 0, 3, 8, 5);   

   848    net->solverSysEq(net, ppRhist, 0); // tempF2 no puede ser la pp0

   849    //if (cols < 8){ fout << "Get Inverse"; net->show_page(net, tempF2, 'f', 0, 3, 8, 5);}      

   850    net->matrix_multiply(net, matC2, ppRhist, ppRcount);

   851    //if (cols <= 10) { fout << "* X   pp matC2" << matC2; net->show_page(net, matC2, 'f', 0, 3, 10, 5); }

   852    // se  termina de construir  la plataforma para cubic  smoothing  matC2!!!

   853    // BLANQUEA ESTA MATRIZ PARA USAR EN RHO HISTORICO ACUMULADO

   854    //net->matrixDivValue(net, ppCorr, ppCorr, double(nTicksLineal - 1), aryDBin, aryDBin);

   855    //void Net::matrixMultValue(Net* net, unsigned short pageT, unsigned short pageA, double val, bool * ary_rows,

   856    net->matrixMultValue(net, ppRcount, ppRcount, 0, nullptr, nullptr);

   857    net->set_work_sheet(net, ppRcount, rrows, ccols);  //creo no hace falta

   858    net->matrixMultValue(net, ppRhist, ppRhist, 0, nullptr, nullptr);

   859    net->set_work_sheet(net, ppRhist, rrows, ccols);  //creo no hace falta

   860 //*/

   861 

   862 ///* inicializa el puntero donde empieza la captura de data

   863    unsigned short rows(rrows - 1);

   864    net->set_work_sheet(net, ppDataIn, rows, cols);

   865    //------------mesh-----------   

   866    stockPtr = net->goto_row(net, ppDataIn, 1, 'u');

   867    for (unsigned short thisRow = 1; thisRow <= net->get_rows_in_page(ppDataIn, 'f'); thisRow++) {

   868       ptr = stockPtr->get_forward_ptr();

   869       //fout << "\n\n\trptr row: " << rptr->get_n_row() << "\t(" << ptr->get_row() << ", " << ptr->get_col() << ")"

   870       for (unsigned short thisCol = 1; thisCol <= net->get_cols_in_page(ppDataIn, 'f'); thisCol++) {

   871          NODEPTR root_nt(nullptr), ptr_new_node(nullptr);

   872          for (unsigned short i = 1; i <= ntNodes; i++) {

   873             ptr_new_node = ptr_new_node->create_Node();            

   874             ptr_new_node->set_key_nt(i);  // every node has a sequential key 

   875             //fout << "\n\t(" << row << ", " << col << ") ntNode i: " << i << " key: " << ptr_new_node->get_key_nt();      

   876             //ptr_nueva_celda->Tree_Insert_nt(root_nt, ptr_new_node); to test binary tree      

   877             ptr->RB_Insert_data_nt(ptr, root_nt, ptr_new_node);  // the rb_tree

   878             ptr->set_ntHead(root_nt);

   879             //out("", "alpha//inOrder"); hout << "<\p>";       ptr->Tree_Inorder_nt(ptr, root_nt, 1);      

   880             //out("", "PreOrder"); hout << "<\p>";        ptr_nueva_celda->Tree_PreOrder_nt(ptr_nueva_celda, root_nt);

   881             //delete  ptr_new_node; // esta instruccion NO! no va

   882          }         

   883          ptr = ptr->get_next_ptr();

   884       }

   885       stockPtr = stockPtr->get_down_ptr();

   886    }

   887    //------------mesh-----------

   888 

   889 

   890    stockPtr = net->goto_row(net, ppDataIn, 1, 'f');

   891    //fout << "\n\tThis Row holds the dbTReeDATa " << stockPtr->get_n_row();

   892 //  este arbol va a almacenar la correlacion relativa entre stocks  

   893    ROWPTR rootRowHolDB;

   894    rootRowHolDB = stockPtr = net->goto_row(net, ppDataIn, 1, 'f');

   895    CELLRECORDPTR crptr(stockPtr->get_cell_record_ptr());

   896    CELLPTR db_root(stockPtr->get_cell_root_db_data());  /// esta es la cabeza de dbTree

   897    CELLPTR ptrData(nullptr), ptr1(nullptr);

   898    fout << "\n\tTotal Number of assets allocated:  " << net->get_rows_in_page(ppDataIn, 'f') << endl;

   899    //db_root = net->goto_row(net, ppDataIn, 1, 'f')->get_cell_root_db_data();

   900 //   

   901    rootStocks = stockPtr->get_db_root_ptr();

   902    for (i = 1; i <= net->get_rows_in_page(ppDataIn, 'f'); i++) {

   903       stockPtr->tickInPoinTo(stockPtr->get_forward_ptr());

   904       stockPtr = stockPtr->get_down_ptr();

   905    }

   906 

   907    net->set_work_sheet(net, ppTime, rows, cols);

   908    net->set_work_sheet(net, ppDB, rows, cols);

   909    net->set_work_sheet(net, ppU, rows, 1);

   910    net->set_work_sheet(net, ppRTime, rows, 1);

   911 

   912    bool* aryCols = new bool[net->get_net_cols() + 1];

   913    bool* aryStocksCorr = new bool[rows + 1];

   914    bool* aryStockAux = new bool[net->get_rows_in_page(ppDataIn, 'f')];

   915    bool* aryStock = new bool[net->get_rows_in_page(ppDataIn, 'f')];

   916    for (i = 1; i <= net->get_rows_in_page(ppDataIn, 'f'); i++) { aryStockAux[i] = aryStock[i] = 0; }

   917 

   918    bool* aryPortfolio = new bool[30];//  new bool[minPortfolio + 1];      

   919    bool* aryDBinEq = new bool[net->get_net_rows()];

   920    bool* aryDBin = new bool[net->get_rows_in_page(ppDataIn, 'f')];

   921    bool* aryDBinTemp = new bool[net->get_rows_in_page(ppDataIn, 'f')];

   922    bool* aryDB = new bool[net->get_rows_in_page(ppDataIn, 'f')];

   923    bool* previousDB = new bool[net->get_rows_in_page(ppDataIn, 'f')];

   924    for (i = 1; i <= net->get_rows_in_page(ppDataIn, 'f'); i++) previousDB[i] = 0;

   925 

   926    normal_distribution rndNormStock0(double(rrows / 2), 1.);  // como concentra de donde escoge la data}

   927    normal_distribution rndNormStock1(.25 * (double)rrows, 2);  // como concentra de donde escoge la data}

   928    normal_distribution rndNormStock2(.50 * (double)rrows, .2035);  // como concentra de donde escoge la d

   929    normal_distribution rndNormStock3(.75 * (double)rrows, 2);  // como concentra de donde escoge la data}

   930                                  //(mean, stdev)    concentro en la parte inferior   

   931    //fout << "  activity around these rows: " <<  unsigned short( .25 * rrows)  << " " << unsigned short(.50 * rr

   932    //fout << "  activity around these rows: " <<  0 << " and "<< stockCounterDB - 1;

   933    uniform_int_distribution rndIntUniDist_0CntrDB(0, stockCounterDB - 1);

   934 

   935    boost::random::uniform_int_distribution<> dist0tostockCounterDB{ 0, stockCounterDB };

   936    uniform_int_distribution rndIntUniDist_0CntrDBcentral(stockCounterDB * .25, .75 * stockCounterDB); // me 

   937    uniform_int_distribution rndIntUniDist_1CntrDBcentral(stockCounterDB * .50, .75 * stockCounterDB);

   938    boost::random::uniform_int_distribution rndIntUniDist_2CntrDBcentral(stockCounterDB * .48, .52 * stockCou

   939 

   940    typedef boost::mt19937 RNGType;

   941    RNGType rng(time(0));

   942    double meaND(.50 * (double)rrows), sigmaND(1.0);

   943    boost::normal_distribution randNormalInt(meaND, sigmaND);

   944    //boost::variate_generator< RNGType, boost::normal_distribution >  randStock(rng, randNormalInt);

   945    //int ndd = randStock();

   946    //randStock.operator();

   947    //randStock.engine

   948    //std::time_t now = std::time(0);

   949    //boost::random::mt19937 gen{ static_cast(now) };

   950    //boost::random::bernoulli_distribution<> distB;

   951    //fout << "*******bernoulli_distribution************    "  << distB(rng) << '\n';   

   952    //int n = randStock(rng, randNormalInt);

   953    //uniform_int_distribution rndIntUniDist_1CntrDBcentral(stockCounterDB*.75, .75*stockCounterDB);

   954    //open the available DB, shift randomly pointers

   955    unsigned short shftSTock(0);

   956    for (i = 0; i < j; i++) {

   957       fileID[i] = core + stockID[i] + ".txt";

   958       //fout << "\n\tstockID[" << i << "]\t" << stockID[i] << "   " << fileID[i] << endl;

   959       fDB[i].open(fileID[i], ios::in);

   960       if (!fDB[i]) {

   961          printf("Error!");

   962          fout.flush() << "\n\t:911: This file does not exist " << fileID[i] << "  exit forced\n";

   963          exit(1);

   964       }

   965       shftSTock = dist0tostockCounterDB(generator);      //much better randomness

   966       //fout << "\n\tstockID[" << right << setw(3) << i << "]\t" << stockID[i] << "   " << fileID[i] << "  shift: "

   967       //fout << "\n\t:770: stockID[" << right << setw(3) << i << "]" << setw(7) << right << stockID[i] << " ---> " 

   968       while (shftSTock--) fDB[i] >> datum;   /// shift in this file i   

   969    }

   970    timesLaspse = dist0tostockCounterDB(generator) / minDB;

   971    if (!timesLaspse) timesLaspse = 1;

   972 

   973    stockPtr = net->goto_row(net, ppDataIn, 1, 'f');

   974    rootStocks = stockPtr->get_db_root_ptr();

   975    //fout << "\n\tThe default format is \" %ws wall, %us user + %ss system = %ts CPU(%p%)";

   976    cpu_timer timer;

   977    cpu_times times;

   978    long int  prevTimes(0);

   979    //fout << "\n\tLet's Go ---> "  << " timer.format()---> " << timer.format();

   980 

   981    //TO CHECK A PARTICULAR STOCK //stockID[s] = "GNTX";

   982    //s = 0;   fout << "\n\tTest this stock---> " << setw(8) << left << stockID[s];

   983    //string choosenStockID = "XLFN";     //fout << "\n\tTest this stock---> " << choosenStockID;  //GE

   984 

   985    bool firsTimeThischoosenStockID = true;  //true  to show / false not show

   986    bool onlyOnceSone = true;

   987    unsigned short choosenStock = 0;

   988    unsigned short choosenStockInRow = 0;

   989    unsigned short pin(3);   /// donde inicia 

   990    

   991    minDB = 2;  //comentar, forzar aqui este parametro XSN

   992    

   993    fprmtr.flush() << "\n"

   994       << cols << "\t"

   995       << nTicksLineal << "\t"

   996       << ntNodes << "\t"

   997       << factor_correlation << "\t"

   998       << factor_linear_correlation << "\t"

   999       << slope << "\t"

   1000       //<< setw( 5) << setprecision(3) << hedgeBand

   1001       << minDB;

   1002 

   1003    //ptime pt = second_clock::universal_time();

   1004    ptime pt2 = second_clock::local_time();

   1005    string ptString = to_iso_string(pt2);

   1006    //fbs << "\n"//<< setw(15) << ptString

   1007    //stFrom = 2.0, stTo = 500;   ///comment just to print capacity of exsan at the bottom does not allow normal w

   1008    //if(!xsn){

   1009    if (1) {

   1010       out("h1", "PARAMETERS");    // SOFT FACTOR SOMOOTH DATA 

   1011       //out("", stFrom, " $tocks ",  stTo, "Investment: ", myInvestment, "  min Inv/Stock: ", minInvPerStock);

   1012       out("", "Investment: ", myInvestment, "  min Inv/Stock: ", minInvPerStock, "# Ticks -cols-: ", cols, " beta: 

   1013       out("", "HedgeBand ", lowHB, " <-- hedgeband="" nbsp=""> ", upHB, " R( ", factor_correlation, " ; ", factor_lin

   1014       out("", "Expected Return: ", expectedReturn * 10., "%  minDB: ", minDB, "  timesLapse: ", timesLaspse, "   ti

   1015       out("", "Check Trigger Counter: ", checkTrigger, " Number of times dice is thrown: ", geNSTOCKS, " EndLess: "

   1016       out("", "Run: ", run, " onlyInteger", onlyInteger, "hedge: ", hedge, " ntNodes: ", ntNodes, "limitWeightFacto

   1017       out("", "dbFile: ", dbFile );

   1018    }

   1019 

   1020    fout.flush() << "\n\t|<--------e-x-s-a-n---hft------->|";

   1021    //fstat << "\n----------------------------------------------------- " <<  setw(15) << ptString << "  " << pt.d

   1022    while (!portfolio && --geNSTOCKS) {  //portfolio control externo si 0 entra a generar portfolio 1  solo lectur

   1023       //if (backFromDangerousBlock) { backFromDangerousBlock = 0; fout.flush() << "\n\t:853: BackFromDangerousBlock

   1024       if (noEnd && geNSTOCKS == 1) {

   1025          //crear un tabla logica de  0/1  R r slope

   1026          //cada hit return pierde un diez milesimo

   1027          geNSTOCKS = 3333;

   1028          //fout << "\n\tRESET PARAMETERS every " << geNSTOCKS << " ticks";

   1029          /*

   1030          if (0.9999*factor_correlation  > .95) {

   1031             ///fout << "\n\tprevious RHO " << factor_correlation;

   1032             factor_correlation *= .9999;

   1033             //fout << "\tnew RHO " << factor_correlation;

   1034             //slope *= 0.999;

   1035             //factor_linear_correlation *= 0.999;

   1036             //expectedReturn *= 0.999;

   1037          }

   1038          */

   1039          //fout << "\n\n\tRESET Endless - RHO: " << factor_correlation << " Slope: " << slope << "\tLineal_Rho: " << 

   1040          //fout << "\n\tRHO: " << factor_correlation << "\trho: " << factor_linear_correlation << "\tslope: " << slop

   1041       }

   1042       ///*

   1043       do {

   1044 readNewDatum:

   1045          /// here the block to resest timer         

   1046          //es mucho mas balanceado  al usar las otras distribuciones consume mucho tiempo y hace imposib

   1047          s = dist0tostockCounterDB(generator);  //corre toda la micro base a la misma velocidad, no simula most activ

   1048          if (firsTimeThischoosenStockID) {

   1049             firsTimeThischoosenStockID = !firsTimeThischoosenStockID;

   1050             s0 = s;

   1051             thiStock = stockID[s0];

   1052          }

   1053 

   1054          //s = rndNormStock2(generator); // distribucion normal, centrada y stdev .2  bien punteado

   1055          //s = rndNormStock0(generator); // distribucion normal, centrada y stdev 1

   1056          /*

   1057          if(geNSTOCKS <= grandTotal*.90) { //the last 1/3rd of grandTotal concentracion

   1058             //los ticks del final rotan en esta concentración

   1059             if (geNSTOCKS <= grandTotal * .5) {

   1060                //pin = 2;

   1061                //s = rndNormStock2(generator);

   1062                s = rndIntUniDist_2CntrDBcentral(generator);

   1063                //conctrate in the midle with stdev = 1

   1064             }

   1065             else{

   1066                if (pin == 1)     s = rndNormStock1(generator);

   1067                else

   1068                   if (pin == 2) s = rndNormStock2(generator);

   1069                   else          s = rndNormStock3(generator);

   1070                pin--;

   1071                if (!pin) pin = 3;

   1072             }

   1073             //s = (unsigned short)rndIntUniDist_0CntrDB(generator);

   1074             //if (geNSTOCKS <= 55)

   1075             //fout << "\n\tpin: " << pin << "  geNSTOCKS: " << geNSTOCKS;

   1076          }

   1077          else{ // first 2/3 of geNSTOCK to populate DB

   1078             s = dist(generator);

   1079          }

   1080          */

   1081       } while (s < 0 || s >= stockCounterDB);  // asegura que s esta en el rango 

   1082       //fout.flush() << "\n\n\trandom file id s: " << s;      

   1083       /* //MOSTREMOS LA CONCENTRACION DE PRECIOS

   1084       if (nrolls && !(nrolls % 100) ) { //añadir que sea por lo menos nfiles**cols  poblada

   1085          fout << "\n\n\t" << stFrom << "  " << stTo;

   1086          fout << std::fixed; fout.precision(1);

   1087          //unsigned short mxP = 0;

   1088          //unsigned short minP = 100000;

   1089          unsigned short indexP = 0;

   1090          for (unsigned short ip = 0; ip < nintervals; ++ip) {

   1091             fout << "\n\t" << stTo*float(ip) / nintervals << "-" << stTo*float(ip + 1) / nintervals << ": " << string(p

   1092             //fout << nstars << " " << nrolls;

   1093             //countP = p[ip];

   1094             if (p[ip] * nstars / nrolls >= 10) {

   1095                indexP = ip + 1;

   1096                fout << "\tIndex captured " << indexP << "  Stars: " << p[ip] * nstars / nrolls;

   1097             }

   1098          }

   1099          if (indexP) {

   1100             nrolls = 0;

   1101             //fout << "\n\tNEW RANGE:": << stTo << "   " ;

   1102             //range stock cost selection

   1103             stPrice = (indexP) * (stTo - stFrom) /( nintervals*2.0);

   1104             //stFrom = stTo*float(indexP - 1);

   1105             stFrom  = stPrice*(1. - stDeltaPercent / 100.);

   1106             stTo    = stPrice*(1. + stDeltaPercent / 100.);

   1107             //stTo = stTo*float(indexP);

   1108             fout << "\n\t" << stFrom << "\t\t" << stTo;

   1109             stDeltaPercent *= 0.7;

   1110             ///if(starsMax*.5 > 10) starsMax *= 0.5; degenera

   1111             for (unsigned short ip = 0; ip < nintervals; ++ip) p[ip] = 0;

   1112             factor_correlation = 0.93;

   1113          }

   1114       }

   1115       ///*/

   1116       fout << std::fixed; fout.precision(2);

   1117       if (fDB[s].eof()) { //read file reached the end of it

   1118          if (firsTimeThischoosenStockID && thiStock == stockID[s]) {

   1119             fout.flush() << "\n\t\t\t\t\t:939: EOF has been reached " << fileID[s];

   1120          }

   1121          fDB[s].close(); // net->kill_exsan(net); return; }

   1122          fDB[s].open(fileID[s], ios::in); //fout << "\tre Open ";

   1123          //stockPtr->set_nTick(0);  ///no creo esta instruccion sigue la actividad

   1124          stockPtr->tickInPoinTo(stockPtr->get_forward_ptr());

   1125          fDB[s] >> datum;

   1126       }

   1127       else { //normal read of data

   1128          //fDB[s] >> datum;

   1129          //{pp_lastIN, ppnt_temp, ppnt_data, ppnt_medium };                                

   1130          //if (thiStock == stockID[s]) 

   1131          dt = val.get_float(1, fDB[s]);

   1132       }

   1133       //fout << "\n\t:960: datum read " << dt << "  stock:" << fileID[s];      

   1134       if (val.get_valid()) { //!avoid enter 

   1135          datum = dt;

   1136          //if (firsTimeThischoosenStockID && thiStock == stockID[s]) fout.flush() << "\n\n\t:966: Asset " << setw(5) 

   1137          if (is_val_in_range_t(datum, stFrom, stTo)) {

   1138             /*if (backFromDangerousBlock) {

   1139                //backFromDangerousBlock = 0; 

   1140                //fout.flush() << "\n\t:968: BackFromDangerousBlock flag set to zero/back to read ";

   1141                fout << "\n\t:970: BackFromDangerousBlock datum read " << dt << "  stock:" << fileID[s];

   1142             }*/

   1143             if (firsTimeThischoosenStockID && thiStock == stockID[s]) fout.flush() << "  OK!";

   1144             rowPtr = rr_ptr->iStockInDB(rootStocks, stockID[s]);

   1284                   ptr = ptr->get_next_ptr(); // idem to previuos

   1285                   fout.flush() << "\n\t:1034: (cols - 1) Tree data\n\t"; ptr->Tree_Inorder_nt_Traverse(ptr, ptr->get_ntHead

   1286                   //fout << "\n\t:1021: Tree time "; ptr->Tree_Inorder_nt(ptr, ptr->get_ntHead(), ppnt_time);  fout << endl

   1287                   //*/

   1288                   //++p[(unsigned long int) ((nintervals - 1)*(datum - stFrom) / (stTo - stFrom))];

   1289                   nrolls++;

   1290                   //fout << "\n\tFirst Record ever IN-> " << setw(8) << left << stockID[s];

   1291                   //fout << "-datum ---> " << "(" << ptr->get_row() << ", " << ptr->get_col() << "): " << datum ;

   1292                   //inData = 1;                                 

   1293                   //else fout << "\tDiscarded not in range <>  " << endl;            

   1294                   stockPtr = stockPtr->get_down_ptr();

   1295                   //fout.flush() << "\n\t\t:1059: END First Time Ever Asset In :975: nrolls: " << nrolls;

   1296                }

   1297             }//se cierra if (!rowPtr) {//Stock n

   1298             else {//fout.flush() << "\n\t\t:1042: BEGIN Asset is already In DB " << setw(8) << left << stockID[s] << "\

   1299                //fout.flush() << "\n\t\t:1073:\tdatum in range rowPtr->get_ptrLasTick()->get_col(): " << rowPtr->get_ptrL

   1300                /*

   1301                if (backFromDangerousBlock) {

   1302                   //backFromDangerousBlock = 0;

   1303                   fout.flush() << "\n\t\t:1130: BEGIN Asset is already In DB " << setw(8) << left << stockID[s] << "\tdatum

   1304                   fout.flush() << "\n\t:1131: BackFromDangerousBlock flag set to zero/back to read ";

   1305                   fout << "\n\t:1132: datum read " << dt << "  stock:" << fileID[s];

   1306                }

   1307                */

   1308                if (rowPtr->get_ptrLasTick()->get_col() > net->get_cols_in_page(ppDataIn, 'f')) { //end_hft();            

   1309                }

   1310                ////////////// prior error overflow check and exit, now input

   1311                ptr = rowPtr->get_ptrLasTick();  //ptr points where datum will be in                        

   1312                //previous_nt_PreDatum = previous_nt_Datum = nullptr; //?

   1313                //previousPreDatum = previousPreDatum = nullptr; //?

   1314 

   1315                if (ptr->get_ushort(pp_key_index) > 1) {//fout.flush() << "\n\t\t\t:1115: > 1 index: " << ptr->get_ushort(

   1316                   ptr->inOrderSearch_nt_ptr(ptr, ptr->get_ntHead(), ptr->get_ushort(pp_key_index), previous_nt_Datum = null

   1317                   ptr->inOrderSearch_nt_ptr(ptr, ptr->get_ntHead(), ptr->get_ushort(pp_key_index) - 1, previous_nt_PreDatum

   1318                   /*

   1319                   if(ptr->get_col() > 2){

   1320                      ptr->inOrderSearch_nt_ptr(ptr, ptr->get_ntHead(), ptr->get_ushort(pp_key_index)    , previous_nt_Datum =

   1321                      ptr->inOrderSearch_nt_ptr(ptr, ptr->get_ntHead(), ptr->get_ushort(pp_key_index) - 1, previous_nt_PreDatu

   1322                   }

   1323                   else

   1324                      if (ptr->get_col() >= 2) {

   1325                         ptr->inOrderSearch_nt_ptr(ptr, ptr->get_ntHead(), ptr->get_ushort(pp_key_index)   , previous_nt_Datum =

   1326                         ptr->inOrderSearch_nt_ptr(ptr, ptr->get_ntHead(), ptr->get_ushort(pp_key_index) - 1, previous_nt_PreDat

   1327                      }

   1328                      else {  //(ptr->get_col() == 1)

   1329                         fout << "\n\t\t\t:1150: BEGINS index > 1  "; if (ntNodes == 2)fout << "\tERROR this should not appear i

   1330                         ptr->inOrderSearch_nt_ptr(ptr, ptr->get_ntHead(), ptr->get_ushort(pp_key_index)   , previous_nt_Datum =

   1331                         ptr->inOrderSearch_nt_ptr(ptr, ptr->get_ntHead(), ptr->get_ushort(pp_key_index) - 1, previous_nt_PreDat

   1332                      }

   1333                   */

   1334                   //fout.flush() << "\n\t\t\t:1111: ends index > 1 :1104: ";

   1335                }

   1336                else {//fout.flush() << "\n\t\t:1138: 0 || 1  index: " << setprecision(0) << ptr->get_ushort(pp_key_index)

   1337                   if (ptr->get_ushort(pp_key_index) == 1) {//fout.flush() << "\n\t\t:1137: BEGINS index = 1"; if (ntNodes =

   1338                      if (ptr->get_col() >= 2) {//fout << "\t:1138: col: " << ptr->get_col(); if (ntNodes == 1)fout << "\tERRO

   1339                         ptr->inOrderSearch_nt_ptr(ptr, ptr->get_ntHead(), 1, previous_nt_Datum = nullptr);//OK                              

   1340                         previousPreDatum = ptr->get_previous_ptr();  // the last in previous tree                              

   1341                         previousPreDatum->inOrderSearch_nt_ptr(previousPreDatum, previousPreDatum->get_ntHead(), ntNodes, previ

   1342                         //fout.flush() << "\n\t\t\t:1111: col 1 ends :1127:";

   1343                      }

   1344                      else {//fout.flush() << "\t:1146: col 1";                     

   1345                         ptr->inOrderSearch_nt_ptr(ptr, ptr->get_ntHead(), 1, previous_nt_Datum = nullptr);//OK

   1346                         previousPreDatum = net->goto_col(net, ppDataIn, ptr->get_row(), net->get_cols_in_page(ppDataIn, 'f'), '

   1347                         previousPreDatum->inOrderSearch_nt_ptr(previousPreDatum, previousPreDatum->get_ntHead(), ntNodes, previ

   1348                         //fout.flush() << "\n\t\t\t:1117: col 1 ends :1133:";

   1349                      }

   1350                      //fout.flush() << "\n\t\t:1140: ENDS index = 1  :1127:";

   1351                   }

   1352                   else {//fout.flush() << "\n\t\t:1152: start a new cluster, index = 0";

   1353                      if (ntNodes != 1) {//fout.flush() << "\t:1153:  ntNodes: = " << ntNodes;

   1354                         //if (thiStock == stockID[s]){fout << "\n\t\t\t:1155: " << stockID[s] << " BEGINS index = 0 ntNOdes NOT

   1355                         /*

   1356                         if (ptr->get_col() > 2) {

   1357                            //previousDatum = net->goto_col(net, ppDataIn, rowPtr->get_n_row(), net->get_cols_in_page(ppDataIn, 'f

   1358                            previousDatum = ptr->get_previous_ptr();

   1359                            previousDatum->inOrderSearch_nt_ptr(previousDatum, previousDatum->get_ntHead(), ntNodes    , previous_

   1360                            previousDatum->inOrderSearch_nt_ptr(previousDatum, previousDatum->get_ntHead(), ntNodes - 1, previous_

   1361                            //if (!previous_nt_Datum){fout << "\n\t:1098: ***ERROR*** EMERGENCY EXIT";  rr_ptr->DiscardStockTree(r

   1362                            //fout << "\n\t:1123: Tree data  previousDatum"; previousDatum->Tree_Inorder_nt(previousDatum, previou

   1363                            //previous_nt_Datum = previousDatum->inOrderSearch_nt(previousDatum, previousDatum->get_ntHead(), ntNo

   1364                            //prev_nt_Val = previous_nt_Datum->get_nt_data(ppnt_data);       //fout << "\n\t prev_nt_Val: " << pre

   1365                            //previous_nt_PreDatum = previousDatum->inOrderSearch_nt(previousDatum, previousDatum->get_ntHead(), n

   1366                         }

   1367                         else

   1368                         */

   1369                         if (ptr->get_col() >= 2) {

   1370                            if (firsTimeThischoosenStockID && thiStock == stockID[s]) {

   1371                               fout.flush() << "\t:1184:  col: " << ptr->get_col();

   1372                            }

   1373                            previousDatum = ptr->get_previous_ptr();

   1374                            previousDatum->inOrderSearch_nt_ptr(previousDatum, previousDatum->get_ntHead(), ntNodes, previous_nt_D

   1375                            previousDatum->inOrderSearch_nt_ptr(previousDatum, previousDatum->get_ntHead(), ntNodes - 1, previous_

   1376                         }

   1377                         else {//fout.flush() << "\n\t\t\t:1179: in col 1";

   1378                            if (firsTimeThischoosenStockID && thiStock == stockID[s]) {

   1379                               fout.flush() << "\n\t\t\t:1183: BEGINS index = 0 ntNOdes != 1  col: " << ptr->get_col();

   1380                            }//(ptr->get_col() == 1)

   1381                            previousDatum = ptr->get_previous_ptr();

   1382                            previousDatum = net->goto_col(net, ppDataIn, ptr->get_row(), net->get_cols_in_page(ppDataIn, 'f'), 'f'

   1383                            previousDatum->inOrderSearch_nt_ptr(previousDatum, previousDatum->get_ntHead(), ntNodes, previous_nt_D

   1384                            previousDatum->inOrderSearch_nt_ptr(previousDatum, previousDatum->get_ntHead(), ntNodes - 1, previous_

   1385                            //fout << "\n\t:1123: Tree data  previousDatum"; previousDatum->Tree_Inorder_nt(previousDatum, previou

   1386                            //previous_nt_Datum = previousDatum->inOrderSearch_nt(previousDatum, previousDatum->get_ntHead(), ntNo

   1387                            //prev_nt_Val = previous_nt_Datum->get_nt_data(ppnt_data);       //fout << "\n\t prev_nt_Val: " << pre

   1388                            //previous_nt_PreDatum = previousDatum->inOrderSearch_nt(previousDatum, previousDatum->get_ntHead(), n

   1389                         }

   1390                      }

   1391                      else {//fout.flush() << "\n\t\t:1195: ntNodes = 1";  //if (thiStock == stockID[s]) fout.flush() << "\n\t

   1392                         if (ptr->get_col() > 2) {//fout.flush() << "  *:1196: col: " << ptr->get_col();//if (thiStock == stockI

   1393                            previousDatum = ptr->get_previous_ptr();

   1394                            previousDatum->inOrderSearch_nt_ptr(previousDatum, previousDatum->get_ntHead(), 1, previous_nt_Datum =

   1395                            previousPreDatum = previousDatum->get_previous_ptr();

   1396                            previousPreDatum->inOrderSearch_nt_ptr(previousPreDatum, previousPreDatum->get_ntHead(), 1, previous_n

   1397                         }

   1398                         else {

   1399                            if (ptr->get_col() == 2) {//fout.flush() << " *:1203: col = 2";    //if (thiStock == stockID[s])fout <

   1400                               previousDatum = ptr->get_previous_ptr();

   1401                               previousDatum->inOrderSearch_nt_ptr(previousDatum, previousDatum->get_ntHead(), 1, previous_nt_Datum 

   1402                               previousPreDatum = net->goto_col(net, ppDataIn, rowPtr->get_n_row(), net->get_cols_in_page(ppDataIn, 

   1403                               previousPreDatum->inOrderSearch_nt_ptr(previousPreDatum, previousPreDatum->get_ntHead(), 1, previous_

   1404                            }

   1405                            else {//fout.flush() << " *:1209: col = 1";//if (thiStock == stockID[s]) fout << "\n\t\t:1234: 1 BEGIN

   1406                               previousDatum = net->goto_col(net, ppDataIn, rowPtr->get_n_row(), net->get_cols_in_page(ppDataIn, 'f'

   1407                               previousDatum->inOrderSearch_nt_ptr(previousDatum, previousDatum->get_ntHead(), 1, previous_nt_Datum 

   1408                               previousPreDatum = previousDatum->get_previous_ptr();

   1409                               previousPreDatum->inOrderSearch_nt_ptr(previousPreDatum, previousPreDatum->get_ntHead(), 1, previous_

   1410                            }

   1411                         }

   1412                      }

   1413                   }

   1414                }

   1415                //***************************                        

   1416                prev_nt_PreVal = previous_nt_PreDatum->get_nt_data(ppnt_data);  //fout.flush() << "\n\t\t:1221: nt_PreVal:

   1417                prev_nt_Val = previous_nt_Datum->get_nt_data(ppnt_data);     //fout.flush() << " :1220: nt_Val: " << prev_

   1418                dprevious = ep * abs(prev_nt_Val - prev_nt_PreVal);             //fout.flush() << " :1222: dprevious: " <<

   1419 

   1420                //if(

   1421                   //firsTimeThischoosenStockID &&  

   1422                   //thiStock == stockID[s]){

   1423                   //fout.flush() << "\n\t\t:1234: " << stockID[s] << "(pre-prev, prev, datum)->(" << setprecision(2) << pre

   1424                //}                  

   1425                ///*

   1426                if (is_val_in_range_t(datum, prev_nt_Val - dprevious, prev_nt_Val + dprevious) ||

   1427                   is_val_in_range_t(datum, prev_nt_PreVal - dprevious, prev_nt_PreVal + dprevious)) {

   1428                   //fout.flush() << "\n\t:1240: " << stockID[s] << " denied datum: " << setw(15) << setprecision(6) << datu

   1429                   /*

   1430                   if (

   1431                      //firsTimeThischoosenStockID &&

   1432                      thiStock == stockID[s]) {

   1433                      fout.flush() << "\n\t:1242: " << stockID[s] << " denied datum: " << setw(15) << setprecision(6) << datum

   1434                      if (is_val_in_range_t(datum, prev_nt_Val    - dprevious, prev_nt_Val    + dprevious)) fout.flush() << "\

   1435                      if (is_val_in_range_t(datum, prev_nt_PreVal - dprevious, prev_nt_PreVal + dprevious)) fout.flush() << "\

   1436                   }

   1437                   */

   1438                   //dprevious = 0;

   1439                   //previous_nt_PreDatum = previous_nt_Datum = nullptr;

   1440                   //fout.flush() << "\n\t\t:1251: " << stockID[s] << " does not comply with imposed filter " << datum << " 

   1441                   //if(thiStock == stockID[s]) {fout << " rejected data no vol add"; }

   1442                   //fout << "\n\tVf_2: " << previousPreDatum->get_data(ppDataIn) <<  "\tVf_1: " << previousDatum->get_data(

   1443                   //fout << "\n\tCompare with 2 previous data previous ep * previuos diff = " << ep * abs(previousDatum->ge

   1444                   //previousDatum->set_data(ppTime, timer.elapsed().wall / timeZoomFactor);

   1445                   //if (!onlyOnceSone && stockID[s] == choosenStockID) f1db << "\t\t\t\t\t\t\t°°-°° update TimeStamp co

   1446                }

   1447                else {

   1448                   //*/   

   1449                      //fout.flush() << "\n\t\t:1237: in (" << ptr->get_row() << ", " << ptr->get_col() << ") index: " << setp

   1450                      //fout.flush() << "\t:1237: rowPtr->get_nTick() > 2 :  " << rowPtr->get_nTick() <<  " <-complete cluster="" nbsp="" p="">

   1451                   ptr->inOrderSearch_nt_ptr(ptr, ptr->get_ntHead(), ptr->get_ushort(pp_key_index) + 1, node_ptr = nullptr);

   1452                   /*

   1453                   if (!node_ptr) {fout << "\tnullptr";  rr_ptr->DiscardStockTree(rr_ptr, rootStocks);net->kill_exsan(net);   

   1454                   //*/

   1455                   node_ptr->set_nt_data(ppnt_data, datum);  //entra data

   1456                   node_ptr->set_nt_data(ppnt_time, (double)timer.elapsed().wall / timeZoomFactor); // timeStamp of data

   1457                   //fout.flush() << "\tafter data in nTree index: " << ptr->get_ushort(pp_key_index);

   1458                   ptr->set_ushort(pp_key_index, ptr->get_ushort(pp_key_index) + 1);

   1459                   //fout << "\n\tTree data last in record "; ptr->Tree_Inorder_nt(ptr, ptr->get_ntHead(), ppnt_data); cerr 

   1460                   //fout.flush() << "\n\t\tptr in ( " << ptr->get_row() << ", " << ptr->get_col() << ") index: " << ptr->ge

   1461                   //puede ir arriba ?               

   1462                   if (!rowPtr->get_forward_ptr()->get_bool(pp_bool)) {

   1463                      rowPtr->get_forward_ptr()->set_bool(pp_bool, 1);  // avisa que hay cambio en el reg

   1464                      //fout << "\n\t---->rowPtr->get_forward_ptr()->get_bool(pp_bool) has been set, reg updated";

   1465                      //fout << "\n\t:1175: ----> reg updated: " << rowPtr->get_n_row();

   1466                   }

   1467 

   1468                   if (ptr->get_ushort(pp_key_index) == ntNodes) {//fout.flush() << "\t:1248: index = ntNodes cluster have b

   1469                      ptr->set_ushort(pp_key_index, 0); // Node is completed 

   1470                      sum1 = sum2 = 0;

   1471                      ptr->Sum_nt_ind1_ind2(ptr, ptr->get_ntHead(), sum1 = 0, ppnt_data, sum2 = 0, ppnt_time);

   1472                      rowPtr->tickIn(ppDataIn, sum1 / (double)ntNodes);//  recien aqui avanza

   1473                      ptr->set_data(ppTime, sum2 / (double)ntNodes);

   1474                      if(xsn) ptr->set_data(ppDB, ptr->get_data(ppDataIn)); // just to show data in sin la inicializacion prev

   1475                      if (firsTimeThischoosenStockID && thiStock == stockID[s]) {

   1476                         fout.flush() << "  :11396: DONE Cluster! col: " << ptr->get_col();

   1477                         fout << "\n\t:1397: Last Tree data"; ptr->Tree_Inorder_nt(ptr, ptr->get_ntHead(), ppnt_data); //fout <<

   1478                         //fout << "\n\t:1280: Tree time     "; ptr->Tree_Inorder_nt(ptr, ptr->get_ntHead(), ppnt_time); // fout

   1479                         //fout << "\n\t:1280: ppDataIn"; net->displayMKT(net, ppDataIn, aryStock, nullptr, 0, 5, widthCol - 1, 

   1480                      }

   1481                      inData = 1;

   1482                      if (ptr->get_col() == net->get_cols_in_page(ppDataIn, 'f')) {

   1483                         //if(thiStock == stockID[s]) {fout.flush() << " complete record\n";}

   1484                         //fout << "\n\t\t\t--> reg trigering: " << rowPtr->get_n_row();

   1485                         if (!readyDB) {

   1486                            completeRec = 0; //COUNTER

   1487                            rr_ptr->rowTree_In_OrderStockCompleteRecordCounter(rr_ptr, rootStocks, cols, completeRec);

   1488                            if (completeRec > completeRecDB * stockCounterDB) {

   1489                               readyDB = 1;

   1490                               //fout << "\n\t---->check is available now DB is " << completeRecDB << "% complete  readyDB = 1";

   1491                               //fout << "\n\t:1439: readyDB = 1; ";   net->displayMKT(net, ppDataIn, aryStock, nullptr, 0, 5, width

   1492                            }

   1493                         }

   1494                         //else    check = 1;

   1495 

   1496                         //times = timer.elapsed();

   1497                         //ptr->set_data(ppTime, (double)times.wall / timeZoomFactor);

   1498                         //ptr->set_data(ppTime, timer.elapsed().wall / timeZoomFactor);

   1499                         rowPtr->tickInPoinTo(rowPtr->get_forward_ptr());

   1500                      }

   1501                   }

   1502                   //bool static thisBlockdone(0);

   1503                   static unsigned short  counterthisBlock(4);

   1504                   if (0 && xsn && !(geNSTOCKS % net->get_rows_in_page(ppDataIn, 'f')) && counterthisBlock) {                     

   1505                      {                     

   1506                      fout << "\n\t:1454: Polulating ExSan - Uploading DB     Counter: " << counterthisBlock << "  pp: " << pp

   1507                      fout.flush() << "\t" << thread_clock::now();

   1508                      //net->displayMKT(net, ppDataIn, aryStock, nullptr, 0, 2, 5, 2); //system("pause");

   1509                      net->displayMKT(net, ppDB, aryStock, nullptr, 0, 2, 5, 2); //system("pause");                              

   1510                      //fout.flush() << "\n\t

   1511                      --counterthisBlock;                        

   1512                      }                     

   1513                   }

   1514                   //rowPtr->tickIn(ppDataIn, datum);

   1515                   //enable this to see only when record has been completed

   1516                   //inData = 1;

   1517                   //fout << "\n\tIN-> " << setw(8) << left << stockID[s];

   1518                   //fout << "-datum ---> " << "(" << ptr->get_row() << ", " << ptr->get_col() << "): " << datum << " end of

   1519 //////control when to start check                     

   1520                   //*

   1521                   if(!readyDB){

   1522                      //fout << "\n";

   1523                      //these 2 instructions togheter

   1524                      completeRec = 0; //COUNTER

   1525                      rr_ptr->rowTree_In_OrderStockCompleteRecordCounter(rr_ptr, rootStocks, cols, completeRec);

   1526                      if (completeRec > completeRecDB * stockCounterDB) {

   1527                         readyDB = 1;

   1528                         fout << "\n\t:1476: ---->check is available now DB is " << completeRecDB << "% complete";

   1529                      }

   1530                   }

   1531                   else {

   1532                      checkCounter++;

   1533                      //fout << "\n\t:1471: Hit checkCounter: " << checkCounter << "/" << checkTrigger;

   1534                      if (checkCounter == checkTrigger) {                        

   1535                         check = 1;

   1536                         //fout << "\n\t:1484: set check because ready DB is set, checkCounter equal checkTrigger: " << checkCou

   1537                      }

   1538                   }

   1539                   //*/

   1540                   //////control when to start check

   1541                   //check = 1;  // at the end of a record

   1542                   //++p[(unsigned long int) ((nintervals - 1)*(datum - stFrom) / (stTo - stFrom))];

   1543                   //nrolls++;

   1544                   /*

   1545                   if (!rowPtr->get_forward_ptr()->get_bool(pp_bool)) {

   1546                      rowPtr->get_forward_ptr()->set_bool(pp_bool, 1);   // avisa que hay cambio en el reg

   1547                      fout << "\n\t---->rowPtr->get_forward_ptr()->get_bool(pp_bool) has been set";

   1548                   }

   1549                   */

   1550                   //times = timer.elapsed();

   1551                   //ptr->set_data(ppTime, (double)times.wall / timeZoomFactor);

   1552                   //ptr->set_data(ppTime, timer.elapsed().wall / timeZoomFactor);

   1553                   //rowPtr->tickInPoinTo(rowPtr->get_forward_ptr());

   1554                   //fout.flush() << "\n\t\t:1338: ENDS datum in back to read a new datum";

   1555                }// time stamp is updated

   1556                //ptr->set_data(ppTime, timer.elapsed().wall / timeZoomFactor); ???? esto elimino en fecha Mayo 20

   1557                //if (!stPtr->get_forward_ptr()->get_bool(ppRTime)) stPtr->get_forward_ptr()->set_bool(ppRTime, 1);   // a

   1558                //if(!onlyOnceSone && stockID[s] == choosenStockID) f1db << setw(15) << timer.elapsed().wall / timeZoomFac

   1559                //fout << "\n\t\t:1240: ends datum in range and into db :1140: ";

   1560                ////******************   

   1561 

   1562                //fout << "\n\tIN-> " << setw(8) << left << stockID[s] << "\tdatum: " << datum ;  //setfill('.') <<

   1563                //fout << "\n\tppDataIn"; net->displayMKT(net, ppDataIn, aryStock, nullptr, 0, 4, widthCol, 0); //system("

   1564                //fout << "\n\tppTime";   net->displayMKT(net,   ppTime, aryStock, nullptr, 0, 4, widthCol, 0);

   1565       /*

   1566                if (geNSTOCKS >= 10 && s == 0) {

   1567                   fout << "\n\tEXIT  - datum- " << datum;

   1568                   //i = rowPtr->get_n_row();

   1569                   //i = stockCounterDB / 2;

   1570                   i = 1;

   1571                   aryStockAux[i] = 1;

   1572                   fout << "\n\tppDataIn"; net->displayMKT(net, ppDataIn, aryStockAux, nullptr, 0, 10, 10);

   1573                   fout << "\n\tppTime";   net->displayMKT(net,   ppTime, aryStockAux, nullptr, 0, 10, 10, 4);

   1574                   aryStockAux[i] = 0;

   1575                   fout << "\n\t------------------END-----------------------------";

   1576                }

   1577    */            //fout << "\n\t\t:1556: ENDS StockIsInDbAlready :1251:";

   1578             }

   1579          }

   1580          //else fout << "   :1367: discarded DATUM not in range it closes :897:\n";         

   1581       }

   1582       else fout << "\n\t\t\t\t:1536: Invalid datum -not a number- Stock: "  << setw(7) << stockID[s] << " " << val.

   1583       

   1584       /*

   1585       if(inData){

   1586          //fout << "\n\tREAL DATA  ppDataIn"; net->displayMKT(net, ppDataIn, aryStock, nullptr, 0, 5, widthCol, presC

   1587          fout << "\n\t(inData)TIME STAMP ppTime";   net->displayMKT(net,   ppTime, aryStock, nullptr, 0, 5, widthCol,

   1588          inData = 0;

   1589       }

   1590       //*/

   1591       //check = false; //test input a singl stock enable next instruction          

   1592       if (1 && check) {  // 0 do not look for portfolio jump the whole program   

   1593          static unsigned short  counterthisBlock(1);

   1594          if (1 && xsn  && counterthisBlock) {      //xssn   

   1595             {   

   1596                //fout << "\n\t:1521: Polulating ExSan - Uploading DB     Counter: " << counterthisBlock << "  pp: " << pp

   1601                   //printf("Error! Couldn't Statistics File: ", balanceSheet);      

   1602                   fout.flush() << "\tCouldn't open Parameter Sheet File: " << txtFileXSN;

   1603                   exit(1);

   1604                }

   1605                do {

   1606                   getline(fxsn, line);

   1607                   fout << "\n\t" << line;

   1608                } while (!fxsn.eof());

   1609                fxsn.close();               

   1610                fout.flush() << "\n\t" << thread_clock::now();               

   1611                fout << "\n\t:1611: ExSan Frame ready for Volatily dependent selection DB  Counter: " << counterthisBlock 

   1612                --counterthisBlock;

   1613             }

   1614          }         

   1615 

   1616          nTicksLineal = nTL;  /// no entiendo la razon de esta instrucion

   1617          checkCounter = 0;

   1618          /*

   1619          fout << "\n\t:1460: CHECK---- either a wrap around or no room for new data in DB "

   1620              << "\tgeNSTOCKS: " << geNSTOCKS

   1621              << "\tnTicksLineal " << nTicksLineal << "\t:nTL " << nTL;         

   1622          fout << "\n\t:1461: As it is *A ppDataIn"; net->displayMKT(net, ppDataIn, aryStock, nullptr, 0, 5, widthCol-

   1623          /*/

   1624 

   1625          if(0){  //python block

   1626             /* Python block

   1627             

   1628             fout << "\n\t:1461:PYTHON BLOCK As it is *A ppDataIn"; net->displayMKT(net, ppDataIn, aryStock, nullptr, 0,

   1629             fout << "before calling  result: " << ++result;

   1630             //---CallPython Service Open-----

   1631             fstream ftx("tx.txt");

   1632             fstream frx("rx.txt");

   1633             Py_Initialize();

   1634             fout.close();

   1635             hout.close();

   1636             //---Call Python Service Close------

   1637 

   1638          

   1639             PyObject* objTRX = Py_BuildValue("s", "usingTxRx.py");

   1640             FILE* fileTRX = _Py_fopen_obj(objTRX, "r+");

   1641             if (fileTRX != NULL) {

   1642                cout << "\n\t--Execute script usingTxRx.py";

   1643                PyRun_SimpleFile(fileTRX, "usingTxRx.py");

   1644             }

   1645          

   1646             frx >> result;

   1647          

   1648             //--------Python Service Done - Open------------------------

   1649             //std::ofstream fout, hout;   // asume que es una variable local nueva????

   1650             fout.open(out_txt_file_name, ios::out | fstream::app); // open the output file

   1651             hout.open(out_html_file_name, ios::out | fstream::app); // open the output file                

   1652             Py_Finalize();

   1653             ftx.close();

   1654             ftx.close();

   1655             //---------Python Service Done - Close----------

   1656             cout << "\n\t\t--Back in C/C++ after Python Call result: " << result;

   1657             fout << "\n\t\t--Back in C/C++ after Python Call result: " << result;

   1658             //*/

   1659             

   1660          }

   1661 

   1662          /*

   1663          if(stockCounterDB <= 2 ) {

   1664             CELLPTR  ptr(nullptr);

   1665             fout << "\n\tTRAVERSE IN ORDER TO VERYFY INPUT\n";

   1666             //for (i = 1; i <= net->get_rows_in_page(ppDataIn, 'f'); i++) {

   1667             for (i = 1; i <= 3; i++) {  // las tres primeras filas

   1668                ptr = net->point_to(net, ppDataIn, i, 1, 'f');

   1669                for (j = 1; j <= net->get_cols_in_page(ppDataIn, 'f'); j++) {

   1670                   //fout << "\n\tindex: " << ptr->get_ushort(pp_key_index) <<  endl;

   1671                   ptr->Tree_Inorder_nt(ptr, ptr->get_ntHead(), ppnt_data);

   1672                   fout << endl;

   1673                   ptr = ptr->get_next_ptr();

   1674                }

   1675                fout << endl;

   1676             }

   1677          }

   1678          //*/

   1679          //fout << "\n\t:1480: ppTime";                                                                              

   1680          //fout << "\n\t:1481: Timer current mark---> " << setw(10) << setprecision(6) << timer.elapsed().wall / time

   1681          /*

   1682          cpu_times times = timer.elapsed();

   1683          fout << "\n\n\ttimer.format()---> " << timer.format();

   1684          fout << "\n\ttimes.wall---> " << times.wall;

   1685          //fout << "\n\ttimes.user---> " << times.user;   fout << "\n\ttimes.user " << times.system;

   1686          //*/

   1687          //fout << "\n\tRelative Timer  ppRTime";   net->displayMKT(net, ppRTime, aryStock, nullptr, 0, 3, 10, 0);

   1688          //fout << "\n\tMost active stock  #ticks:-> " << maxF; // << "  ppDataIn";   net->displayMKT(net, ppDataIn, ar

   1689          //fout << "\n\tppTime Elapsed Time Tick by Tick times.wall---> " << setw(10) << setprecision(6) << times.wal

   1690          //quizas este bloque atraves del arbol

   1691          //me parece que aqui se hace la seleccion de la data en base al conteo de actividad

   1692          //no de mas activo

   1693          //buscar los menores en la columna de set_hiTime

   1694          /// last tick in complete  Jun 22 Start

   1695          //fout << "\n\t:1700: last tick in";

   1696          /*

   1697          for (i = 1; i <= net->get_rows_in_page(ppDataIn, 'f'); i++) { //SERIA BUENO SOLO CORREGIR LOS NECESARIOS REG

   1698          //for (i = 1; i <= 10; i++) {  //only for test

   1699             rowPtr = net->goto_row(net, ppDataIn, i, 'f');

   1700             ptr = rowPtr->get_ptrLasTick();

   1701             if(ptr->get_ushort(pp_key_index) && ptr->get_ushort(pp_key_index) < ntNodes){//OK

   1702                //hay calculo repetido, habria que detectar los que no han cambiado

   1703                ptr->set_data(ppDataIn, 0); //do not erase, this is the initial val

   1704                ptr->set_data(ppTime, 0); //do not erase, this is the initial val

   1705                //fout << "\n\t:1350: Reset Tre-set-data:-> " << ptr->get_data(ppDataIn) << " - " << ptr->get_data(ppTime)

   1706                fout << "\n\tLast incomplete cluster: " << ptr->get_ushort(pp_key_index) << " row: " << i;

   1707                //fout << "\tLast Tree in\n"; ptr->Tree_Inorder_nt(ptr, ptr->get_ntHead(), ppnt_data); fout << endl; ptr->

   1708                //fout << "\t(data - time) Current( " << ptr->get_data(ppDataIn) << " - "  << ptr->get_data( ppTime) << ")

   1709                j = ptr->get_ushort(pp_key_index);  //fout << "\n\t(" << i << "," << j << ")";// j es actualizada en cada 

   1710                ptr->Tree_Inorder_nt_update_Data_Time(ptr, ptr->get_ntHead(), ppDataIn , ppTime,   j, ptr->get_ushort(pp_k

   1711                fout << "\t:1353: UPDATED (" <<  setw(2) << i << ", " <<  setw(2) << ptr->get_col() << ") " << setw(5) << 

   1712             }

   1713          }//OK

   1714          fout << "\n\t:1356: UPDATED check *A1 ppDataIn"; net->displayMKT(net, ppDataIn, aryStock, nullptr, 0, 5, wid

   1715          */

   1716          /// last tick in complete  Jun 22 End

   1717          // solo entran a la db los que ary no sea cero  ojo!!!!!         

   1718          completeDB = 0;         

   1719          times = timer.elapsed();  //!!!importante no borrar es el punto de referencia¡¡¡

   1720          //fout << "\n\tCurrent times.wall " << times.wall << "\tPrevious  " << prevTimes;                        

   1721          //fout << "\n\tTimer current mark -used-as-reference--> " << setw(15) << setprecision(6) << times.wall / tim

   1722          //!!!importante no borrar es el punto de referencia¡¡¡

   1723          maxF = 0;

   1724          stPtr = net->goto_row(net, ppDataIn, 1, 'f');

   1725          crptr->DiscarDB(crptr, db_root, 'f');

   1726          counterSt = 0;

   1727          change = false;

   1728          onlyOnce = 1; //not used yet!!!

   1729          dataCounter[2] = dataCounter[3] = dataCounter[4] = 0;

   1730          // averiguar el promedio tickInTimer  

   1731          for (i = 1; i <= net->get_rows_in_page(ppDataIn, 'f'); i++) {//OK revised Aug 27

   1732             //sobra esta instruccion

   1733             //aryDB[i] = 0; // nadie en db para portfolio este es parametro para correLinealPLus            

   1734             //if (aryStock[i] && stPtr->get_nTick() > maxF) maxF = stPtr->get_nTick(); //no entiendo que hace esta inst

   1735             // si esta proximo al ultimo Tick InTime

   1736             // vuelve a calcular el chrono time aun cuando no hay cambio???

   1737             // hay que usar una bandera para evitar este recalculo                        

   1738             //if(stPtr->get_nTick() > cols  &&  stPtr->get_forward_ptr()->get_bool(pp_bool)) {  // solo de aquellos que

   1739             if (stPtr->get_nTick() >= net->get_cols_in_page(ppDataIn, 'f') &&   // ONLY COMPLETE RECORD/FULL CLUSTER

   1740                (   stPtr->get_forward_ptr()->get_bool(pp_bool) || //those belonging to the current check

   1741                   stPtr->get_forward_ptr()->get_next_ptr()->get_bool(pp_bool)) //from previous check it TimeMaxGap

   1742                ) {  //is set when it changes

   1743 

   1744                //just stadistics

   1745                if (stPtr->get_forward_ptr()->get_bool(pp_bool)) dataCounter[2]++;  //los propios de este check

   1746                if (stPtr->get_forward_ptr()->get_next_ptr()->get_bool(pp_bool)) dataCounter[3]++;  //de la anterior corri

   1747 

   1748                ///*:regTimeSaver: maybe comment this block to keep the stocks for next round if there is not enough  Nov 

   1749                stPtr->get_forward_ptr()->set_bool(pp_bool, 0);                  // reset OUTSIDE THE LOOP, no            

   1750                stPtr->get_forward_ptr()->get_next_ptr()->set_bool(pp_bool, 0);  // reset previous in            

   1751                ///*/

   1752 

   1753                //XSN-> why it considers only those that are apdated????? a bell is ringed at the end of the record

   1754                // consider only those who changed in the round, I think it is ok

   1755                //fout << "\n\t:1481: Updated Stock: " << setw(4) << stPtr->get_n_row() << ": " << setw(6) << stPtr->get_s

   1756                //////////////////////////   from uppper block                              

   1757                ptr = stPtr->get_ptrLasTick();

   1758                if (ptr->get_ushort(pp_key_index) && ptr->get_ushort(pp_key_index) < ntNodes) {//OK               

   1759                   ptr->set_data(ppDataIn, 0); //do not erase, this is the initial val

   1760                   ptr->set_data(ppTime, 0); //do not erase, this is the initial val

   1761                   //fout << "\n\t:1350: Reset Tre-set-data:-> " << ptr->get_data(ppDataIn) << " - " << ptr->get_data(ppTime

   1762                   //fout << "\n\t:1384: Last incomplete cluster: " << ptr->get_ushort(pp_key_index) << " row: " << i;

   1763                   //fout << "\tLast Tree in\n"; ptr->Tree_Inorder_nt(ptr, ptr->get_ntHead(), ppnt_data); fout << endl; ptr-

   1764                   //fout << "\t(data - time) Current( " << ptr->get_data(ppDataIn) << " - "  << ptr->get_data( ppTime) << "

   1765                   j = ptr->get_ushort(pp_key_index);  //fout << "\n\t(" << i << "," << j << ")";// j es actualizada en cada

   1766                   ptr->Tree_Inorder_nt_update_Data_Time(ptr, ptr->get_ntHead(), ppDataIn, ppTime, j, ptr->get_ushort(pp_key

   1767                   //fout << "\t:1719: UPDATED (" << setw(2) << i << ", " << setw(2) << ptr->get_col() << ") " << setw(5) <<

   1768                }

   1769                //////////////////////////               

   1770                

   1771                //*----------------------------------

   1772                // cluster traversal 

   1773                if (0) {  //para garantizar una poblacion necesaria

   1774                //if(geNSTOCKS <= .1* grandTotal){  //para garantizar una poblacion necesaria

   1775 

   1776                   fout << "\n\t:1574: Begin --- cluster traversal----- nStocks: " << nStocksMg;

   1777                   //unsigned short nPointers(countElementInAry(aryDBin, true, firstRow, lastRow));

   1778                

   1779                   for (i = 0; i <= nPointers - 1; i++) { 

   1780                      aryStockPtr[i] = nullptr;

   1781                      aryPtr[i]     = nullptr;

   1782                      aryStockPtr[i] = net->goto_row(net, ppDataIn, i + 1, 'f');                  

   1783                      pltM.idStockInQue(aryStockPtr[i]->get_stock_name());

   1784                      aryPtr[i] = aryStockPtr[i]->get_ptrLasTick();

   1785                   }

   1786                   //aryStockPtr[0] = net->goto_row(net, ppDataIn, 1, 'f');

   1787                   //aryStockPtr[1] = net->goto_row(net, ppDataIn, 2, 'f');

   1788                   //aryStockPtr[2] = net->goto_row(net, ppDataIn, 3, 'f');

   1789                

   1790                   //for (i = 0; i <= nPointers - 1; i++) {

   1791                      //ptr points where datum will be in

   1792                      //OK revised Feb 15

   1793                      //aryPtr[i] = aryStockPtr[i]->get_ptrLasTick();  

   1794                      //fout << "\n\t: (" << aryPtr[i]->get_row() << ", " << aryPtr[i]->get_col() << ") = " << aryPtr[i]->get_

   1795 

   1796                   //}

   1797                   fout << "\n";               

   1798                   for (j = 1; j <= net->get_cols_in_page(ppDataIn, 'f'); j++) {//OK revised Aug 27                                                

   1799                   //for (i = 1; i <= 1; i++) {//OK revised Aug 27                                 

   1800                      for (i = 0; i <= nPointers - 1; i++) {//OK revised Aug 27                                 

   1801                      //for (std::size_t i = 0; i < nPointers; ++i)

   1802                         fout << "\t: ("  << aryPtr[i]->get_row() << ", "  << aryPtr[i]->get_col() << ")-> " << aryPtr[i]->get_d

   1803                         //doNodeClustering

   1804                         aryPtr[i]->Tree_nt_CandleParameters(aryPtr[i], aryPtr[i]->get_ntHead(), ppnt_data, pp_openVal, pp_lowVa

   1805 

   1806                         aryPtr[i] = aryPtr[i]->get_next_ptr();

   1807                         if(aryPtr[i]->get_col() > net->get_cols_in_page(ppDataIn, 'f')) aryPtr[i] = aryStockPtr[i]->get_forward

   1808                      }      

   1809                      fout << "\n";

   1810                   }               

   1811                 

   1812                   fout << "\n\tData RANGE <" << superMin << " - " << superMax << ">";

   1813                   net->set_work_sheet(net, pp_openVal, net->get_rows_in_page(ppDataIn, 'f'), net->get_cols_in_page(ppDataIn

   1814                   net->set_work_sheet(net, pp_lowVal, net->get_rows_in_page(ppDataIn, 'f'), net->get_cols_in_page(ppDataIn,

   1815                   net->set_work_sheet(net, pp_highVal, net->get_rows_in_page(ppDataIn, 'f'), net->get_cols_in_page(ppDataIn

   1816                   net->set_work_sheet(net, pp_closeVal, net->get_rows_in_page(ppDataIn, 'f'), net->get_cols_in_page(ppDataI

   1817                

   1818                   fout << "\n\t:1589: pp_openVal";   net->displayMKT(net, pp_openVal, aryStock, nullptr, 0, 5, widthCol - 1, 

   1819                   fout << "\n\t:1589: pp_lowVal";      net->displayMKT(net, pp_lowVal,    aryStock, nullptr, 0, 5, widthCol - 1, 

   1820                   fout << "\n\t:1589: pp_highVal";   net->displayMKT(net, pp_highVal, aryStock, nullptr, 0, 5, widthCol - 1, 

   1821                   fout << "\n\t:1589: pp_closeVal";   net->displayMKT(net, pp_closeVal,aryStock, nullptr, 0, 5, widthCol - 1,

   1822                

   1823                   unsigned short idGraph(0);

   1824 

   1825                   pltM.set_titleMg("HISTORICAL DATA - Snapshot of Market, sometime after 2000 " + idGraph);

   1826 

   1829                               

   1830                   pltM.set_path(plot_data);

   1831                   pltM.set_idPlotmG(++idPlotG);

   1832 

   1833                   unsigned short * indexNtNodeAry = new unsigned short[nStocksMg];

   1834                   fstream* fAry     = new fstream[nStocksMg];  //candle

   1835                   fstream* fAryData = new fstream[nStocksMg];  //full data

   1836 

   1837                   string* AryDataFileName = new string[nStocksMg];  //full data

   1838                   string* AryDataFileName2 = new string[nStocksMg];  //full data

   1839 

   1840                   double* minfAryData = new double[nStocksMg];  //full data

   1841                   double* maxfAryData = new double[nStocksMg];  //full data

   1842 

   1843                   double* minfAry = new double[nStocksMg];  //candle

   1844                   double* maxfAry = new double[nStocksMg];  //candel

   1845 

   1846                   for (unsigned short ff = 0; ff < nStocksMg; ff++) {

   1847                      minfAry[ff] = minfAryData[ff] = 10000000.;

   1848                      maxfAry[ff] = maxfAryData[ff] = 0;

   1849                      indexNtNodeAry[ff] = 0;                                 

   1850                      AryDataFileName[ff] = plot_data + "_cndlData_" + to_string(idPlotG) + to_string(ff) + "_" + topic_id_job

   1851                      //fAry[ff].open(plot_data + to_string(ff) + "_" + topic_id_job + ".txt", ios::out);               

   1852                      fAry[ff].open(AryDataFileName[ff], ios::out);

   1853 

   1854                      AryDataFileName2[ff] = plot_data + "_rawData_" + to_string(idPlotG) + to_string(ff) + "_" + topic_id_job

   1855                      //fAryData[ff].open(plot_data + "_rawData_" + to_string(ff) + "_" + topic_id_job + ".txt", ios::out);

   1856                      fAryData[ff].open(AryDataFileName2[ff], ios::out);

   1857                   }

   1858 

   1859                   for (i = 0; i <= nPointers - 1; i++) {                  

   1860                      aryPtr[i] = aryStockPtr[i]->get_ptrLasTick();

   1861                      //fout << "\n\t: (" << aryPtr[i]->get_row() << ", " << aryPtr[i]->get_col() << ") = " << aryPtr[i]->get_

   1862                   }

   1863                   fout << "\n";

   1864                

   1865                   //const enum pages_nt { pp_lastIN, ppnt_time, ppnt_data, ppnt_medium };  // es necesario el elemento zero

   1866                   //unsigned short* ary_ntPage = new unsigned short[ppnt_medium];

   1867                

   1868                   for (j = 1; j <= net->get_cols_in_page(ppDataIn, 'f'); j++) {//OK revised Aug 27                                                               

   1869                      for (i = 0; i <= nPointers - 1; i++) {//OK revised Aug 27                     

   1870                            //fout << "\t: (" << aryPtr[i]->get_row() << ", " << aryPtr[i]->get_col() << ")-> " << aryPtr[i]->ge

   1871                            switch (aryPtr[i]->get_row()) {

   1872                               case 1:  //fAry[0] << "\t: (" << aryPtr[i]->get_row() << ", " << aryPtr[i]->get_col() << ")-> " << 

   1873                                  if (j == 1)   fAry[0] <<  ntNodes / 2 ;    else fAry[0] << ntNodes / 2 + j * ntNodes;

   1874                                  fAry[0] << "\t" << aryPtr[i]->get_data(pp_openVal) << "\t" << aryPtr[i]->get_data(pp_lowVal) << "\

   1875 

   1876                                  if (aryPtr[i]->get_data(pp_lowVal) < minfAry[0])       minfAry[0] = aryPtr[i]->get_data(pp_lowVal)

   1877                                  else if (maxfAry[0] < aryPtr[i]->get_data(pp_highVal)) maxfAry[0] = aryPtr[i]->get_data(pp_highVal

   1878 

   1879                                  break;

   1880 

   1881                               case 2:  //fAry[1] << "\t: (" << aryPtr[i]->get_row() << ", " << aryPtr[i]->get_col() << ")-> " << ar

   1882                                  if (j == 1)   fAry[1] << ntNodes / 2;    else fAry[1] << ntNodes / 2 + (j-1) * ntNodes;

   1883                                  fAry[1] << "\t" << aryPtr[i]->get_data(pp_openVal) << "\t" << aryPtr[i]->get_data(pp_lowVal) << "\

   1884 

   1885                                  if (aryPtr[i]->get_data(pp_lowVal) < minfAry[1])       minfAry[1] = aryPtr[i]->get_data(pp_lowVal)

   1886                                  else if (maxfAry[1] < aryPtr[i]->get_data(pp_highVal)) maxfAry[1] = aryPtr[i]->get_data(pp_highVal

   1887 

   1888                                  break;

   1889 

   1890 

   1891                               case 3:  //fAry[2] << "\t: (" << aryPtr[i]->get_row() << ", " << aryPtr[i]->get_col() << ")-> " << 

   1892                                  if (j == 1)   fAry[2] << ntNodes / 2;    else fAry[2] << ntNodes / 2 + (j-1) * ntNodes;

   1893                                  fAry[2] << "\t" << aryPtr[i]->get_data(pp_openVal) << "\t" << aryPtr[i]->get_data(pp_lowVal) << "\

   1894 

   1895                                  if (aryPtr[i]->get_data(pp_lowVal) < minfAry[2])       minfAry[2] = aryPtr[i]->get_data(pp_lowVal)

   1896                                  else if (maxfAry[1] < aryPtr[2]->get_data(pp_highVal)) maxfAry[2] = aryPtr[i]->get_data(pp_highVal

   1897 

   1898                                  break;

   1899 

   1900                               case 4:  //fAry[2] << "\t: (" << aryPtr[i]->get_row() << ", " << aryPtr[i]->get_col() << ")-> " << 

   1901                                  if (j == 1)   fAry[2] << ntNodes / 2;    else fAry[3] << ntNodes / 2 + (j - 1) * ntNodes;

   1902                                  fAry[3] << "\t" << aryPtr[i]->get_data(pp_openVal) << "\t" << aryPtr[i]->get_data(pp_lowVal) << "\

   1903 

   1904                                  if (aryPtr[i]->get_data(pp_lowVal) < minfAry[2])       minfAry[2] = aryPtr[i]->get_data(pp_lowVal)

   1905                                  else if (maxfAry[1] < aryPtr[2]->get_data(pp_highVal)) maxfAry[2] = aryPtr[i]->get_data(pp_highVal

   1906                                  break;

   1907 

   1908                               case 5:  //fAry[2] << "\t: (" << aryPtr[i]->get_row() << ", " << aryPtr[i]->get_col() << ")-> " << 

   1909                                  if (j == 1)   fAry[4] << ntNodes / 2;    else fAry[4] << ntNodes / 2 + j * ntNodes;

   1910                                  fAry[4] << "\t" << aryPtr[i]->get_data(pp_openVal) << "\t" << aryPtr[i]->get_data(pp_lowVal) << "\

   1911 

   1912                                  if (aryPtr[i]->get_data(pp_lowVal) < minfAry[2])       minfAry[2] = aryPtr[i]->get_data(pp_lowVal)

   1913                                  else if (maxfAry[1] < aryPtr[2]->get_data(pp_highVal)) maxfAry[2] = aryPtr[i]->get_data(pp_highVal

   1914                                  break;

   1915                            }

   1916 

   1917                            switch (aryPtr[i]->get_row()) {

   1918                               case 1: 

   1919                                  aryPtr[i]->Tree_Inorder_nt_toFile(aryPtr[i], aryPtr[i]->get_ntHead(), ppnt_data, indexNtNodeAry[0]

   1920                                  break;

   1921                               case 2:                               

   1922                                  aryPtr[i]->Tree_Inorder_nt_toFile(aryPtr[i], aryPtr[i]->get_ntHead(), ppnt_data, indexNtNodeAry[1]

   1923                                  break;

   1924 

   1925                               case 3:                                

   1926                                  aryPtr[i]->Tree_Inorder_nt_toFile(aryPtr[i], aryPtr[i]->get_ntHead(),  ppnt_data, indexNtNodeAry[2

   1927                                  break;

   1928 

   1929                               case 4:

   1930                                  aryPtr[i]->Tree_Inorder_nt_toFile(aryPtr[i], aryPtr[i]->get_ntHead(), ppnt_data, indexNtNodeAry[3]

   1931                                  break;

   1932 

   1933                               case 5:

   1934                                  aryPtr[i]->Tree_Inorder_nt_toFile(aryPtr[i], aryPtr[i]->get_ntHead(), ppnt_data, indexNtNodeAry[4]

   1935                                  break;

   1936                            }                        

   1937 

   1938                         aryPtr[i] = aryPtr[i]->get_next_ptr();

   1939                         if (aryPtr[i]->get_col() > net->get_cols_in_page(ppDataIn, 'f')) aryPtr[i] = aryStockPtr[i]->get_forwar

   1940                      }

   1941                      //fout << "\n";

   1942                      //fAry[aryPtr[i]->get_row()] << "\n";

   1943                   }

   1944 

   1945                   double supermax(0), supermin(50000);

   1946                   for (unsigned short ff = 0; ff < nStocksMg; ff++) {

   1947                      fout << "\n\t: file  " << ff << "\tmin1:  " << minfAryData[ff] << "\tmax1:  " << maxfAryData[ff];

   1948                      fout << "\n\t: file  " << ff << "\tmin2:  " << minfAry[ff] << "\tmax2:  " << maxfAry[ff];

   1949                      if (minfAry[ff] < supermin) supermin = minfAry[ff];

   1950                      if (maxfAry[ff] > supermax) supermax = maxfAry[ff];

   1951 

   1952                       fAry[ff].close();

   1953                      fAryData[ff].close();

   1954                      pltM.dataFilesInQue(AryDataFileName2[ff]);

   1955                      pltM.dataFilesInQueCndl(AryDataFileName[ff]);

   1956                   }

   1957                               

   1958                   pltM.set_xrangeMg(1, net->get_cols_in_page(ppDataIn, 'f') * ntNodes);

   1959                   //pltM.set_yrangeMg(stFrom, stTo);

   1960                   pltM.set_yrangeMg(supermin, supermax);

   1961                            

   1962                   //pltM.extract_mulGraph();

   1963                   //pltM.resetMG();  //  Before clear container:"; para la siguiente pasada               

   1964                   /*               

   1965                   for (i = 0; i <= nPointers - 1; i++) {

   1966                      delete aryStockPtr[i];

   1967                      delete aryPtr[i];

   1968                   }

   1969                   */               

   1970                   ///delete aryStockPtr;

   1971                   //delete aryPtr;

   1972                   fout << "\n\t:1978: End --- cluster traversal-----";

   1973                }

   1974                //*/

   1975                //-------------cluster traversal--------------------

   1976                meanTimer = 0;

   1977                //if (stPtr->whereTickIn() > cols) 

   1978                ptr = stPtr->get_forward_ptr();  //

   1979                //fout << endl;  

   1980                for (k = 1; k <= cols; k++) {//fout << " + " << ptr->get_data(ppTime);

   1981                   meanTimer += ptr->get_data(ppTime);

   1982                   ptr = ptr->get_next_ptr();

   1983                }

   1984                //fout << "\n\teach times.wall " << times.wall;

   1985                stPtr->set_hiTime(times.wall / timeZoomFactor - meanTimer / cols);

   1986                //fout << "\tmeanTimer: " << meanTimer << "/#cols: " << meanTimer / cols << "  relative elapsed time " << 

   1987                stPtr->get_forward_ptr()->set_data(ppRTime, times.wall / timeZoomFactor - meanTimer / cols);

   1988                crptr->RB_Insert_data(db_root, stPtr->get_forward_ptr(), 'f', ppRTime);

   1989                counterSt++;

   1990                if (!change) change = true;

   1991                ///*

   1992                //fout << "\n\t" << counterSt << " Insert... " << stPtr->get_forward_ptr()->get_data(ppRTime);

   1993                //fout << "\n\tInside IN ORDER timeStamp";  net->InOrderData(net, crptr, db_root, ppRTime);

   1994                ///*/  

   1995             }

   1996             //Dec 3

   1997             //stPtr->get_forward_ptr()->set_bool(pp_bool, 0);  //here copy of this environment

   1998             //dataCounter[3] = 0;

   1999             //if(stPtr->get_forward_ptr()->get_bool(pp_bool)){

   2000                //stPtr->get_forward_ptr()set_bool(pp_bool, stPtr->get_forward_ptr()->get_bool(pp_bool))

   2001                //dataCounter[3]++;

   2002             //}

   2003             //stPtr->get_forward_ptr()->set_bool(pp_bool, 0);  // reset current environment                

   2004             //fout << "\n\tAfter If - Inside IN ORDER timeStamp -one at the time- DB ppRTime"; net->InOrderData(net, cr

   2005             stPtr = stPtr->get_down_ptr();

   2006          }//ok  timeZoomFactor  1.e6  NO TOPAR ESTE BLOQUE!!! no topar!!! Sept  19         

   2007          statVector[2] = (double)dataCounter[2];   // esta corrida

   2008          statVector[3] = (double)dataCounter[3];   // anterior corrida         

   2009          statVector[4] = (double)counterSt;        //esta corrida total

   2010          //fstat << "\n\n\t:1576:";  for (int i = 0; i <= 4; i++) fstat << "\t" << setw(7) << statVector[i]; fstat <<

   2011          /*

   2012          for (int i = 0; i <= 2; i++) {

   2013             double frac(0);

   2014             modf(statVector[i], &frac);

   2015             if (frac) fstat << setw(7) << setprecision(3) << statVector[i] << " ";

   2016             else fstat << setw(5) << statVector[i] << " ";

   2017          }fstat << " selected from input" << endl;

   2018          */

   2019          //if(change)   fout << "\n\tCHANGE DB";

   2020          prevTimes = times.wall; // do not comment this, time reference         

   2021          //fout << "\n\t:1830: Reference Time clock times.wall---> " << setw(10) << setprecision(6) << times.wall / t

   2022          //fout << "\n\t:1831: ppRTime Chrono---> ppRTime";    net->displayMKT(net, ppRTime, aryStock, nullptr, 0, 3, 1

   2023          /*

   2024          if(db_root){//dummy to visulalize

   2025             fout << "\n\t:1835: TimeStamp dbTree:" ;

   2026             unsigned short counT = 0;

   2027             net->InOrderData(net, crptr, db_root, ppRTime, counT);                 

   2028             fout << "\n\tchange =  " << change << "\tExpected minDB: " << minDB << " <>  " << counT << " :counterSt";

   2029          }

   2030          //*/

   2031          //change = 0; // normal op comment here enable to test  reset stock change

   2032          //minDB = 4; // s comment all the time

   2033                

   2034          if(change && counterSt >= minDB) {//ok!!!LABEL

   2035             static unsigned short counterthisBlock(1);

   2036             if (1 && xsn && !(geNSTOCKS % net->get_rows_in_page(ppDataIn, 'f')) && counterthisBlock) {  //XSN

   2037                {

   2038                   fout << "\n\t:2045: Snapshot populating ExSan Counter: " << counterthisBlock << "  pp: "

   2039                   fout.flush() << "\t" << thread_clock::now();

   2040                   //net->displayMKT(net, ppDataIn, aryStock, nullptr, 0, 2, 5, 2); //system("pause");

   2041                   net->displayMKT(net, ppDB, aryStock, nullptr, 0, 2, 6, 2);                                               

   2042                   --counterthisBlock;

   2043                }

   2044             }

   2045             unsigned short counterST = 0;

   2046             //fout << "\n\t:1850: TimeStamp dbTree:" ;   net->InOrderData(net, crptr, db_root, ppRTime, counterST);

   2047             //fout << "\n\t:1851: --- chrono filtered stocks db --- basic db counterST:--> " << counterST << " >= " << 

   2048             imin = minDB;  //Mar 7   between the firs imin search the max

   2049             min2 = 0;

   2050             completeDB = 0;  //ok

   2051             for (i = 1; i <= net->get_rows_in_page(ppDataIn, 'f'); i++)   aryDB[i] = 0; // nadie en db para portfolio est

   2052             net->timeMaxGap(net, crptr, db_root, ppRTime, pp_bool, counterSt, imin, min2 = 0, completeDB, aryDB);

   2053             //fout << endl;

   2054             statVector[5] = completeDB; //??? esto corrige la cuenta

   2055             //fstat << "\n\t:1615:";  for (int i = 0; i <= 5; i++) fstat << "\t" << setw(7) << statVector[i]; fstat << 

   2056             /*

   2057             for (int i = 0; i <= 3; i++) {

   2058                //double frac(0);

   2059                //modf(statVector[i], &frac);

   2060                //if (frac) fstat << setw(7) << setprecision(3) << statVector[i] << " ";

   2061                //else

   2062                   fstat << setw(4) << statVector[i] << " ";

   2063             }fstat << " selected from timing" << endl;

   2064             /*/

   2065             /* dummy block

   2066             if(completeDB <= 10){ 

   2067                fout << "\n\t:1870: NEW METHOD Max Delta between records: " << setw(4) << min2 << "\tcompleteDB: " << comp

   2068                //fout << "\n\t:1493:Tick times.wall---> " << setw(10) << setprecision(2) << times.wall / timeZoomFactor <

   2069                //fout << "\n\t:1494:NEW BEFORE RE ARRENGE ppTime completeDB: " << completeDB;   net->displayMKT(net,   pp

   2070                fout << "\n\t:1871: NEW BEFORE RE ARRENGE ppDataIn *B";                  net->displayMKT(net, ppDataIn, ar

   2071             }

   2072             //*/

  

   2077             if (completeDB >= minDB) {  //Mar 7 // 

   2078                //fout << "\n\n\n\t:2084: completeDB " << setw(3) << completeDB << " >= " << minDB << " <-:mindb: nbsp="" p="">

   2079                ///*if (completeDB < 10) {

   2080                //fout << "\n\t:1577: ********** stocks in  db chrono selected ****************************";

   2081                //fout << "\n\t:1578: completeDB:-> " << completeDB << " > " << minDBsearchRHO << " <-:mindbsearchrho p="" ttim="">

   2082                //fout << "\n\t:1579: NEW METHOD Max Delta between records: " << setw(4) << min2 << "\tcompleteDB: " << co

   2083                //fout << "\n\t:1580B: Tick times.wall---> " << setw(10) << setprecision(2) << times.wall / timeZoomFactor

   2084                //fout << "\n\t:1581: NEW BEFORE RE ARRENGE ppTime completeDB: " << completeDB;   net->displayMKT(net, ppT

   2085                //fout << "\n\t:1936: NEW BEFORE RE ARRENGE *B ppDataIn"; net->displayMKT(net, ppDataIn, aryDB, nullptr, 0

   2086                

   2087                if (0 && xsn && !(geNSTOCKS % 100)) {                  

   2088                   static unsigned short  counterthisBlock(4);

   2089                   {                                    

   2090                   fout << "\n\t:2097: Number of datum read: " << grandTotal - geNSTOCKS << "\t" << thread_clock::now() <

   2091                   fout.flush() << "\n\t:2098: -AT THIS INSTANT- Stocks selected that can be used to establish correlation";

   2092                   --counterthisBlock;

   2093                   }

   2094                }

   2095                ////*/}

   2096 

 

   2098                //fout << "\n\tppTime Elapsed Time Tick by Tick AFTER times.wall---> " << setw(10) << setprecision(6) << t

   2099                //fout << "\n\tppData in TO PORTFOLIO";                                                   net->displayMKT(net, ppDataIn, aryDB, nullptr, 0, 

   2100                //nrolls = 0;         for (unsigned short ip = 0; ip < nintervals; ++ip) p[ip] = 0;            

   2101 

   2102                //fout << "\n\n\t__It seems there is always a different MATRIX, no need to check if it is a new one_____";

   2103                //fout << "\n\tCOMPLETE DB ONLY AROUND THE HIGH -activity- minDB: " << minDB << "  min expected correlatio

   2104                //fout << "\n\tppTime Elapsed Time Tick by Tick AFTER times.wall---> " << setw(10) << setprecision(6) << t

   2105                //fout << "\n\tppData PORTFOLIO DB to be considered";                                                                           net->displayMKT(net, ppDataI

   2106                //si es necesario antes de repetir todo este bloque hay que verificar si la matriz

   2107                // ha cambiado.. .hay que hacer una resta respecto de un backup

   2108                //quizas no hace falta restar toda la pp sino en el calculo de los tiempos ver si hay 

   2109                //cambio

   2110                //check if DB is a different one, a lo mejor si es importante verificar esto seria necesario solo una             

   2111                // resta de matrices               

   2112                //fout << "\n\tnew DB used for cubic interpolation aryDB has the selected stocks after chromo";            

   2113                //fout << "\n\t:2124C:***BEFORE RE ARRENGE ppDataIn"; net->displayMKT(net, ppDataIn, aryDB, nullptr, 0, 5,

   2114                //fout << "\n\t:1590:***BEFORE RE ARRENGE ppTime";        net->displayMKT(net,   ppTime, aryDB, nullptr, 0

   2115                /*//dummy to visulalize what is on db

   2116                if(db_root){

   2117                   fout << "\n\t:11594: DB Tree Data:\n" ;

   2118                   net->InOrderData(net, crptr, db_root, ppRTime);

   2119                }

   2120                //*/

   2121                //fout <<   "\n\t:1963: ROW-COL Re-Order ";

   2122                net->reArrangeRowData(net, crptr, db_root, ppDataIn, ppDB, cols, pp_key_index);  //only data is re-arrenge

   2123                net->all_boundaries(net, ppDB, 'f', aryDB, firstRow, lastRow, nullptr, firstCol, lastCol);

   2124                net->set_work_sheet(net, ppDB, net->get_rows_in_page(ppDB, 'f'), net->get_cols_in_page(ppDB, 'f'));

   2125                

   2126                //fout << "\n\n\t:2132: Re-Arranged INPUT before smoothing - *C ppDB";         net->displayMKT(net,   ppDB

   2127                //fout << "\n\t:1680: Time Stamp Cluster - *C ppTime"; net->displayMKT(net, ppTime, aryDB, nullptr, 0, 5, 

   2128                //fout << "\n\t:1681: Dummy traversal ppDB"; net->traverse_nt_record(net, crptr, db_root, ppDB, cols, 1, a

   2129                            

   2130                //////VRA  Measuring Volatility with the Relative Average Daily Range

   2131                if(0) { //ppDB the re arranged ordered input DB                  

   2132                   for (i = firstRow; i <= lastRow; i++) { //                   

   2133                      if (!aryDB[i])continue;

   2134                      stockPtr = net->go_to_row(net, i);

   2242                                     i = lastRow;

   2243                                  }

   2244                                  //} while (ptr); // the whole record set to 0 ===???

   2245                                  //fout << "\tgoto readNewDatum";   //goto readNewDatum;            NOO!!!!!

   2246                               }                        

   2247                               ptr = net->point_to(net, ppDB, i, net->get_cols_in_page(ppDB, 'f'), 'f');  //last in record to force 

   2248                            }      

   2249                            ptr = ptr->get_next_ptr();

   2250                         } while (ptr->get_col() <= net->get_cols_in_page(ppDB, 'f'));

   2251                      }

   2252                      //else fout << "\n\t row: " << i << " sum val is negative";

   2253                   }

   2254                }

   2255                //fout << "\n\t:2244: Re-Arranged INPUT -Final Volatility DB- before smoothing - *C ppDB";   net->displayM

   2256                //////VRA  Measuring Volatility with the Relative Average Daily Range   VRA END   

   2257 

   3122                               }

   3123                               */

   3124                               ///dummy block to visualize sol*/                           

   3125                               

   3126                               //if(1){   // para forzar la entrada                           

   3127                               //HEDGING BAND

   3128                               //fstat  << setw(10) << abs(abs(negSum) / posSum  - 1.) ;

   3129                               //if (is_val_in_range_t(1. - ((posSum + abs(negSum)) / abSum)) &&

   3130                               if(0 && xsn){

   3131                                  fout << "\n\t:2957: before hedge checking count: " << count << endl;

   3132                                  fout << "\n\t:2958: countAssetMinus: " << countAsset << " <- counta="" countassetminus="" nbsp="" p="">

   3133                               }

   3134                               evenOdd = 0;

   3135                               if (!(countAsset % 2) && countAssetPlus == countAsset / 2 && countAssetMinus == countAsset / 2) {

   3136                                  evenOdd = 1; //                                 fout << "\n\tOK PORTFOLIO - even number ";                                 

   3137                               }

   3138                               else {// odd number

   3139                                  if (countAssetMinus < countAssetPlus) {

   3140                                     if (countAssetMinus + 1 == countAssetPlus) {

   3141                                        evenOdd = 1; // fout << "\n\tOK PORTFOLIO - odd ";                                        

   3142                                     }

   3143                                  }

   3144                                  else {

   3145                                     if (countAssetPlus + 1 == countAssetMinus) {

   3146                                        evenOdd = 1;  //fout << "\n\tOK PORTFOLIO - odd ";

   3147                                     }

   3148                                  }

   3149                               }

   3150                               evenOdd = 0;  // the number of short - direct less than 2

   3151                               if (countAssetPlus >= countAssetMinus && countAssetPlus - countAssetMinus <= 2) evenOdd = 1;

   3152                               else

   3153                                  if (countAssetPlus < countAssetMinus && countAssetMinus - countAssetPlus <= 2) evenOdd = 1;

   3154 

   3155                               //if (evenOdd) fout << "\n\t:2526: PORTFOLIO difference is <= 2"; else fout << "\n\t:2503:  NO!!!! PO

   3156                               ///*

   3157                               bool dummyPortfolio(1);  //set to zero to avoid this if block  1 normal execution

   3158                               if (dummyPortfolio && 

   3159                                  //evenOdd && 

   3160                                  //abs(abs(negSum) / posSum - 1.) < hedgeBand &&   //el concepto de hedge Band ha cambiado

   3161                                  //negSum &&  // no hace falta

   3162                                  //is_val_in_range_t(temp) &&   // bloqueo esta instruccion para que se ejecute el portfolio

   3163                                  //abs(posSum / abSum) - 0.5 <= hedgeBand &&

   3164                                  count >= minDB) {//cambiar por un minimo en portfolio                              

   3165                               //*/

   3166                                  /*/

   3167                                  if (negSum && is_val_in_range_t(temp) &&

   3168                                     count >= minDB) {//cambiar por un minimo

   3169                                  *

   3170                                  fout << "\n\n\t:2310: START PORTFOLIO  Stock count: " << count << endl;

   3171                                  //fout << "\n\t:2206:YES HEDGING!!!!    hedgeBand: " << hedgeBand;

   3172                                  //fout << "\n\t:2207: °Original Adding Up Weights: " << setprecision(8) << setw(12) << sum << "\n\t

   3173                                  //fout << "\n\tSolution has been verified\t\ttemp val is around -0.1e-7 <= t <= 0.1e-7 : " << setpre

   3174 

   3175                                  /* dummy block to visualize Wi SOL

   3176                                  aryCols[net->get_net_cols()] = 1; // solo deja seteado la col independiente

   3177                                  fout << "\n\t:2212: -*-Sys Eq Solution";  net->show_page(net, ppCorr, 'f', 0, 3, 10, 4, aryDBin, ary

   3178                                  aryCols[net->get_net_cols()] = 0;

   3179                                  ///*/

   3180                                  //fout << "\n\t:L2361:posSum: " << posSum << "\tfabs(negSum): " << fabs(negSum) << "\tAsset Portafol

   3181                                  //fout.flush() << "\n\t:L2363: Got to normalize Wi en db tree if no change  posSum: " << posSum <<  

   3182                                  //*

   3183                                  //if (counterIN < 10) {

   3184                                     //fout << "\n\t:2320: At Portfolio Tick times.wall---> " << setw(10) << setprecision(2) << times.wa

   3185                                     //fout << "\n\t:1780: Reference Time clock times.wall---> " << setw(10) << setprecision(6) << times

   3186                                     //fout << "\n\t:2320: At Portfolio ppRTime Chrono---> ppRTime";    net->displayMKT(net, ppRTime, aryD

   3187                                     //fout << "\n\t:2320: At Portfolio ppDataIn"; net->displayMKT(net, ppDataIn, aryDBin, nullptr, 0, 5

   3188                                     //fout << "\n\t:2320: At Portfolio RE ARRENGE ppTime completeDB: " << completeDB;   net->displayMKT

   3189                                  //}

   3190                                  //*/

   3191                                  //fout.flush() << "\n\t:3021: BEFORE do";                                 

   3192                                  fout << "\n\n\n\t:3192: PORTFOLIO Selected Stocks ppDB";    net->displayMKT(net, ppDB, aryDB, nullptr,

   3193                                  do {//ib: 2120:

   3194                                     temp = 0;

   3195                                     abSum = sum = posSum = negSum = 0;

   3196                                     hdplus = hdminus = hdsum = 0;

   3197                                     change = false;

   3198                                     //fout << "\n\t:2551: ppCorr Wi last col:  " << lastCol << "\t" << net->get_cols_in_page(ppCorr, 'f

   3199                                     ptr = net->point_to(net, ppCorr, firstRow, lastCol, 'f');   //fout << "\tptr OK ";

   3200                                     auxPtr = net->point_to(net, ppDB, firstRow, net->get_cols_in_page(ppDB, 'f'), 'f');//BID PRICE

   3201                                     //temp = 0;

   3202                                     counter = 0;

   3203                                     //fout << "\n\t:3203: Available Funds:" << setprecision(2) << setw(15) << myInvestment; fout.flush(

   3204                                     do { //ib :2131:

   3205                                        //fout.flush() << "\n\t" << setw(5) << net->goto_row(net, ppDataIn, auxPtr->get_row(), 'f')->get_s

   3206                                        //fout.flush() << "\n\tbid price row(" << auxPtr->get_row() << "<" <<  net->goto_row(net, ppDataIn

   3207                                        ptr->set_data(ppCorr, ptr->get_data(ppCorr) / prevabSum);

   3208                                        //fout << "\n\t:2553: new w_" << ptr->get_row() << " = " << setprecision(4) <get_data(ppCorr

   3209                                        //if(ptr->get_data(ppCorr) < 0) ptr->set_data(ppCorr, ptr->get_data(ppCorr) / fabs(prevnegSum));

   3210                                        //else ptr->set_data(ppCorr, ptr->get_data(ppCorr) / prevposSum);

   3211                                        abSum += fabs(ptr->get_data(ppCorr));

   3212                                        //sum   += ptr->get_data(ppCorr);

   3213                                        if (ptr->get_data(ppCorr) > 0) posSum += ptr->get_data(ppCorr);

   3214                                        else                           negSum += ptr->get_data(ppCorr);

   3215 

   3216                                        rowPtr = net->goto_row(net, ppCorr, ptr->get_row(), 'f');              

   3217                                        if (rowPtr->get_backward_ptr()->get_data(ppCorr) * ptr->get_data(ppCorr) < 0) {

   3218                                           //fout << "\t:2508: new normalized w_" << ptr->get_row() << " = " << ptr->get_data(ppCorr) << " c

   3219                                           ptr->set_data(ppCorr, -1. * ptr->get_data(ppCorr));

   3220                                        }

   3221                                        if (rowPtr->get_backward_ptr()->get_data(ppCorr) == 1.) hdplus += fabs(ptr->get_data(ppCorr));

   3222                                        else                                         hdminus += fabs(ptr->get_data(ppCorr));

   3223                                        counter++;

   3224                                        if (onlyInteger && !short((myInvestment * ptr->get_data(ppCorr) / auxPtr->get_data(ppDB)))) {  // 

   3225                                           //fout << "\n\t\tshort((myInvest* ptr->get_data(ppCorr) / auxPtr->get_data(ppDB)): " << myInvestm

   3226                                           //fout << "\tw_i / $stock- ptr->get_data(ppCorr)- : " << " / " << auxPtr->get_data(ppDB) <<  "= "

   3227                                           //fout << "\n\t°*°No need to check the rest of Assets Big Correlated counter before\n\tNumber o

   3228                                           // 

   3229                                           //fout.flush() << "\n\t:2580: This for only integer BEFORE masterRecursive   

   3230                                           if (countElementInAry(aryDBin, true, 1, lastCol) > minDB) { 

   3231                                              net->masterRecursive(net, crptr, rootRowHolDB, db_root, ptr, ppCorrBU, scorr, aryDBin, count)

   3232                                              //fout << "\n\t:2583: Back From masterRecursive counter: " << counter;

   3233                                           }

   3234                                           else counter = minDB - 1;  // force to enter the if

   3235                                           if (counter < minDB || !db_root) {

   3236                                              ////*

   3237                                              //if (!db_root ) {fout << "\n\t\t2 head of db nullptr counter: " << counter;                                                   }      

   3238                                              //if (!counter) fout << "\n\t\t2 ZERO counter: " << counter;                                                   

   3239                                              //fout << "\n\t\tgoto keepOnProgram;";

   3240                                              goto keepOnProgram;

   3241                                              //net->kill_exsan(net); return;

   3242                                           }

   3243                                           else {

   3244                                              //counterIN = counter;                                                                                                

   3245                                             //minDB in portfolio

   3246                             net->all_boundaries(net, ppCorrBU, 'f', aryDBin);

   3247                                              net->set_work_sheet(net, ppCorrBU, lastRow, lastCol);   

   3248 

   3249                                              ///new  

   3250                                              net->set_work_sheet(net, ppTilda, lastRow, lastRow);

   3251                                              net->set_work_sheet(net, ppCorr, lastRow, lastRow);

   3252                                      displayMKT(net, ppTilda, aryDBin, aryDBin, 0, 3, 1

   3253                                              net->matrixSumValue(net, ppCorr, ppTilda, 0, aryDBin, aryDBin);  

   3254                                              //fout << "\n\t\t:2261: restored  ppCorr"; net->di, 

   3255                                              //fout << "\n\t\t°*2*° goto selectedRhos";

   3256                                              goto selectedRhos;

   3257                                           }

   3258                                        }

   3259                                        if (ptr->get_row() <= lastRow) {

   3260                                           do {

   3261                                              ptr = ptr->get_s_ptr();

   3262                                              auxPtr = auxPtr->get_s_ptr();

   3263                                           } while (!aryDBin[ptr->get_row()] && ptr->get_row() <= lastRow);

   3264                                        }

   3265                                     } while (ptr->get_row() <= lastRow);

   3266                                     fout.flush() << "\n\t:3266: NORMALIZED-SCALED Adding Up Weights: " << setprecision(8) << setw(12) <

   3267                                     //fout << "\n\tDummy Call STOCKS IN PORTFOLIO " << countElementInAry(aryDBin, true, firstRow, lastR

   3268                                     //if (posSum - negSum == 1.) fout << "\t°*°OK "; else fout.flush() << "\t***ERROR sum W_i: " << s

   3269                                     if (change) {

   3270                                        //prevabSum += fabs(temp);

   3271                                        prevabSum = 1. - fabs(temp);

   3272                                        //fout << "\n\t°°there is change prevabSum = " << prevabSum;

   3273                                     }

   3274                                  } while (change); //ib :2202:

   3275                                  fout << "\n\t:3275: end normalizar el output °°° Adding Up Weights sum: " << setprecision(8) << s

   3276                                  //fout << "\n\t:2891: Final Updated Wi ppCorr ";  net->show_page(net, ppCorr, 'f', 0, 8, 12, 8, aryD

   3277                                  hdsum = hdplus + hdminus;

   3278                                  /* dummy block

   3279                                  fout.flush() << "\n\t:3106: Final + hdplus: " << hdplus << "  -hdminus: " << hdminus << "  hdsum: " 

   3280                                  if (is_val_in_range_t(hdplus / hdsum, lowHB, upHB)) {  // criteria for hedging

   3281                                     fout.flush() << "\n\t:310: YES HEDGING, In range " << lowHB << " < " << hdplus / hdsum << " < " << 

   3282                                  }

   3283                                  else fout.flush() << "\n\t:3110: NO  HEDGING, NOT in range " << lowHB << " < " << hdplus / hdsum << 

   3284                                  //*/

   3285                                  //le hdplus(0), hdminus(0), hdsum(0); //                                        

   3286                                  //fout << "\n\t:2639: Stock Counter?: " << counter;// << "\tabs(posSum  " << posSum << " / " << abSu

   3287                                  ///*  

   3293                                  if (is_val_in_range_t(hdplus / hdsum, lowHB, upHB)) {   // to make it wider

   3294                                     fout << "\n\t:3300: -----------------------------------------------";

   3295                                     fout << "\n\t:3301: HEDGING (hdplus/hdsum) Ok! In range " << lowHB << " < " << hdplus / hdsum << " 

   3296                                     ptr = net->point_to(net, ppCorr, firstRow, lastCol, 'f');

   3297                                     do { //

   3298                                        //++counter;                                       

   3299                                        stockPtr = net->goto_row(net, ppCorr, ptr->get_row(), 'f');

   3300                                        //fout << stockPtr->get_ptrLasTick()->get_data(ppDataIn) << endl; //no es correcto

   3301                                        //stockPtr->set_stock_name(to_string(ptr->get_row()));

   3302                                        //stockPtr->set_stock_name(numToString(ptr->get_row()));                                 

   3303                                        //precio  ??? esta captando 10 antes

   3304                                        //ptr->get_previous_ptr()->set_data(ppCorr, stockPtr->get_ptrLasTick()->get_data(ppDataIn)); //???

   3305                                        //estas lineas corrigen lo anterior

   3306                                        auxPtr = net->point_to(net, ppDB, ptr->get_row(), net->get_cols_in_page(ppDB, 'f'), 'f');

   3307                                        ptr->get_previous_ptr()->set_data(ppCorr, auxPtr->get_data(ppDB)); // recupera el ultimo precio y 

   3308                                        // el ultimo tick en la primera columna  

   3309                                        //fout << "\n\t:2409: " << setw(6)<< stockPtr->get_stock_name() << "\tData stored: " << ptr->get_p

   3310                                        //**** ? from  //esta bien para acelerar data sobre la que trabaja portfolio

   3311                                        //stockPtr->get_forward_ptr()->set_data(ppU, stockPtr->get_ptrLasTick()->get_data(ppDataIn));

   3312                                        // cambio Sept 12

   3313                                        stockPtr->get_forward_ptr()->set_data(ppU, auxPtr->get_data(ppDB));

   3314                                        //stockPtr->get_forward_ptr()->set_data(ppDataIn, auxPtr->get_data(ppDB)); ///  el mismo dato con 

   3315                                        // pero pierde tiempo marcando un dato extra que ya salio antes

   3316                                        //stockPtr->get_forward_ptr()->set_data(ppDataIn, stockPtr->get_ptrLasTick()->get_data(ppDataIn));

   3317                                        //stockPtr->get_forward_ptr()->set_data(ppDataIn, 0); /// ?????

   3318 

   3319                                        //fout << "\n\tValue stored in ppU & ppDatain -used to compare prev val-" << setw(7) << stockPtr->

   3320                                        //**** ? to

   3321                                        // n shares in table 

   3322                                        //onlyInteger = 0;  //COMENT HERE TO SET AT THE BEGINING

   3323                                        /*

   3324                                        if (onlyInteger)   ptr->get_previous_ptr()->get_previous_ptr()->set_data(ppCorr, int(fabs(ptr->get_d

   3325                                        else  ptr->get_previous_ptr()->get_previous_ptr()->set_data(ppCorr, 0.9999 * fabs(ptr->get_data(pp

   3326                                        /// hago una minima correccion para que al sumar no pase del total disponible????                     

   3327                                        //if(ptr->get_previous_ptr()->get_previous_ptr()->get_data(ppCorr)) fout << "\n\t:2418: n shares i

   3328                                        stockPtr->get_forward_ptr()->get_next_ptr()->get_next_ptr()->get_next_ptr()->set_data(ppDataIn, pt

   3329                                        

   3330                                        stockPtr->get_forward_ptr()->set_data(ppTilda, ptr->get_previous_ptr()->get_previous_ptr()->get_da

   3331                                                                                                                            //last tick price// read real data bid

   3332                                        stockPtr->get_forward_ptr()->set_data(ppDataIn, ptr->get_previous_ptr()->get_data(ppCorr) * copysi

   3333                                        //copysignf(1.0, ptr->get_data(ppCorr))

   3334                                        //fout << "\t\tFraccion " << ptr->get_previous_ptr()->get_previous_ptr()->get_data(ppCorr);

   3335                                        //fout << "\t\t Creo debería ser w*I/$stock " << int(   ptr->get_data(ppCorr)*myInvestment / ptr->g

   3336                                        if (ptr->get_previous_ptr()->get_previous_ptr()->get_data(ppCorr))

   3337                                           ptr->get_previous_ptr()->get_previous_ptr()->get_previous_ptr()->set_data(ppCorr, ptr->get_previo

   3338 

   3339                                        if (ptr->get_previous_ptr()->get_previous_ptr()->get_data(ppCorr) && ptr->get_previous_ptr()->get_

   3340                                           myInvestment -= ptr->get_previous_ptr()->get_previous_ptr()->get_previous_ptr()->get_data(ppCorr)

   3341                                           fout.flush() << "\n\t:2686: // this stock is not eliminated here this stock out inv$: " << setpre

   3342                                           //aryDBin[ptr->get_row()] = aryDB[ptr->get_row()] = 0;  // no eliminar aqui este valor

   3343                                           fout.flush() << "\n\t:2688: Stock Counter: " << count;

   3344                                           count--;

   3345                                           //fout.flush() << "\t:2461: Updated Because investment to low Stock Counter: " << count;

   3346                                           if (count < minDB) {//

   3347                                              fout.flush() << "\n\t:2692: Total Stock Counter  " << count << " is less than " << minDB << " :m

   3348                                              firstRow = lastRow;  // para que no entre en el for siguiente

   3349                                              ptr = net->point_to(net, ppCorr, lastRow - 1, lastCol, 'f');

   3350                                           }

   3351                                          

   3352                                        }

   3353                                        */

   3354                                        //if (ptr->get_data(ppCorr) > 0) posSum += ptr->get_data(ppCorr);

   3355                                        //else negSum += ptr->get_data(ppCorr);

   3356                                        //print(ptr->get_data(ppCorr), "  ", sum);

   3358                                        do {

   3359                                           ptr = ptr->get_s_ptr();

   3360                                        } while (aryDB[ptr->get_row()] == 0 && ptr->get_row() <= lastRow);

   3361                                     } while (ptr->get_row() <= lastRow);

   3362                                     fout.flush() << "\n\t:3362: Adding Up Weights: " << setprecision(8) << setw(12) << sum << "  +Sum:"

   3363                                     //fout << "\n\tppDB Re-Arrenged Input DB to determine Correlation - high Freq Simmmilar ppDB |ok|";

   3364                                     //fout << "\n\tYES Selection Portfolio  counter:  " << counterIN << "/" << minPortfolio << endl;

   3365                                     //net->TreeInOrderPlot(net, crptr, db_root, ppDB, nTicksLineal, aryDBin);                              

   3366                                     //fout << "\n\t:2467: Run: " << run;

   3367                                     //if (!run) geNSTOCKS = 0;

   3368                                     //run--;                                    

   3369                                     // almacena lo que esta en portfolio para emergency recovery                                    

   3370                                     ///   stockPtr->set_stock_name(stock);

   3371                                     //rr_ptr->RB_Insert_row(rr_ptr, rootStocks, stockPtr, 's', 0);

   3372                                     //quizas esto se puede hacer en el paso anterior

   3373                                     //fout << "\n\t:2725: Store PORTFOLIO items TREE AND IN EMERGENCY FILE exsan\\out_" << id_job << ".

   3374                                     //July   PREPARES FOR A NEW TREE

   3375                                     fts.open("c:\\\....\\\\out_" + id_job + ".txt", ios::out);

   3376                                     fts << "\n\tEMERGENCY FILE IN CASE OF CRASH ***  c:......\\\\out_" + id_job + ".txt  nTick se

   3377                                     // de discard atravesar 

   3378                                     goodReturn = 0;

   3379                                     //counter = 0;  no usar el valor anterior

   3380                                     //net->DiscarDB(net, crptr, rootRowHolDB, db_root, 'f');

   3381                                     //hay que rehacer esta instruccion a traves de net

   3382                                     rr_ptr->DiscardStockTree(rr_ptr, rootStocks); 

   3383                                     //fout << "\n\t:2727: se pierde algunas filas? PREPARE NEW SCENARIO rows [" << firstRow << " - " <<

   3384                                     /// ------next instructions ok!!!

   3385                                     stockPtr = net->goto_row(net, ppDataIn, firstRow, 'f');

   3386                                     rootStocks = stockPtr->get_db_root_ptr();

   3387                                     fts << run + 1 << "\n";

   3388                                     fout  << "\n\t:3216: run: " << run << "  counter: " <<  counter;

   3389                                     abSum = 0;

   3390                                     initialInvestment = 0;

   3391                                     j = counter; //save previous val

   3392                                     counter = 0;

   3393                                     for (i = firstRow; i <= lastRow; i++) {

   3394                                        if (aryDBin[i]) {

   3395                                           counter++;  // tiene que descontar todo lo que había antes

   3396                                           fts << stockPtr->get_stock_name() << " " << stockPtr->get_forward_ptr()->get_data(ppDataIn) << "\

   3397                                           //fout << "\n\t:2744: Into DB: " << stockPtr->get_stock_name() << "  ";

   3398                                           stockPtr->set_nTick(1);

   3399                                           stockPtr->set_nTickCopy(1);   // Sept 12

   3400                                           stockPtr->set_hiTime(0);  ///ok cero= para contar los ticks en contra

   3401                                           rr_ptr->RB_Insert_row(rr_ptr, rootStocks, stockPtr, 's', 0);

   3402                                           //net->RB_Insert_data(net, rootRowHolDB, db_root, stockPtr, 'f', ppDataIn);  //NO!!! version corr

   3403                                           ptr = stockPtr->get_forward_ptr()->get_next_ptr();  //ubico ptr      

   3404                                           for (unsigned short in = 0; in <= 7; in++) {  //7 es correcto prepara el escenario

   3405                                              ptr->set_data(ppDataIn, 0);

   3406                                              ptr = ptr->get_next_ptr();

   3407                                           }

   3408                                           ptr = net->point_to(net, ppCorr, i, lastCol, 'f');

   3409                                           //fout << "\n\t:2756: wi lastCol " << ptr->get_data(ppCorr) << "   final-normalized " << ptr->get

   3410                                           ptr->set_data(ppCorr, ptr->get_data(ppCorr) / hdsum);   

   3411                                           //fout << "\n\t:2775: normalized w_i becomes: " << ptr->get_data(ppCorr);    // hasta aqui el nue

   3412                                           if (fabs(ptr->get_data(ppCorr)) > limitWeightFactor) {//fout << "\t:2784: OUT, w_i is bigger than

   3413                                              aryDBin[ptr->get_row()] = aryDB[ptr->get_row()] = 0;  // no eliminar aqui este valor

   4612          }

   4613          //*/

   4614          if (0 && xsn && !((grandTotal - geNSTOCKS ) % 333)) {

   4615             static unsigned short  counterthisBlock(4);

   4616             {

   4617             if(counterthisBlock){

   4618                fout << "\n\t:4416: Number of datum read: " << grandTotal - geNSTOCKS << "\t" << thread_clock::now();

   4619                fout << "\n\t:4417: No Portfolio. Back to read a new DATUM";

   4620                /*

   4621                fout << "\n\t:4422: Number of datum read:" << grandTotal - geNSTOCKS << "\t" << thread_clock::now();

   4622                fout.flush() << "\n\t:2766: Sys Eq *SOLUTUION IN LAST FULL COLUMN* RANGE Rows[ " << firstRow << " - " << l

   4623                fout.flush() << "\n\t:2767: ppCorr";  net->show_page(net, ppCorr, 'f', 0, 3, 8, 7, aryDBin, aryCols);

   4624                //fout.flush() << "\n\t

   4625                */

   4626                --counterthisBlock;

   4627                }

   4628             }

   4629          }

   4630 

   4631 keepOnProgram:

   4632          check = !check;

   4633          //fout.flush() << "\n\t:3837: Here |keepOnProgram| check has been reseted,  ends RUN: " << geNSTOCKS << "\ti

   4634       }  // cierra if (check)            

   4635       //else fout << "\n\t:1504: no check ";

   4636    }//cierra while (!portfolio && --geNSTOCKS)

   4658    rr_ptr->DiscardStockTree(rr_ptr, rootStocks);

   4659    net->kill_exsan(net);

   4660    fout << XSNto;   

   4661    //fout << "\n\tstockCounterDB: " << stockCounterDB;

   4662    for (i = 0; i < stockCounterDB; i++) {//CLOSE   all files

   4663       //fout << "\n\t CLOSE FILE ID" <<  " " << fileID[i] << endl;   

   4664       fDB[i].close();

   4665    }

   4666    f1db.close();

   4667    fstat.close();

   4668    fstatR.close();

   4669    fprmtr.close();

   4670    fsos.close();

   4671    if (xsn) { fxsn.close(); }

   4672 

   4673    

   4674    //fbs << endl;  // 

   4675    fbs.close();

   4676    if(!xsn) Beep(500, 77);  fout << "\n\t:4484: Beep ExSan has been killed  ";  /// f,t

   4677    //backUP balance sheet   en dos directorios en c y google drive 

   4678    fbs.close();

   4679 

   4680 

   4681 

   4682    /*

   4686    */

   4687 

   4688 

   4689 /* this is blocked termporarily for a review  May 27

   4697 

   4698    copy_bs += topic + "_" + id_job + ".txt";

   4699    copy_bs_to_GC += topic + "_" + id_job + ".txt";

   4700    //copy_bs += "_";

   4701    //copy_bs += id_job;

   4702    //copy_bs += ".txt";

   4703    char output_copy[100];

   4704    unsigned short i1(0), length = copy_bs.length();

   4705 

   4706    do {

   4707       output_copy[i1] = copy_bs[i1];

   4708    } while (++i1 <= length);

   4709    if(!xsn) print("1 action ---> ", output_copy);

   4710    system(output_copy);

   4711 

   4712    i1 = 0, length = copy_bs_to_GC.length();

   4713    char output_copy_gd[100];

   4714    do {

   4715       output_copy_gd[i1] = copy_bs_to_GC[i1];

   4716    } while (++i1 <= length);

   4717    if (!xsn) print("2 action ---> ", output_copy_gd);

   4718    system(output_copy_gd);

   4719 

   4720    //string cdDos = "cd c:\\";

   4721    string cdDos = "cd..";

   4722    char output_cdDos[100];

   4723    i1 = 0, length = cdDos.length();

   4724    do {

   4725       output_cdDos[i1] = cdDos[i1];

   4726    } while (++i1 <= length);

   4727    //print("3 action ---> ", output_cdDos);

   4728    system(output_copy);

   4729 

   4730 */

   4756    fout.flush();// << "\n\tJUST BEFORE RETURN, LEAVING Portfolio Simulator, back to main()";

   4761    return;

   4762 }

   4763 /***********END hft*****************/

   4764 //for (k = 0; k < 100; k++) if(bigRHO[k]) fout << "\n\t" << k << " " << bigRHO[k];

   4765 //if(setRHO && db_root && counterIN > 1 && counterIN < 7) { // only display here

   4766 //countElementInAry(aryDBin, true, firstRow, lastRow) - 1;  

   4767 

   4768 /****************************/

   4769 void end_hft(NETPTR net, ROWRECORDPTR rr_ptr, ROWPTR rootStocks) {  //, rr_ptr, rootStocks

   4770    rr_ptr->DiscardStockTree(rr_ptr, rootStocks);

   4771    fout.flush() << "\n\n\t:46:\t\tERROR";

   4780    f1db.close();

   4781    fstat.close();

   4782    fstatR.close();

   4783    fbs.close();

   4800    i1 = 0, length = copy_bs_to_GC.length();

   4801    char output_copy_gd[100];

   4802    do {

   4803       output_copy_gd[i1] = copy_bs_to_GC[i1];

   4804    } while (++i1 <= length);

   4805    print("2 action ---> ", output_copy_gd);

   4806    system(output_copy_gd);

   4807 

   4809    string cdDos = "cd..";

   4810    char output_cdDos[100];

   4811    i1 = 0, length = cdDos.length();

   4812    do {

   4813       output_cdDos[i1] = cdDos[i1];

   4814    } while (++i1 <= length);

   4815    //print("3 action ---> ", output_cdDos);

   4816    system(output_copy);

   4817    */

   4818    return;

   4819 }

   4820 /***********END end_hft*****************/


This  module (5K lines of  source  C++ code) is based on ExSan a multipurpose master library, It is a console-oriented worksheet tool written in C++11 that is comparable in functionality to Excel or Matlab. Some Outputs  in the next entries of this blog.  I am looking for a job as a C/C++ developer / programmer 

ExSan is already plugged into  Interactive Brokers C++ API to perform live market data analysis

My portfolio https://lnkd.in/dPC3ZuDr    Personal https://lnkd.in/dDuC9uMi  


Polulating ExSan with Market Data Tick by Tick
         Low Latency Systematic Trading Algorithm         
      Previous Post       Next Post 

+ + C   E x S a n   C + +
D o   N o t   A c c e p t   D e f a u l t s
T h i n k   D i f f e r e n t

Flag Counter

Comments

Popular posts from this blog

Back Testing Algorithmic Trading Modern Portfolio Simulator

ExSan can monitor data market activity of several hundred contracts at the tick-by-tick level, 360 stocks in this run. ExSan is already plugged-in to Interactive Brokers C++ API