-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathParseFOptionDescription.h
126 lines (105 loc) · 4.24 KB
/
ParseFOptionDescription.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
/************************************************************************
* Copyright(c) 2012, 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. *
************************************************************************/
#pragma once
// slight modifications to the original ParseOptionDescripion
// to handle different names in description: full month, full option side
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/qi_symbols.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/stl.hpp>
#include "MarketSymbol.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
namespace iqfeed { // IQFeed
struct structParsedFOptionDescription {
std::string& sUnderlying;
boost::uint8_t& nMonth;
boost::uint16_t& nYear;
ou::tf::OptionSide::EOptionSide& eOptionSide;
double& dblStrike;
structParsedFOptionDescription(
std::string& sUnderlying_,
boost::uint8_t& nMonth_, boost::uint16_t& nYear_,
ou::tf::OptionSide::EOptionSide& eOptionSide_, double& dblStrike_ ):
sUnderlying( sUnderlying_ ),
nMonth( nMonth_ ), nYear( nYear_ ), eOptionSide( eOptionSide_ ), dblStrike( dblStrike_ ) {};
};
} // namespace iqfeed
} // namespace tf
} // namespace ou
using adapted_foption_t = ou::tf::iqfeed::structParsedFOptionDescription;
BOOST_FUSION_ADAPT_STRUCT(
adapted_foption_t,
(std::string, sUnderlying)
(boost::uint8_t&, nMonth)
(boost::uint16_t&, nYear)
(ou::tf::OptionSide::EOptionSide&, eOptionSide)
(double&, dblStrike)
)
namespace ou { // One Unified
namespace tf { // TradeFrame
namespace iqfeed { // IQFeed
namespace qi = boost::spirit::qi;
template<typename Iterator>
struct FOptionDescriptionParser: qi::grammar<Iterator, adapted_foption_t()> {
FOptionDescriptionParser(): FOptionDescriptionParser::base_type(start) {
symMonths.add
( "JANUARY", 1 )
( "FEBRUARY", 2 )
( "MARCH", 3 )
( "APRIL", 4 )
( "MAY", 5 )
( "JUNE", 6 )
( "JULY", 7 )
( "AUGUST", 8 )
( "SEPTEMBER", 9 )
( "OCTOBER", 10 )
( "NOVEMBER", 11 )
( "DECEMBER", 12 )
;
symOptionSide.add
( "CALL", OptionSide::Call )
( "PUT", OptionSide::Put )
;
// define option processing rules
ruleMonth %= symMonths;
ruleNoSpaceString = +(qi::char_ - qi::char_(' '));
ruleNotAMonth = ruleNoSpaceString - symMonths;
ruleUnderlyingSymbol %= +(*qi::char_(' ') >> ruleNotAMonth);
//ruleUnderlyingSymbol %= +(-qi::lit(' ') >> ((+(qi::char_ - qi::char_(' '))) - symMonths));
ruleYear %= qi::uint_;
ruleStrike %= qi::float_;
ruleOptionSide %= symOptionSide;
start %=
ruleUnderlyingSymbol
>> qi::lit( ' ' ) > ruleMonth
> qi::lit( ' ' ) > ruleYear
> qi::lit( ' ' ) > ruleOptionSide
> qi::lit( ' ' ) > ruleStrike
;
}
qi::symbols<char, boost::uint8_t> symMonths;
qi::symbols<char, ou::tf::OptionSide::EOptionSide> symOptionSide;
qi::rule<Iterator, std::string()> ruleNoSpaceString;
qi::rule<Iterator, std::string()> ruleNotAMonth;
qi::rule<Iterator, std::string()> ruleUnderlyingSymbol;
qi::rule<Iterator, boost::uint8_t()> ruleMonth;
qi::rule<Iterator, boost::uint16_t()> ruleYear;
qi::rule<Iterator, double()> ruleStrike;
qi::rule<Iterator, ou::tf::OptionSide::EOptionSide()> ruleOptionSide;
qi::rule<Iterator, adapted_foption_t()> start;
};
} // namespace iqfeed
} // namespace tf
} // namespace ou