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

Class for streaming SensitivityRecords from csv file. More...

#include <orea/engine/sensitivityfilestream.hpp>

+ Inheritance diagram for SensitivityInputStream:
+ Collaboration diagram for SensitivityInputStream:

Public Member Functions

 SensitivityInputStream (char delim=',', const std::string &comment="#")
 Constructor. More...
 
virtual ~SensitivityInputStream ()
 
void setStream (std::istream *stream)
 
SensitivityRecord next () override
 Returns the next SensitivityRecord in the stream. More...
 
void reset () override
 Resets the stream so that SensitivityRecord objects can be streamed again. More...
 
- Public Member Functions inherited from SensitivityStream
virtual ~SensitivityStream ()
 Destructor. More...
 
virtual SensitivityRecord next ()=0
 Returns the next SensitivityRecord in the stream. More...
 
virtual void reset ()=0
 Resets the stream so that SensitivityRecord objects can be streamed again. More...
 

Private Member Functions

SensitivityRecord processRecord (const std::vector< std::string > &entries) const
 Create a record from a collection of strings. More...
 

Private Attributes

std::istream * stream_
 Handle on the stram. More...
 
char delim_
 Csv file delimiter. More...
 
std::string comment_
 Csv file comment string. More...
 
QuantLib::Size lineNo_
 Keep track of line number for messages. More...
 

Detailed Description

Class for streaming SensitivityRecords from csv file.

Definition at line 34 of file sensitivityfilestream.hpp.

Constructor & Destructor Documentation

◆ SensitivityInputStream()

SensitivityInputStream ( char  delim = ',',
const std::string &  comment = "#" 
)

Constructor.

Definition at line 37 of file sensitivityfilestream.hpp.

38 : delim_(delim), comment_(comment), lineNo_(0) {}
QuantLib::Size lineNo_
Keep track of line number for messages.
std::string comment_
Csv file comment string.

◆ ~SensitivityInputStream()

virtual ~SensitivityInputStream ( )
virtual

Definition at line 39 of file sensitivityfilestream.hpp.

39{} // Declare virtual destructor

Member Function Documentation

◆ setStream()

void setStream ( std::istream *  stream)

Set stream for function

Definition at line 37 of file sensitivityfilestream.cpp.

37 {
38 stream_ = stream;
39}
std::istream * stream_
Handle on the stram.
+ Here is the caller graph for this function:

◆ next()

SensitivityRecord next ( )
overridevirtual

Returns the next SensitivityRecord in the stream.

Implements SensitivityStream.

Definition at line 41 of file sensitivityfilestream.cpp.

41 {
42 // Get the next valid SensitivityRecord
43 string line;
44 while (getline(*stream_, line)) {
45 // Update the current line number
46 ++lineNo_;
47
48 // Trim leading and trailing space
49 boost::trim(line);
50
51 // If line is empty or a comment line, skip to next
52 if (line.empty() || boost::starts_with(line, comment_))
53 continue;
54
55 // Try to parse line in to a SensitivityRecord
56 DLOG("Processing line number " << lineNo_ << ": " << line);
57 vector<string> entries;
58 boost::split(
59 entries, line, [this](char c) { return c == delim_; }, boost::token_compress_off);
60 return processRecord(entries);
61 }
62
63 // If we get to here, no more lines to process so return empty record
64 return SensitivityRecord();
65}
SensitivityRecord processRecord(const std::vector< std::string > &entries) const
Create a record from a collection of strings.
#define DLOG(text)
+ Here is the call graph for this function:

◆ reset()

void reset ( )
overridevirtual

Resets the stream so that SensitivityRecord objects can be streamed again.

Implements SensitivityStream.

Definition at line 67 of file sensitivityfilestream.cpp.

67 {
68 // Reset to beginning of file and line number
69 stream_->clear();
70 stream_->seekg(0, std::ios::beg);
71 lineNo_ = 0;
72}

◆ processRecord()

SensitivityRecord processRecord ( const std::vector< std::string > &  entries) const
private

Create a record from a collection of strings.

Definition at line 74 of file sensitivityfilestream.cpp.

74 {
75
76 QL_REQUIRE(entries.size() == 10, "On line number " << lineNo_ << ": A sensitivity record needs 10 entries");
77
78 SensitivityRecord sr;
79 sr.tradeId = entries[0];
80 sr.isPar = parseBool(entries[1]);
81
82 auto p = deconstructFactor(entries[2]);
83 sr.key_1 = p.first;
84 sr.desc_1 = p.second;
85 tryParseReal(entries[3], sr.shift_1);
86
87 p = deconstructFactor(entries[4]);
88 sr.key_2 = p.first;
89 sr.desc_2 = p.second;
90 tryParseReal(entries[5], sr.shift_2);
91
92 sr.currency = entries[6];
93 sr.baseNpv = parseReal(entries[7]);
94 sr.delta = parseReal(entries[8]);
95 tryParseReal(entries[9], sr.gamma); // might be #N/A, if not computed
96
97 return sr;
98}
bool tryParseReal(const string &s, QuantLib::Real &result)
bool parseBool(const string &s)
Real parseReal(const string &s)
pair< RiskFactorKey, string > deconstructFactor(const string &factor)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ stream_

std::istream* stream_
private

Handle on the stram.

Definition at line 50 of file sensitivityfilestream.hpp.

◆ delim_

char delim_
private

Csv file delimiter.

Definition at line 52 of file sensitivityfilestream.hpp.

◆ comment_

std::string comment_
private

Csv file comment string.

Definition at line 54 of file sensitivityfilestream.hpp.

◆ lineNo_

QuantLib::Size lineNo_
private

Keep track of line number for messages.

Definition at line 56 of file sensitivityfilestream.hpp.