-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathStrike.cpp
144 lines (125 loc) · 4.94 KB
/
Strike.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
/************************************************************************
* Copyright(c) 2011, 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. *
************************************************************************/
#include "Strike.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
namespace option { // options
Strike::Strike()
: m_dblStrike( 0 ),
m_bWatchable( false ), m_nWatching( 0 )
{
}
Strike::Strike( double dblStrike )
: m_dblStrike( dblStrike ),
m_bWatchable( false ), m_nWatching( 0 )
{
}
Strike::Strike( const Strike& rhs )
: m_dblStrike( rhs.m_dblStrike ),
m_call( rhs.m_call ), m_put( rhs.m_put ),
m_bWatchable( false ), m_nWatching( 0 )
{
assert( 0 == rhs.m_nWatching );
}
Strike::~Strike() {
}
Strike& Strike::operator=( const Strike& rhs ) {
assert( 0 == rhs.m_nWatching );
assert( 0 == m_nWatching );
m_dblStrike = rhs.m_dblStrike;
m_call = rhs.m_call;
m_put = rhs.m_put;
return *this;
};
void Strike::AssignCall( Instrument::pInstrument_t pInstrument, pProvider_t pDataProvider, pProvider_t pGreekProvider ) {
assert( 0 == m_call.use_count() );
assert( ou::tf::OptionSide::Call == pInstrument->GetOptionSide() );
if ( 0 != m_call.use_count() ) { // look at this: not needed given the above assertion
if ( 0 < m_nWatching ) m_call->StopWatch();
}
m_call.reset( new ou::tf::option::Call( pInstrument, pDataProvider, pGreekProvider ) );
if ( 0 < m_nWatching ) m_call->StartWatch();
};
void Strike::AssignPut( Instrument::pInstrument_t pInstrument, pProvider_t pDataProvider, pProvider_t pGreekProvider ) {
assert( 0 == m_put.use_count() );
assert( ou::tf::OptionSide::Put == pInstrument->GetOptionSide() );
if ( 0 != m_put.use_count() ) { // look at this: not needed given the above assertion
if ( 0 < m_nWatching ) m_put->StopWatch();
}
m_put.reset( new ou::tf::option::Put( pInstrument, pDataProvider, pGreekProvider ) );
if ( 0 < m_nWatching ) m_put->StartWatch();
};
void Strike::AssignCall( Instrument::pInstrument_t pInstrument, pProvider_t pDataProvider ) {
assert( 0 == m_call.use_count() );
assert( ou::tf::OptionSide::Call == pInstrument->GetOptionSide() );
if ( 0 != m_call.use_count() ) { // look at this: not needed given the above assertion
if ( 0 < m_nWatching ) m_call->StopWatch();
}
m_call.reset( new ou::tf::option::Call( pInstrument, pDataProvider ) );
if ( 0 < m_nWatching ) m_call->StartWatch();
};
void Strike::AssignPut( Instrument::pInstrument_t pInstrument, pProvider_t pDataProvider ) {
assert( 0 == m_put.use_count() );
assert( ou::tf::OptionSide::Put == pInstrument->GetOptionSide() );
if ( 0 != m_put.use_count() ) { // look at this: not needed given the above assertion
if ( 0 < m_nWatching ) m_put->StopWatch();
}
m_put.reset( new ou::tf::option::Put( pInstrument, pDataProvider ) );
if ( 0 < m_nWatching ) m_put->StartWatch();
};
void Strike::EmitValues( double dblPriceUnderlying ) {
if ( m_call ) m_call->EmitValues( dblPriceUnderlying );
std::cout << std::endl;
if ( m_put ) m_put->EmitValues( dblPriceUnderlying );
std::cout << std::endl;
}
void Strike::SaveSeries( const std::string& sPrefix ) {
if ( m_call ) m_call->SaveSeries( sPrefix );
if ( m_put ) m_put->SaveSeries( sPrefix );
}
void Strike::SetWatchableOn() {
if ( !m_bWatchable ) {
m_bWatchable = true;
// won't be watching anything, as can't set watching without first having watchable
}
}
void Strike::SetWatchableOff() {
if ( m_bWatchable ) {
m_bWatchable = false;
if ( 0 != m_nWatching ) { // turn off watching, if enabled, or do we let this go down naturally instead?
// WatchStop();
// m_nWatching = 0; // this is kinda dangerous
}
}
}
void Strike::WatchStart() {
if ( m_bWatchable ) {
++m_nWatching;
if ( 1 == m_nWatching ) {
if ( m_call ) m_call->StartWatch();
if ( m_put ) m_put->StartWatch();
}
}
}
void Strike::WatchStop() {
assert( 0 != m_nWatching );
-- m_nWatching;
if ( 0 == m_nWatching ) {
if ( m_call ) m_call->StopWatch();
if ( m_put ) m_put->StopWatch();
}
}
} // namespace option
} // namespace tf
} // namespace ou