25#include <ql/experimental/math/piecewiseintegral.hpp>
26#include <ql/math/integrals/simpsonintegral.hpp>
27#include <ql/math/matrixutilities/symmetricschurdecomposition.hpp>
28#include <ql/processes/eulerdiscretization.hpp>
51 return out <<
"CrState";
53 QL_FAIL(
"Did not recognise cross asset model type " <<
static_cast<int>(type) <<
".");
88 const Matrix& correlation,
const SalvagingAlgorithm::Type salvaging,
91 discretization_(discretization) {
96 const std::vector<QuantLib::ext::shared_ptr<FxBsParametrization>>& fxParametrizations,
97 const Matrix& correlation,
const SalvagingAlgorithm::Type salvaging,
99 :
LinkableCalibratedModel(), irModels_(currencyModels), rho_(correlation), salvaging_(salvaging), measure_(measure),
100 discretization_(discretization) {
101 for (Size i = 0; i < currencyModels.size(); ++i) {
102 p_.push_back(currencyModels[i]->parametrizationBase());
104 for (Size i = 0; i < fxParametrizations.size(); ++i) {
105 p_.push_back(fxParametrizations[i]);
112 stateProcess_ = QuantLib::ext::make_shared<CrossAssetStateProcess>(shared_from_this());
124 "currency " << ccy.code() <<
" not present in cross asset model");
133 "equity name " << name <<
" not present in cross asset model");
142 "commodity name " << name <<
" not present in cross asset model");
151 "inflation index " << index <<
" not present in cross asset model");
160 "credit name " << name <<
" not present in cross asset model");
167 for (Size i = 0; i <
p_.size(); ++i) {
178 "CrossAssetModel::brownians(): asset class " << t <<
", component " << i <<
" not known.");
184 "CrossAssetModel::auxBrownians(): asset class " << t <<
", component " << i <<
" not known.");
190 "CrossAssetModel::stateVariables(): asset class " << t <<
", component " << i <<
" not known.");
196 "CrossAssetModel::arguments(): asset class " << t <<
", component " << i <<
" not known.");
202 "CrossAssetModel::modelType(): asset class " << t <<
", component " << i <<
" not known.");
207 QL_REQUIRE(
idx_[(Size)t].size() > i,
208 "CrossAssetModel::idx(): asset class " << t <<
", component " << i <<
" not known.");
209 return idx_[(Size)t][i];
213 QL_REQUIRE(offset <
brownians(t, i),
"c-offset (" << offset <<
") for asset class " << t <<
" and index " << i
214 <<
" must be in 0..." <<
brownians(t, i) - 1);
215 QL_REQUIRE(
cIdx_[(Size)t].size() > i,
216 "CrossAssetModel::cIdx(): asset class " << t <<
", component " << i <<
" not known.");
217 return cIdx_[(Size)t][i] + offset;
221 QL_REQUIRE(offset <
brownians(t, i) +
auxBrownians(t, i),
"c-offset (" << offset <<
") for asset class " << t
222 <<
" and index " << i <<
" must be in 0..."
224 QL_REQUIRE(
wIdx_[(Size)t].size() > i,
225 "CrossAssetModel::wIdx(): asset class " << t <<
", component " << i <<
" not known.");
226 return wIdx_[(Size)t][i] + offset;
230 QL_REQUIRE(offset <
stateVariables(t, i),
"p-offset (" << offset <<
") for asset class " << t <<
" and index " << i
232 QL_REQUIRE(
pIdx_[(Size)t].size() > i,
233 "CrossAssetModel::pIdx(): asset class " << t <<
", component " << i <<
" not known.");
234 return pIdx_[(Size)t][i] + offset;
238 QL_REQUIRE(offset <
arguments(t, i),
"a-offset (" << offset <<
") for asset class " << t <<
" and index " << i
239 <<
" must be in 0..." <<
arguments(t, i) - 1);
240 QL_REQUIRE(
aIdx_[(Size)t].size() > i,
241 "CrossAssetModel::aIdx(): asset class " << t <<
", component " << i <<
" not known.");
242 return aIdx_[(Size)t][i];
246 const Size jOffset)
const {
251 const Size iOffset,
const Size jOffset) {
252 Size row =
cIdx(s, i, iOffset);
253 Size column =
cIdx(t, j, jOffset);
254 QL_REQUIRE(row != column ||
close_enough(
value, 1.0),
"correlation must be 1 at (" << row <<
"," << column <<
")");
255 QL_REQUIRE(
value >= -1.0 &&
value <= 1.0,
"correlation must be in [-1,1] at (" << row <<
"," << column <<
")");
278 const bool usePiecewiseIntegration)
const {
280 if (!usePiecewiseIntegration) {
288 std::vector<Time> allTimes;
289 for (Size i = 0; i <
p_.size(); ++i) {
291 allTimes.insert(allTimes.end(),
p_[i]->parameterTimes(j).begin(),
p_[i]->parameterTimes(j).end());
298std::pair<CrossAssetModel::AssetType, CrossAssetModel::ModelType>
300 if (QuantLib::ext::dynamic_pointer_cast<IrHwParametrization>(
p_[i]))
302 if (QuantLib::ext::dynamic_pointer_cast<IrLgm1fParametrization>(
p_[i]))
304 if (QuantLib::ext::dynamic_pointer_cast<FxBsParametrization>(
p_[i]))
306 if (QuantLib::ext::dynamic_pointer_cast<InfDkParametrization>(
p_[i]))
308 if (QuantLib::ext::dynamic_pointer_cast<InfJyParameterization>(
p_[i]))
310 if (QuantLib::ext::dynamic_pointer_cast<CrLgm1fParametrization>(
p_[i]))
312 if (QuantLib::ext::dynamic_pointer_cast<CrCirppParametrization>(
p_[i]))
314 if (QuantLib::ext::dynamic_pointer_cast<EqBsParametrization>(
p_[i]))
316 if (QuantLib::ext::dynamic_pointer_cast<CommoditySchwartzParametrization>(
p_[i]))
318 if (QuantLib::ext::dynamic_pointer_cast<CrStateParametrization>(
p_[i]))
320 QL_FAIL(
"parametrization " << i <<
" has unknown type");
326 if (
auto p = QuantLib::ext::dynamic_pointer_cast<IrHwParametrization>(
p_[i])) {
329 if (QuantLib::ext::dynamic_pointer_cast<IrLgm1fParametrization>(
p_[i])) {
332 if (QuantLib::ext::dynamic_pointer_cast<FxBsParametrization>(
p_[i]))
334 if (QuantLib::ext::dynamic_pointer_cast<InfDkParametrization>(
p_[i]))
336 if (QuantLib::ext::dynamic_pointer_cast<InfJyParameterization>(
p_[i]))
338 if (QuantLib::ext::dynamic_pointer_cast<CrLgm1fParametrization>(
p_[i]))
340 if (QuantLib::ext::dynamic_pointer_cast<CrCirppParametrization>(
p_[i]))
342 if (QuantLib::ext::dynamic_pointer_cast<EqBsParametrization>(
p_[i]))
344 if (QuantLib::ext::dynamic_pointer_cast<CommoditySchwartzParametrization>(
p_[i]))
346 if (QuantLib::ext::dynamic_pointer_cast<CrStateParametrization>(
p_[i]))
348 QL_FAIL(
"parametrization " << i <<
" has unknown type");
352 if (
auto p = QuantLib::ext::dynamic_pointer_cast<IrHwParametrization>(
p_[i])) {
355 if (
auto p = QuantLib::ext::dynamic_pointer_cast<IrLgm1fParametrization>(
p_[i])) {
358 if (QuantLib::ext::dynamic_pointer_cast<FxBsParametrization>(
p_[i]))
360 if (QuantLib::ext::dynamic_pointer_cast<InfDkParametrization>(
p_[i]))
362 if (QuantLib::ext::dynamic_pointer_cast<InfJyParameterization>(
p_[i]))
364 if (QuantLib::ext::dynamic_pointer_cast<CrLgm1fParametrization>(
p_[i]))
366 if (QuantLib::ext::dynamic_pointer_cast<CrCirppParametrization>(
p_[i]))
368 if (QuantLib::ext::dynamic_pointer_cast<EqBsParametrization>(
p_[i]))
370 if (QuantLib::ext::dynamic_pointer_cast<CommoditySchwartzParametrization>(
p_[i]))
372 if (QuantLib::ext::dynamic_pointer_cast<CrStateParametrization>(
p_[i]))
374 QL_FAIL(
"parametrization " << i <<
" has unknown type");
378 if (
auto p = QuantLib::ext::dynamic_pointer_cast<IrHwParametrization>(
p_[i])) {
382 if (
auto p = QuantLib::ext::dynamic_pointer_cast<IrLgm1fParametrization>(
p_[i])) {
386 if (QuantLib::ext::dynamic_pointer_cast<FxBsParametrization>(
p_[i]))
388 if (QuantLib::ext::dynamic_pointer_cast<InfDkParametrization>(
p_[i]))
390 if (QuantLib::ext::dynamic_pointer_cast<InfJyParameterization>(
p_[i]))
392 if (QuantLib::ext::dynamic_pointer_cast<CrLgm1fParametrization>(
p_[i]))
394 if (QuantLib::ext::dynamic_pointer_cast<CrCirppParametrization>(
p_[i]))
396 if (QuantLib::ext::dynamic_pointer_cast<EqBsParametrization>(
p_[i]))
398 if (QuantLib::ext::dynamic_pointer_cast<CommoditySchwartzParametrization>(
p_[i]))
400 if (QuantLib::ext::dynamic_pointer_cast<CrStateParametrization>(
p_[i]))
402 QL_FAIL(
"parametrization " << i <<
" has unknown type");
407 idx_[(Size)t].push_back(i);
418 QL_REQUIRE(
wIdx_[(Size)t].back() ==
cIdx_[(Size)t].back(),
419 "CrossAssetModel::updateIndices(): assertion error, wIdx ("
420 <<
wIdx_[(Size)t].back() <<
") != cIdx (" <<
cIdx_[(Size)t].back() <<
") for asset type " << t
421 <<
" at index " <<
wIdx_[(Size)t].size() <<
" for Euler discretization");
423 QL_REQUIRE(
wIdx_[(Size)t].back() ==
pIdx_[(Size)t].back(),
424 "CrossAssetModel::updateIndices(): assertion error, wIdx ("
425 <<
wIdx_[(Size)t].back() <<
") != pIdx (" <<
pIdx_[(Size)t].back() <<
") for asset type " << t
426 <<
" at index " <<
wIdx_[(Size)t].size() <<
" for Exact discretization");
435 Size cIdxTmp = 0, wIdxTmp = 0, pIdxTmp = 0, aIdxTmp = 0;
454 "All IR models must be of the same type (HW, LGM can not be mixed)");
459 irModels_.push_back(QuantLib::ext::make_shared<LinearGaussMarkovModel>(
460 QuantLib::ext::dynamic_pointer_cast<IrLgm1fParametrization>(
p_[i]),
measure_,
463 irModels_.push_back(QuantLib::ext::make_shared<HwModel>(QuantLib::ext::dynamic_pointer_cast<IrHwParametrization>(
p_[i]),
484 fxModels_.push_back(QuantLib::ext::make_shared<FxBsModel>(QuantLib::ext::dynamic_pointer_cast<FxBsParametrization>(
p_[i])));
499 "there must be n-1 fx "
500 "for n ir parametrizations, found "
508 Size uniqueCurrencies = 0;
509 std::vector<Currency> currencies;
512 for (Size j = 0; j < i; ++j) {
513 if (
ir(i)->currency() == currencies[j])
516 uniqueCurrencies += tmp;
517 currencies.push_back(
ir(i)->currency());
523 QL_REQUIRE(
fx(i)->currency() ==
ir(i + 1)->currency(),
524 "fx parametrization #" << i <<
" must be for currency of ir parametrization #" << (i + 1)
525 <<
", but they are " <<
fx(i)->currency() <<
" and " <<
ir(i + 1)->currency()
551 auto tmp = QuantLib::ext::dynamic_pointer_cast<CrCirppParametrization>(
p_[i]);
552 QL_REQUIRE(tmp,
"CrossAssetModelPlus::initializeParametrizations(): expected CrCirppParametrization");
553 crcirppModel_.push_back(QuantLib::ext::make_shared<CrCirpp>(tmp));
555 crcirppModel_.push_back(QuantLib::ext::shared_ptr<CrCirpp>());
585 Currency eqCcy =
eq(i)->currency();
589 "Invalid currency for equity " <<
eqbs(i)->name());
591 QL_FAIL(
"Invalid currency (" << eqCcy.code() <<
") for equity " <<
eqbs(i)->name());
599 QuantLib::ext::shared_ptr<CommoditySchwartzParametrization> csp =
600 QuantLib::ext::dynamic_pointer_cast<CommoditySchwartzParametrization>(
p_[i]);
601 QuantLib::ext::shared_ptr<CommoditySchwartzModel> csm =
602 csp ? QuantLib::ext::make_shared<CommoditySchwartzModel>(csp, getComSchwartzDiscretization(
discretization_))
631 Currency comCcy =
com(i)->currency();
635 "Invalid currency for commodity " <<
combs(i)->name());
637 QL_FAIL(
"Invalid currency (" << comCcy.code() <<
") for commodity " <<
combs(i)->name());
652 rho_ = Matrix(n, n, 0.0);
653 for (Size i = 0; i < n; ++i)
657 QL_REQUIRE(
rho_.rows() == n &&
rho_.columns() == n,
"correlation matrix is " <<
rho_.rows() <<
" x "
658 <<
rho_.columns() <<
" but should be "
664 Size n =
rho_.rows();
665 Size m =
rho_.columns();
666 QL_REQUIRE(
rho_.columns() == n,
"correlation matrix (" << n <<
" x " << m <<
" must be square");
667 for (Size i = 0; i < n; ++i) {
668 for (Size j = 0; j < m; ++j) {
669 QL_REQUIRE(
close_enough(
rho_[i][j],
rho_[j][i]),
"correlation matrix is not symmetric, for (i,j)=("
670 << i <<
"," << j <<
") rho(i,j)=" <<
rho_[i][j]
671 <<
" but rho(j,i)=" <<
rho_[j][i]);
673 "correlation matrix has invalid entry at (i,j)=(" << i <<
"," << j <<
") equal to "
676 QL_REQUIRE(
close_enough(
rho_[i][i], 1.0),
"correlation matrix must have unit diagonal elements, "
678 <<
rho_[i][i] <<
" for i=" << i);
683 SymmetricSchurDecomposition ssd(
rho_);
684 for (Size i = 0; i < ssd.eigenvalues().size(); ++i) {
685 QL_REQUIRE(ssd.eigenvalues()[i] >= 0.0,
686 "correlation matrix has negative eigenvalue at " << i <<
" (" << ssd.eigenvalues()[i] <<
")");
692 for (Size i = 0; i <
p_.size(); ++i) {
701 for (Size i = 0; i <
arguments_.size(); ++i) {
702 QL_REQUIRE(
arguments_[i] != NULL,
"unexpected error: argument " << i <<
" is null");
715 "the parametrizations must be given in the following order: ir, "
716 "fx, inf, cr, eq, com, found "
722 <<
" parametrizations given in total");
726 const Size ccy,
const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
OptimizationMethod& method,
727 const EndCriteria& endCriteria,
const Constraint& constraint,
const std::vector<Real>& weights) {
733 const Size ccy,
const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
OptimizationMethod& method,
734 const EndCriteria& endCriteria,
const Constraint& constraint,
const std::vector<Real>& weights) {
740 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
742 const Constraint& constraint,
const std::vector<Real>& weights) {
748 const AssetType& assetType,
const Size idx,
const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
750 const std::vector<Real>& weights) {
752 "Unsupported AssetType for BS calibration");
753 for (Size i = 0; i < helpers.size(); ++i) {
754 std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> h(1, helpers[i]);
761 const AssetType& assetType,
const Size aIdx,
const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
763 const std::vector<Real>& weights) {
765 "Unsupported AssetType for BS calibration");
771 const Size index,
const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
OptimizationMethod& method,
772 const EndCriteria& endCriteria,
const Constraint& constraint,
const std::vector<Real>& weights) {
773 for (Size i = 0; i < helpers.size(); ++i) {
774 std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> h(1, helpers[i]);
782 const Size index,
const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
OptimizationMethod& method,
783 const EndCriteria& endCriteria,
const Constraint& constraint,
const std::vector<Real>& weights) {
784 for (Size i = 0; i < helpers.size(); ++i) {
785 std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> h(1, helpers[i]);
793 const Size index,
const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
OptimizationMethod& method,
794 const EndCriteria& endCriteria,
const Constraint& constraint,
const std::vector<Real>& weights) {
801 const Size index,
const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
OptimizationMethod& method,
802 const EndCriteria& endCriteria,
const Constraint& constraint,
const std::vector<Real>& weights) {
810 const map<Size, bool>& toCalibrate,
const Constraint& constraint,
811 const vector<Real>& weights) {
815 std::fill(fixedParams.begin(), fixedParams.end(),
true);
818 for (
const auto& kv : toCalibrate) {
821 std::transform(fixedParams.begin(), fixedParams.end(), tmp.begin(), fixedParams.begin(),
822 std::logical_and<bool>());
833 const vector<QuantLib::ext::shared_ptr<CalibrationHelper>>& helpers,
835 const Constraint& constraint,
const vector<Real>& weights) {
837 for (Size i = 0; i < helpers.size(); ++i) {
838 vector<QuantLib::ext::shared_ptr<CalibrationHelper>> h(1, helpers[i]);
847 const Size index,
const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
OptimizationMethod& method,
848 const EndCriteria& endCriteria,
const Constraint& constraint,
const std::vector<Real>& weights) {
849 for (Size i = 0; i < helpers.size(); ++i) {
850 std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> h(1, helpers[i]);
858 const Size index,
const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
OptimizationMethod& method,
859 const EndCriteria& endCriteria,
const Constraint& constraint,
const std::vector<Real>& weights) {
860 for (Size i = 0; i < helpers.size(); ++i) {
861 std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> h(1, helpers[i]);
871 boost::unordered_map<cache_key, std::pair<Real, Real>>::const_iterator it =
cache_infdkI_.find(k);
875 V0 =
infV(i, ccy, 0, t);
876 V_tilde =
infV(i, ccy, t, T) -
infV(i, ccy, 0, T) +
infV(i, ccy, 0, t);
877 cache_infdkI_.insert(std::make_pair(k, std::make_pair(V0, V_tilde)));
880 V0 = it->second.first;
881 V_tilde = it->second.second;
883 return std::make_pair(V0, V_tilde);
887 QL_REQUIRE(t < T ||
close_enough(t, T),
"infdkI: t (" << t <<
") <= T (" << T <<
") required");
889 std::pair<Real, Real> Vs =
infdkV(i, t, T);
892 Real Hyt =
Hy(i).
eval(*
this, t);
893 Real HyT =
Hy(i).
eval(*
this, T);
897 const auto& zts =
infdk(i)->termStructure();
898 auto dc =
irlgm1f(0)->termStructure()->dayCounter();
899 bool indexIsInterpolated =
true;
901 Real It = growth_t * std::exp(Hyt * z - y - V0);
902 Real Itilde_t_T =
inflationGrowth(zts, T, dc, indexIsInterpolated) / growth_t * std::exp((HyT - Hyt) * z + V_tilde);
908 return std::make_pair(It, Itilde_t_T);
919 Real I_tildeS =
infdkI(i, t, S, z, y).second;
920 Real I_tildeT =
infdkI(i, t, T, z, y).second;
921 Real Pn_t_T =
lgm(ccy)->discountBond(t, T, irz);
923 Real yySwaplet = (I_tildeT / I_tildeS) * Pn_t_T * C_tilde - Pn_t_T;
929 const Real y)
const {
932 QL_REQUIRE(t < T ||
close_enough(t, T),
"crlgm1fS: t (" << t <<
") <= T (" << T <<
") required");
934 "model at " << i <<
" is not CR-LGM1F");
936 boost::unordered_map<cache_key, std::pair<Real, Real>>::const_iterator it =
cache_crlgm1fS_.find(k);
938 Real Hlt =
Hl(i).
eval(*
this, t);
939 Real HlT =
Hl(i).
eval(*
this, T);
945 Real Hzt =
Hz(0).
eval(*
this, t);
946 Real HzT =
Hz(0).
eval(*
this, T);
953 V0 = 0.5 * Hlt * Hlt * zetal0 - Hlt * zetal1 + 0.5 * zetal2 + Hzt * Hlt * zetanl0 - Hzt * zetanl1;
954 V_tilde = -0.5 * (HlT * HlT - Hlt * Hlt) * zetal0 + (HlT - Hlt) * zetal1 -
955 (HzT * HlT - Hzt * Hlt) * zetanl0 + (HzT - Hzt) * zetanl1;
958 V0 =
crV(i, ccy, 0, t);
959 V_tilde =
crV(i, ccy, t, T) -
crV(i, ccy, 0, T) +
crV(i, ccy, 0, t);
961 cache_crlgm1fS_.insert(std::make_pair(k, std::make_pair(V0, V_tilde)));
964 V0 = it->second.first;
965 V_tilde = it->second.second;
969 Real St =
crlgm1f(i)->termStructure()->survivalProbability(t) * std::exp(-Hlt * z + y - V0);
970 Real Stilde_t_T =
crlgm1f(i)->termStructure()->survivalProbability(T) /
971 crlgm1f(i)->termStructure()->survivalProbability(t) * std::exp(-(HlT - Hlt) * z + V_tilde);
972 return std::make_pair(St, Stilde_t_T);
976 const Real s)
const {
978 "model at " << i <<
" is not CR-CIR");
980 return std::make_pair(s, 1.0);
982 return std::make_pair(s,
crcirppModel_[i]->survivalProbability(t, T, y));
986 Real HyT =
Hy(i).
eval(*
this, T);
1005 rhofy * (HfT * HyT *
integral(*
this,
P(
az(ccy),
ay(i)), t, T) -
1009 rhoxy * (HyT *
integral(*
this,
P(
sx(ccy - 1),
ay(i)), t, T) -
1016 Real HlT =
Hl(i).
eval(*
this, T);
1017 Real HfT =
Hz(ccy).
eval(*
this, T);
1026 rhofl * (HfT * HlT *
integral(*
this,
P(
az(ccy),
al(i)), t, T) -
1030 rhoxl * (HlT *
integral(*
this,
P(
sx(ccy - 1),
al(i)), t, T) -
1034Handle<ZeroInflationTermStructure>
inflationTermStructure(
const QuantLib::ext::shared_ptr<CrossAssetModel>& model, Size index) {
1037 return model->infdk(index)->termStructure();
1039 return model->infjy(index)->realRate()->termStructure();
1041 QL_FAIL(
"Expected inflation model to be either DK or JY.");
1046 const Size index,
const Size i, std::vector<bool>& res) {
1048 for (Size k = 0; k <
arguments(t, j); ++k) {
1049 std::vector<bool> tmp1(
p_[
idx(t, j)]->parameter(k)->size(),
true);
1050 if ((param == Null<Size>() || k == param) && t == v && index == j) {
1051 for (Size ii = 0; ii < tmp1.size(); ++ii) {
1052 if (i == Null<Size>() || i == ii) {
1057 res.insert(res.end(), tmp1.begin(), tmp1.end());
1063 QL_REQUIRE(param == Null<Size>() || param <
arguments(t, index),
"parameter for " << t <<
" at " << index <<
" ("
1064 << param <<
") out of bounds 0..."
1066 std::vector<bool> res(0);
virtual void initializeParametrizations()
const QuantLib::ext::shared_ptr< Parametrization > eq(const Size i) const
virtual void finalizeArguments()
virtual void checkModelConsistency() const
Size pIdx(const AssetType t, const Size i, const Size offset=0) const
std::vector< std::vector< Size > > auxBrownians_
const QuantLib::ext::shared_ptr< InfDkParametrization > infdk(const Size i) const
IrModel::Measure measure_
static constexpr Size numberOfAssetTypes
virtual Size getNumberOfStateVariables(const Size i) const
Size cIdx(const AssetType t, const Size i, const Size offset=0) const
const QuantLib::ext::shared_ptr< Parametrization > com(const Size i) const
Size comIndex(const std::string &comName) const
Size arguments(const AssetType t, const Size i) const
std::vector< std::vector< Size > > numArguments_
void setCorrelation(const AssetType s, const Size i, const AssetType t, const Size j, const Real value, const Size iOffset=0, const Size jOffset=0)
void calibrateInfDkVolatilitiesIterative(const Size index, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
void calibrateInfDkReversionsGlobal(const Size index, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
void calibrateInfJyGlobal(QuantLib::Size index, const std::vector< QuantLib::ext::shared_ptr< QuantLib::CalibrationHelper > > &helpers, QuantLib::OptimizationMethod &method, const QuantLib::EndCriteria &endCriteria, const std::map< QuantLib::Size, bool > &toCalibrate, const QuantLib::Constraint &constraint=QuantLib::Constraint(), const std::vector< QuantLib::Real > &weights=std::vector< QuantLib::Real >())
virtual void initialize()
virtual Size getNumberOfAuxBrownians(const Size i) const
std::vector< std::vector< Size > > cIdx_
std::pair< Real, Real > infdkV(const Size i, const Time t, const Time T)
virtual Size getNumberOfBrownians(const Size i) const
const QuantLib::ext::shared_ptr< Integrator > integrator() const
QuantLib::ext::shared_ptr< CrossAssetStateProcess > stateProcess() const
const QuantLib::ext::shared_ptr< IrLgm1fParametrization > irlgm1f(const Size ccy) const
const QuantLib::ext::shared_ptr< EqBsParametrization > eqbs(const Size ccy) const
void calibrateBsVolatilitiesIterative(const AssetType &assetType, const Size aIdx, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
virtual void initializeCorrelation()
void checkCorrelationMatrix() const
Size crName(const std::string &name) const
void calibrateIrLgm1fVolatilitiesIterative(const Size ccy, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
Size auxBrownians() const
void calibrateInfDkVolatilitiesGlobal(const Size index, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
void calibrateCrLgm1fReversionsIterative(const Size index, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
Size infIndex(const std::string &index) const
std::pair< Real, Real > crlgm1fS(const Size i, const Size ccy, const Time t, const Time T, const Real z, const Real y) const
void setIntegrationPolicy(const QuantLib::ext::shared_ptr< Integrator > integrator, const bool usePiecewiseIntegration=true) const
Size ccyIndex(const Currency &ccy) const
virtual Size getNumberOfParameters(const Size i) const
std::vector< std::vector< ModelType > > modelType_
std::pair< Real, Real > crcirppS(const Size i, const Time t, const Time T, const Real y, const Real s) const
virtual void initializeArguments()
QuantLib::ext::shared_ptr< CrossAssetStateProcess > stateProcess_
boost::unordered_map< cache_key, std::pair< Real, Real >, cache_hasher > cache_crlgm1fS_
Size totalNumberOfBrownians_
const QuantLib::ext::shared_ptr< CrLgm1fParametrization > crlgm1f(const Size i) const
virtual std::pair< AssetType, ModelType > getComponentType(const Size i) const
void generateArguments() override
std::vector< std::vector< Size > > pIdx_
std::vector< bool > MoveParameter(const AssetType t, const Size param, const Size index, const Size i)
virtual void initDefaultIntegrator()
Real infdkYY(const Size i, const Time t, const Time S, const Time T, const Real z, const Real y, const Real irz)
std::vector< Size > components_
std::vector< QuantLib::ext::shared_ptr< Parametrization > > p_
std::vector< QuantLib::ext::shared_ptr< CrCirpp > > crcirppModel_
const QuantLib::ext::shared_ptr< Parametrization > fx(const Size ccy) const
void calibrateCrLgm1fVolatilitiesIterative(const Size index, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
Size eqIndex(const std::string &eqName) const
SalvagingAlgorithm::Type salvaging_
std::vector< QuantLib::ext::shared_ptr< IrModel > > irModels_
std::pair< Real, Real > infdkI(const Size i, const Time t, const Time T, const Real z, const Real y)
void updateIndices(const AssetType &t, const Size i, const Size cIdx, const Size wIdx, const Size pIdx, const Size aIdx)
const QuantLib::ext::shared_ptr< CommoditySchwartzParametrization > combs(const Size ccy) const
Real infV(const Size idx, const Size ccy, const Time t, const Time T) const
std::vector< std::vector< Size > > brownians_
void calibrateInfDkReversionsIterative(const Size index, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
Size aIdx(const AssetType t, const Size i, const Size offset=0) const
std::vector< std::vector< Size > > idx_
Size wIdx(const AssetType t, const Size i, const Size offset=0) const
void calibrateIrLgm1fReversionsIterative(const Size ccy, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
Discretization discretization_
void calibrateInfJyIterative(QuantLib::Size inflationModelIndex, QuantLib::Size parameterIndex, const std::vector< QuantLib::ext::shared_ptr< QuantLib::CalibrationHelper > > &helpers, QuantLib::OptimizationMethod &method, const QuantLib::EndCriteria &endCriteria, const QuantLib::Constraint &constraint=QuantLib::Constraint(), const std::vector< QuantLib::Real > &weights=std::vector< QuantLib::Real >())
Real crV(const Size idx, const Size ccy, const Time t, const Time T) const
Size idx(const AssetType t, const Size i) const
boost::unordered_map< cache_key, std::pair< Real, Real >, cache_hasher > cache_infdkI_
Size totalNumberOfParameters_
void calibrateBsVolatilitiesGlobal(const AssetType &assetType, const Size aIdx, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
QuantLib::ext::shared_ptr< Integrator > integrator_
ModelType modelType(const AssetType t, const Size i) const
std::vector< QuantLib::ext::shared_ptr< FxModel > > fxModels_
std::vector< std::vector< Size > > stateVariables_
void appendToFixedParameterVector(const AssetType t, const AssetType v, const Size param, const Size index, const Size i, std::vector< bool > &res)
const QuantLib::ext::shared_ptr< Parametrization > cr(const Size i) const
std::vector< std::vector< Size > > aIdx_
Size components(const AssetType t) const
Size stateVariables(const AssetType t, const Size i) const
std::vector< QuantLib::ext::shared_ptr< CommodityModel > > comModels_
std::vector< std::vector< Size > > wIdx_
const QuantLib::ext::shared_ptr< LinearGaussMarkovModel > lgm(const Size ccy) const
CrossAssetModel(const std::vector< QuantLib::ext::shared_ptr< Parametrization > > ¶metrizations, const Matrix &correlation=Matrix(), const SalvagingAlgorithm::Type salvaging=SalvagingAlgorithm::None, const IrModel::Measure measure=IrModel::Measure::LGM, const Discretization discretization=Discretization::Exact)
const QuantLib::ext::shared_ptr< Parametrization > inf(const Size i) const
const QuantLib::ext::shared_ptr< Parametrization > ir(const Size ccy) const
const Matrix & correlation() const
void calibrateIrLgm1fGlobal(const Size ccy, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
Size totalNumberOfAuxBrownians_
Size n_aux() const override
Size m_aux() const override
Linear Gauss Morkov Model.
Size n_aux() const override
Size m_aux() const override
Calibrated model class with linkable parameters.
const QuantLib::ext::shared_ptr< Constraint > & constraint() const
EndCriteria::Type endCriteria() const
Returns end criteria result.
virtual void calibrate(const std::vector< QuantLib::ext::shared_ptr< CalibrationHelper > > &, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >(), const std::vector< bool > &fixParameters=std::vector< bool >())
Calibrate to a set of market instruments (usually caps/swaptions)
std::vector< QuantLib::ext::shared_ptr< Parameter > > arguments_
Real value(const Array ¶ms, const std::vector< QuantLib::ext::shared_ptr< CalibrationHelper > > &)
analytics for the cross asset model
Real integral(const CrossAssetModel &model, const E &e, const Real a, const Real b)
const P2_< E1, E2 > P(const E1 &e1, const E2 &e2)
hull white n Factor model class
some inflation related utilities.
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
LinearGaussMarkovModel LGM
Handle< ZeroInflationTermStructure > inflationTermStructure(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, Size index)
Real inflationGrowth(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, Size index, Time S, Time T, Real irState, Real rrState, bool indexIsInterpolated)
parameter giving access to calibration machinery
Real eval(const CrossAssetModel &x, const Real t) const
INF H component. May relate to real rate portion of JY model or z component of DK model.
QuantLib::Real eval(const CrossAssetModel &x, const QuantLib::Real t) const
Real eval(const CrossAssetModel &x, const Real t) const
INF alpha component. May relate to real rate portion of JY model or z component of DK model.
Real eval(const CrossAssetModel &x, const Real t) const
INF zeta component. May relate to real rate portion of JY model or z component of DK model.
Real eval(const CrossAssetModel &x, const Real t) const