Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
TradeStrike Class Reference

#include <ored/portfolio/tradestrike.hpp>

+ Collaboration diagram for TradeStrike:

Classes

struct  StrikeYield
 

Public Types

enum class  Type { Price , Yield }
 
typedef TradeMonetary StrikePrice
 

Public Member Functions

 TradeStrike ()
 
 TradeStrike (Type type, const QuantLib::Real &value)
 
 TradeStrike (const QuantLib::Real &value, const std::string &currency)
 
 TradeStrike (const QuantLib::Real &value, QuantLib::Compounding compounding)
 
QuantLib::Real value () const
 
Type type () const
 
std::string currency ()
 
const QuantLib::Compounding & compounding ()
 
StrikePricestrikePrice () const
 
StrikeYieldstrikeYield () const
 
void setValue (const QuantLib::Real &value)
 
void setCurrency (const std::string &currency)
 
void fromXML (XMLNode *node, const bool isRequired=true, const bool allowYieldStrike=false)
 
XMLNodetoXML (XMLDocument &doc) const
 
const bool empty () const
 

Private Attributes

boost::variant< StrikeYield, StrikePricestrike_
 
Type type_
 
bool onlyStrike_ = false
 
bool noStrikePriceNode_ = false
 

Detailed Description

Definition at line 30 of file tradestrike.hpp.

Member Typedef Documentation

◆ StrikePrice

Definition at line 37 of file tradestrike.hpp.

Member Enumeration Documentation

◆ Type

enum class Type
strong
Enumerator
Price 
Yield 

Definition at line 32 of file tradestrike.hpp.

Constructor & Destructor Documentation

◆ TradeStrike() [1/4]

Definition at line 47 of file tradestrike.hpp.

◆ TradeStrike() [2/4]

TradeStrike ( Type  type,
const QuantLib::Real &  value 
)

Definition at line 35 of file tradestrike.cpp.

35 : type_(type) {
36 if (type_ == Type::Price)
37 strike_ = TradeMonetary(value);
38 else
39 strike_ = StrikeYield(value);
40}
boost::variant< StrikeYield, StrikePrice > strike_
Definition: tradestrike.hpp:69
QuantLib::Real value() const
+ Here is the call graph for this function:

◆ TradeStrike() [3/4]

TradeStrike ( const QuantLib::Real &  value,
const std::string &  currency 
)

Definition at line 42 of file tradestrike.cpp.

43 strike_ = TradeMonetary(value, currency);
44}
std::string currency()
+ Here is the call graph for this function:

◆ TradeStrike() [4/4]

TradeStrike ( const QuantLib::Real &  value,
QuantLib::Compounding  compounding 
)

Definition at line 46 of file tradestrike.cpp.

47 strike_ = StrikeYield(value, compounding);
48}
const QuantLib::Compounding & compounding()
+ Here is the call graph for this function:

Member Function Documentation

◆ value()

QuantLib::Real value ( ) const

Definition at line 115 of file tradestrike.cpp.

115 {
116 return boost::apply_visitor(StrikeValue(), strike_);
117}
+ Here is the caller graph for this function:

◆ type()

Type type ( ) const

Definition at line 53 of file tradestrike.hpp.

53{ return type_; };

◆ currency()

std::string currency ( )

Definition at line 119 of file tradestrike.cpp.

119 {
120 QL_REQUIRE(type_ == Type::Price, "TradeStrike currency only valid when Strike type is Price");
121 return strikePrice().currency();
122}
std::string currency() const
StrikePrice & strikePrice() const
Definition: tradestrike.hpp:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compounding()

const QuantLib::Compounding & compounding ( )

Definition at line 124 of file tradestrike.cpp.

124 {
125 QL_REQUIRE(type_ == Type::Yield, "TradeStrike currency only valid when Strike type is Yield");
126 return strikeYield().compounding;
127}
StrikeYield & strikeYield() const
Definition: tradestrike.hpp:58
QuantLib::Compounding compounding
Definition: tradestrike.hpp:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strikePrice()

StrikePrice & strikePrice ( ) const

Definition at line 57 of file tradestrike.hpp.

57{ return boost::get<StrikePrice>(strike_); }
+ Here is the caller graph for this function:

◆ strikeYield()

StrikeYield & strikeYield ( ) const

Definition at line 58 of file tradestrike.hpp.

58{ return boost::get<StrikeYield>(strike_); }
+ Here is the caller graph for this function:

◆ setValue()

void setValue ( const QuantLib::Real &  value)

Definition at line 129 of file tradestrike.cpp.

129 {
130 if (type_ == Type::Price) {
132 } else {
134 }
135}
void setValue(const QuantLib::Real &value)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCurrency()

void setCurrency ( const std::string &  currency)

Definition at line 137 of file tradestrike.cpp.

137 {
138 QL_REQUIRE(type_ == Type::Price, "TradeStrike currency only valid when Strike type is Price");
140}
void setCurrency(const std::string &currency)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromXML()

void fromXML ( XMLNode node,
const bool  isRequired = true,
const bool  allowYieldStrike = false 
)

Definition at line 50 of file tradestrike.cpp.

50 {
51 XMLNode* dataNode = XMLUtils::getChildNode(node, "StrikeData");
52 if (dataNode) {
53 // first look for StrikeYield node
54 if (XMLNode* yieldNode = XMLUtils::getChildNode(dataNode, "StrikeYield")) {
55 QL_REQUIRE(allowYieldStrike, "StrikeYield not supported for this trade type.");
56 StrikeYield strikeYield;
57 strikeYield.yield = XMLUtils::getChildValueAsDouble(yieldNode, "Yield", true);
59 parseCompounding(XMLUtils::getChildValue(yieldNode, "Compounding", false, "SimpleThenCompounded"));
62 } else {
63 TradeMonetary strikePrice;
64 if (XMLNode* priceNode = XMLUtils::getChildNode(dataNode, "StrikePrice"))
65 strikePrice.fromXMLNode(priceNode);
66 else {
67 // in order to remain backward compatible we also allow to be set up
68 // without the StrikePrice node
69 strikePrice.fromXMLNode(dataNode);
70 noStrikePriceNode_ = true;
71 }
74 }
75 } else {
76 // if just a strike is present
77 string s = XMLUtils::getChildValue(node, "Strike", isRequired);
78 if (!s.empty()) {
79 strike_ = TradeMonetary(s);
81 onlyStrike_ = true;
82 }
83 }
84}
void fromXMLNode(XMLNode *node)
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
Compounding parseCompounding(const string &s)
Convert text to QuantLib::Compounding;.
Definition: parsers.cpp:376
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const

Definition at line 86 of file tradestrike.cpp.

86 {
87 XMLNode* node;
88 if (onlyStrike_) {
89 // can only happen for a StrikePrice
90 auto sp = QuantLib::ext::get<StrikePrice>(strike_);
91 node = doc.allocNode("Strike", boost::lexical_cast<std::string>(sp.valueString()));
92 } else {
93 node = doc.allocNode("StrikeData");
95 // maintain backward compatibility, must be a Strike Type Price to get here
96 strikePrice().toXMLNode(doc, node);
97 } else {
98 XMLNode* subNode;
99 if (type_ == Type::Yield) {
100 auto yld = strikeYield();
101 subNode = doc.allocNode("StrikeYield");
102 XMLUtils::addChild(doc, subNode, "Yield", yld.yield);
103 XMLUtils::addChild(doc, subNode, "Compounding", to_string(yld.compounding));
104 } else {
105 auto sp = strikePrice();
106 subNode = doc.allocNode("StrikePrice");
107 sp.toXMLNode(doc, subNode);
108 }
109 XMLUtils::appendNode(node, subNode);
110 }
111 }
112 return node;
113}
void toXMLNode(XMLDocument &doc, XMLNode *node)
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ empty()

const bool empty ( ) const

Definition at line 142 of file tradestrike.cpp.

142 {
143 try {
144 return value() == Null<Real>();
145 } catch (...) {
146 return true;
147 }
148}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ strike_

boost::variant<StrikeYield, StrikePrice> strike_
mutableprivate

Definition at line 69 of file tradestrike.hpp.

◆ type_

Type type_
private

Definition at line 70 of file tradestrike.hpp.

◆ onlyStrike_

bool onlyStrike_ = false
private

Definition at line 71 of file tradestrike.hpp.

◆ noStrikePriceNode_

bool noStrikePriceNode_ = false
private

Definition at line 72 of file tradestrike.hpp.