-
Notifications
You must be signed in to change notification settings - Fork 157
/
Tracker.h
146 lines (111 loc) · 4.63 KB
/
Tracker.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
/************************************************************************
* Copyright(c) 2020, One Unified. All rights reserved. *
* email: [email protected] *
* *
* 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. *
************************************************************************/
/*
* File: Tracker.h
* Author: [email protected]
* Project: TFOptionCombos
* Created on Novemeber 8, 2020, 11:41 AM
*/
/*
Rolls a long call up or a long put down to take profit
=> as a vertical or as a diagonal based upon chain provided
On a long option, if it goes down and passes through $0.10, mark that strike.
when combo starts moving positive, buy in at $0.10 at a similar difference to see
if can make some more on the recovery
*/
// TODO: pass in a function to test if roll target already exists
// acts as a gate to transition
#pragma once
#include <TFTrading/Position.h>
#include <TFOptions/Chain.h>
#include <TFOptions/Option.h>
namespace ou { // One Unified
namespace tf { // TradeFrame
namespace option { // options
class Tracker {
public:
using pPosition_t = ou::tf::Position::pPosition_t;
using pOption_t = ou::tf::option::Option::pOption_t;
using chain_t = ou::tf::option::Chain<ou::tf::option::chain::OptionName>;
using fConstructedOption_t = std::function<void(pOption_t)>;
using fConstructOption_t = std::function<void(const std::string&, fConstructedOption_t&&)>;
using fLegRoll_t = std::function<pPosition_t(pPosition_t old, pOption_t )>;
using fLegClose_t = std::function<void(pPosition_t)>;
Tracker();
Tracker( const Tracker& ) = delete;
Tracker( Tracker&& );
~Tracker();
void Initialize(
pPosition_t pPosition
, bool bLock
, const chain_t* pChain
, fConstructOption_t&&
, fLegRoll_t&&
, fLegClose_t&&
);
bool TestLong( boost::posix_time::ptime, double dblUnderlyingSlope, double dblUnderlyingPrice );
bool TestShort( boost::posix_time::ptime, double dblUnderlyingSlope, double dblUnderlyingPrice );
void TestItmRoll( boost::gregorian::date, boost::posix_time::time_duration );
void Emit();
void ForceRoll();
void ForceClose();
void Quiesce(); // called from Collar
protected:
private:
bool m_bLock; // do not roll longs up or down
using compare_t = std::function<bool(double,double)>;
compare_t m_compare;
using lu_strike_t = std::function<double(double)>;
lu_strike_t m_luStrike;
using lu_name_t = std::function<std::string(double)>;
lu_name_t m_luNameAtStrike;
double m_dblStrikePosition;
ou::tf::OptionSide::EOptionSide m_sidePosition;
double m_dblUnderlyingPrice;
double m_dblUnderlyingSlope;
enum class ETransition {
Unknown // unused
, Initial // on creation, waiting for basic position
, Vacant_Init
, Vacant // candidate construction preparation
, Acquire // candidate construction
, Spread // candidate spread - wait for spread stats/stability
, Track_Long // actively tracking price
, Track_Short // actibvely tracking price
, Roll_start // needs to process the calendar roll at expiry
, Close_start // force a close
, Quiesce // stop tracking
, Done // prepare for destruction
};
ETransition m_transition;
ETransition m_track_type; // Track_Long or Track_Short
const chain_t* m_pChain;
pPosition_t m_pPosition; // existing option / position
pOption_t m_pOptionCandidate; // track an option for next position with roll
// TestLong: vertical or diagonal change
// TestShort: calendar roll, if enough premium difference, else close leg
fConstructOption_t m_fConstructOption;
fLegRoll_t m_fLegRoll; // use two leg OrderCombo
fLegClose_t m_fLegClose; // use one leg OrderCombo
void Initialize( pPosition_t );
void OptionCandidate_Construct( boost::posix_time::ptime, double strikeItm );
void OptionCandidate_HandleQuote( const ou::tf::Quote& );
void OptionCandidate_StartWatch();
void OptionCandidate_StopWatch();
void LegRoll();
void LegClose();
};
} // namespace option
} // namespace tf
} // namespace ou