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

NPVCalculator. More...

#include <orea/engine/valuationcalculator.hpp>

+ Inheritance diagram for NPVCalculator:
+ Collaboration diagram for NPVCalculator:

Public Member Functions

 NPVCalculator (const std::string &baseCcyCode, Size index=0)
 base ccy and index to write to More...
 
virtual void calculate (const QuantLib::ext::shared_ptr< Trade > &trade, Size tradeIndex, const QuantLib::ext::shared_ptr< SimMarket > &simMarket, QuantLib::ext::shared_ptr< NPVCube > &outputCube, QuantLib::ext::shared_ptr< NPVCube > &outputCubeNettingSet, const Date &date, Size dateIndex, Size sample, bool isCloseOut=false) override
 
virtual void calculateT0 (const QuantLib::ext::shared_ptr< Trade > &trade, Size tradeIndex, const QuantLib::ext::shared_ptr< SimMarket > &simMarket, QuantLib::ext::shared_ptr< NPVCube > &outputCube, QuantLib::ext::shared_ptr< NPVCube > &outputCubeNettingSet) override
 
virtual Real npv (Size tradeIndex, const QuantLib::ext::shared_ptr< Trade > &trade, const QuantLib::ext::shared_ptr< SimMarket > &simMarket)
 
void init (const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const QuantLib::ext::shared_ptr< SimMarket > &simMarket) override
 
void initScenario () override
 
- Public Member Functions inherited from ValuationCalculator
virtual ~ValuationCalculator ()
 
virtual void calculate (const QuantLib::ext::shared_ptr< Trade > &trade, Size tradeIndex, const QuantLib::ext::shared_ptr< SimMarket > &simMarket, QuantLib::ext::shared_ptr< NPVCube > &outputCube, QuantLib::ext::shared_ptr< NPVCube > &outputCubeNettingSet, const Date &date, Size dateIndex, Size sample, bool isCloseOut=false)=0
 
virtual void calculateT0 (const QuantLib::ext::shared_ptr< Trade > &trade, Size tradeIndex, const QuantLib::ext::shared_ptr< SimMarket > &simMarket, QuantLib::ext::shared_ptr< NPVCube > &outputCube, QuantLib::ext::shared_ptr< NPVCube > &outputCubeNettingSet)=0
 
virtual void init (const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const QuantLib::ext::shared_ptr< SimMarket > &simMarket)=0
 
virtual void initScenario ()=0
 

Protected Attributes

std::string baseCcyCode_
 
Size index_
 
std::vector< Handle< Quote > > ccyQuotes_
 
std::vector< double > fxRates_
 
std::vector< Size > tradeCcyIndex_
 

Detailed Description

NPVCalculator.

Calculate the NPV of the given trade, convert to base currency and divide by the numeraire If the NPV() call throws, we log an exception and write 0 to the cube

Definition at line 87 of file valuationcalculator.hpp.

Constructor & Destructor Documentation

◆ NPVCalculator()

NPVCalculator ( const std::string &  baseCcyCode,
Size  index = 0 
)

base ccy and index to write to

Definition at line 90 of file valuationcalculator.hpp.

Member Function Documentation

◆ calculate()

void calculate ( const QuantLib::ext::shared_ptr< Trade > &  trade,
Size  tradeIndex,
const QuantLib::ext::shared_ptr< SimMarket > &  simMarket,
QuantLib::ext::shared_ptr< NPVCube > &  outputCube,
QuantLib::ext::shared_ptr< NPVCube > &  outputCubeNettingSet,
const Date &  date,
Size  dateIndex,
Size  sample,
bool  isCloseOut = false 
)
overridevirtual

Implements ValuationCalculator.

Reimplemented in MultiStateNPVCalculator.

Definition at line 55 of file valuationcalculator.cpp.

58 {
59 if (!isCloseOut)
60 outputCube->set(npv(tradeIndex, trade, simMarket), tradeIndex, dateIndex, sample, index_);
61}
virtual Real npv(Size tradeIndex, const QuantLib::ext::shared_ptr< Trade > &trade, const QuantLib::ext::shared_ptr< SimMarket > &simMarket)
+ Here is the call graph for this function:

◆ calculateT0()

void calculateT0 ( const QuantLib::ext::shared_ptr< Trade > &  trade,
Size  tradeIndex,
const QuantLib::ext::shared_ptr< SimMarket > &  simMarket,
QuantLib::ext::shared_ptr< NPVCube > &  outputCube,
QuantLib::ext::shared_ptr< NPVCube > &  outputCubeNettingSet 
)
overridevirtual

Implements ValuationCalculator.

Reimplemented in MultiStateNPVCalculator.

Definition at line 63 of file valuationcalculator.cpp.

65 {
66 outputCube->setT0(npv(tradeIndex, trade, simMarket), tradeIndex, index_);
67}
+ Here is the call graph for this function:

◆ npv()

Real npv ( Size  tradeIndex,
const QuantLib::ext::shared_ptr< Trade > &  trade,
const QuantLib::ext::shared_ptr< SimMarket > &  simMarket 
)
virtual

Definition at line 69 of file valuationcalculator.cpp.

70 {
71 Real npv = trade->instrument()->NPV();
72 if (close_enough(npv, 0.0))
73 return npv;
74 Real fx = fxRates_[tradeCcyIndex_[tradeIndex]];
75 Real numeraire = simMarket->numeraire();
76 return npv * fx / numeraire;
77}
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init()

void init ( const QuantLib::ext::shared_ptr< Portfolio > &  portfolio,
const QuantLib::ext::shared_ptr< SimMarket > &  simMarket 
)
overridevirtual

Implements ValuationCalculator.

Definition at line 31 of file valuationcalculator.cpp.

31 {
32 DLOG("init NPVCalculator");
33 tradeCcyIndex_.resize(portfolio->size());
34 std::set<std::string> ccys;
35 for (auto const& [tradeId, trade] : portfolio->trades())
36 ccys.insert(trade->npvCurrency());
37
38 size_t i = 0;
39 for (auto const& [tradeId, trade] : portfolio->trades()) {
40 tradeCcyIndex_[i] = std::distance(ccys.begin(), ccys.find(trade->npvCurrency()));
41 i++;
42 }
43
44 ccyQuotes_.resize(ccys.size());
45 for (Size i = 0; i < ccys.size(); ++i)
46 ccyQuotes_[i] = (simMarket->fxRate(*std::next(ccys.begin(), i) + baseCcyCode_));
47 fxRates_.resize(ccys.size());
48}
std::vector< Handle< Quote > > ccyQuotes_
#define DLOG(text)

◆ initScenario()

void initScenario ( )
overridevirtual

Implements ValuationCalculator.

Definition at line 50 of file valuationcalculator.cpp.

50 {
51 for (Size i = 0; i < ccyQuotes_.size(); ++i)
52 fxRates_[i] = ccyQuotes_[i]->value();
53}
SafeStack< ValueType > value

Member Data Documentation

◆ baseCcyCode_

std::string baseCcyCode_
protected

Definition at line 108 of file valuationcalculator.hpp.

◆ index_

Size index_
protected

Definition at line 109 of file valuationcalculator.hpp.

◆ ccyQuotes_

std::vector<Handle<Quote> > ccyQuotes_
protected

Definition at line 111 of file valuationcalculator.hpp.

◆ fxRates_

std::vector<double> fxRates_
protected

Definition at line 112 of file valuationcalculator.hpp.

◆ tradeCcyIndex_

std::vector<Size> tradeCcyIndex_
protected

Definition at line 113 of file valuationcalculator.hpp.