Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
BlackScholesModelBuilderBase Class Referenceabstract

#include <ored/model/blackscholesmodelbuilderbase.hpp>

+ Inheritance diagram for BlackScholesModelBuilderBase:
+ Collaboration diagram for BlackScholesModelBuilderBase:

Public Member Functions

 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
 
- Public Member Functions inherited from ModelBuilder
void recalibrate () const
 
virtual void forceRecalculate ()
 
virtual bool requiresRecalibration () const=0
 

ModelBuilder interface

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_
 
void forceRecalculate () override
 
bool requiresRecalibration () const override
 
 BlackScholesModelBuilderBase (const Handle< YieldTermStructure > &curve, const QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > &process)
 
virtual void setupDatesAndTimes () const
 
virtual std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > getCalibratedProcesses () const =0
 
virtual std::vector< std::vector< Real > > getCurveTimes () const =0
 
virtual std::vector< std::vector< std::pair< Real, Real > > > getVolTimesStrikes () const =0
 
void performCalculations () const override
 
bool calibrationPointsChanged (const bool updateCache) const
 

Detailed Description

Definition at line 41 of file blackscholesmodelbuilderbase.hpp.

Constructor & Destructor Documentation

◆ BlackScholesModelBuilderBase() [1/3]

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 
)

Definition at line 32 of file blackscholesmodelbuilderbase.cpp.

36 : curves_(curves), processes_(processes), simulationDates_(simulationDates), addDates_(addDates),
37 timeStepsPerYear_(timeStepsPerYear) {
38
39 QL_REQUIRE(!curves_.empty(), "BlackScholesModelBuilderBase: no curves given");
40
41 marketObserver_ = QuantLib::ext::make_shared<MarketObserver>();
42
43 for (auto const& c : curves_)
44 registerWith(c);
45
46 for (auto const& p : processes_) {
47 registerWith(p->blackVolatility());
48 registerWith(p->riskFreeRate());
49 registerWith(p->dividendYield());
50 marketObserver_->registerWith(p->stateVariable());
51 }
52
53 registerWith(marketObserver_);
54
55 // notify observers of all market data changes, not only when not calculated
56 alwaysForwardNotifications();
57
59 for (auto const& p : processes_) {
60 vols_.push_back(p->blackVolatility());
61 allCurves_.push_back(p->riskFreeRate());
62 allCurves_.push_back(p->dividendYield());
63 }
64}
std::vector< Handle< YieldTermStructure > > allCurves_
std::vector< Handle< BlackVolTermStructure > > vols_
QuantLib::ext::shared_ptr< MarketObserver > marketObserver_
const std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > processes_
const std::vector< Handle< YieldTermStructure > > curves_

◆ BlackScholesModelBuilderBase() [2/3]

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 
)

Definition at line 25 of file blackscholesmodelbuilderbase.cpp.

28 : BlackScholesModelBuilderBase(std::vector<Handle<YieldTermStructure>>{curve},
29 std::vector<QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess>>{process},
30 simulationDates, addDates, timeStepsPerYear) {}
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() [3/3]

BlackScholesModelBuilderBase ( const Handle< YieldTermStructure > &  curve,
const QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > &  process 
)
protected

Definition at line 66 of file blackscholesmodelbuilderbase.cpp.

68 : BlackScholesModelBuilderBase(curve, process, {}, {}, 1) {}

Member Function Documentation

◆ model()

Handle< BlackScholesModelWrapper > model ( ) const

Definition at line 70 of file blackscholesmodelbuilderbase.cpp.

70 {
71 calculate();
72 return model_;
73}
RelinkableHandle< BlackScholesModelWrapper > model_

◆ forceRecalculate()

void forceRecalculate ( )
overridevirtual

Reimplemented from ModelBuilder.

Definition at line 80 of file blackscholesmodelbuilderbase.cpp.

+ Here is the call graph for this function:

◆ requiresRecalibration()

bool requiresRecalibration ( ) const
overridevirtual

Implements ModelBuilder.

Definition at line 75 of file blackscholesmodelbuilderbase.cpp.

75 {
77 return calibrationPointsChanged(false) || marketObserver_->hasUpdated(false) || forceCalibration_;
78}
bool calibrationPointsChanged(const bool updateCache) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setupDatesAndTimes()

void setupDatesAndTimes ( ) const
protectedvirtual

Reimplemented in CommodityApoModelBuilder.

Definition at line 86 of file blackscholesmodelbuilderbase.cpp.

86 {
87 Date referenceDate = curves_.front()->referenceDate();
90 for (auto const& d : simulationDates_) {
91 if (d >= referenceDate)
93 }
94
95 std::vector<Real> times;
96 for (auto const& d : effectiveSimulationDates_) {
97 times.push_back(curves_.front()->timeFromReference(d));
98 }
99
100 Size steps = std::max(std::lround(timeStepsPerYear_ * times.back() + 0.5), 1l);
101 discretisationTimeGrid_ = TimeGrid(times.begin(), times.end(), steps);
102}
Date referenceDate
Definition: utilities.cpp:442
std::vector< Size > steps
+ Here is the caller graph for this function:

◆ getCalibratedProcesses()

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

Implemented in BlackScholesModelBuilder, LocalVolModelBuilder, and CommodityApoModelBuilder.

+ Here is the caller graph for this function:

◆ getCurveTimes()

virtual std::vector< std::vector< Real > > getCurveTimes ( ) const
protectedpure virtual

Implemented in BlackScholesModelBuilder, LocalVolModelBuilder, and CommodityApoModelBuilder.

+ Here is the caller graph for this function:

◆ getVolTimesStrikes()

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

Implemented in BlackScholesModelBuilder, LocalVolModelBuilder, and CommodityApoModelBuilder.

+ Here is the caller graph for this function:

◆ performCalculations()

void performCalculations ( ) const
overrideprotected

Definition at line 104 of file blackscholesmodelbuilderbase.cpp.

104 {
105 if (requiresRecalibration()) {
106
107 // update vol and curves cache
108
110
111 // reset market observer's updated flag
112
113 marketObserver_->hasUpdated(true);
114
115 // setup model
116
117 model_.linkTo(QuantLib::ext::make_shared<BlackScholesModelWrapper>(getCalibratedProcesses(), effectiveSimulationDates_,
119
120 // notify model observers
121 model_->notifyObservers();
122 }
123}
virtual std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > getCalibratedProcesses() const =0
+ Here is the call graph for this function:

◆ calibrationPointsChanged()

bool calibrationPointsChanged ( const bool  updateCache) const
protected

Definition at line 125 of file blackscholesmodelbuilderbase.cpp.

125 {
126
127 // get times for curves and times / strikes for vols
128
129 std::vector<std::vector<Real>> curveTimes = getCurveTimes();
130 std::vector<std::vector<std::pair<Real, Real>>> volTimesStrikes = getVolTimesStrikes();
131
132 // build data
133
134 std::vector<std::vector<Real>> curveData;
135 for (Size i = 0; i < curveTimes.size(); ++i) {
136 curveData.push_back(std::vector<Real>());
137 for (Size j = 0; j < curveTimes[i].size(); ++j) {
138 curveData.back().push_back(allCurves_[i]->discount(curveTimes[i][j]));
139 }
140 }
141
142 std::vector<std::vector<Real>> volData;
143 for (Size i = 0; i < volTimesStrikes.size(); ++i) {
144 volData.push_back(std::vector<Real>());
145 for (Size j = 0; j < volTimesStrikes[i].size(); ++j) {
146 Real k = volTimesStrikes[i][j].second;
147 // check for null = ATM
148 if (k == Null<Real>())
149 k = atmForward(processes_[i]->x0(), processes_[i]->riskFreeRate(), processes_[i]->dividendYield(),
150 volTimesStrikes[i][j].first);
151 volData.back().push_back(vols_[i]->blackVol(volTimesStrikes[i][j].first, k));
152 }
153 }
154
155 // check if something has changed
156 return cache_.hasChanged(curveTimes, curveData, volTimesStrikes, volData, updateCache);
157}
virtual std::vector< std::vector< Real > > getCurveTimes() const =0
virtual std::vector< std::vector< std::pair< Real, Real > > > getVolTimesStrikes() const =0
bool hasChanged(const std::vector< std::vector< Real > > &curveTimes, const std::vector< std::vector< Real > > &curveData, const std::vector< std::vector< std::pair< Real, Real > > > &volTimesStrikes, const std::vector< std::vector< Real > > &volData, const bool updateCache)
Real atmForward(const Real s0, const Handle< YieldTermStructure > &r, const Handle< YieldTermStructure > &q, const Real t)
helper function that computes the atm forward
Definition: utilities.cpp:483
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ curves_

const std::vector<Handle<YieldTermStructure> > curves_
protected

Definition at line 75 of file blackscholesmodelbuilderbase.hpp.

◆ processes_

const std::vector<QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess> > processes_
protected

Definition at line 76 of file blackscholesmodelbuilderbase.hpp.

◆ simulationDates_

const std::set<Date> simulationDates_
protected

Definition at line 77 of file blackscholesmodelbuilderbase.hpp.

◆ addDates_

const std::set<Date> addDates_
protected

Definition at line 77 of file blackscholesmodelbuilderbase.hpp.

◆ timeStepsPerYear_

const Size timeStepsPerYear_
protected

Definition at line 78 of file blackscholesmodelbuilderbase.hpp.

◆ effectiveSimulationDates_

std::set<Date> effectiveSimulationDates_
mutableprotected

Definition at line 80 of file blackscholesmodelbuilderbase.hpp.

◆ discretisationTimeGrid_

TimeGrid discretisationTimeGrid_
mutableprotected

Definition at line 81 of file blackscholesmodelbuilderbase.hpp.

◆ model_

RelinkableHandle<BlackScholesModelWrapper> model_
mutableprotected

Definition at line 83 of file blackscholesmodelbuilderbase.hpp.

◆ forceCalibration_

bool forceCalibration_ = false
protected

Definition at line 85 of file blackscholesmodelbuilderbase.hpp.

◆ marketObserver_

QuantLib::ext::shared_ptr<MarketObserver> marketObserver_
protected

Definition at line 86 of file blackscholesmodelbuilderbase.hpp.

◆ vols_

std::vector<Handle<BlackVolTermStructure> > vols_
protected

Definition at line 88 of file blackscholesmodelbuilderbase.hpp.

◆ allCurves_

std::vector<Handle<YieldTermStructure> > allCurves_
protected

Definition at line 89 of file blackscholesmodelbuilderbase.hpp.

◆ cache_

CalibrationPointCache cache_
mutableprotected

Definition at line 90 of file blackscholesmodelbuilderbase.hpp.