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

#include <ored/portfolio/builders/commodityapomodelbuilder.hpp>

+ Inheritance diagram for CommodityApoModelBuilder:
+ Collaboration diagram for CommodityApoModelBuilder:

Public Member Functions

 CommodityApoModelBuilder (const Handle< YieldTermStructure > &curve, const QuantLib::Handle< QuantLib::BlackVolTermStructure > &vol, const QuantLib::ext::shared_ptr< QuantExt::CommodityAveragePriceOption > &apo, const bool dontCalibrate)
 
- Public Member Functions inherited from BlackScholesModelBuilderBase
 BlackScholesModelBuilderBase (const std::vector< Handle< YieldTermStructure > > &curves, const std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > &processes, const std::set< Date > &simulationDates, const std::set< Date > &addDates, const Size timeStepsPerYear)
 
 BlackScholesModelBuilderBase (const Handle< YieldTermStructure > &curve, const QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > &process, const std::set< Date > &simulationDates, const std::set< Date > &addDates, const Size timeStepsPerYear)
 
Handle< BlackScholesModelWrappermodel () const
 
void forceRecalculate () override
 
bool requiresRecalibration () const override
 
- Public Member Functions inherited from ModelBuilder
void recalibrate () const
 
virtual void forceRecalculate ()
 
virtual bool requiresRecalibration () const=0
 

Protected Member Functions

void setupDatesAndTimes () const override
 
std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > getCalibratedProcesses () const override
 
std::vector< std::vector< Real > > getCurveTimes () const override
 
std::vector< std::vector< std::pair< Real, Real > > > getVolTimesStrikes () const override
 
- Protected Member Functions inherited from BlackScholesModelBuilderBase
 BlackScholesModelBuilderBase (const Handle< YieldTermStructure > &curve, const QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > &process)
 
void performCalculations () const override
 
bool calibrationPointsChanged (const bool updateCache) const
 

Protected Attributes

QuantLib::ext::shared_ptr< QuantExt::CommodityAveragePriceOptionapo_
 
bool dontCalibrate_ = false
 
- Protected Attributes inherited from BlackScholesModelBuilderBase
const std::vector< Handle< YieldTermStructure > > curves_
 
const std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > processes_
 
const std::set< Date > simulationDates_
 
const std::set< Date > addDates_
 
const Size timeStepsPerYear_
 
std::set< Date > effectiveSimulationDates_
 
TimeGrid discretisationTimeGrid_
 
RelinkableHandle< BlackScholesModelWrappermodel_
 
bool forceCalibration_ = false
 
QuantLib::ext::shared_ptr< MarketObservermarketObserver_
 
std::vector< Handle< BlackVolTermStructure > > vols_
 
std::vector< Handle< YieldTermStructure > > allCurves_
 
CalibrationPointCache cache_
 

Detailed Description

Definition at line 36 of file commodityapomodelbuilder.hpp.

Constructor & Destructor Documentation

◆ CommodityApoModelBuilder()

CommodityApoModelBuilder ( const Handle< YieldTermStructure > &  curve,
const QuantLib::Handle< QuantLib::BlackVolTermStructure > &  vol,
const QuantLib::ext::shared_ptr< QuantExt::CommodityAveragePriceOption > &  apo,
const bool  dontCalibrate 
)

Definition at line 27 of file commodityapomodelbuilder.cpp.

31 : BlackScholesModelBuilderBase(curve, QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(
32 Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.0)),
33 Handle<YieldTermStructure>(QuantLib::ext::make_shared<QuantLib::FlatForward>(
34 0, NullCalendar(), 0.0, Actual365Fixed())),
35 Handle<YieldTermStructure>(QuantLib::ext::make_shared<QuantLib::FlatForward>(
36 0, NullCalendar(), 0.0, Actual365Fixed())),
37 vol)),
38 apo_(apo), dontCalibrate_(dontCalibrate) {}
BlackScholesModelBuilderBase(const std::vector< Handle< YieldTermStructure > > &curves, const std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > &processes, const std::set< Date > &simulationDates, const std::set< Date > &addDates, const Size timeStepsPerYear)
QuantLib::ext::shared_ptr< QuantExt::CommodityAveragePriceOption > apo_

Member Function Documentation

◆ setupDatesAndTimes()

void setupDatesAndTimes ( ) const
overrideprotectedvirtual

Reimplemented from BlackScholesModelBuilderBase.

Definition at line 40 of file commodityapomodelbuilder.cpp.

40 {
41 // we don't need the simulation dates or timegrid and we populate the curve / vol times directly below
42 return;
43}

◆ getCalibratedProcesses()

std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > getCalibratedProcesses ( ) const
overrideprotectedvirtual

Implements BlackScholesModelBuilderBase.

Definition at line 46 of file commodityapomodelbuilder.cpp.

46 {
47 // nothing to do, return original processes
48 return processes_;
49}
const std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > processes_

◆ getCurveTimes()

std::vector< std::vector< Real > > getCurveTimes ( ) const
overrideprotectedvirtual

Implements BlackScholesModelBuilderBase.

Definition at line 51 of file commodityapomodelbuilder.cpp.

51 {
52 // collect times relevant on the discount curve
53 std::vector<Real> times;
55 return {times};
56 if (apo_->underlyingFlow()->date() > curves_.front()->referenceDate())
57 times.push_back(curves_.front()->timeFromReference(apo_->underlyingFlow()->date()));
58 return {times};
59}
const std::vector< Handle< YieldTermStructure > > curves_

◆ getVolTimesStrikes()

std::vector< std::vector< std::pair< Real, Real > > > getVolTimesStrikes ( ) const
overrideprotectedvirtual

Implements BlackScholesModelBuilderBase.

Definition at line 61 of file commodityapomodelbuilder.cpp.

61 {
62 // collect times relevant on the vol surface
63 std::vector<std::pair<Real, Real>> result;
65 return {result};
66 auto vol = processes_.front()->blackVolatility();
67 std::set<QuantLib::Date> expiries;
68 Real effectiveStrike = apo_->effectiveStrike();
69 try {
70 effectiveStrike -= apo_->accrued(curves_.front()->referenceDate());
71 } catch (...) {
72 // The accrued calculation might fail due to missing fixings and this will cause an error in the
73 // instrument pricing. We don't throw an error here since the apo might actually be expired so
74 // that no pricing is required at all.
75 }
76 for (auto const& p : apo_->underlyingFlow()->indices()) {
77 if (p.first > curves_.front()->referenceDate()) {
78 if (apo_->underlyingFlow()->useFuturePrice()) {
79 Date expiry = p.second->expiryDate();
80 if (expiries.find(expiry) == expiries.end()) {
81 result.push_back(std::make_pair(vol->timeFromReference(expiry), effectiveStrike));
82 expiries.insert(expiry);
83 }
84 } else {
85 if (expiries.find(p.first) == expiries.end()) {
86 result.push_back(std::make_pair(vol->timeFromReference(p.first), effectiveStrike));
87 expiries.insert(p.first);
88 }
89 }
90 }
91 }
92 return {result};
93}

Member Data Documentation

◆ apo_

QuantLib::ext::shared_ptr<QuantExt::CommodityAveragePriceOption> apo_
protected

Definition at line 49 of file commodityapomodelbuilder.hpp.

◆ dontCalibrate_

bool dontCalibrate_ = false
protected

Definition at line 50 of file commodityapomodelbuilder.hpp.