-
Notifications
You must be signed in to change notification settings - Fork 154
/
ComboTrading.cpp
1512 lines (1270 loc) · 64.9 KB
/
ComboTrading.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/************************************************************************
* Copyright(c) 2015, One Unified. All rights reserved. *
* email: info@oneunified.net *
* *
* This file is provided as is WITHOUT ANY WARRANTY *
* without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* This software may not be used nor distributed without proper license *
* agreement. *
* *
* See the file LICENSE.txt for redistribution information. *
************************************************************************/
// started 2015/11/08
#include <memory>
#include <algorithm>
#include <functional>
#include <boost/lexical_cast.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <wx/app.h>
#include <wx/timer.h>
#include <TFTrading/InstrumentManager.h>
#include <TFTrading/AccountManager.h>
#include <TFTrading/OrderManager.h>
#include <TFIQFeed/BuildSymbolName.h>
#include <TFIQFeed/BuildInstrument.h>
#include <TFVuTrading/DragDropInstrument.h>
#include "ComboTrading.h"
/*
* 2019/03/05
* Books of inspiration:
*
* 0470920157 No-Hype Options Trading: Myths, Realities, and Strategies That Really Work == 2011 by Kerry W. Given
* page 108 shows historical volatility chart as backdrop, edge could be used as entry for edges of back spreads
*
* 978-1-118-98058-3 Profiting from Weekly Options == 2015 by Robert J. Seifert
* pg 91 credit spread aka vertical spread
* pg 98 2 to 1 backspread
*
*
* 20160522 Issues:
* don't save without IB contract - should be good now, but validate
* need to watch implied volatility
* LiveChart:
* future with implied volatility curve (pull from HedgedBollinger
* futureoptions, options: track implied volatility
*
*
* 20151109 To Do:
* based upon Day Trading Options by Jeff Augen
* read cboe file and sort symbols - done
* run the pivot scanner, filter by volume and volatility (install in library of scanners)
* or select based upon the c-c, o-c, c-o profiles and volatility surfaces
* sort top and pick 10 symbols (watch daily while building remaining code)
* watch with underlying plus 2 or 3 strike call/puts around at the money (option management)
* select combo and trade/watch the options watched from open (position/portfolio)
* track p/l over the day (portfolio)
* exit at day end, or some minimum profit level with trailing parabolic stop
* build up the volatility indicators mentioned in the boot
* live chart for each symbol and associated combo
* save the values at session end
*
* implied volatility surface: pg 84
* historical volatility calcs: pg 91
* c-c, c-o, o-c hist. vol. calcs: pg 94
* calcs by weekday: pg 99
* strangles better than straddles: pg 108
*
* then chapter 4 working with price spike charts
*
* 20151112 - important steps:
* historical volatility
* track stocks at 20:00 'this all has a familiar ring to it'
* underlying and three strikes at atm. trade them on opening
* track profit over day and exit same day or next day?
* es, gc,
* hard code for now, build up infrastructure, and automate over time
* manually pick the symbols,
* run a process for each and watch
* save at end of day
* wait for flag to exit.
*
* 20151113 most important thing:
* track atm for a series of instruments
* keep a series of trades prepared
* show the intraday price spike charts
*
*/
namespace {
static const std::string c_sDisplayName_App( "Combo Trading" );
static const std::string c_sDisplayName_Vendor( "One Unified Net Limited" );
static const std::string c_sFileName_Base( "ComboTrading" );
//static const std::string c_sDirectory_Base( "../" );
static const std::string c_sFileName_SymbolSubset( c_sFileName_Base + ".ser" );
static const std::string c_sFileName_DataBase( c_sFileName_Base + ".db" );
static const std::string c_sFileName_State( c_sFileName_Base + ".state" );
static const std::string c_sFileName_Series( "/app/" + c_sFileName_Base );
}
IMPLEMENT_APP(AppComboTrading)
const std::string sFileNameMarketSymbolSubset( c_sFileName_SymbolSubset );
bool AppComboTrading::OnInit() {
wxApp::OnInit();
wxApp::SetAppDisplayName( c_sDisplayName_App );
wxApp::SetVendorName( c_sDisplayName_Vendor );
wxApp::SetVendorDisplayName( c_sDisplayName_Vendor );
//bool bExit = GetExitOnFrameDelete();
//SetExitOnFrameDelete( true );
m_pFPP = nullptr;
m_pFOC = nullptr;
m_pFPPOE = nullptr;
m_pMPPOE = nullptr;
m_pPPPOE = nullptr;
m_pCPPOE = nullptr;
m_sizerPM = nullptr;
m_scrollPM = nullptr;
m_sizerScrollPM = nullptr;
m_pLastPPP = nullptr;
m_pFCharts = nullptr;
m_pFInteractiveBrokers = nullptr;
m_pPanelCharts = nullptr;
//m_pPanelOptionCombo = nullptr;
m_pOptionEngine = std::make_unique<ou::tf::option::Engine>( m_fedrate );
m_pOptionEngine->m_fBuildWatch
= [this](pInstrument_t pInstrument)->pWatch_t {
ou::tf::Watch::pWatch_t pWatch( new ou::tf::Watch( pInstrument, m_pData1Provider ) );
return pWatch;
};
m_pOptionEngine->m_fBuildOption
= [this](pInstrument_t pInstrument)->pOption_t {
ou::tf::option::Option::pOption_t pOption( new ou::tf::option::Option( pInstrument, m_pData1Provider ) );
return pOption;
};
m_pFrameMain = new FrameMain( 0, wxID_ANY, c_sDisplayName_App, wxDefaultPosition, wxSize( 800, 1000 ) );
m_pFrameMain->SetName( "primary" );
//std::cout << "frame main: primary" << std::endl;
wxWindowID idFrameMain = m_pFrameMain->GetId();
//m_pFrameMain->Bind( wxEVT_SIZE, &AppStrategy1::HandleFrameMainSize, this, idFrameMain );
//m_pFrameMain->Bind( wxEVT_MOVE, &AppStrategy1::HandleFrameMainMove, this, idFrameMain );
//m_pFrameMain->Bind( wxEVT_MOVE, [this](const wxMoveEvent& event){
// wxPoint point = event.GetPosition();
// std::cout << "FrameMain position: " << point.x << "," << point.y << std::endl;
//}, idFrameMain );
//m_pFrameMain->Center();
//m_pFrameMain->Move( 100, 500 );
//m_pFrameMain->SetSize( 800, 1000 );
SetTopWindow( m_pFrameMain );
//wxPoint posFrameMain = m_pFrameMain->GetPosition();
//std::cout << "Frame Ppsition: " << posFrameMain.x << "," << posFrameMain.y << std::endl;
wxBoxSizer* psizerMain;
psizerMain = new wxBoxSizer(wxVERTICAL);
m_pFrameMain->SetSizer(psizerMain);
wxBoxSizer* m_sizerControls;
m_sizerControls = new wxBoxSizer( wxHORIZONTAL );
psizerMain->Add( m_sizerControls, 0, wxLEFT|wxTOP|wxRIGHT, 5 );
// populate variable in FrameWork01
m_pPanelProviderControl = new ou::tf::PanelProviderControl( m_pFrameMain, wxID_ANY );
m_sizerControls->Add( m_pPanelProviderControl, 0, wxEXPAND|wxRIGHT, 5);
m_pPanelProviderControl->Show( true );
m_tws->SetClientId( 3 );
LinkToPanelProviderControl();
/*
m_pPanelManualOrder = new ou::tf::PanelManualOrder( m_pFrameMain, wxID_ANY );
m_sizerControls->Add( m_pPanelManualOrder, 0, wxEXPAND|wxRIGHT, 5);
m_pPanelManualOrder->Enable( false ); // portfolio isn't working properly with manual order instrument field
//m_pPanelManualOrder->Enable( true ); // portfolio isn't working properly with manual order instrument field
m_pPanelManualOrder->Show( true );
m_pPanelManualOrder->SetOnNewOrderHandler( MakeDelegate( this, &AppComboTrading::HandlePanelNewOrder ) );
m_pPanelManualOrder->SetOnSymbolTextUpdated( MakeDelegate( this, &AppComboTrading::HandlePanelSymbolText ) );
m_pPanelManualOrder->SetOnFocusPropogate( MakeDelegate( this, &AppComboTrading::HandlePanelFocusPropogate ) );
*/
/*
m_pPanelOptionsParameters = new PanelOptionsParameters( m_pFrameMain, wxID_ANY );
m_sizerControls->Add( m_pPanelOptionsParameters, 1, wxEXPAND, 0);
m_pPanelOptionsParameters->Show( true );
m_pPanelOptionsParameters->SetOnStart( MakeDelegate( this, &AppStrategyRunner::HandleBtnStart ) );
m_pPanelOptionsParameters->SetOnStop( MakeDelegate( this, &AppStrategyRunner::HandleBtnStop ) );
m_pPanelOptionsParameters->SetOnSave( MakeDelegate( this, &AppStrategyRunner::HandleBtnSave ) );
m_pPanelOptionsParameters->SetOptionNearDate( boost::gregorian::date( 2012, 4, 20 ) );
m_pPanelOptionsParameters->SetOptionFarDate( boost::gregorian::date( 2012, 6, 15 ) );
*/
wxBoxSizer* m_sizerStatus = new wxBoxSizer( wxHORIZONTAL );
psizerMain->Add( m_sizerStatus, 1, wxEXPAND|wxALL, 5 );
m_pPanelLogging = new ou::tf::PanelLogging( m_pFrameMain, wxID_ANY );
//m_sizerStatus->Add( m_pPanelLogging, 1, wxALL | wxEXPAND, 0);
m_sizerStatus->Add( m_pPanelLogging, 1, wxALL | wxEXPAND, 0);
m_pPanelLogging->Show( true );
m_pFrameMain->Show( true );
// m_idPortfolio = boost::gregorian::to_iso_string( boost::gregorian::day_clock::local_day() ) + "StickShift";
m_idPortfolioMaster = "master"; // keeps name constant over multiple days
//m_bData1Connected = false;
//m_bExecConnected = false;
m_dblMinPL = m_dblMaxPL = 0.0;
m_pIQFeedSymbolListOps = new ou::tf::IQFeedSymbolListOps( m_listIQFeedSymbols );
m_pIQFeedSymbolListOps->Status.connect( [this]( const std::string sStatus ){
CallAfter( [sStatus](){
std::cout << sStatus << std::endl;
});
});
FrameMain::vpItems_t vItemsSymbols;
typedef FrameMain::structMenuItem mi; // vxWidgets takes ownership of the objects
vItemsSymbols.push_back( new mi( "a1 New Symbol List Remote", MakeDelegate( m_pIQFeedSymbolListOps, &ou::tf::IQFeedSymbolListOps::ObtainNewIQFeedSymbolListRemote ) ) );
vItemsSymbols.push_back( new mi( "a2 New Symbol List Local", MakeDelegate( m_pIQFeedSymbolListOps, &ou::tf::IQFeedSymbolListOps::ObtainNewIQFeedSymbolListLocal ) ) );
vItemsSymbols.push_back( new mi( "a3 Load Symbol List", MakeDelegate( m_pIQFeedSymbolListOps, &ou::tf::IQFeedSymbolListOps::LoadIQFeedSymbolList ) ) );
vItemsSymbols.push_back( new mi( "a4 Save Symbol Subset", MakeDelegate( this, &AppComboTrading::HandleMenuActionSaveSymbolSubset ) ) );
vItemsSymbols.push_back( new mi( "a5 Load Symbol Subset", MakeDelegate( this, &AppComboTrading::HandleMenuActionLoadSymbolSubset ) ) );
wxMenu* pMenuSymbols = m_pFrameMain->AddDynamicMenu( "Symbol List", vItemsSymbols );
FrameMain::vpItems_t vItemsActions;
vItemsActions.push_back( new mi( "Federal Funds Yield Curve", MakeDelegate( this, &AppComboTrading::HandleMenuActionEmitYieldCurve ) ) );
//vItems.push_back( new mi( "load weeklies", MakeDelegate( &m_process, &Process::LoadWeeklies ) ) );
vItemsActions.push_back( new mi( "Save Series", MakeDelegate( this, &AppComboTrading::HandleMenuActionSaveSeries ) ) );
//vItems.push_back( new mi( "Load DataBase", MakeDelegate( this, &AppComboTrading::HandleLoadDatabase ) ) );
wxMenu* pMenuActions = m_pFrameMain->AddDynamicMenu( "Actions", vItemsActions );
m_timerGuiRefresh.SetOwner( this );
Bind( wxEVT_TIMER, &AppComboTrading::HandleGuiRefresh, this, m_timerGuiRefresh.GetId() );
m_timerGuiRefresh.Start( 250 );
m_pFrameMain->Bind( wxEVT_CLOSE_WINDOW, &AppComboTrading::OnClose, this ); // start close of windows and controls
m_pFrameMain->SetAutoLayout( true );
m_pFrameMain->Layout();
BuildFrameCharts();
BuildFrameInteractiveBrokers();
BuildFramePortfolioPosition(); // needed by the database loader
BuildFrameOptionCombo(); // this one is having problems
ou::tf::PortfolioManager& pm( ou::tf::PortfolioManager::GlobalInstance() );
pm.OnPortfolioLoaded.Add( MakeDelegate( this, &AppComboTrading::HandlePortfolioLoad ) );
pm.OnPositionLoaded.Add( MakeDelegate( this, &AppComboTrading::HandlePositionLoad ) );
if ( true ) {
m_pFPPOE = new FrameMain( m_pFrameMain, wxID_ANY, "Portfolio/Position/Order/Execution" );
m_pFPPOE->SetName( "PPOE" );
//std::cout << "frame main: ppoe" << std::endl;
m_pMPPOE = new MPPOE_t;
m_pPPPOE = new PPPOE_t( m_pMPPOE, m_pFPPOE );
m_pPPPOE->Show();
m_pCPPOE = new CPPOE_t( m_pMPPOE, m_pPPPOE );
//m_pCPPOE->LoadInitialData();
m_pFPPOE->Show();
}
try {
if ( boost::filesystem::exists( c_sFileName_DataBase ) ) {
// boost::filesystem::remove( sDbName );
}
m_db.OnRegisterTables.Add( MakeDelegate( this, &AppComboTrading::HandleRegisterTables ) );
m_db.OnRegisterRows.Add( MakeDelegate( this, &AppComboTrading::HandleRegisterRows ) );
m_db.SetOnPopulateDatabaseHandler( MakeDelegate( this, &AppComboTrading::HandlePopulateDatabase ) );
m_db.SetOnLoadDatabaseHandler( MakeDelegate( this, &AppComboTrading::HandleLoadDatabase ) );
m_db.Open( c_sFileName_DataBase );
}
catch(...) {
std::cout << "database fault on " << c_sFileName_DataBase << std::endl;
}
m_pFrameMain->Move( 100, 500 );
m_pFrameMain->Raise();
CallAfter(
[this](){
LoadState();
} );
return 1;
}
//int AppComboTrading::OnExit() {
// OnExit is called after destroying all application windows and controls,
// but before wxWidgets cleanup.
//return wxApp::OnExit();
//}
void AppComboTrading::ProvideOptionList( const std::string& sSymbol, ou::tf::PanelCharts::fSymbol_t function ) {
m_listIQFeedSymbols.SelectOptionsByUnderlying( sSymbol, function );
}
void AppComboTrading::BuildFrameInteractiveBrokers( void ) {
m_pFInteractiveBrokers = new FrameMain( m_pFrameMain, wxID_ANY, "Interactive Brokers", wxDefaultPosition, wxSize( 900, 500 ),
wxCAPTION|wxRESIZE_BORDER
);
m_pFInteractiveBrokers->SetName( "IB" );
//std::cout << "frame main: ib" << std::endl;
FrameMain* itemFrame1 = m_pFInteractiveBrokers;
wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
itemFrame1->SetSizer(itemBoxSizer2);
m_splitPanels = new wxSplitterWindow( itemFrame1, wxID_ANY, wxDefaultPosition, wxSize(100, 100), wxSP_LIVE_UPDATE );
m_splitPanels->SetMinimumPaneSize(20);
m_pPanelIBAccountValues = new ou::tf::GridIBAccountValues( m_splitPanels, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
m_pPanelIBAccountValues->SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
m_pPanelIBPositionDetails = new ou::tf::GridIBPositionDetails( m_splitPanels, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
m_pPanelIBPositionDetails->SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
m_splitPanels->SplitVertically(m_pPanelIBAccountValues, m_pPanelIBPositionDetails, 50);
itemBoxSizer2->Add(m_splitPanels, 1, wxGROW|wxALL, 2);
if ( ou::tf::keytypes::EProviderIB == m_pExecutionProvider->ID() ) {
ou::tf::ib::TWS::pProvider_t pProviderIB = ou::tf::ib::TWS::Cast( m_pExecutionProvider );
pProviderIB->OnPositionDetailHandler = MakeDelegate( m_pPanelIBPositionDetails, &ou::tf::GridIBPositionDetails::UpdatePositionDetailRow );
pProviderIB->OnAccountValueHandler = MakeDelegate( m_pPanelIBAccountValues, &ou::tf::GridIBAccountValues::UpdateAccountValueRow );
}
m_pFInteractiveBrokers->SetAutoLayout( true );
m_pFInteractiveBrokers->Layout();
wxPoint point = m_pFCharts->GetPosition();
point.x -= 400;
point.y -= 200;
m_pFInteractiveBrokers->SetPosition( point );
m_pFInteractiveBrokers->Show();
}
void AppComboTrading::BuildFrameCharts( void ) {
m_pFCharts = new FrameMain( m_pFrameMain, wxID_ANY, "Instrument Management", wxDefaultPosition, wxSize( 900, 500 ),
// wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX
wxCAPTION|wxRESIZE_BORDER
);
m_pFCharts->SetName( "charts" );
//std::cout << "frame main: charts" << std::endl;
wxBoxSizer* psizer;
psizer = new wxBoxSizer(wxVERTICAL);
m_pFCharts->SetSizer( psizer );
m_pPanelCharts = new ou::tf::PanelCharts( m_pFCharts, -1, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
psizer->Add(m_pPanelCharts, 1, wxGROW|wxALL, 2);
namespace args = boost::phoenix::placeholders;
m_pPanelCharts->signalRegisterInstrument.connect( boost::phoenix::bind( &AppComboTrading::RegisterInstrument, this, args::arg1 ) ); // use of this signal needs some cleaning
m_pPanelCharts->signalLoadInstrument.connect( boost::phoenix::bind( &AppComboTrading::LoadInstrument, this, args::arg1 ) );
m_pPanelCharts->signalRetrieveOptionList.connect( boost::phoenix::bind( &AppComboTrading::ProvideOptionList, this, args::arg1, args::arg2 ) );
//m_pPanelCharts->SetProviders( m_pData1Provider, m_pData2Provider, m_pExecutionProvider );
m_pPanelCharts->m_fSelectInstrument =
[this](const ou::tf::Allowed::EInstrument selector, const wxString& sUnderlying)->pInstrument_t {
std::shared_ptr<ou::tf::IQFeedInstrumentBuild> pBuild;
pBuild.reset( new ou::tf::IQFeedInstrumentBuild( m_pPanelCharts ) );
namespace ph = std::placeholders;
pBuild->fLookupIQFeedDescription = std::bind( &AppComboTrading::LookupDescription, this, ph::_1, ph::_2 );
pBuild->fBuildInstrument = [this,pBuild](ou::tf::IQFeedInstrumentBuild::ValuesForBuildInstrument& values){
BuildInstrument( values, [pBuild](pInstrument_t pInstrument){
pBuild->InstrumentUpdated( pInstrument ); // this is the call back into the gui when contract id has been populated
});
};
return pBuild->HandleNewInstrumentRequest( selector, sUnderlying );
};
m_pPanelCharts->m_fBuildInstrumentFromIqfeed =
[this](const std::string& sName)->pInstrument_t {
ou::tf::iqfeed::InMemoryMktSymbolList::trd_t trd( m_listIQFeedSymbols.GetTrd( sName ) );
return ou::tf::iqfeed::BuildInstrument( sName, trd );
};
// build the callback for when PanelCharts/GridOptionChain_impl needs to build a full instrument
// for result of drag and drop operations
m_pPanelCharts->m_fBuildOptionInstrument =
// first lambda builds an instrument given IQFeed option name and parameters
// can this use the code from m_fBuildInstrumentFromIqfeed above?
[this](pInstrument_t pUnderlyingInstrument, const std::string& sIQFeedOptionName, boost::gregorian::date date, double strike, ou::tf::PanelCharts::fBuildOptionInstrumentComplete_t f){
ou::tf::iqfeed::InMemoryMktSymbolList::trd_t trd( m_listIQFeedSymbols.GetTrd( sIQFeedOptionName ) ); // TODO: check for errors
std::string sGenericOptionName = ou::tf::Instrument::BuildGenericOptionName( pUnderlyingInstrument->GetInstrumentName(), date.year(), date.month(), date.day(), trd.eOptionSide, strike );
ou::tf::InstrumentManager& im( ou::tf::InstrumentManager::GlobalInstance() );
pInstrument_t pOptionInstrument;
if ( im.Exists( sGenericOptionName, pOptionInstrument ) ) {
if ( nullptr != f ) {
f( pOptionInstrument );
}
}
else {
pOptionInstrument = ou::tf::iqfeed::BuildInstrument( sGenericOptionName, trd, date );
ou::tf::ib::TWS::Contract contract;
contract.conId = pUnderlyingInstrument->GetContract();
// this request uses contract id to obtain basic symbol of the underlying
// TODO: 2018/09/08 this double lookup shouldn't be required, the underlying IB name should be already be stored as an alternate name
m_tws->RequestContractDetails(
contract,
[this, pOptionInstrument, pUnderlyingInstrument, f](const ou::tf::ib::TWS::ContractDetails& details, pInstrument_t& pInstrument){
// the resulting symbol can then be used to plug into the final option request to obtain
// the contract details for the option
pInstrument_t pOptionInstrument_ = pOptionInstrument; // bypasses a const problem through the capture
m_tws->RequestContractDetails(
details.contract.symbol, pOptionInstrument_,
[this, pUnderlyingInstrument, f](const ou::tf::ib::TWS::ContractDetails& details, pInstrument_t& pInstrument){
// the contract details fill in the contract in the instrument, which can then be passed back to the caller
// as a fully defined, registered instrument
RegisterInstrument( pInstrument ); // TODO: does the instrument need to be registered? Is this the best place for this?
if ( nullptr != f ) {
f( pInstrument );
}
},
nullptr // request complete
);
},
nullptr, // request complete
pUnderlyingInstrument );
}
};
m_pPanelCharts->m_fCalcOptionGreek_Add = [this]( pOption_t pOption, pWatch_t pWatchUnderlying ){
m_pOptionEngine->Add( pOption, pWatchUnderlying );
};
m_pPanelCharts->m_fCalcOptionGreek_Remove = [this]( pOption_t pOption, pWatch_t pWatchUnderlying ){
m_pOptionEngine->Remove( pOption, pWatchUnderlying );
};
m_pPanelCharts->m_fBuildOption = [this](pInstrument_t pInstrument, pOption_t& pOption){
pOption = m_pOptionEngine->FindOption( pInstrument );
};
m_pPanelCharts->m_fBuildWatch = [this](pInstrument_t pInstrument, pWatch_t& pWatch){
pWatch = m_pOptionEngine->FindWatch( pInstrument );
};
m_pFCharts->SetAutoLayout( true );
m_pFCharts->Layout();
int ixItem;
// prepended in reverse order
ixItem = m_pFrameMain->AddFileMenuItem( _( "Load Config" ) );
Bind( wxEVT_COMMAND_MENU_SELECTED, &AppComboTrading::HandleLoad, this, ixItem, -1 );
ixItem = m_pFrameMain->AddFileMenuItem( _( "Save Config" ) );
Bind( wxEVT_COMMAND_MENU_SELECTED, &AppComboTrading::HandleSave, this, ixItem, -1 );
wxPoint point = m_pFCharts->GetPosition();
point.x += 400;
point.y += 200;
m_pFCharts->SetPosition( point );
m_pFCharts->Show();
}
AppComboTrading::pInstrument_t AppComboTrading::LoadInstrument( const std::string& name ) {
//std::cout << "AppComboTrading::LoadInstrument: " << name << std::endl;
pInstrument_t p;
ou::tf::InstrumentManager& im( ou::tf::InstrumentManager::GlobalInstance() );
if ( !im.Exists( name, p ) ) { // the call will supply instrument if it exists
throw std::runtime_error( "instrument does not exist" );
}
return p;
}
// todo:
// map of instruments prior to contract
// map of instruments with contract
// map of instruments from instrument manager
void AppComboTrading::BuildInstrument( ou::tf::IQFeedInstrumentBuild::ValuesForBuildInstrument& values, fInstrumentFromIB_t callback ) {
std::cout << "AppComboTrading::BuildInstrument: " << values.sKey << " ";
ou::tf::InstrumentManager& im( ou::tf::InstrumentManager::GlobalInstance() );
if ( im.Exists( values.sKey, values.pInstrument ) ) { // the call will supply instrument if it exists
std::cout << "exists ..." << std::endl;
callback( values.pInstrument );
}
else { // build
std::cout << "build ..." << std::endl;
if ( 0 == m_listIQFeedSymbols.Size() ) {
std::cout << "AppComboTrading::BuildInstrument: m_listIQFeedSymbols not loaded" << std::endl;
}
else {
typedef ou::tf::iqfeed::InMemoryMktSymbolList list_t;
typedef list_t::trd_t trd_t;
const trd_t& trd( m_listIQFeedSymbols.GetTrd( values.sIQF ) );
switch ( trd.sc ) {
case ou::tf::iqfeed::ESecurityType::Equity:
case ou::tf::iqfeed::ESecurityType::IEOption:
values.pInstrument = ou::tf::iqfeed::BuildInstrument( values.sKey, trd );
break;
case ou::tf::iqfeed::ESecurityType::Future:
case ou::tf::iqfeed::ESecurityType::FOption:
// TODO: will need to change this to match what is in BasketTrading for creation from fundamentals
values.pInstrument = ou::tf::iqfeed::BuildInstrument( values.sKey, trd, boost::gregorian::date( trd.nYear, trd.nMonth, values.day ) ); // for ib future/fo overrides not supplied by trd
break;
default:
throw std::runtime_error( "ppComboTrading::BuildInstrument: can't process the default" );
}
GetContractFor( values.sIB, values.pInstrument, callback );
}
}
}
void AppComboTrading::BuildFramePortfolioPosition( void ) {
m_pFPP = new FrameMain( m_pFrameMain, wxID_ANY, "Portfolio Management", wxDefaultPosition, wxSize( 900, 500 ),
// wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX
wxCAPTION|wxRESIZE_BORDER
);
m_pFPP->SetName( "portfolio" );
//std::cout << "frame main: portfolio" << std::endl;
m_pFPP->SetAutoLayout( true );
m_sizerPM = new wxBoxSizer(wxVERTICAL);
m_pFPP->SetSizer(m_sizerPM);
//m_scrollPM is used for holding the PanelPortfolioPosition instances
m_scrollPM = new wxScrolledWindow( m_pFPP, -1, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
m_sizerPM->Add(m_scrollPM, 1, wxGROW|wxALL, 5);
//m_scrollPM->SetScrollbars(1, 1, 0, 0);
m_scrollPM->SetScrollRate(4, 4);
m_sizerScrollPM = new wxBoxSizer(wxVERTICAL);
m_scrollPM->SetSizer( m_sizerScrollPM );
wxPoint point = m_pFPP->GetPosition();
point.x += 500;
point.y += 100;
m_pFPP->SetPosition( point );
m_pFPP->Show();
m_pFPP->Layout();
}
void AppComboTrading::BuildFrameOptionCombo() {
m_pFOC = new FrameMain( m_pFrameMain, wxID_ANY, "Option Combo Sandbox", wxDefaultPosition, wxSize( 900, 500 ),
// wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX
wxCAPTION|wxRESIZE_BORDER
);
m_pFOC->SetName( "sandbox" );
//std::cout << "frame main: sandbox" << std::endl;
m_pFOC->SetAutoLayout( true );
m_sizerFOC = new wxBoxSizer( wxVERTICAL );
m_pFOC->SetSizer( m_sizerFOC );
//m_scrollOC is used for holding the pPanelOptionCombo instances
m_scrollFOC = new wxScrolledWindow( m_pFOC, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
m_sizerFOC->Add(m_scrollFOC, 1, wxGROW|wxALL, 4);
//m_scrollFOC->SetScrollbars(5, 5, 10, 10);
m_scrollFOC->SetScrollRate(4, 4);
m_sizerScrollOC = new wxBoxSizer( wxVERTICAL );
m_scrollFOC->SetSizer( m_sizerScrollOC );
wxPoint point = m_pFOC->GetPosition();
point.x += 700;
point.y += 200;
m_pFOC->SetPosition( point );
m_pFOC->Show();
HandleNewPanelOptionCombo( idPortfolio_t( "sandbox" ), "experimenting with option combinations" );
m_pFOC->Layout();
}
AppComboTrading::pPanelOptionCombo_t AppComboTrading::HandleNewPanelOptionCombo( const idPortfolio_t& idPortfolio, const std::string& sDescription ) {
typedef ou::tf::PortfolioGreek::pPortfolioGreek_t pPortfolioGreek_t;
typedef ou::tf::PositionGreek::pPositionGreek_t pPositionGreek_t;
pPanelOptionCombo_t pPanelOptionCombo;
pPanelOptionCombo = new ou::tf::PanelOptionCombo( m_scrollFOC ); // start with one empty portfolio
pPanelOptionCombo->m_fBootStrapNextPanelOptionCombo = [this](const idPortfolio_t& idPortfolio_, const std::string& sDescription_){
HandleNewPanelOptionCombo( idPortfolio_, sDescription_ );
};
pPanelOptionCombo->m_fConstructPortfolioGreek = [this](ou::tf::PanelOptionCombo& poc, const idPortfolio_t& idPortfolio, const std::string& sDescription){
if ( idPortfolio.empty() ) {
std::cout << "portfolio id is required" << std::endl;
}
else {
mapPortfoliosSandbox_t::iterator iter = m_mapPortfoliosSandbox.find( idPortfolio );
if ( m_mapPortfoliosSandbox.end() == iter ) {
pPortfolioGreek_t pPortfolioGreek( new ou::tf::PortfolioGreek(
idPortfolio, ou::tf::PortfolioGreek::idAccountOwner_t( "none" ), idPortfolio_t( "self" ),
ou::tf::Portfolio::EPortfolioType::Standard, "USD", sDescription
) );
poc.SetPortfolioGreek( pPortfolioGreek );
m_mapPortfoliosSandbox.insert( mapPortfoliosSandbox_t::value_type( pPortfolioGreek->Id(), structPortfolioSandbox( &poc ) ) );
}
else {
std::cout << "portfolio id " << idPortfolio << " already exists" << std::endl;
}
}
m_pFOC->Layout();
//m_sizerScrollOC->Layout();
};
pPanelOptionCombo->m_fConstructPositionGreek
= [this](pInstrument_t pOptionInstrument, pInstrument_t pUnderlyingInstrument, pPortfolioGreek_t pPortfolioGreek, ou::tf::PanelOptionCombo::fAddPositionGreek_t f) {
// convert OptionInstrument to option_t, convert UnderlyingInstrument to watch_t
// register with engine
ou::tf::InstrumentManager& im( ou::tf::InstrumentManager::GlobalInstance() );
if ( im.Exists( pOptionInstrument ) ) {
// is typically built at the m_pPanelCharts->m_fBuildOptionInstrument point in time
//std::cout << "### verify the code at m_fConstructPositionGreek as instrument exists: " << pInstrument->GetInstrumentName() << " ###" << std::endl;
}
else {
std::cout << "AppComboTrading::BuildFrameOptionCombo: registering " << pOptionInstrument->GetInstrumentName() << ", should have been accomplished prior to this?" << std::endl;
im.Register( pOptionInstrument );
}
assert( 0 != pUnderlyingInstrument.use_count() );
assert( 0 != pUnderlyingInstrument.get() );
pWatch_t pWatch = m_pOptionEngine->FindWatch( pUnderlyingInstrument ); // construct watch from instrument
assert( 0 != pWatch.use_count() );
assert( 0 != pWatch.get() );
assert( 0 != pOptionInstrument.use_count() );
assert( 0 != pOptionInstrument.get() );
pOption_t pOption = m_pOptionEngine->FindOption( pOptionInstrument ); // construct option from instrument
assert( 0 != pOption.use_count() );
assert( 0 != pOption.get() );
pPositionGreek_t pPositionGreek( new ou::tf::PositionGreek( pOption, pWatch ) );
pPortfolioGreek->AddPosition( pOptionInstrument->GetInstrumentName(), pPositionGreek );
if ( nullptr != f )
f( pPositionGreek );
// position needs to start the watch, needs both option and underlying
// then add to engine here? who removes from engine? does the panel manage the list
};
pPanelOptionCombo->m_fSelectInstrument = [this]()->pInstrument_t {
namespace ph = std::placeholders;
std::shared_ptr<ou::tf::IQFeedInstrumentBuild> pBuild;
pBuild.reset( new ou::tf::IQFeedInstrumentBuild( m_pLastPPP ) );
pBuild->fLookupIQFeedDescription = std::bind( &AppComboTrading::LookupDescription, this, ph::_1, ph::_2 );
pBuild->fBuildInstrument = [this,pBuild](ou::tf::IQFeedInstrumentBuild::ValuesForBuildInstrument& values){
BuildInstrument( values, [pBuild](pInstrument_t pInstrument){
pBuild->InstrumentUpdated( pInstrument ); // this is the call back into the gui when contract id has been populated
});
};
return pBuild->HandleNewInstrumentRequest( ou::tf::Allowed::All, "" ); // the dialog pops up in this call
};
pPanelOptionCombo->m_fColumnWidthChanged = [this](int nColumn, int width, ou::tf::PanelOptionCombo& poc){
poc.SaveColumnSizes( m_gcsPanelOptionCombo );
UpdateColumns_PanelOptionCombo();
};
namespace ph = std::placeholders;
pPanelOptionCombo->m_fRegisterWithEngine = std::bind( &ou::tf::option::Engine::Add, m_pOptionEngine.get(), ph::_1, ph::_2 );
pPanelOptionCombo->m_fRemoveFromEngine = std::bind( &ou::tf::option::Engine::Remove, m_pOptionEngine.get(), ph::_1, ph::_2 );
pPanelOptionCombo->m_fLookUpInstrument = [this](const idInstrument_t& idInstrument, pInstrument_t& pInstrument)->pInstrument_t {
ou::tf::InstrumentManager& im( ou::tf::InstrumentManager::GlobalInstance() );
if ( im.Exists( idInstrument, pInstrument ) ) {
// all is good, pInstrument is assigned
}
else {
std::string message( "pPOC->m_fLookUpInstrument can't find " );
message += idInstrument;
throw std::runtime_error( message );
}
return pInstrument;
};
pPanelOptionCombo->m_fConstructPortfolioGreek( *pPanelOptionCombo, idPortfolio, sDescription );
//wxBoxSizer* pSizer = new wxBoxSizer(wxHORIZONTAL);
//m_sizerScrollOC->Add( pSizer, 1, wxGROW|wxALL, 1 );
//pSizer->Add( pPanelOptionCombo, 1, wxALL|wxEXPAND, 1);
//m_sizerScrollOC->Add( pPanelOptionCombo, 0, wxALL|wxGROW, 6 );
pPanelOptionCombo->AssignToSizer( m_sizerScrollOC );
m_sizerScrollOC->Layout();
return pPanelOptionCombo;
}
// 20151124 priority: get the symbols tracking, draw charts, and watch volatility on futures and equities
// 20151128 use the code in start to obtain the symbol info for populating the portfolio/position info
void AppComboTrading::TestSymbols( void ) {
// need iqfeed marketsymbols to be loaded before this can start
if ( 0 == m_listIQFeedSymbols.Size() )
throw std::runtime_error( "iqfeed market symbols need to be loaded first" );
// if ( !m_bStarted ) {
if ( true ) {
try {
// new stuff
// the cycle being:
// build the iqfeed instrument
// send it off to ib to get the contract
// then get it into multi-expiry
// then start building the options
// calculate expiry and flesh out bundle
// but also may be working with portfolio/position situations
struct Symbol {
std::string sName;
std::string sIq;
std::string sIb;
Symbol( const std::string& sName_ ): sName( sName_ ), sIq( sName_ ), sIb( sName_ ) {};
Symbol( const std::string& sName_, const std::string& sIq_, const std::string& sIb_ ):
sName( sName_ ), sIq( sIq_ ), sIb( sIb_ ) {};
};
typedef std::vector<Symbol> vSymbol_t;
vSymbol_t vSymbol;
// list of equities to monitor
vSymbol.push_back( Symbol( "GLD" ) );
// create generic symbol: futures and equities, and possibly from weeklies
struct Future {
std::string sName;
std::string sIqBaseName;
boost::uint16_t nYear;
boost::uint8_t nMonth;
std::string sIbBaseName;
Future(
const std::string& sName_, const std::string& sIqBaseName_,
boost::uint16_t nYear_, boost::uint8_t nMonth_,
const std::string& sIbBaseName_ ):
sName( sName_ ), sIqBaseName( sIqBaseName_ ),
nYear( nYear_ ), nMonth( nMonth_ ),
sIbBaseName( sIbBaseName_ )
{}
};
typedef std::vector<Future> vFuture_t;
vFuture_t vFuture;
// list of futures to monitor
vFuture.push_back( Future( "GC-2015-12", "QGC", 2015, 12, "GC" ) );
// build futures name and add to vSymbol
// ie, create the iqfeed name for the future, then pass off the name for instrument building
for ( vFuture_t::const_iterator iter = vFuture.begin(); vFuture.end() != iter; ++iter ) {
std::string sName = ou::tf::iqfeed::BuildFuturesName( iter->sIqBaseName, iter->nYear, iter->nMonth );
vSymbol.push_back( Symbol( iter->sName, sName, iter->sIbBaseName ) );
}
// 20151122 build list of options to monitor as well
// then can mix and match into positions and portfolios
// which implies ...
// need some structures here to assign the code seeded/generated portfolio and position combinations
// then can generify stuff and get into a separate compilation unit
struct Option {
std::string sName;
std::string sIqBaseName;
ou::tf::OptionSide::EOptionSide side;
double dblStrike;
boost::uint16_t nYear;
boost::uint8_t nMonth;
boost::uint8_t nDay;
std::string sIbBaseName;
Option( const std::string& sName_, ou::tf::OptionSide::EOptionSide side_,
const std::string& sIqBaseName_, const std::string& sIbBaseName_,
boost::uint16_t nYear_, boost::uint8_t nMonth_, boost::uint8_t nDay_, double dblStrike_ ):
sName( sName_ ), side( side_ ),
sIqBaseName( sIqBaseName_ ), sIbBaseName( sIbBaseName_ ),
nYear( nYear_ ), nMonth( nMonth_ ), nDay( nDay_ ), dblStrike( dblStrike ) {}
};
typedef std::vector<Option> vOption_t;
vOption_t vOption;
vOption.push_back( Option( "GLD-P-2015-12-11-112.0", ou::tf::OptionSide::Call, "GLD", "GLD", 2015, 12, 11, 112.0 ) );
for ( vOption_t::const_iterator iter = vOption.begin(); vOption.end() != iter; ++iter ) {
std::string sName =
ou::tf::iqfeed::BuildOptionName( iter->sIqBaseName, iter->nYear, iter->nMonth, iter->nDay, iter->dblStrike, iter->side );
vSymbol.push_back( Symbol( iter->sName, sName, iter->sIbBaseName ) );
}
// 20151122 at this point, we have our own instrument names, the names to be used for
// registering, so at this point, we can perform a retrieval, or build new ones.
// some may need some building, some may need retrieval
// 2015/11/22 take this code and put into module as it will be re-used not only in startup
// but in other real time locations
{
namespace args = boost::phoenix::placeholders;
typedef boost::function<void ( pInstrument_t)> cbInstrument_t;
// function object for building instruments from a list
struct BuildInstrument {
typedef ou::tf::Instrument::pInstrument_t pInstrument_t;
typedef ou::tf::iqfeed::InMemoryMktSymbolList list_t;
typedef list_t::trd_t trd_t;
const list_t& list;
cbInstrument_t f;
BuildInstrument( const list_t& list_, cbInstrument_t f_ ): list( list_ ), f( f_ ) {};
void operator()( const Symbol& u ) {
pInstrument_t pInstrument;
const trd_t& trd( list.GetTrd( u.sIq ) );
switch ( trd.sc ) {
case ou::tf::iqfeed::ESecurityType::Equity:
case ou::tf::iqfeed::ESecurityType::Future:
pInstrument = ou::tf::iqfeed::BuildInstrument( u.sName, trd );
// now hand it off to the IB for contract insertion
f( pInstrument );
break;
case ou::tf::iqfeed::ESecurityType::IEOption:
// will need to check that Symbol is registered and available in order to build
throw std::runtime_error( "can't process the BuildInstrument IEOption" );
break;
case ou::tf::iqfeed::ESecurityType::FOption:
throw std::runtime_error( "can't process the BuildInstrument FOption" );
break;
default:
throw std::runtime_error( "can't process the BuildInstrument default" );
}
}
};
// build instruments.. equities and futures, then pass to the bundle to fill in the options
// in GetContractFor, need to see if the instrument already exists, or is this done up above somewhere?
struct GetInstrument {
typedef ou::tf::iqfeed::InMemoryMktSymbolList list_t;
BuildInstrument build;
cbInstrument_t cbBundle;
GetInstrument( const list_t& list_, cbInstrument_t cbContract, cbInstrument_t cbBundle_ ): build( list_, cbContract ), cbBundle( cbBundle_ ) {}
void operator()( const Symbol& u ) {
// see if the instrument already exists,
ou::tf::InstrumentManager& im( ou::tf::InstrumentManager::GlobalInstance() );
ou::tf::Instrument::pInstrument_t pInstrument; //empty instrument
if ( im.Exists( u.sName, pInstrument ) ) { // the call will supply instrument if it exists
cbBundle( pInstrument );
}
else {
build( u );
}
}
};
// 20151227 broke this with IB symbol changes
// std::for_each( vSymbol.begin(), vSymbol.end(),
// GetInstrument( m_listIQFeedSymbols,
// boost::phoenix::bind( &AppComboTrading::GetContractFor, this, args::arg1 ),
// boost::phoenix::bind( &AppComboTrading::LoadUpBundle, this, args::arg1 )
// )
// );
}
}
catch (...) {
std::cout << "problems with AppStickShift::Start" << std::endl;
}
}
}
void AppComboTrading::GetContractFor( const std::string& sBaseName, pInstrument_t pInstrument, fInstrumentFromIB_t callback ) {
if ( m_bIBConnected ) {
m_tws->RequestContractDetails(
sBaseName, pInstrument,
[this, callback]( const ou::tf::ib::TWS::ContractDetails& details, pInstrument_t& pInstrument ){
CallAfter([callback, pInstrument](){ // put into GUI thread
callback( pInstrument );
});
},
[]( bool ){}
);
}
else {
std::cout << "AppComboTrading::GetContractFor: IB Not Connected" << std::endl;
}
}
// futures expire: 17:15 est
// foption expire: 13:30 est
// option expire: 16:00 est
// holiday expire: 13:00 est 2015/11/27 - weekly option
void AppComboTrading::RegisterInstrument( pInstrument_t pInstrument ) {
//std::cout << "AppComboTrading::RegisterInstrument: " << pInstrument->GetInstrumentName() << std::endl;
ou::tf::InstrumentManager& im( ou::tf::InstrumentManager::GlobalInstance() );
if ( im.Exists( pInstrument ) ) {
//std::cout << "Info: Instrument already registered: " << pInstrument->GetInstrumentName() << std::endl;
// now there are duplicate instruments. replace inbound with the one registered?
}
else {
assert( 0 != pInstrument->GetContract() );
im.Register( pInstrument );
//std::cout << "Info: Instrument/Contract registered: " << pInstrument->GetInstrumentName() << std::endl;
}
}
// this may need to steal code from ConstructEquityPosition0, and ConstructEquityPosition1
void AppComboTrading::LoadUpBundle( ou::tf::Instrument::pInstrument_t pInstrument ) {
// 2015/11/22 need to fix this code up
BundleTracking::BundleDetails details( "GC", "QGC" );
// need to figure out proper expiry time
// also need to figure if more options can be watched in order to provide volatility surfaces
// I think I have a day calculator (which doesn't know holidays though )
// and will need to convert to utc
// if there are many symbols, strikes, and expiries, may need to run a different thread for calculating the greeks and IV
boost::gregorian::date expiry2( boost::gregorian::date( 2015, 12, 28 ) );
details.vOptionExpiryDay.push_back( expiry2 );
boost::gregorian::date expiry3( boost::gregorian::date( 2016, 1, 26 ) );
details.vOptionExpiryDay.push_back( expiry3 );
m_vBundleTracking.push_back( BundleTracking( "GC" ) ); // can I do some sort of move semantics here?
m_vBundleTracking.back().SetBundleParameters( details );
}
void AppComboTrading::UpdateColumns_PanelPortfolioPositions() {
std::for_each( m_mapPortfoliosTrading.begin(), m_mapPortfoliosTrading.end(),
[this](mapPortfoliosTrading_t::value_type& vt){
vt.second.pT->SetColumnSizes( m_gcsPanelPortfolioPosition );
});
}
void AppComboTrading::UpdateColumns_PanelOptionCombo() {
std::for_each( m_mapPortfoliosSandbox.begin(), m_mapPortfoliosSandbox.end(), [this](mapPortfoliosSandbox_t::value_type& vt){
vt.second.pT->SetColumnSizes( m_gcsPanelOptionCombo );
} );
}
void AppComboTrading::HandlePortfolioLoad( pPortfolio_t& pPortfolio ) {
m_pLastPPP = new ou::tf::PanelPortfolioPosition( m_scrollPM );
m_pLastPPP->SetColumnSizes( m_gcsPanelPortfolioPosition );
m_pLastPPP->m_fColumnWidthChanged = [this](int nColumn, int width, ou::tf::PanelPortfolioPosition& ppp ){
ppp.SaveColumnSizes( m_gcsPanelPortfolioPosition );
UpdateColumns_PanelPortfolioPositions();
};
m_sizerScrollPM->Add( m_pLastPPP, 1, wxALL|wxEXPAND, 0);
m_sizerScrollPM->Layout();
std::cout
<< "Adding Portfolio: "
<< "T=" << pPortfolio->GetRow().ePortfolioType
<< ",O=" << pPortfolio->GetRow().idOwner
<< ",ID=" << pPortfolio->GetRow().idPortfolio
<< std::endl;
namespace ph = std::placeholders;
m_pLastPPP->SetPortfolio( pPortfolio );
m_pLastPPP->m_fConstructPortfolio = std::bind( &AppComboTrading::HandleConstructPortfolio, this, ph::_1, ph::_2, ph::_3 );
m_pLastPPP->m_fConstructPosition = std::bind( &AppComboTrading::ConstructEquityPosition1b, this, ph::_1, ph::_2, ph::_3 ); // something to be fixed here?
m_pLastPPP->m_fSelectInstrument =
[this]()->pInstrument_t {
std::shared_ptr<ou::tf::IQFeedInstrumentBuild> pBuild;