-
Notifications
You must be signed in to change notification settings - Fork 156
/
Option.cpp
74 lines (63 loc) · 3.58 KB
/
Option.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
/************************************************************************
* Copyright(c) 2013, 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. *
************************************************************************/
//#include "StdAfx.h"
#include <boost/lexical_cast.hpp>
#include <TFTrading/KeyTypes.h>
#include "Option.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
namespace iqfeed { // IQFeed
const char rchCallMonth[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L' };
const char rchPutMonth[] = { 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X' };
// something similar in BuildSymbolName.cpp
void ComposeOptionName(
std::string& sCall, std::string& sPut,
const std::string& sUnderlying, ou::tf::OptionSide::EOptionSide option, ptime dtExpiry, double dblStrike ) {
std::string sDay;
boost::gregorian::date::day_type day = dtExpiry.date().day();
sDay = ( ( 9 < day ) ? "" : "0" ) + boost::lexical_cast<std::string>( day );
std::string sYear = boost::lexical_cast<std::string>( dtExpiry.date().year() );
std::string sStrike = boost::lexical_cast<std::string>( dblStrike );
sCall = sUnderlying + sYear.substr( 2, 2 ) + sDay + rchCallMonth[ dtExpiry.date().month() - 1 ] + sStrike;
sPut = sUnderlying + sYear.substr( 2, 2 ) + sDay + rchPutMonth[ dtExpiry.date().month() - 1 ] + sStrike;
}
// 2014/09/30 some similar code in IQFeed/IQFeedProvider.cpp
void SetAlternateName( const pInstrument_t& pInstrument ) {
assert( ou::tf::InstrumentType::Option == pInstrument->GetInstrumentType() );
boost::gregorian::date dateExpiry = pInstrument->GetExpiry();
boost::gregorian::date::day_type day = dateExpiry.day() + 1; // IQFeed dates are the saturday after expiry
char chMonth;
switch ( pInstrument->GetOptionSide() ) {
case ou::tf::OptionSide::Call:
chMonth = rchCallMonth[ dateExpiry.month() - 1 ];
break;
case ou::tf::OptionSide::Put:
chMonth = rchPutMonth[ dateExpiry.month() - 1 ];
break;
default: throw std::runtime_error( "ou::tf::iqfeed::option::AddAlternateName: no option side specified" );
}
assert( 0 ); // 20151227 need to fix this, see IQFeedProvider.cpp file
// main option instrument name should be our own, and the iqfeed name set as the alternate name
// uncomment the following once fixed with standard and iqfeed specific names
// BuildSymbolName.h is the standard way to build the names now
// pInstrument->SetAlternateName( ou::tf::keytypes::EProviderIQF,
// pInstrument->GetUnderlyingName()
// + boost::lexical_cast<std::string>( dateExpiry.year() ).substr( 2, 2 )
// + ( ( 9 < day ) ? "" : "0" ) + boost::lexical_cast<std::string>( day )
// + chMonth
// + boost::lexical_cast<std::string>( pInstrument->GetStrike() ) );
}
} // namespace iqfeed
} // namespace TradeFrame
} // namespace ou