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

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

+ Inheritance diagram for FdGaussianCam:
+ Collaboration diagram for FdGaussianCam:

Public Member Functions

 FdGaussianCam (const Handle< CrossAssetModel > &cam, const std::string &currency, const Handle< YieldTermStructure > &curve, const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< InterestRateIndex > > > &irIndices, const std::set< Date > &simulationDates, const Size stateGridPoints=50, const Size timeStepsPerYear=24, const Real mesherEpsilon=1E-4, const IborFallbackConfig &iborFallbackConfig=IborFallbackConfig::defaultConfig())
 
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
 
Real extractT0Result (const RandomVariable &result) const override
 
RandomVariable pay (const RandomVariable &amount, const Date &obsdate, const Date &paydate, const std::string &currency) const override
 
void releaseMemory () 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
 

Private Member Functions

void performCalculations () const override
 
RandomVariable getFutureBarrierProb (const std::string &index, const Date &obsdate1, const Date &obsdate2, const RandomVariable &barrier, const bool above) 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
 

Private Attributes

Handle< CrossAssetModelcam_
 
std::string currency_
 
Handle< YieldTermStructure > curve_
 
std::set< Date > simulationDates_
 
Size stateGridPoints_
 
Size timeStepsPerYear_
 
Real mesherEpsilon_
 
IborFallbackConfig iborFallbackConfig_
 
Date referenceDate_
 
std::set< Date > effectiveSimulationDates_
 
std::unique_ptr< LgmBackwardSolver > solver_
 
std::map< std::tuple< Size, Date, Date >, RandomVariableirIndexValueCache_
 

Additional Inherited Members

- Public Types inherited from Model
enum class  Type { MC , FD }
 
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 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_
 

Detailed Description

Definition at line 39 of file fdgaussiancam.hpp.

Constructor & Destructor Documentation

◆ FdGaussianCam()

FdGaussianCam ( const Handle< CrossAssetModel > &  cam,
const std::string &  currency,
const Handle< YieldTermStructure > &  curve,
const std::vector< std::pair< std::string, QuantLib::ext::shared_ptr< InterestRateIndex > > > &  irIndices,
const std::set< Date > &  simulationDates,
const Size  stateGridPoints = 50,
const Size  timeStepsPerYear = 24,
const Real  mesherEpsilon = 1E-4,
const IborFallbackConfig iborFallbackConfig = IborFallbackConfig::defaultConfig() 
)

Definition at line 43 of file fdgaussiancam.cpp.

49 : ModelImpl(curve->dayCounter(), stateGridPoints, {currency}, irIndices, {}, {}, {}, simulationDates,
50 iborFallbackConfig),
51 cam_(cam), currency_(currency), curve_(curve), simulationDates_(simulationDates),
52 stateGridPoints_(stateGridPoints), timeStepsPerYear_(timeStepsPerYear), mesherEpsilon_(mesherEpsilon),
53 iborFallbackConfig_(iborFallbackConfig) {
54
55 // check inputs
56
57 QL_REQUIRE(!cam_.empty(), "model is empty");
58
59 // register with observables
60
61 registerWith(curve_);
62 registerWith(cam_);
63} // FdGaussianCam ctor
std::set< Date > simulationDates_
Handle< CrossAssetModel > cam_
Handle< YieldTermStructure > curve_
IborFallbackConfig iborFallbackConfig_
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

Member Function Documentation

◆ type()

Type type ( ) const
overridevirtual

Implements Model.

Definition at line 50 of file fdgaussiancam.hpp.

◆ referenceDate()

const Date & referenceDate ( ) const
overridevirtual

Implements Model.

Definition at line 65 of file fdgaussiancam.cpp.

65 {
66 calculate();
67 return referenceDate_;
68}
+ 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 191 of file fdgaussiancam.cpp.

193 {
194
195 QL_REQUIRE(!memSlot, "FdGaussianCam::npv(): mem slot not allowed.");
196 QL_REQUIRE(!filter.initialised(), "FdGaussianCam::npv(): filter not allowed");
197 QL_REQUIRE(!addRegressor1.initialised(), "FdGaussianCam::npv(). addRegressor1 not allowed");
198 QL_REQUIRE(!addRegressor2.initialised(), "FdGaussianCam::npv(). addRegressor2 not allowed");
199
200 calculate();
201
202 Real t1 = amount.time();
203 Real t0 = timeFromReference(obsdate);
204
205 // handle case when amount is deterministic
206
207 if (amount.deterministic()) {
208 RandomVariable result(amount);
209 result.setTime(t0);
210 return result;
211 }
212
213 // handle stochastic amount
214
215 QL_REQUIRE(t1 != Null<Real>(),
216 "FdGaussianCam::npv(): can not roll back amount wiithout time attached (to t0=" << t0 << ")");
217 RandomVariable result = solver_->rollback(amount, t1, t0);
218 result.setTime(t0);
219 return result;
220}
std::unique_ptr< LgmBackwardSolver > solver_
Real timeFromReference(const Date &d) const
Definition: model.hpp:92
SafeStack< Filter > filter
+ Here is the call graph for this function:
+ Here is the caller 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 135 of file fdgaussiancam.cpp.

139 {
140 calculate();
141 auto ir = std::find_if(irIndices_.begin(), irIndices_.end(),
142 [&indexInput](const std::pair<IndexInfo, QuantLib::ext::shared_ptr<InterestRateIndex>>& p) {
143 return p.first.name() == indexInput;
144 });
145 QL_REQUIRE(ir != irIndices_.end(),
146 "FdGaussianCam::fwdComp() ir index " << indexInput << " not found, this is unexpected");
147 LgmVectorised lgmv(cam_->lgm(0)->parametrization());
148 auto on = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(ir->second);
149 QL_REQUIRE(on, "FdGaussianCam::fwdCompAvg(): expected on index for " << indexInput);
150 // only used to extract fixing and value dates
151 auto coupon = QuantLib::ext::make_shared<QuantExt::OvernightIndexedCoupon>(
152 end, 1.0, start, end, on, gearing, spread, Date(), Date(), DayCounter(), false, includeSpread, lookback * Days,
153 rateCutoff, fixingDays);
154 // get model time and state
155 Date effobsdate = std::max(referenceDate(), obsdate);
156 if (isAvg) {
157 return lgmv.averagedOnRate(on, coupon->fixingDates(), coupon->valueDates(), coupon->dt(), rateCutoff,
158 includeSpread, spread, gearing, lookback * Days, cap, floor, localCapFloor,
159 nakedOption, timeFromReference(effobsdate),
160 solver_->stateGrid(timeFromReference(effobsdate)));
161 } else {
162 return lgmv.compoundedOnRate(on, coupon->fixingDates(), coupon->valueDates(), coupon->dt(), rateCutoff,
163 includeSpread, spread, gearing, lookback * Days, cap, floor, localCapFloor,
164 nakedOption, timeFromReference(effobsdate),
165 solver_->stateGrid(timeFromReference(effobsdate)));
166 }
167}
const Date & referenceDate() const override
std::vector< std::pair< IndexInfo, QuantLib::ext::shared_ptr< InterestRateIndex > > > irIndices_
Definition: modelimpl.hpp:112
+ Here is the call graph for this function:

◆ extractT0Result()

Real extractT0Result ( const RandomVariable result) const
overridevirtual

Implements Model.

Definition at line 222 of file fdgaussiancam.cpp.

222 {
223
224 calculate();
225
226 // roll back to today (if necessary)
227
228 RandomVariable r = npv(result, referenceDate(), Filter(), boost::none, RandomVariable(), RandomVariable());
229
230 // we expect the results to be determinstic as per LgmBackwardSolver interface
231
232 QL_REQUIRE(r.deterministic(), "FdGaussianCam::extractT0Result(): internal error, expected result to be "
233 "deterministic after rollback to time t = 0");
234
235 return r.at(0);
236}
RandomVariable npv(const RandomVariable &amount, const Date &obsdate, const Filter &filter, const boost::optional< long > &memSlot, const RandomVariable &addRegressor1, const RandomVariable &addRegressor2) const override
+ Here is the call graph for this function:

◆ pay()

RandomVariable pay ( const RandomVariable amount,
const Date &  obsdate,
const Date &  paydate,
const std::string &  currency 
) const
overridevirtual

Implements Model.

Definition at line 184 of file fdgaussiancam.cpp.

185 {
186 auto result = ModelImpl::pay(amount, obsdate, paydate, currency);
187 result.setTime(timeFromReference(obsdate));
188 return result;
189}
RandomVariable pay(const RandomVariable &amount, const Date &obsdate, const Date &paydate, const std::string &currency) const override
Definition: modelimpl.cpp:101
+ Here is the call graph for this function:

◆ releaseMemory()

void releaseMemory ( )
overridevirtual

Reimplemented from Model.

Definition at line 70 of file fdgaussiancam.cpp.

70{ irIndexValueCache_.clear(); }
std::map< std::tuple< Size, Date, Date >, RandomVariable > irIndexValueCache_

◆ performCalculations()

void performCalculations ( ) const
overrideprivate

Definition at line 72 of file fdgaussiancam.cpp.

72 {
73
74 if (simulationDates_.empty())
75 return;
76
77 // set ref date
78
79 referenceDate_ = curve_->referenceDate();
80
81 // build solver
82
83 solver_ = std::unique_ptr<LgmBackwardSolver>(
84 new LgmFdSolver(cam_->lgm(0), timeFromReference(*simulationDates_.rbegin()), QuantLib::FdmSchemeDesc::Douglas(),
86
87 // set up eff sim dates
88
91 for (auto const& d : simulationDates_) {
92 if (d >= referenceDate())
94 }
95
96 // set additional results provided by this model
97
98 auto ar = getAdditionalResultsMap(cam_->lgm(0)->getCalibrationInfo());
99 additionalResults_.insert(ar.begin(), ar.end());
100}
std::set< Date > effectiveSimulationDates_
std::map< std::string, boost::any > additionalResults_
Definition: model.hpp:153
std::map< std::string, boost::any > getAdditionalResultsMap(const LgmCalibrationInfo &info)
+ Here is the call graph for this function:

◆ getFutureBarrierProb()

RandomVariable getFutureBarrierProb ( const std::string &  index,
const Date &  obsdate1,
const Date &  obsdate2,
const RandomVariable barrier,
const bool  above 
) const
overrideprivatevirtual

Implements ModelImpl.

Definition at line 102 of file fdgaussiancam.cpp.

103 {
104 QL_FAIL("getFutureBarrierProb not implemented by FdGaussianCam");
105}

◆ getIndexValue()

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

Implements ModelImpl.

Definition at line 107 of file fdgaussiancam.cpp.

107 {
108 QL_FAIL("FdGaussianGam::getIndexValue(): non-ir indices are not allowed, got fx/eq/com index #" << indexNo);
109}

◆ getIrIndexValue()

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

Implements ModelImpl.

Definition at line 111 of file fdgaussiancam.cpp.

111 {
112 Date fixingDate = d;
113 if (fwd != Null<Date>())
114 fixingDate = fwd;
115 // ensure a valid fixing date
116 fixingDate = irIndices_[indexNo].second->fixingCalendar().adjust(fixingDate);
117 // look up required fixing in cache and return it if found
118 if (auto cacheValue = irIndexValueCache_.find(std::make_tuple(indexNo, d, fixingDate));
119 cacheValue != irIndexValueCache_.end()) {
120 return cacheValue->second;
121 }
122 // compute value, add to cache and return it
123 LgmVectorised lgmv(cam_->irlgm1f(0));
124 auto result = lgmv.fixing(irIndices_[indexNo].second, fixingDate, timeFromReference(d),
125 solver_->stateGrid(timeFromReference(d)));
126 result.setTime(timeFromReference(d));
127 irIndexValueCache_[std::make_tuple(indexNo, d, fixingDate)] = result;
128 return result;
129}
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
+ Here is the call graph for this function:

◆ getInfIndexValue()

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

Implements ModelImpl.

Definition at line 131 of file fdgaussiancam.cpp.

131 {
132 QL_FAIL("FdGaussianGam::getInfIndexValue(): non-ir indices are not allowed, got inf index #" << indexNo);
133}

◆ getDiscount()

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

Implements ModelImpl.

Definition at line 169 of file fdgaussiancam.cpp.

169 {
170 LgmVectorised lgmv(cam_->lgm(0)->parametrization());
171 return lgmv.discountBond(timeFromReference(s), timeFromReference(t), solver_->stateGrid(timeFromReference(s)));
172}
+ Here is the call graph for this function:

◆ getNumeraire()

RandomVariable getNumeraire ( const Date &  s) const
overrideprivatevirtual

Implements ModelImpl.

Definition at line 174 of file fdgaussiancam.cpp.

174 {
175 LgmVectorised lgmv(cam_->lgm(0)->parametrization());
176 return lgmv.numeraire(timeFromReference(s), solver_->stateGrid(timeFromReference(s)));
177}
+ Here is the call graph for this function:

◆ getFxSpot()

Real getFxSpot ( const Size  idx) const
overrideprivatevirtual

Implements ModelImpl.

Definition at line 179 of file fdgaussiancam.cpp.

179 {
180 QL_FAIL("FdGaussianCam::getFxSpot(): this is a single ccy model, there is no fx spot for idx " << idx
181 << " available.");
182}

Member Data Documentation

◆ cam_

Handle<CrossAssetModel> cam_
private

Definition at line 80 of file fdgaussiancam.hpp.

◆ currency_

std::string currency_
private

Definition at line 81 of file fdgaussiancam.hpp.

◆ curve_

Handle<YieldTermStructure> curve_
private

Definition at line 82 of file fdgaussiancam.hpp.

◆ simulationDates_

std::set<Date> simulationDates_
private

Definition at line 83 of file fdgaussiancam.hpp.

◆ stateGridPoints_

Size stateGridPoints_
private

Definition at line 84 of file fdgaussiancam.hpp.

◆ timeStepsPerYear_

Size timeStepsPerYear_
private

Definition at line 85 of file fdgaussiancam.hpp.

◆ mesherEpsilon_

Real mesherEpsilon_
private

Definition at line 86 of file fdgaussiancam.hpp.

◆ iborFallbackConfig_

IborFallbackConfig iborFallbackConfig_
private

Definition at line 87 of file fdgaussiancam.hpp.

◆ referenceDate_

Date referenceDate_
mutableprivate

Definition at line 90 of file fdgaussiancam.hpp.

◆ effectiveSimulationDates_

std::set<Date> effectiveSimulationDates_
mutableprivate

Definition at line 91 of file fdgaussiancam.hpp.

◆ solver_

std::unique_ptr<LgmBackwardSolver> solver_
mutableprivate

Definition at line 92 of file fdgaussiancam.hpp.

◆ irIndexValueCache_

std::map<std::tuple<Size, Date, Date>, RandomVariable> irIndexValueCache_
mutableprivate

Definition at line 95 of file fdgaussiancam.hpp.