31 | | const int max_window_size = 121; |
32 | | |
33 | | /* |
34 | | HDDEDATA CALLBACK DdeCallback( |
35 | | UINT uType, // Transaction type. |
36 | | UINT uFmt, // Clipboard data format. |
37 | | HCONV hconv, // Handle to the conversation. |
38 | | HSZ hsz1, // Handle to a string. |
39 | | HSZ hsz2, // Handle to a string. |
40 | | HDDEDATA hdata, // Handle to a global memory object. |
41 | | DWORD dwData1, // Transaction-specific data. |
42 | | DWORD dwData2) // Transaction-specific data. |
43 | | { |
44 | | return 0; |
45 | | } |
46 | | |
47 | | void DDERequest(DWORD idInst, HCONV hConv, char* szItem) |
48 | | { |
49 | | HSZ hszItem = DdeCreateStringHandle(idInst, szItem, 0); |
50 | | HDDEDATA hData = DdeClientTransaction(NULL,0,hConv,hszItem,CF_TEXT, |
51 | | XTYP_ADVSTART,TIMEOUT_ASYNC , NULL); //TIMEOUT_ASYNC |
52 | | if (hData==NULL) |
53 | | { |
54 | | printf("Request failed: %s\n", szItem); |
55 | | } |
56 | | |
57 | | if (hData==0) |
58 | | { |
59 | | printf("Request failed: %s\n", szItem); |
60 | | } |
61 | | } |
62 | | |
63 | | DWORD WINAPI ThrdFunc( LPVOID n ) |
64 | | { |
65 | | return 0; |
66 | | } |
67 | | */ |
| 31 | const int max_window_size = 30; |
343 | | for(set<set<pair<int,int>>>::iterator model_type = model_types.begin();model_type!=model_types.end();model_type++) |
344 | | {// prechadza rozne typy kanalov, a poctu regresorov |
345 | | for(int window_size = max_window_size-1;window_size < max_window_size;window_size++) |
346 | | { |
347 | | //models.push_back(new model((*model_type),true,true,window_size,0,&data_matrix)); // to su len konstruktory, len inicializujeme rozne typy |
348 | | //models.push_back(new model((*model_type),false,true,window_size,0,&data_matrix)); |
349 | | models.push_back(new model((*model_type),true,false,window_size,0,&data_matrix)); |
350 | | models.push_back(new model((*model_type),false,false,window_size,0,&data_matrix)); |
351 | | } |
352 | | |
353 | | //set<pair<int,int>> empty_list; |
354 | | //models.push_back(new model(empty_list,false,true,100,0,&data_matrix)); |
355 | | } |
356 | | |
357 | | mat result_lognc; |
358 | | // mat result_preds; |
373 | | //pocet stlpcov data_matrix je pocet casovych krokov |
374 | | vec cur_res_lognc; |
375 | | // vec preds; |
376 | | vector<string> nazvy; |
377 | | for(vector<model*>::iterator model_ref = models.begin();model_ref!=models.end();model_ref++) |
378 | | {//posuvam s apo models, co je pole modelov urobene o cyklus vyssie. Teda som v case time a robim to tam pre vsetky typy modelov, kombinace regresorov |
379 | | (*model_ref)->data_update(time); //pozret sa preco je toto tu nutne |
380 | | |
381 | | cout << "Updated." << endl; |
382 | | //if (time = max_model_order) nazvy.push_back(models.model_ref]);// ako by som mohol dostat nazov modelu? |
383 | | |
384 | | if((*model_ref)->my_rarx!=NULL) //vklada normalizacni faktor do cur_res_lognc |
385 | | { |
386 | | cout << "Maxlik vertex:" << (*model_ref)->my_rarx->posterior->minimal_vertex->get_coordinates() << endl; |
387 | | cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_rarx->posterior->_ll()); |
388 | | } |
389 | | else |
390 | | { |
391 | | cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_arx->_ll()); |
392 | | } |
393 | | |
394 | | if(time == max_window_size-1) |
395 | | { |
396 | | //*********************** |
397 | | int sample_size = 100000; |
398 | | //*********************** |
399 | | |
400 | | pair<vec,mat> samples; |
401 | | if((*model_ref)->my_arx!=NULL) |
| 302 | |
| 303 | while(data_matrix.rows()!=0) |
| 304 | { |
| 305 | for(int i=0;i<models.size();i++) |
| 306 | { |
| 307 | delete models[i]; |
| 308 | } |
| 309 | |
| 310 | models.clear(); |
| 311 | models.push_back(new model(model_type,true,false,max_window_size,0,&data_matrix)); |
| 312 | models.push_back(new model(model_type,false,false,max_window_size,0,&data_matrix)); |
| 313 | |
| 314 | for(int time = max_model_order;time<max_window_size;time++) //time<data_matrix.cols() |
| 315 | { |
| 316 | vec cur_res_lognc; |
| 317 | |
| 318 | vector<string> nazvy; |
| 319 | for(vector<model*>::iterator model_ref = models.begin();model_ref!=models.end();model_ref++) |
| 320 | { |
| 321 | (*model_ref)->data_update(time); |
| 322 | |
| 323 | cout << "Updated:" << time << endl; |
| 324 | |
| 325 | if(time == max_window_size-1) |
406 | | else |
407 | | { |
408 | | samples = (*model_ref)->my_rarx->posterior->sample(sample_size,true); |
409 | | } |
410 | | |
411 | | char fstring[80]; |
412 | | strcpy(fstring,file_string); |
413 | | strcat(fstring,(*model_ref)->name); |
414 | | strcat(fstring,".txt"); |
415 | | |
416 | | //cout << samples.first << endl; |
417 | | |
418 | | myfilew.open(fstring,ios::app); |
419 | | |
420 | | /* |
421 | | for(int i = 0;i<samples.first.size();i++) |
422 | | { |
423 | | myfilew << samples.first.get(i) << ","; |
424 | | } |
425 | | myfilew << endl; |
426 | | */ |
427 | | |
428 | | for(int j = 0;j<samples.second.rows()+1;j++) |
429 | | { |
430 | | for(int i = 0;i<samples.second.cols();i++) |
431 | | { |
432 | | if(j!=samples.second.rows()) |
433 | | { |
434 | | myfilew << samples.second.get(j,i) << ","; |
435 | | } |
436 | | /* |
437 | | else |
438 | | { |
439 | | myfilew << "0,"; |
440 | | } |
441 | | */ |
442 | | } |
443 | | myfilew << endl; |
444 | | } |
445 | | |
446 | | cout << "*************************************" << endl; |
447 | | |
448 | | myfilew.close(); |
449 | | } |
450 | | |
451 | | /* // PREDICTIONS |
452 | | pair<vec,vec> predictions = (*model_ref)->predict(500,time,&LapRNG); |
453 | | |
454 | | cout << predictions.first << endl << predictions.second << endl; |
455 | | |
456 | | double avg_prediction = (predictions.first*predictions.second)/(predictions.first*ones(predictions.first.size())); |
457 | | |
458 | | (*model_ref)->predictions.ins((*model_ref)->predictions.size(),avg_prediction); |
459 | | |
460 | | myfilew.open(fstring,ios::app); |
461 | | myfilew << avg_prediction << ","; |
462 | | myfilew.close(); |
463 | | */ |
464 | | |
465 | | //preds.ins(0,data_matrix.get(0,time+1)); |
466 | | } |
467 | | |
468 | | |
469 | | /* // REAL PRICE |
470 | | myfilew.open(fstring,ios::app); |
471 | | myfilew << data_matrix.get(0,time+1) << endl; |
472 | | myfilew.close(); |
473 | | */ |
474 | | |
475 | | result_lognc.ins_col(result_lognc.cols(),cur_res_lognc); |
476 | | // result_preds.ins_col(result_preds.cols(),preds); |
477 | | |
478 | | // cout << "Updated." << endl; |
479 | | |
480 | | /* |
481 | | myfilew.open(fstring,ios::app); |
482 | | |
483 | | // myfile << my_rarx->posterior->minimal_vertex->get_coordinates()[0]; |
484 | | |
485 | | if(time == max_model_order) |
486 | | { |
487 | | for(int i = 0;i<cur_res_lognc.size();i++) |
488 | | { |
489 | | for(set<pair<int,int>>::iterator ar_ref = models[i]->ar_components.begin();ar_ref != models[i]->ar_components.end();ar_ref++) |
490 | | { |
491 | | myfilew << (*ar_ref).second << (*ar_ref).first; |
492 | | } |
493 | | |
494 | | myfilew << "."; |
495 | | |
496 | | if(models[i]->my_arx == NULL) |
497 | | { |
498 | | myfilew << "1"; |
499 | | } |
500 | | else |
501 | | { |
502 | | myfilew << "0"; |
503 | | } |
504 | | |
505 | | if(models[i]->has_constant) |
506 | | { |
507 | | myfilew << "1"; |
508 | | } |
509 | | else |
510 | | { |
511 | | myfilew << "0"; |
512 | | } |
513 | | |
514 | | myfilew << ","; |
515 | | } |
516 | | |
517 | | myfilew << endl; |
518 | | } |
519 | | |
520 | | |
521 | | // for(int i = 0;i<cur_res_lognc.size();i++) |
522 | | // { |
523 | | // myfilew << cur_res_lognc[i] << ' ';//zmenil som ciarku ze medzeru |
524 | | // } |
525 | | |
526 | | |
527 | | myfilew << endl; |
528 | | |
529 | | myfilew.close(); |
530 | | */ |
531 | | |
532 | | } |
533 | | |
534 | | |
535 | | |
536 | | // EXPERIMENT: One step ahead price prediction. Comparison of classical and robust model using optimal trading |
537 | | // with maximization of logarithm of one-step ahead wealth. |
538 | | |
539 | | |
540 | | |
541 | | /* |
542 | | cout << "One experiment finished." << endl; |
543 | | |
544 | | ofstream myfile; |
545 | | myfile.open("c:\\robust_ar1.txt",ios::app); |
546 | | myfile << endl; |
547 | | myfile.close(); |
548 | | |
549 | | myfile.open("c:\\robust_ar2.txt",ios::app); |
550 | | myfile << endl; |
551 | | myfile.close();*/ |
552 | | |
553 | | |
554 | | //emlig* emlig1 = new emlig(emlig_size); |
555 | | |
556 | | //emlig1->step_me(0); |
557 | | //emlig* emlig2 = new emlig(emlig_size); |
558 | | |
559 | | /* |
560 | | emlig1->set_correction_factors(4); |
561 | | |
562 | | for(int j = 0;j<emlig1->correction_factors.size();j++) |
563 | | { |
564 | | for(set<my_ivec>::iterator vec_ref = emlig1->correction_factors[j].begin();vec_ref!=emlig1->correction_factors[j].end();vec_ref++) |
565 | | { |
566 | | cout << j << " "; |
567 | | |
568 | | for(int i=0;i<(*vec_ref).size();i++) |
569 | | { |
570 | | cout << (*vec_ref)[i]; |
571 | | } |
572 | | |
573 | | cout << endl; |
574 | | } |
575 | | }*/ |
576 | | |
577 | | /* |
578 | | vec condition5 = "1.0 1.0 1.01";//"-0.3 1.7 1.5"; |
579 | | |
580 | | emlig1->add_condition(condition5); |
581 | | //emlig1->step_me(0); |
582 | | |
583 | | |
584 | | vec condition1a = "-1.0 1.02 0.5"; |
585 | | //vec condition1b = "1.0 1.0 1.01"; |
586 | | emlig1->add_condition(condition1a); |
587 | | //emlig2->add_condition(condition1b); |
588 | | |
589 | | vec condition2a = "-0.3 1.7 1.5"; |
590 | | //vec condition2b = "-1.0 1.0 1.0"; |
591 | | emlig1->add_condition(condition2a); |
592 | | //emlig2->add_condition(condition2b); |
593 | | |
594 | | vec condition3a = "0.5 -1.01 1.0"; |
595 | | //vec condition3b = "0.5 -1.01 1.0"; |
596 | | |
597 | | emlig1->add_condition(condition3a); |
598 | | //emlig2->add_condition(condition3b); |
599 | | |
600 | | vec condition4a = "-0.5 -1.0 1.0"; |
601 | | //vec condition4b = "-0.5 -1.0 1.0"; |
602 | | |
603 | | emlig1->add_condition(condition4a); |
604 | | //cout << "************************************************" << endl; |
605 | | //emlig2->add_condition(condition4b); |
606 | | //cout << "************************************************" << endl; |
607 | | |
608 | | //cout << emlig1->minimal_vertex->get_coordinates(); |
609 | | |
610 | | //emlig1->remove_condition(condition3a); |
611 | | //emlig1->step_me(0); |
612 | | //emlig1->remove_condition(condition2a); |
613 | | //emlig1->remove_condition(condition1a); |
614 | | //emlig1->remove_condition(condition5); |
615 | | |
616 | | |
617 | | //emlig1->step_me(0); |
618 | | //emlig2->step_me(0); |
619 | | |
620 | | |
621 | | // DA SE POUZIT PRO VYPIS DO SOUBORU |
622 | | // emlig1->step_me(0); |
623 | | |
624 | | //emlig1->remove_condition(condition1); |
625 | | |
626 | | |
627 | | |
628 | | |
629 | | |
630 | | /* |
631 | | for(int i = 0;i<100;i++) |
632 | | { |
633 | | cout << endl << "Step:" << i << endl; |
634 | | |
635 | | double condition[emlig_size+1]; |
636 | | |
637 | | for(int k = 0;k<=emlig_size;k++) |
638 | | { |
639 | | condition[k] = (rand()-RAND_MAX/2)/1000.0; |
640 | | } |
641 | | |
642 | | |
643 | | vec* condition_vec = new vec(condition,emlig_size+1); |
644 | | emlig1->add_condition(*condition_vec); |
645 | | |
646 | | /* |
647 | | for(polyhedron* toprow_ref = emlig1->statistic.rows[emlig_size]; toprow_ref != emlig1->statistic.end_poly; toprow_ref = toprow_ref->next_poly) |
648 | | { |
649 | | cout << ((toprow*)toprow_ref)->probability << endl; |
650 | | } |
651 | | */ |
652 | | /* |
653 | | cout << emlig1->statistic_rowsize(emlig_size) << endl << endl; |
654 | | |
655 | | /* |
656 | | if(i-emlig1->number_of_parameters >= 0) |
657 | | { |
658 | | pause(30); |
659 | | } |
660 | | */ |
661 | | |
662 | | // emlig1->step_me(i); |
663 | | |
664 | | /* |
665 | | vector<int> sizevector; |
666 | | for(int s = 0;s<=emlig1->number_of_parameters;s++) |
667 | | { |
668 | | sizevector.push_back(emlig1->statistic_rowsize(s)); |
669 | | } |
670 | | */ |
671 | | //} |
672 | | |
673 | | |
674 | | |
675 | | |
676 | | /* |
677 | | emlig1->step_me(1); |
678 | | |
679 | | vec condition = "2.0 0.0 1.0"; |
680 | | |
681 | | emlig1->add_condition(condition); |
682 | | |
683 | | vector<int> sizevector; |
684 | | for(int s = 0;s<=emlig1->number_of_parameters;s++) |
685 | | { |
686 | | sizevector.push_back(emlig1->statistic_rowsize(s)); |
687 | | } |
688 | | |
689 | | emlig1->step_me(2); |
690 | | |
691 | | condition = "2.0 1.0 0.0"; |
692 | | |
693 | | emlig1->add_condition(condition); |
694 | | |
695 | | sizevector.clear(); |
696 | | for(int s = 0;s<=emlig1->number_of_parameters;s++) |
697 | | { |
698 | | sizevector.push_back(emlig1->statistic_rowsize(s)); |
699 | | } |
700 | | */ |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | data_matrix.del_row(0); |
| 357 | } |
| 358 | |
| 359 | |
| 360 | |
| 361 | |