-
Notifications
You must be signed in to change notification settings - Fork 154
/
ComboTrading.h
354 lines (274 loc) · 11.7 KB
/
ComboTrading.h
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
/************************************************************************
* 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. *
************************************************************************/
#pragma once
#include <map>
#include <vector>
#include <memory>
#include <functional>
#include <boost/serialization/version.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/thread.hpp>
#include <wx/splitter.h>
#include <OUCommon/Worker.h>
#include <TFTrading/DBOps.h>
#include <TFTrading/PortfolioManager.h>
#include <TFOptions/Engine.h>
#include <TFOptions/NoRiskInterestRateSeries.h>
#include <TFVuTrading/FrameMain.h>
#include <TFVuTrading/PanelLogging.h>
#include <TFVuTrading/PanelManualOrder.h>
#include <TFVuTrading/PanelOptionCombo.h>
#include <TFVuTrading/PanelPortfolioPosition.h>
#include <TFVuTrading/GridColumnSizer.h>
#include <TFVuTrading/GridIBPositionDetails.h>
#include <TFVuTrading/GridIBAccountValues.h>
#include <TFVuTrading/ModelPortfolioPositionOrderExecution.h>
#include <TFVuTrading/PanelPortfolioPositionOrderExecution.h>
#include <TFVuTrading/ControllerPortfolioPositionOrderExecution.h>
#include <TFBitsNPieces/FrameWork01.h>
#include <TFBitsNPieces/IQFeedSymbolListOps.h>
#include <TFBitsNPieces/IQFeedInstrumentBuild.h>
#include "Process.h"
#include "PanelCharts.h"
#include "BundleTracking.h"
/// \brief Option Combo Trading, code started 2015/11/08
///
/// Based upon the book 'Day Trading Options' by Jeff Augen
class AppComboTrading:
public wxApp, public ou::tf::FrameWork01<AppComboTrading> {
friend class boost::serialization::access;
friend ou::tf::FrameWork01<AppComboTrading>;
public:
protected:
private:
typedef ou::tf::Portfolio::idPortfolio_t idPortfolio_t;
typedef ou::tf::Portfolio::pPortfolio_t pPortfolio_t;
typedef ou::tf::Position::pPosition_t pPosition_t;
typedef ou::tf::ModelPortfolioPositionOrderExecution MPPOE_t;
typedef ou::tf::PanelPortfolioPositionOrderExecution PPPOE_t;
typedef ou::tf::ControllerPortfolioPositionOrderExecution CPPOE_t;
typedef ou::tf::Instrument::idInstrument_t idInstrument_t;
typedef ou::tf::Instrument::pInstrument_t pInstrument_t;
typedef ou::tf::Watch::pWatch_t pWatch_t;
typedef ou::tf::option::Option::pOption_t pOption_t;
typedef ou::tf::PanelPortfolioPosition::fAddPosition_t fAddPostion_t;
typedef std::vector<BundleTracking> vBundleTracking_t;
typedef std::function<void(pInstrument_t)> fInstrumentFromIB_t;
struct structManualOrder {
// ou::tf::PanelManualOrder* pDialogManualOrder;
ou::tf::ib::TWS::ContractDetails details;
pInstrument_t pInstrument;
} m_IBInstrumentInfo;
struct structConstructEquityPosition {
pPortfolio_t pPortfolio;
fAddPostion_t fAddPosition;
//DelegateAddPosition_t function;
} m_EquityPositionCallbackInfo;
template<typename T>
struct structAutoNull {
T* pT;
structAutoNull(): pT( nullptr ) {}
structAutoNull( T* pT_ ): pT( pT_ ) {}
~structAutoNull() { pT = nullptr; }
};
typedef structAutoNull<ou::tf::PanelPortfolioPosition> structPortfolioTrading;
typedef structAutoNull<ou::tf::PanelOptionCombo> structPortfolioSandbox;
typedef std::map<std::string,structPortfolioTrading> mapPortfoliosTrading_t;
typedef std::map<std::string,structPortfolioSandbox> mapPortfoliosSandbox_t;
ou::action::Worker m_worker;
wxTimer m_timerGuiRefresh;
double m_dblMaxPL;
double m_dblMinPL;
//ou::tf::LiborFromIQFeed m_libor; // deprecated
ou::tf::FedRateFromIQFeed m_fedrate;
std::unique_ptr<ou::tf::option::Engine> m_pOptionEngine;
Process m_process; // single position
vBundleTracking_t m_vBundleTracking; // one per underlying and related options to track
ou::tf::keytypes::idPortfolio_t m_idPortfolioMaster;
pPortfolio_t m_pPortfolioMaster;
mapPortfoliosTrading_t m_mapPortfoliosTrading;
mapPortfoliosSandbox_t m_mapPortfoliosSandbox;
ou::tf::PanelPortfolioPosition* m_pLastPPP; // helps getting new positions to correct window
FrameMain* m_pFrameMain;
FrameMain* m_pFPP;
FrameMain* m_pFPPOE;
FrameMain* m_pFCharts;
FrameMain* m_pFInteractiveBrokers;
FrameMain* m_pFOC;
ou::tf::PanelCharts* m_pPanelCharts;
// PanelOptionsParameters* m_pPanelOptionsParameters;
ou::tf::PanelLogging* m_pPanelLogging;
ou::tf::PanelManualOrder* m_pPanelManualOrder;
//ou::tf::PanelOptionCombo* m_pPanelOptionCombo;
typedef ou::tf::PanelOptionCombo PanelOptionCombo;
typedef PanelOptionCombo* pPanelOptionCombo_t;
//typedef std::vector<PanelOptionCombo*> vPanelOptionCombo_t;
//vPanelOptionCombo_t m_vPanelOptionCombo;
MPPOE_t* m_pMPPOE;
PPPOE_t* m_pPPPOE;
CPPOE_t* m_pCPPOE;
wxSplitterWindow* m_splitPanels;
ou::tf::GridIBAccountValues* m_pPanelIBAccountValues;
ou::tf::GridIBPositionDetails* m_pPanelIBPositionDetails;
wxBoxSizer* m_sizerPM;
wxScrolledWindow* m_scrollPM;
wxBoxSizer* m_sizerScrollPM;
ou::tf::GridColumnSizer m_gcsPanelPortfolioPosition;
ou::tf::GridColumnSizer m_gcsPanelOptionCombo;
ou::tf::DBOps m_db;
wxBoxSizer* m_sizerFOC;
wxScrolledWindow* m_scrollFOC;
wxBoxSizer* m_sizerScrollOC;
ou::tf::iqfeed::InMemoryMktSymbolList m_listIQFeedSymbols;
ou::tf::IQFeedSymbolListOps* m_pIQFeedSymbolListOps;
ou::tf::IQFeedSymbolListOps::vExchanges_t m_vExchanges;
ou::tf::IQFeedSymbolListOps::vClassifiers_t m_vClassifiers;
void LookupDescription( const std::string& sSymbolName, std::string& sDescription );
void BuildInstrument( ou::tf::IQFeedInstrumentBuild::ValuesForBuildInstrument&, fInstrumentFromIB_t );
void RegisterInstrument( pInstrument_t );
pInstrument_t LoadInstrument( const std::string& );
void HandleSave( wxCommandEvent& event );
void HandleLoad( wxCommandEvent& event );
void GetContractFor( const std::string& sBaseName, pInstrument_t pInstrument, fInstrumentFromIB_t );
void LoadUpBundle( ou::tf::Instrument::pInstrument_t pInstrument );
void ConstructEquityPosition1a( const std::string& sName, pPortfolio_t, fAddPostion_t); // step 1
void ConstructEquityPosition1b( pInstrument_t, pPortfolio_t, fAddPostion_t); // step 1
void ConstructEquityPosition2( pInstrument_t& pInstrument ); // step 2
virtual bool OnInit();
//virtual int OnExit();
virtual void OnAssertFailure( const wxChar*, int, const wxChar*, const wxChar*, const wxChar* );
//virtual void HandleEvent( wxEvtHandler*, wxEventFunction, wxEvent& ) const;
void OnClose( wxCloseEvent& event );
void TestSymbols( void );
void HandleMenuActionEmitYieldCurve( void );
void HandleMenuActionSaveSeries( void );
void HandleSaveValues( void );
void BuildFrameCharts( void );
void BuildFramePortfolioPosition( void );
void BuildFrameInteractiveBrokers( void );
void BuildFrameOptionCombo( void );
void HandlePanelNewOrder( const ou::tf::PanelManualOrder::Order_t& order );
void HandlePanelSymbolText( const std::string& sName ); // use IB to start, use IQFeed symbol file later on
void HandlePanelFocusPropogate( unsigned int ix );
void OnData1Connecting( int );
void OnData1Connected( int );
void OnData1Disconnecting( int );
void OnData1Disconnected( int );
void OnExecConnecting( int );
void OnExecConnected( int );
void OnExecDisconnecting( int );
void OnExecDisconnected( int );
void OnIQFeedConnected( int );
void OnIQFeedDisconnecting( int );
void HandleSaveButton( void );
void HandlePopulateDatabase( void );
void HandleLoadDatabase( void );
void HandleRegisterTables( ou::db::Session& session );
void HandleRegisterRows( ou::db::Session& session );
void HandleGuiRefresh( wxTimerEvent& event );
void HandlePortfolioLoad( pPortfolio_t& pPortfolio );
void HandlePositionLoad( pPosition_t& pPosition );
void ProvideOptionList( const std::string& sSymbol, ou::tf::PanelCharts::fSymbol_t );
// void HandleMenuActionInitializeSymbolSet();
void HandleMenuActionSaveSymbolSubset();
void HandleMenuActionLoadSymbolSubset();
pPanelOptionCombo_t HandleNewPanelOptionCombo( const idPortfolio_t& idPortfolio, const std::string& sDescription );
void HandleConstructPortfolio( ou::tf::PanelPortfolioPosition&,const std::string&, const std::string& ); // portfolioid, description
void UpdateColumns_PanelPortfolioPositions();
void UpdateColumns_PanelOptionCombo();
void SaveState();
void LoadState();
template<typename Archive>
void save( Archive& ar, const unsigned int version ) const {
//ar & boost::serialization::base_object<const TreeItemResources>(*this);
ar & *m_pFrameMain;
ar & *m_pFCharts;
ar & *m_pFInteractiveBrokers;
ar & *m_pFPP;
ar & *m_pFOC;
ar & *m_pFPPOE;
ar & m_splitPanels->GetSashPosition();
ar & *m_pPanelIBAccountValues;
ar & *m_pPanelIBPositionDetails;
ar & *m_pPanelCharts;
ar & m_mapPortfoliosSandbox.size();
std::for_each( m_mapPortfoliosSandbox.begin(), m_mapPortfoliosSandbox.end(), [&ar](const mapPortfoliosSandbox_t::value_type& vt){
ar & vt.first;
ar & *vt.second.pT;
});
ar & m_gcsPanelPortfolioPosition;
ar & m_gcsPanelOptionCombo;
}
template<typename Archive>
void load( Archive& ar, const unsigned int version ) {
//ar & boost::serialization::base_object<TreeItemResources>(*this);
ar & *m_pFrameMain;
ar & *m_pFCharts;
ar & *m_pFInteractiveBrokers;
if ( 3 <= version ) {
ar & *m_pFPP;
}
if ( 4 <= version ) {
ar & *m_pFOC;
}
if ( 2 <= version ) {
ar & *m_pFPPOE;
}
int x;
ar & x;
m_splitPanels->SetSashPosition( x );
ar & *m_pPanelIBAccountValues;
ar & *m_pPanelIBPositionDetails;
if ( 5 <= version ) {
ar & *m_pPanelCharts;
}
if ( 8 <= version ) {
mapPortfoliosSandbox_t::size_type size;
ar & size;
assert( 1 <= size ); // ComboTrading creates at least one panel
ou::tf::PortfolioGreek::idPortfolio_t idPortfolio;
ar & idPortfolio; // discard the first idPortfolio
ar & *m_mapPortfoliosSandbox.begin()->second.pT; // recreate the prebuilt entry
size--; // account for the prebuilt entry
for ( mapPortfoliosSandbox_t::size_type ix = 0; ix < size; ix++ ) {
ar & idPortfolio;
pPanelOptionCombo_t pPanelOptionCombo;
pPanelOptionCombo = HandleNewPanelOptionCombo( idPortfolio, "" );
ar & *pPanelOptionCombo;
//m_sizerScrollOC->FitInside( pPanelOptionCombo );
//m_sizerFOC->FitInside( m_scrollFOC );
}
}
else {
if ( 7 <= version ) {
//pPanelOptionCombo_t pPanelOptionCombo;
//pPanelOptionCombo = HandleNewPanelOptionCombo( "sandbox", "pre-load" );
ar & *m_mapPortfoliosSandbox.begin()->second.pT; // should only be one entry;
}
}
if ( 6 <= version ) {
ar & m_gcsPanelPortfolioPosition;
UpdateColumns_PanelPortfolioPositions();
ar & m_gcsPanelOptionCombo;
UpdateColumns_PanelOptionCombo();
}
//m_sizerFOC->FitInside( m_scrollFOC );
//m_sizerScrollOC->FitInside( m_scrollFOC );
m_sizerScrollOC->Layout();
m_sizerFOC->Layout();
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
BOOST_CLASS_VERSION(AppComboTrading, 8)
DECLARE_APP(AppComboTrading)