23#include <ql/instruments/overnightindexedswap.hpp>
24#include <ql/instruments/vanillaswap.hpp>
26#include <ql/cashflows/fixedratecoupon.hpp>
27#include <ql/cashflows/iborcoupon.hpp>
28#include <ql/cashflows/overnightindexedcoupon.hpp>
29#include <ql/indexes/iborindex.hpp>
30#include <ql/indexes/swapindex.hpp>
34std::size_t
HwCG::numeraire(
const Date& d,
const std::size_t x,
const Handle<YieldTermStructure>& discountCurve,
35 const std::string& discountCurveId)
const {
41 Real t = p()->termStructure()->timeFromReference(d);
47 return (discountCurve.empty() ? p()->termStructure() : discountCurve)->discount(t);
56 const Handle<YieldTermStructure>& discountCurve,
57 const std::string& discountCurveId)
const {
66 Real t = p()->termStructure()->timeFromReference(d);
67 Real T = p()->termStructure()->timeFromReference(e);
68 Real ts = p()->termStructure()->timeFromReference(ds);
69 Real Ts = p()->termStructure()->timeFromReference(es);
76 g_,
cg_add(
g_,
cg_mult(
g_, g, x),
cg_mult(
g_,
cg_const(
g_, 0.5),
cg_mult(
g_, y,
cg_mult(
g_, g, g)))));
79 return (discountCurve.empty() ? p()->termStructure() : discountCurve)->discount(t);
82 return (discountCurve.empty() ? p()->termStructure() : discountCurve)->discount(T);
92 const Handle<YieldTermStructure>& discountCurve,
93 const std::string& discountCurveId)
const {
99 numeraire(d, x, discountCurve, discountCurveId));
106std::size_t
HwCG::fixing(
const QuantLib::ext::shared_ptr<InterestRateIndex>& index,
const Date& fixingDate,
const Date& t,
107 const std::size_t x)
const {
116 Date today = Settings::instance().evaluationDate();
124 }
else if (
auto ibor = QuantLib::ext::dynamic_pointer_cast<IborIndex>(index)) {
128 Date d1 = std::max(t, ibor->valueDate(
fixingDate));
129 Date d2 = ibor->maturityDate(d1);
131 Time dt = ibor->dayCounter().yearFraction(d1, d2);
133 std::size_t disc1 =
discountBond(t, d1, x, ibor->forwardingTermStructure(),
"fwd_" + index->name());
134 std::size_t disc2 =
discountBond(t, d2, x, ibor->forwardingTermStructure(),
"fwd_" + index->name());
139 QL_FAIL(
"HwCG::fixing(): only ibor indices handled so far, index = " << index->name());
void setVariable(const std::string &name, const std::size_t node)
QuantExt::ComputationGraph & g_
std::size_t numeraire(const Date &d, const std::size_t x, const Handle< YieldTermStructure > &discountCurve=Handle< YieldTermStructure >(), const std::string &discountCurveId="default") const
std::vector< std::pair< std::size_t, std::function< double(void)> > > & modelParameters_
std::function< QuantLib::ext::shared_ptr< IrLgm1fParametrization >()> p_
std::set< Date > effSimDates_
std::size_t reducedDiscountBond(const Date &d, const Date &e, const std::size_t x, const Handle< YieldTermStructure > &discountCurve=Handle< YieldTermStructure >(), const std::string &discountCurveId="default") const
std::size_t fixing(const QuantLib::ext::shared_ptr< InterestRateIndex > &index, const Date &fixingDate, const Date &t, const std::size_t x) const
std::size_t discountBond(const Date &d, Date e, const std::size_t x, const Handle< YieldTermStructure > &discountCurve=Handle< YieldTermStructure >(), const std::string &discountCurveId="default") const
basis implementation for a script engine model
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
std::size_t cg_const(ComputationGraph &g, const double value)
std::size_t cg_subtract(ComputationGraph &g, const std::size_t a, const std::size_t b, const std::string &label)
std::size_t cg_exp(ComputationGraph &g, const std::size_t a, const std::string &label)
std::size_t cg_negative(ComputationGraph &g, const std::size_t a, const std::string &label)
std::size_t cg_mult(ComputationGraph &g, const std::size_t a, const std::size_t b, const std::string &label)
std::size_t cg_add(ComputationGraph &g, const std::size_t a, const std::size_t b, const std::string &label)
std::size_t cg_var(ComputationGraph &g, const std::string &name, const bool createIfNotExists)
std::size_t cg_div(ComputationGraph &g, const std::size_t a, const std::size_t b, const std::string &label)
std::string to_string(const LocationInfo &l)
std::size_t addModelParameter(ComputationGraph &g, std::vector< std::pair< std::size_t, std::function< double(void)> > > &m, const std::string &id, std::function< double(void)> f)
Date getSloppyDate(const Date &d, const bool sloppyDates, const std::set< Date > &dates)
string conversion utilities