Changeset 1358 for applications

Show
Ignore:
Timestamp:
05/06/11 19:13:05 (13 years ago)
Author:
sindj
Message:

DDE data. JS

Location:
applications/robust
Files:
3 added
2 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/CMakeLists.txt

    r976 r1358  
    1515 
    1616add_library(robustlib robustlib.cpp robustlib.h) 
     17add_library(DDEClient ddeclient.cpp ddeclient.h dcerrors.h) 
    1718 
    18 EXEC(main robustlib ) 
     19EXEC(main robustlib DDEClient) 
    1920 
    2021 
  • applications/robust/main.cpp

    r1357 r1358  
    1313#include <fstream> 
    1414#include <itpp/itsignal.h> 
     15#include <windows.h> 
     16#include "DDEClient.h" 
     17#include <conio.h> 
     18 
    1519 
    1620using namespace itpp; 
     
    2529        itpp::Laplace_RNG LapRNG = Laplace_RNG(); 
    2630 
     31        WORD wConvNo; 
     32        char szType[] = "request"; 
     33        char szData[21];  
     34        char szItem[] = "EURUSD"; 
     35        char szService[] = "MT4"; 
     36        char szTopic[] = "BID"; 
     37        char szFormat[] = "CF_TEXT"; 
     38        DWORD dwTimeout = 0; 
     39        //char szAccess[] = "string"; 
     40 
     41        if(!DCInit())  
     42        { 
     43                cout << "DDE doesn't work." << endl; 
     44        } 
     45        else 
     46        { 
     47                // The following if-block shows a complete conversation with a 
     48                // single transaction. You therefore do not need to free any memory 
     49                // explicitly. 
     50 
     51                // connect to server 
     52                if (!DCConnect(&wConvNo,szService, szTopic))  
     53                { 
     54                        cout << "Couldn't connect DDE." << endl; 
     55                } 
     56                else 
     57                { 
     58                        // do synchronous request transaction, wait max. 1000 ms,  
     59                        // return data as string 
     60                        if(!DCRequestString(wConvNo,szItem,100000)) 
     61                        { 
     62                                cout << "No data available." << endl; 
     63                        } 
     64                        else 
     65                        { 
     66                                if(!DCAsynchTransactionCompleted(wConvNo,DCDA[wConvNo]->dwTransID,true)) 
     67                                { 
     68                                        cout << "Asynchronous transaction error." << endl; 
     69                                } 
     70                                else 
     71                                { 
     72                                // output data to console if transaction complete 
     73                                // DCDA[wConvNo]->pszData is the pointer to the data string 
     74                                        cprintf(DCDA[wConvNo]->pszData); 
     75                                        DCFreeDdeMem(wConvNo); 
     76                                } 
     77                        } 
     78                        // end conversation 
     79                        if(!DCDisconnect(wConvNo)) 
     80                        { 
     81                                cout << "Couldn't disconnect DDE." << endl; 
     82                        }  
     83                } 
     84        } 
     85         
    2786        /* 
    2887        // EXPERIMENT: 100 AR model generated time series of length of 30 from y_t=0.95*y_(t-1)+0.05*y_(t-2)+0.2*e_t,  
     
    173232                vector<vec> conditions; 
    174233                //emlig* emliga = new emlig(2); 
    175                 RARX* my_rarx = new RARX(2,8,false); 
     234                RARX* my_rarx = new RARX(2,10,false); 
    176235                 
    177236                 
     
    224283                                         
    225284                                        vec sample_prediction; 
     285                                        vec averaged_params = zeros(imp_samples.second.rows()); 
    226286                                        for(int t = 0;t<imp_samples.first.size();t++) 
    227287                                        { 
     
    232292 
    233293                                                sample_prediction.ins(0,lap_sample*imp_samples.second.get_col(t)); 
    234                                         } 
    235  
    236                                          
    237                                         vec sample_pow = sample_prediction; 
     294 
     295                                                averaged_params += imp_samples.first[t]*imp_samples.second.get_col(t); 
     296                                        } 
     297 
     298                                        averaged_params = averaged_params*(1/(imp_samples.first*ones(imp_samples.first.size()))); 
     299 
     300                                        // cout << "Averaged estimated parameters: " << averaged_params << endl; 
     301                                         
     302                                        vec sample_pow = sample_prediction;                                      
    238303                                         
    239304                                        // cout << sample_prediction << endl;