31#include <qle/models/lgmfdsolver.hpp>
34#include <ql/math/comparison.hpp>
35#include <ql/quotes/simplequote.hpp>
44 const Handle<YieldTermStructure>& curve,
45 const std::vector<std::pair<std::string, QuantLib::ext::shared_ptr<InterestRateIndex>>>& irIndices,
46 const std::set<Date>& simulationDates,
const Size stateGridPoints,
47 const Size timeStepsPerYear,
const Real mesherEpsilon,
49 :
ModelImpl(curve->dayCounter(), stateGridPoints, {currency}, irIndices, {}, {}, {}, simulationDates,
51 cam_(cam), currency_(currency), curve_(curve), simulationDates_(simulationDates),
52 stateGridPoints_(stateGridPoints), timeStepsPerYear_(timeStepsPerYear), mesherEpsilon_(mesherEpsilon),
53 iborFallbackConfig_(iborFallbackConfig) {
57 QL_REQUIRE(!cam_.empty(),
"model is empty");
83 solver_ = std::unique_ptr<LgmBackwardSolver>(
104 QL_FAIL(
"getFutureBarrierProb not implemented by FdGaussianCam");
108 QL_FAIL(
"FdGaussianGam::getIndexValue(): non-ir indices are not allowed, got fx/eq/com index #" << indexNo);
113 if (fwd != Null<Date>())
120 return cacheValue->second;
132 QL_FAIL(
"FdGaussianGam::getInfIndexValue(): non-ir indices are not allowed, got inf index #" << indexNo);
136 const Date& start,
const Date& end,
const Real spread,
const Real gearing,
137 const Integer lookback,
const Natural rateCutoff,
const Natural fixingDays,
138 const bool includeSpread,
const Real cap,
const Real floor,
139 const bool nakedOption,
const bool localCapFloor)
const {
142 [&indexInput](
const std::pair<
IndexInfo, QuantLib::ext::shared_ptr<InterestRateIndex>>& p) {
143 return p.first.name() == indexInput;
146 "FdGaussianCam::fwdComp() ir index " << indexInput <<
" not found, this is unexpected");
148 auto on = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(ir->second);
149 QL_REQUIRE(on,
"FdGaussianCam::fwdCompAvg(): expected on index for " << indexInput);
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);
157 return lgmv.
averagedOnRate(on, coupon->fixingDates(), coupon->valueDates(), coupon->dt(), rateCutoff,
158 includeSpread, spread, gearing, lookback * Days, cap, floor, localCapFloor,
162 return lgmv.
compoundedOnRate(on, coupon->fixingDates(), coupon->valueDates(), coupon->dt(), rateCutoff,
163 includeSpread, spread, gearing, lookback * Days, cap, floor, localCapFloor,
180 QL_FAIL(
"FdGaussianCam::getFxSpot(): this is a single ccy model, there is no fx spot for idx " << idx
185 const std::string& currency)
const {
192 const boost::optional<long>& memSlot,
const RandomVariable& addRegressor1,
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");
202 Real t1 = amount.
time();
215 QL_REQUIRE(t1 != Null<Real>(),
216 "FdGaussianCam::npv(): can not roll back amount wiithout time attached (to t0=" << t0 <<
")");
232 QL_REQUIRE(r.
deterministic(),
"FdGaussianCam::extractT0Result(): internal error, expected result to be "
233 "deterministic after rollback to time t = 0");
RandomVariable discountBond(const Time t, const Time T, const RandomVariable &x, const Handle< YieldTermStructure > &discountCurve=Handle< YieldTermStructure >()) const
RandomVariable fixing(const boost::shared_ptr< InterestRateIndex > &index, const Date &fixingDate, const Time t, const RandomVariable &x) const
RandomVariable averagedOnRate(const boost::shared_ptr< OvernightIndex > &index, const std::vector< Date > &fixingDates, const std::vector< Date > &valueDates, const std::vector< Real > &dt, const Natural rateCutoff, const bool includeSpread, const Real spread, const Real gearing, const Period lookback, Real cap, Real floor, const bool localCapFloor, const bool nakedOption, const Time t, const RandomVariable &x) const
RandomVariable numeraire(const Time t, const RandomVariable &x, const Handle< YieldTermStructure > &discountCurve=Handle< YieldTermStructure >()) const
RandomVariable compoundedOnRate(const boost::shared_ptr< OvernightIndex > &index, const std::vector< Date > &fixingDates, const std::vector< Date > &valueDates, const std::vector< Real > &dt, const Natural rateCutoff, const bool includeSpread, const Real spread, const Real gearing, const Period lookback, Real cap, Real floor, const bool localCapFloor, const bool nakedOption, const Time t, const RandomVariable &x) const
std::set< Date > simulationDates_
RandomVariable getInfIndexValue(const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const override
void performCalculations() const override
void releaseMemory() override
RandomVariable getFutureBarrierProb(const std::string &index, const Date &obsdate1, const Date &obsdate2, const RandomVariable &barrier, const bool above) const override
RandomVariable getIrIndexValue(const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) 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
std::unique_ptr< LgmBackwardSolver > solver_
Real getFxSpot(const Size idx) const override
std::map< std::tuple< Size, Date, Date >, RandomVariable > irIndexValueCache_
const Date & referenceDate() const override
RandomVariable getNumeraire(const Date &s) const override
Handle< CrossAssetModel > cam_
Handle< YieldTermStructure > curve_
Real extractT0Result(const RandomVariable &result) const override
std::set< Date > effectiveSimulationDates_
RandomVariable pay(const RandomVariable &amount, const Date &obsdate, const Date &paydate, const std::string ¤cy) const override
RandomVariable getDiscount(const Size idx, const Date &s, const Date &t) const override
RandomVariable getIndexValue(const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) 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
FdGaussianCam(const Handle< CrossAssetModel > &cam, const std::string ¤cy, 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())
std::map< std::string, boost::any > additionalResults_
Real timeFromReference(const Date &d) const
std::vector< std::pair< IndexInfo, QuantLib::ext::shared_ptr< InterestRateIndex > > > irIndices_
RandomVariable pay(const RandomVariable &amount, const Date &obsdate, const Date &paydate, const std::string ¤cy) const override
SafeStack< Filter > filter
fd gaussian cross asset model for single underlying ir model
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
std::map< std::string, boost::any > getAdditionalResultsMap(const LgmCalibrationInfo &info)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.
Real at(const Size i) const
bool deterministic() const
void setTime(const Real time)
string conversion utilities