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
BlackScholesBase Class Reference

#include <ored/scripting/models/blackscholesbase.hpp>

+ Inheritance diagram for BlackScholesBase:
+ Collaboration diagram for BlackScholesBase:

Public Member Functions

 BlackScholesBase (const Size paths, const std::vector< std::string > &currencies, const std::vector< Handle< YieldTermStructure > > &curves, const std::vector< Handle< Quote > > &fxSpots, const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< InterestRateIndex > > > &irIndices, const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< ZeroInflationIndex > > > &infIndices, const std::vector< std::string > &indices, const std::vector< std::string > &indexCurrencies, const Handle< BlackScholesModelWrapper > &model, const std::map< std::pair< std::string, std::string >, Handle< QuantExt::CorrelationTermStructure > > &correlations, const McParams &mcParams, const std::set< Date > &simulationDates, const IborFallbackConfig &iborFallbackConfig)
 
 BlackScholesBase (const Size paths, const std::string &currency, const Handle< YieldTermStructure > &curve, const std::string &index, const std::string &indexCurrency, const Handle< BlackScholesModelWrapper > &model, const Model::McParams &mcParams, const std::set< Date > &simulationDates, const IborFallbackConfig &iborFallbackConfig)
 
Type type () const override
 
const Date & referenceDate () const override
 
RandomVariable npv (const RandomVariable &amount, const Date &obsdate, const Filter &filter, const boost::optional< long > &memSlot, const RandomVariable &addRegressor1, const RandomVariable &addRegressor2) const override
 
RandomVariable fwdCompAvg (const bool isAvg, const std::string &index, const Date &obsdate, const Date &start, const Date &end, const Real spread, const Real gearing, const Integer lookback, const Natural rateCutoff, const Natural fixingDays, const bool includeSpread, const Real cap, const Real floor, const bool nakedOption, const bool localCapFloor) const override
 
void releaseMemory () override
 
void resetNPVMem () override
 
void toggleTrainingPaths () const override
 
Size trainingSamples () const override
 
Size size () const override
 
- Public Member Functions inherited from ModelImpl
 ModelImpl (const DayCounter &dayCounter, const Size size, const std::vector< std::string > &currencies, const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< InterestRateIndex > > > &irIndices, const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< ZeroInflationIndex > > > &infIndices, const std::vector< std::string > &indices, const std::vector< std::string > &indexCurrencies, const std::set< Date > &simulationDates, const IborFallbackConfig &iborFallbackConfig)
 
const std::string & baseCcy () const override
 
Real dt (const Date &d1, const Date &d2) const override
 
RandomVariable pay (const RandomVariable &amount, const Date &obsdate, const Date &paydate, const std::string &currency) const override
 
RandomVariable discount (const Date &obsdate, const Date &paydate, const std::string &currency) const override
 
RandomVariable eval (const std::string &index, const Date &obsdate, const Date &fwddate, const bool returnMissingMissingAsNull=false, const bool ignoreTodaysFixing=false) const override
 
Real fxSpotT0 (const std::string &forCcy, const std::string &domCcy) const override
 
RandomVariable barrierProbability (const std::string &index, const Date &obsdate1, const Date &obsdate2, const RandomVariable &barrier, const bool above) const override
 
Real extractT0Result (const RandomVariable &value) const override
 
- Public Member Functions inherited from Model
 Model (const Size n)
 
virtual ~Model ()
 
virtual Type type () const =0
 
virtual Size size () const
 
virtual Size trainingSamples () const
 
virtual void toggleTrainingPaths () const
 
virtual const Date & referenceDate () const =0
 
virtual const std::string & baseCcy () const =0
 
virtual Real dt (const Date &d1, const Date &d2) const
 
Real timeFromReference (const Date &d) const
 
virtual RandomVariable pay (const RandomVariable &amount, const Date &obsdate, const Date &paydate, const std::string &currency) const =0
 
virtual RandomVariable discount (const Date &obsdate, const Date &paydate, const std::string &currency) const =0
 
virtual RandomVariable npv (const RandomVariable &amount, const Date &obsdate, const Filter &filter, const boost::optional< long > &memSlot, const RandomVariable &addRegressor1, const RandomVariable &addRegressor2) const =0
 
virtual RandomVariable eval (const std::string &index, const Date &obsdate, const Date &fwddate, const bool returnMissingFixingAsNull=false, const bool ignoreTodaysFixing=false) const =0
 
virtual RandomVariable fwdCompAvg (const bool isAvg, const std::string &index, const Date &obsdate, const Date &start, const Date &end, const Real spread, const Real gearing, const Integer lookback, const Natural rateCutoff, const Natural fixingDays, const bool includeSpread, const Real cap, const Real floor, const bool nakedOption, const bool localCapFloor) const =0
 
virtual RandomVariable barrierProbability (const std::string &index, const Date &obsdate1, const Date &obsdate2, const RandomVariable &barrier, const bool above) const =0
 
virtual Real fxSpotT0 (const std::string &forCcy, const std::string &domCcy) const =0
 
virtual Real extractT0Result (const RandomVariable &value) const =0
 
virtual void releaseMemory ()
 
virtual void resetNPVMem ()
 
const std::map< std::string, boost::any > & additionalResults () const
 

Protected Member Functions

void performCalculations () const override
 
RandomVariable getIndexValue (const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const override
 
RandomVariable getIrIndexValue (const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const override
 
RandomVariable getInfIndexValue (const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const override
 
RandomVariable getDiscount (const Size idx, const Date &s, const Date &t) const override
 
RandomVariable getNumeraire (const Date &s) const override
 
Real getFxSpot (const Size idx) const override
 
Matrix getCorrelation () const
 
- Protected Member Functions inherited from ModelImpl
virtual RandomVariable getIndexValue (const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const =0
 
virtual RandomVariable getIrIndexValue (const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const =0
 
virtual RandomVariable getInfIndexValue (const Size indexNo, const Date &d, const Date &fwd) const =0
 
virtual RandomVariable getDiscount (const Size idx, const Date &s, const Date &t) const =0
 
virtual RandomVariable getNumeraire (const Date &s) const =0
 
virtual Real getFxSpot (const Size idx) const =0
 
virtual RandomVariable getFutureBarrierProb (const std::string &index, const Date &obsdate1, const Date &obsdate2, const RandomVariable &barrier, const bool above) const =0
 
- Protected Member Functions inherited from Model
void performCalculations () const override
 

Protected Attributes

const std::vector< Handle< YieldTermStructure > > curves_
 
const std::vector< Handle< Quote > > fxSpots_
 
const Handle< BlackScholesModelWrappermodel_
 
const std::map< std::pair< std::string, std::string >, Handle< QuantExt::CorrelationTermStructure > > correlations_
 
const McParams mcParams_
 
const std::vector< Date > simulationDates_
 
Date referenceDate_
 
std::set< Date > effectiveSimulationDates_
 
TimeGrid timeGrid_
 
std::vector< Size > positionInTimeGrid_
 
std::map< Date, std::vector< RandomVariable > > underlyingPaths_
 
std::map< Date, std::vector< RandomVariable > > underlyingPathsTraining_
 
bool inTrainingPhase_ = false
 
std::map< long, std::tuple< Array, Size, Matrix > > storedRegressionModel_
 
- Protected Attributes inherited from ModelImpl
const DayCounter dayCounter_
 
const std::vector< std::string > currencies_
 
const std::vector< std::string > indexCurrencies_
 
const std::set< Date > simulationDates_
 
const IborFallbackConfig iborFallbackConfig_
 
std::vector< std::pair< IndexInfo, QuantLib::ext::shared_ptr< InterestRateIndex > > > irIndices_
 
std::vector< std::pair< IndexInfo, QuantLib::ext::shared_ptr< ZeroInflationIndex > > > infIndices_
 
std::vector< IndexInfoindices_
 
- Protected Attributes inherited from Model
std::map< std::string, boost::any > additionalResults_
 

Additional Inherited Members

- Public Types inherited from Model
enum class  Type { MC , FD }
 

Detailed Description

Definition at line 39 of file blackscholesbase.hpp.

Constructor & Destructor Documentation

◆ BlackScholesBase() [1/2]

BlackScholesBase ( const Size  paths,
const std::vector< std::string > &  currencies,
const std::vector< Handle< YieldTermStructure > > &  curves,
const std::vector< Handle< Quote > > &  fxSpots,
const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< InterestRateIndex > > > &  irIndices,
const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< ZeroInflationIndex > > > &  infIndices,
const std::vector< std::string > &  indices,
const std::vector< std::string > &  indexCurrencies,
const Handle< BlackScholesModelWrapper > &  model,
const std::map< std::pair< std::string, std::string >, Handle< QuantExt::CorrelationTermStructure > > &  correlations,
const McParams mcParams,
const std::set< Date > &  simulationDates,
const IborFallbackConfig iborFallbackConfig 
)

Definition at line 47 of file blackscholesbase.cpp.

57 : ModelImpl(curves.at(0)->dayCounter(), paths, currencies, irIndices, infIndices, indices, indexCurrencies,
58 simulationDates, iborFallbackConfig),
59 curves_(curves), fxSpots_(fxSpots), model_(model), correlations_(correlations), mcParams_(mcParams) {
60
61 // check inputs
62
63 QL_REQUIRE(!model_.empty(), "model is empty");
64 QL_REQUIRE(!curves_.empty(), "no curves given");
65 QL_REQUIRE(currencies_.size() == curves_.size(), "number of currencies (" << currencies_.size()
66 << ") does not match number of curves ("
67 << curves_.size() << ")");
68 QL_REQUIRE(currencies_.size() == fxSpots_.size() + 1,
69 "number of currencies (" << currencies_.size() << ") does not match number of fx spots ("
70 << fxSpots_.size() << ") + 1");
71
72 QL_REQUIRE(indices_.size() == model_->processes().size(),
73 "mismatch of processes size (" << model_->processes().size() << ") and number of indices ("
74 << indices_.size() << ")");
75
76 // register with observables
77
78 for (auto const& o : fxSpots_)
79 registerWith(o);
80 for (auto const& o : correlations_)
81 registerWith(o.second);
82
83 registerWith(model_);
84
85} // BlackScholesBase ctor
const std::vector< Handle< Quote > > fxSpots_
const Handle< BlackScholesModelWrapper > model_
const std::map< std::pair< std::string, std::string >, Handle< QuantExt::CorrelationTermStructure > > correlations_
const std::vector< Handle< YieldTermStructure > > curves_
const std::vector< std::string > currencies_
Definition: modelimpl.hpp:107
ModelImpl(const DayCounter &dayCounter, const Size size, const std::vector< std::string > &currencies, const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< InterestRateIndex > > > &irIndices, const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< ZeroInflationIndex > > > &infIndices, const std::vector< std::string > &indices, const std::vector< std::string > &indexCurrencies, const std::set< Date > &simulationDates, const IborFallbackConfig &iborFallbackConfig)
Definition: modelimpl.cpp:35
std::vector< IndexInfo > indices_
Definition: modelimpl.hpp:114

◆ BlackScholesBase() [2/2]

BlackScholesBase ( const Size  paths,
const std::string &  currency,
const Handle< YieldTermStructure > &  curve,
const std::string &  index,
const std::string &  indexCurrency,
const Handle< BlackScholesModelWrapper > &  model,
const Model::McParams mcParams,
const std::set< Date > &  simulationDates,
const IborFallbackConfig iborFallbackConfig 
)

Definition at line 39 of file blackscholesbase.cpp.

44 : BlackScholesBase(paths, {currency}, {curve}, {}, {}, {}, {index}, {indexCurrency}, model, {}, mcParams,
45 simulationDates, iborFallbackConfig) {}
BlackScholesBase(const Size paths, const std::vector< std::string > &currencies, const std::vector< Handle< YieldTermStructure > > &curves, const std::vector< Handle< Quote > > &fxSpots, const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< InterestRateIndex > > > &irIndices, const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< ZeroInflationIndex > > > &infIndices, const std::vector< std::string > &indices, const std::vector< std::string > &indexCurrencies, const Handle< BlackScholesModelWrapper > &model, const std::map< std::pair< std::string, std::string >, Handle< QuantExt::CorrelationTermStructure > > &correlations, const McParams &mcParams, const std::set< Date > &simulationDates, const IborFallbackConfig &iborFallbackConfig)

Member Function Documentation

◆ type()

Type type ( ) const
overridevirtual

Implements Model.

Definition at line 68 of file blackscholesbase.hpp.

◆ referenceDate()

const Date & referenceDate ( ) const
overridevirtual

Implements Model.

Definition at line 107 of file blackscholesbase.cpp.

107 {
108 calculate();
109 return referenceDate_;
110}
+ Here is the caller graph for this function:

◆ npv()

RandomVariable npv ( const RandomVariable amount,
const Date &  obsdate,
const Filter filter,
const boost::optional< long > &  memSlot,
const RandomVariable addRegressor1,
const RandomVariable addRegressor2 
) const
overridevirtual

Implements Model.

Definition at line 227 of file blackscholesbase.cpp.

229 {
230
231 calculate();
232
233 // short cut, if amount is deterministic and no memslot is given
234
235 if (amount.deterministic() && !memSlot)
236 return amount;
237
238 // if obsdate is today, take a plain expectation
239
240 if (obsdate == referenceDate())
241 return expectation(amount);
242
243 // build the state
244
245 std::vector<const RandomVariable*> state;
246
247 if (!underlyingPaths_.empty()) {
248 for (auto const& r : underlyingPaths_.at(obsdate))
249 state.push_back(&r);
250 }
251
252 Size nModelStates = state.size();
253
254 if (addRegressor1.initialised() && (memSlot || !addRegressor1.deterministic()))
255 state.push_back(&addRegressor1);
256 if (addRegressor2.initialised() && (memSlot || !addRegressor2.deterministic()))
257 state.push_back(&addRegressor2);
258
259 Size nAddReg = state.size() - nModelStates;
260
261 // if the state is empty, return the plain expectation (no conditioning)
262
263 if (state.empty()) {
264 return expectation(amount);
265 }
266
267 // the regression model is given by coefficients and an optional coordinate transform
268
269 Array coeff;
270 Matrix coordinateTransform;
271
272 // if a memSlot is given and coefficients / coordinate transform are stored, we use them
273
274 bool haveStoredModel = false;
275
276 if (memSlot) {
277 if (auto it = storedRegressionModel_.find(*memSlot); it != storedRegressionModel_.end()) {
278 coeff = std::get<0>(it->second);
279 coordinateTransform = std::get<2>(it->second);
280 QL_REQUIRE(std::get<1>(it->second) == state.size(),
281 "BlackScholesBase::npv(): stored regression coefficients at mem slot "
282 << *memSlot << " are for state size " << std::get<1>(it->second) << ", actual state size is "
283 << state.size() << " (before possible coordinate transform).");
284 haveStoredModel = true;
285 }
286 }
287
288 // if we do not have retrieved a model in the previous step, we create it now
289
290 std::vector<RandomVariable> transformedState;
291
292 if(!haveStoredModel) {
293
294 // factor reduction to reduce dimensionalitty and handle collinearity
295
296 if (mcParams_.regressionVarianceCutoff != Null<Real>()) {
297 coordinateTransform = pcaCoordinateTransform(state, mcParams_.regressionVarianceCutoff);
298 transformedState = applyCoordinateTransform(state, coordinateTransform);
299 state = vec2vecptr(transformedState);
300 }
301
302 // train coefficients
303
304 coeff = regressionCoefficients(amount, state,
305 multiPathBasisSystem(state.size(), mcParams_.regressionOrder,
306 mcParams_.polynomType, std::min(size(), trainingSamples())),
307 filter, RandomVariableRegressionMethod::QR);
308 DLOG("BlackScholesBase::npv(" << ore::data::to_string(obsdate) << "): regression coefficients are " << coeff
309 << " (got model state size " << nModelStates << " and " << nAddReg
310 << " additional regressors, coordinate transform "
311 << coordinateTransform.columns() << " -> " << coordinateTransform.rows() << ")");
312
313 // store model if requried
314
315 if (memSlot) {
316 storedRegressionModel_[*memSlot] = std::make_tuple(coeff, nModelStates, coordinateTransform);
317 }
318
319 } else {
320
321 // apply the stored coordinate transform to the state
322
323 if(!coordinateTransform.empty()) {
324 transformedState = applyCoordinateTransform(state, coordinateTransform);
325 state = vec2vecptr(transformedState);
326 }
327 }
328
329 // compute conditional expectation and return the result
330
331 return conditionalExpectation(state,
332 multiPathBasisSystem(state.size(), mcParams_.regressionOrder, mcParams_.polynomType,
333 std::min(size(), trainingSamples())),
334 coeff);
335}
Size size() const override
const Date & referenceDate() const override
std::map< long, std::tuple< Array, Size, Matrix > > storedRegressionModel_
std::map< Date, std::vector< RandomVariable > > underlyingPaths_
Size trainingSamples() const override
SafeStack< Filter > filter
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
Array regressionCoefficients(RandomVariable r, const std::vector< const RandomVariable * > &regressor, const std::vector< std::function< RandomVariable(const std::vector< const RandomVariable * > &)> > &basisFn, const Filter &filter, const RandomVariableRegressionMethod regressionMethod, const std::string &debugLabel)
RandomVariable expectation(const RandomVariable &r)
RandomVariable conditionalExpectation(const std::vector< const RandomVariable * > &regressor, const std::vector< std::function< RandomVariable(const std::vector< const RandomVariable * > &)> > &basisFn, const Array &coefficients)
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
QuantLib::Real regressionVarianceCutoff
Definition: model.hpp:61
QuantLib::LsmBasisSystem::PolynomialType polynomType
Definition: model.hpp:58
+ Here is the call graph for this function:

◆ fwdCompAvg()

RandomVariable fwdCompAvg ( const bool  isAvg,
const std::string &  index,
const Date &  obsdate,
const Date &  start,
const Date &  end,
const Real  spread,
const Real  gearing,
const Integer  lookback,
const Natural  rateCutoff,
const Natural  fixingDays,
const bool  includeSpread,
const Real  cap,
const Real  floor,
const bool  nakedOption,
const bool  localCapFloor 
) const
overridevirtual

Implements Model.

Definition at line 187 of file blackscholesbase.cpp.

191 {
192 calculate();
193 auto index = std::find_if(irIndices_.begin(), irIndices_.end(), comp(indexInput));
194 QL_REQUIRE(index != irIndices_.end(),
195 "BlackScholesBase::fwdCompAvg(): did not find ir index " << indexInput << " - this is unexpected.");
196 auto on = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(index->second);
197 QL_REQUIRE(on, "BlackScholesBase::fwdCompAvg(): expected on index for " << indexInput);
198 // if we want to support cap / floors we need the OIS CF surface
199 QL_REQUIRE(cap > 999998.0 && floor < -999998.0,
200 "BlackScholesBase:fwdCompAvg(): cap (" << cap << ") / floor (" << floor << ") not supported");
201 QuantLib::ext::shared_ptr<QuantLib::FloatingRateCoupon> coupon;
202 QuantLib::ext::shared_ptr<QuantLib::FloatingRateCouponPricer> pricer;
203 if (isAvg) {
204 coupon = QuantLib::ext::make_shared<QuantExt::AverageONIndexedCoupon>(
205 end, 1.0, start, end, on, gearing, spread, rateCutoff, on->dayCounter(), lookback * Days, fixingDays);
206 pricer = QuantLib::ext::make_shared<AverageONIndexedCouponPricer>();
207 } else {
208 coupon = QuantLib::ext::make_shared<QuantExt::OvernightIndexedCoupon>(end, 1.0, start, end, on, gearing, spread, Date(),
209 Date(), on->dayCounter(), false, includeSpread,
210 lookback * Days, rateCutoff, fixingDays);
211 pricer = QuantLib::ext::make_shared<OvernightIndexedCouponPricer>();
212 }
213 coupon->setPricer(pricer);
214 return RandomVariable(size(), coupon->rate());
215}
std::vector< std::pair< IndexInfo, QuantLib::ext::shared_ptr< InterestRateIndex > > > irIndices_
Definition: modelimpl.hpp:112
+ Here is the call graph for this function:

◆ releaseMemory()

void releaseMemory ( )
overridevirtual

Reimplemented from Model.

Definition at line 337 of file blackscholesbase.cpp.

337 {
338 underlyingPaths_.clear();
340}
std::map< Date, std::vector< RandomVariable > > underlyingPathsTraining_

◆ resetNPVMem()

void resetNPVMem ( )
overridevirtual

Reimplemented from Model.

Definition at line 342 of file blackscholesbase.cpp.

342{ storedRegressionModel_.clear(); }

◆ toggleTrainingPaths()

void toggleTrainingPaths ( ) const
overridevirtual

Reimplemented from Model.

Definition at line 344 of file blackscholesbase.cpp.

◆ trainingSamples()

Size trainingSamples ( ) const
overridevirtual

Reimplemented from Model.

Definition at line 349 of file blackscholesbase.cpp.

+ Here is the caller graph for this function:

◆ size()

Size size ( ) const
overridevirtual

Reimplemented from Model.

Definition at line 351 of file blackscholesbase.cpp.

351 {
354 else
355 return Model::size();
356}
virtual Size size() const
Definition: model.hpp:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ performCalculations()

void performCalculations ( ) const
overrideprotected

Definition at line 112 of file blackscholesbase.cpp.

112 {
113
114 QL_REQUIRE(!inTrainingPhase_,
115 "BlackScholesBase::performCalculations(): state inTrainingPhase should be false, this was "
116 "not resetted appropriately.");
117
118 referenceDate_ = curves_.front()->referenceDate();
119
120 // set up time grid
121
122 effectiveSimulationDates_ = model_->effectiveSimulationDates();
123
124 std::vector<Real> times;
125 for (auto const& d : effectiveSimulationDates_) {
126 times.push_back(timeFromReference(d));
127 }
128
129 timeGrid_ = model_->discretisationTimeGrid();
130 positionInTimeGrid_.resize(times.size());
131 for (Size i = 0; i < positionInTimeGrid_.size(); ++i)
132 positionInTimeGrid_[i] = timeGrid_.index(times[i]);
133
134 underlyingPaths_.clear();
136}
std::set< Date > effectiveSimulationDates_
std::vector< Size > positionInTimeGrid_
Real timeFromReference(const Date &d) const
Definition: model.hpp:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getIndexValue()

RandomVariable getIndexValue ( const Size  indexNo,
const Date &  d,
const Date &  fwd = Null<Date>() 
) const
overrideprotectedvirtual

Implements ModelImpl.

Definition at line 138 of file blackscholesbase.cpp.

138 {
139 Date effFwd = fwd;
140 if (indices_[indexNo].isComm()) {
141 Date expiry = indices_[indexNo].comm(d)->expiryDate();
142 // if a future is referenced we set the forward date effectively used below to the future's expiry date
143 if (expiry != Date())
144 effFwd = expiry;
145 // if the future expiry is past the obsdate, we return the spot as of the obsdate, i.e. we
146 // freeze the future value after its expiry, but keep it available for observation
147 // TOOD should we throw an exception instead?
148 effFwd = std::max(effFwd, d);
149 }
150 QL_REQUIRE(underlyingPaths_.find(d) != underlyingPaths_.end(), "did not find path for " << d);
151 auto res = underlyingPaths_.at(d).at(indexNo);
152 // compute forwarding factor
153 if (effFwd != Null<Date>()) {
154 auto p = model_->processes().at(indexNo);
155 res *= RandomVariable(size(), p->dividendYield()->discount(effFwd) / p->dividendYield()->discount(d) /
156 (p->riskFreeRate()->discount(effFwd) / p->riskFreeRate()->discount(d)));
157 }
158 return res;
159}
+ Here is the call graph for this function:

◆ getIrIndexValue()

RandomVariable getIrIndexValue ( const Size  indexNo,
const Date &  d,
const Date &  fwd = Null<Date>() 
) const
overrideprotectedvirtual

Implements ModelImpl.

Definition at line 161 of file blackscholesbase.cpp.

161 {
162 Date effFixingDate = d;
163 if (fwd != Null<Date>())
164 effFixingDate = fwd;
165 // ensure a valid fixing date
166 effFixingDate = irIndices_.at(indexNo).second->fixingCalendar().adjust(effFixingDate);
167 return RandomVariable(size(), irIndices_.at(indexNo).second->fixing(effFixingDate));
168}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInfIndexValue()

RandomVariable getInfIndexValue ( const Size  indexNo,
const Date &  d,
const Date &  fwd = Null<Date>() 
) const
overrideprotectedvirtual

Implements ModelImpl.

Definition at line 170 of file blackscholesbase.cpp.

170 {
171 Date effFixingDate = d;
172 if (fwd != Null<Date>())
173 effFixingDate = fwd;
174 return RandomVariable(size(), infIndices_.at(indexNo).second->fixing(effFixingDate));
175}
std::vector< std::pair< IndexInfo, QuantLib::ext::shared_ptr< ZeroInflationIndex > > > infIndices_
Definition: modelimpl.hpp:113
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDiscount()

RandomVariable getDiscount ( const Size  idx,
const Date &  s,
const Date &  t 
) const
overrideprotectedvirtual

Implements ModelImpl.

Definition at line 217 of file blackscholesbase.cpp.

217 {
218 return RandomVariable(size(), curves_.at(idx)->discount(t) / curves_.at(idx)->discount(s));
219}
+ Here is the call graph for this function:

◆ getNumeraire()

RandomVariable getNumeraire ( const Date &  s) const
overrideprotectedvirtual

Implements ModelImpl.

Definition at line 221 of file blackscholesbase.cpp.

221 {
222 return RandomVariable(size(), 1.0 / curves_.at(0)->discount(s));
223}
+ Here is the call graph for this function:

◆ getFxSpot()

Real getFxSpot ( const Size  idx) const
overrideprotectedvirtual

Implements ModelImpl.

Definition at line 225 of file blackscholesbase.cpp.

225{ return fxSpots_.at(idx)->value(); }

◆ getCorrelation()

Matrix getCorrelation ( ) const
protected

Definition at line 87 of file blackscholesbase.cpp.

87 {
88 Matrix correlation(indices_.size(), indices_.size(), 0.0);
89 for (Size i = 0; i < indices_.size(); ++i)
90 correlation[i][i] = 1.0;
91 for (auto const& c : correlations_) {
92 IndexInfo inf1(c.first.first), inf2(c.first.second);
93 auto ind1 = std::find(indices_.begin(), indices_.end(), inf1);
94 auto ind2 = std::find(indices_.begin(), indices_.end(), inf2);
95 if (ind1 != indices_.end() && ind2 != indices_.end()) {
96 // EQ, FX, COMM index
97 Size i1 = std::distance(indices_.begin(), ind1);
98 Size i2 = std::distance(indices_.begin(), ind2);
99 correlation[i1][i2] = correlation[i2][i1] = c.second->correlation(0.0); // we assume a constant correlation!
100 }
101 }
102 DLOG("BlackScholesBase correlation matrix:");
103 DLOGGERSTREAM(correlation);
104 return correlation;
105}
#define DLOGGERSTREAM(text)
Definition: log.hpp:632
+ Here is the caller graph for this function:

Member Data Documentation

◆ curves_

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

Definition at line 98 of file blackscholesbase.hpp.

◆ fxSpots_

const std::vector<Handle<Quote> > fxSpots_
protected

Definition at line 99 of file blackscholesbase.hpp.

◆ model_

const Handle<BlackScholesModelWrapper> model_
protected

Definition at line 100 of file blackscholesbase.hpp.

◆ correlations_

const std::map<std::pair<std::string, std::string>, Handle<QuantExt::CorrelationTermStructure> > correlations_
protected

Definition at line 101 of file blackscholesbase.hpp.

◆ mcParams_

const McParams mcParams_
protected

Definition at line 102 of file blackscholesbase.hpp.

◆ simulationDates_

const std::vector<Date> simulationDates_
protected

Definition at line 103 of file blackscholesbase.hpp.

◆ referenceDate_

Date referenceDate_
mutableprotected

Definition at line 106 of file blackscholesbase.hpp.

◆ effectiveSimulationDates_

std::set<Date> effectiveSimulationDates_
mutableprotected

Definition at line 107 of file blackscholesbase.hpp.

◆ timeGrid_

TimeGrid timeGrid_
mutableprotected

Definition at line 108 of file blackscholesbase.hpp.

◆ positionInTimeGrid_

std::vector<Size> positionInTimeGrid_
mutableprotected

Definition at line 109 of file blackscholesbase.hpp.

◆ underlyingPaths_

std::map<Date, std::vector<RandomVariable> > underlyingPaths_
mutableprotected

Definition at line 110 of file blackscholesbase.hpp.

◆ underlyingPathsTraining_

std::map<Date, std::vector<RandomVariable> > underlyingPathsTraining_
mutableprotected

Definition at line 111 of file blackscholesbase.hpp.

◆ inTrainingPhase_

bool inTrainingPhase_ = false
mutableprotected

Definition at line 112 of file blackscholesbase.hpp.

◆ storedRegressionModel_

std::map<long, std::tuple<Array, Size, Matrix> > storedRegressionModel_
mutableprotected

Definition at line 115 of file blackscholesbase.hpp.