hasquant-0.8.0.0: cbits/qlInstrument.cpp
#include <ql/instrument.hpp>
#include <ql/exercise.hpp>
namespace hasquant {
#include "qlEnumObjects.h"
}
#include <ql/rebatedexercise.hpp>
#include <ql/payoff.hpp>
#include <ql/instruments/basketoption.hpp>
#include <ql/instruments/compositeinstrument.hpp>
#include <ql/instruments/stickyratchet.hpp>
#include <ql/instruments/simplechooseroption.hpp>
#include <ql/instruments/complexchooseroption.hpp>
#include <ql/instruments/softbarrieroption.hpp>
#include <ql/instruments/twoassetcorrelationoption.hpp>
#include <ql/instruments/writerextensibleoption.hpp>
#include <ql/instruments/holderextensibleoption.hpp>
#include <ql/instruments/forward.hpp>
#include <ql/instruments/perpetualfutures.hpp>
#include <ql/instruments/vanillaswingoption.hpp>
#include <ql/instruments/capfloor.hpp>
#include <ql/instruments/callabilityschedule.hpp>
#include <ql/instruments/forwardrateagreement.hpp>
#include <ql/instruments/fxforward.hpp>
#include <ql/instruments/bondforward.hpp>
#include <ql/instruments/creditdefaultswap.hpp>
#include <ql/experimental/credit/cdsoption.hpp>
#include <ql/instruments/claim.hpp>
#include <ql/termstructures/yieldtermstructure.hpp>
#include <ql/instruments/vanillaswap.hpp>
#include <ql/instruments/nonstandardswap.hpp>
#include <ql/instruments/nonstandardswaption.hpp>
#include <ql/instruments/floatfloatswap.hpp>
#include <ql/instruments/floatfloatswaption.hpp>
#include <ql/pricingengines/swaption/basketgeneratingengine.hpp>
#include <ql/instruments/bmaswap.hpp>
#include <ql/instruments/overnightindexedswap.hpp>
#include <ql/instruments/constnotionalcrosscurrencyswap.hpp>
#include <ql/instruments/constnotionalcrosscurrencybasisswap.hpp>
#include <ql/instruments/constnotionalcrosscurrencyfixedvsfloatingswap.hpp>
#include <ql/instruments/assetswap.hpp>
#include <ql/experimental/commodities/energycommodity.hpp>
#include <ql/experimental/commodities/energyfuture.hpp>
#include <ql/experimental/commodities/energyswap.hpp>
#include <ql/experimental/commodities/energyvanillaswap.hpp>
#include <ql/experimental/commodities/energybasisswap.hpp>
#include <ql/experimental/commodities/commoditypricinghelpers.hpp>
#include <ql/experimental/commodities/commoditycashflow.hpp>
#include <ql/instruments/zerocouponinflationswap.hpp>
#include <ql/instruments/yearonyearinflationswap.hpp>
#include <ql/instruments/cpiswap.hpp>
#include <ql/instruments/zerocouponswap.hpp>
#include <ql/instruments/equitytotalreturnswap.hpp>
#include <ql/instruments/compoundoption.hpp>
#include <ql/instruments/barrieroption.hpp>
#include <ql/instruments/doublebarrieroption.hpp>
#include <ql/instruments/partialtimebarrieroption.hpp>
#include <ql/instruments/vanillaoption.hpp>
#include <ql/instruments/swaption.hpp>
#include <ql/instruments/vanillaswingoption.hpp>
#include <ql/instruments/forwardvanillaoption.hpp>
#include <ql/instruments/quantoforwardvanillaoption.hpp>
#include <ql/instruments/quantobarrieroption.hpp>
#include <ql/experimental/barrieroption/quantodoublebarrieroption.hpp>
#include <ql/instruments/twoassetbarrieroption.hpp>
#include <ql/instruments/europeanoption.hpp>
#include <ql/instruments/varianceswap.hpp>
#include <ql/experimental/varianceoption/varianceoption.hpp>
#include <ql/instruments/asianoption.hpp>
#include <ql/instruments/vanillastorageoption.hpp>
#include <ql/instruments/lookbackoption.hpp>
#include <ql/instruments/cliquetoption.hpp>
#include <ql/instruments/basketoption.hpp>
#include <ql/instruments/margrabeoption.hpp>
#include <ql/experimental/exoticoptions/himalayaoption.hpp>
#include <ql/experimental/exoticoptions/pagodaoption.hpp>
#include <ql/experimental/exoticoptions/everestoption.hpp>
#include <ql/experimental/credit/cdsoption.hpp>
#include <ql/instruments/bonds/all.hpp>
#include <ql/cashflows/couponpricer.hpp>
#include <ql/cashflows/digitalcoupon.hpp>
#include <ql/cashflows/rangeaccrual.hpp>
#include <ql/cashflows/yoyinflationcoupon.hpp>
#include <ql/pricingengines/bond/bondfunctions.hpp>
#include <ql/experimental/callablebonds/callablebond.hpp>
#include <ql/experimental/swaptions/irregularswap.hpp>
#include <ql/experimental/swaptions/irregularswaption.hpp>
#include <ql/instruments/bonds/convertiblebonds.hpp>
#include <ql/cashflows/cashflows.hpp>
#include <ql/version.hpp>
#if QL_HEX_VERSION >= 0x01440000
#include <ql/cashflows/stubiborcoupon.hpp>
#endif
#include <ql/cashflows/coupon.hpp>
#include <ql/cashflows/averagebmacoupon.hpp>
#include <ql/cashflows/fixedratecoupon.hpp>
#include <ql/cashflows/iborcoupon.hpp>
#include <ql/cashflows/cmscoupon.hpp>
#include <ql/cashflows/capflooredcoupon.hpp>
#include <ql/cashflows/digitalcmscoupon.hpp>
#include <ql/cashflows/digitalcoupon.hpp>
#include <ql/cashflows/digitaliborcoupon.hpp>
#include <ql/cashflows/replication.hpp>
#include <ql/cashflows/overnightindexedcoupon.hpp>
#include <ql/cashflows/overnightindexedcouponpricer.hpp>
#include <ql/cashflows/blackovernightindexedcouponpricer.hpp>
#include <ql/cashflows/multipleresetscoupon.hpp>
#include <ql/cashflows/rangeaccrual.hpp>
#include <ql/cashflows/simplecashflow.hpp>
#include <ql/cashflows/indexedcashflow.hpp>
#include <ql/cashflows/cpicoupon.hpp>
#include <ql/cashflows/cpicouponpricer.hpp>
#include <ql/cashflows/yoyinflationcoupon.hpp>
#include <ql/cashflows/capflooredinflationcoupon.hpp>
#include <ql/cashflows/inflationcouponpricer.hpp>
#include <ql/cashflows/zeroinflationcashflow.hpp>
#include <ql/cashflows/couponpricer.hpp>
#include <ql/cashflows/dividend.hpp>
#include <ql/cashflows/couponpricer.hpp>
#include <ql/cashflows/conundrumpricer.hpp>
#include <ql/cashflows/lineartsrpricer.hpp>
#include <ql/experimental/coupons/cmsspreadcoupon.hpp>
#include <ql/experimental/coupons/digitalcmsspreadcoupon.hpp>
#include <ql/experimental/coupons/lognormalcmsspreadpricer.hpp>
#include <ql/experimental/coupons/quantocouponpricer.hpp>
#include <ql/experimental/coupons/strippedcapflooredcoupon.hpp>
#include <ql/experimental/coupons/swapspreadindex.hpp>
#include <ql/cashflows/equitycashflow.hpp>
#include <ql/indexes/equityindex.hpp>
#include <ql/instruments/inflationcapfloor.hpp>
#include <ql/instruments/cpicapfloor.hpp>
#include <ql/experimental/credit/defaultprobabilitykey.hpp>
#include <ql/experimental/credit/issuer.hpp>
#include <ql/experimental/credit/pool.hpp>
#include <ql/experimental/credit/basket.hpp>
#include <ql/experimental/credit/gaussianlhplossmodel.hpp>
#include <ql/experimental/credit/syntheticcdo.hpp>
#include <ql/experimental/credit/nthtodefault.hpp>
#include <ql/experimental/termstructures/basisswapratehelpers.hpp>
#include <ql/experimental/termstructures/crosscurrencyratehelpers.hpp>
#include <ql/termstructures/yield/multipleresetsswaphelper.hpp>
#include <ql/termstructures/yield/overnightindexfutureratehelper.hpp>
#include <ql/version.hpp>
#include <cmath>
#if QL_HEX_VERSION >= 0x01440000
#include <ql/experimental/termstructures/overnightindexedfundingratehelper.hpp>
#endif
#include "qlaux.h"
#if QL_HEX_VERSION >= 0x01440000
#include <ql/experimental/fx/mtmcrosscurrencybasisswap.hpp>
#include <ql/experimental/fx/fxresetcashflows.hpp>
#include <ql/cashflows/stubiborcoupon.hpp>
#endif
using namespace QuantLib;
#include "qlInstrument.h"
#include "qlMisc.h"
#include "qlTermStructureAux.h"
#include <cstring>
#ifdef QLTRACK_ALLOCATIONS
QL_TRACE_NAME(Leg)
QL_TRACE_NAME(QlAdditionalResult)
#endif
namespace {
// QuantLib <= 1.43 prices an OIS underlying as Ibor coupons; 1.44 dispatches on this same type.
bool qlOvernightUnderlyingSupported(QlError **e, const shared_ptr<FixedVsFloatingSwap>& swap, const char* call) {
#if QL_HEX_VERSION >= 0x01440000
(void)e; (void)swap; (void)call;
return true;
#else
if (!ext::dynamic_pointer_cast<OvernightIndexedSwap>(swap)) return true;
qlUnsupportedVersion(e, call, "1.44");
return false;
#endif
}
Replication::Type qlReplicationType(int type) {
switch (type) {
case hasquant::ReplicationSub: return Replication::Sub;
case hasquant::ReplicationCentral: return Replication::Central;
case hasquant::ReplicationSuper: return Replication::Super;
default: QL_FAIL("unknown replication type " << type);
}
}
int qlReplicationTypeOut(Replication::Type type) {
switch (type) {
case Replication::Sub: return hasquant::ReplicationSub;
case Replication::Central: return hasquant::ReplicationCentral;
case Replication::Super: return hasquant::ReplicationSuper;
default: QL_FAIL("unknown replication type " << type);
}
}
// SecondaryCosts = map<string, ext::any>, used with exactly two concrete alternatives
// (CommodityUnitCost/Money -- see energycommodity.cpp's two any_cast branches), bound as a real
// 2-variant sum: scIsUnitCost[i] selects which of (scAmounts[i], scCurrencies[i]) alone (Money)
// or paired with scUoms[i] (CommodityUnitCost) fills entry i. An empty (n==0) list stands in for
// upstream's nullptr shared_ptr, matching every constructor's own optional-secondaryCosts default.
shared_ptr<SecondaryCosts> qlBuildSecondaryCosts(unsigned n, char **keys, int *isUnitCost, double *amounts,
Currency **currencies, UnitOfMeasure **uoms) {
if (n == 0) return shared_ptr<SecondaryCosts>();
auto sc = ext::make_shared<SecondaryCosts>();
for (unsigned i = 0; i < n; ++i) {
Money amount(*arg(currencies[i]), amounts[i]);
if (isUnitCost[i])
(*sc)[keys[i]] = CommodityUnitCost(amount, *arg(uoms[i]));
else
(*sc)[keys[i]] = amount;
}
return sc;
}
// The structure-of-parallel-arrays representation of a PricingPeriods list, shared by every
// EnergySwap-family constructor's own pricingPeriods argument and by createPricingPeriods'
// output below.
PricingPeriods qlPricingPeriodVector(unsigned n, int *startDates, int *endDates, int *paymentDates,
CommodityType **types, UnitOfMeasure **uoms, double *amounts) {
PricingPeriods pps;
pps.reserve(n);
for (unsigned i = 0; i < n; ++i)
pps.push_back(ext::make_shared<PricingPeriod>(Date(startDates[i]), Date(endDates[i]), Date(paymentDates[i]),
Quantity(*arg(types[i]), *arg(uoms[i]), amounts[i])));
return pps;
}
// r's fields are all zero/null on entry (the caller value-initialises the whole array), so any
// field this leaves untouched is already the correct "unset" value.
void fillResult(struct QlAdditionalResult &r, const any &v) {
if (v.type() == typeid(double)) {
r.type = AdditionalResultDouble;
r.dval = any_cast<double>(v);
} else if (v.type() == typeid(std::string)) {
r.type = AdditionalResultString;
r.sval = tracedup(any_cast<std::string>(v).c_str());
} else if (v.type() == typeid(std::vector<double>)) {
r.type = AdditionalResultDoubleVector;
const std::vector<double> &vec = any_cast<const std::vector<double>&>(v);
r.vlen = static_cast<unsigned>(vec.size());
if (r.vlen) {
double *varr = alloc(new double[r.vlen]);
for (unsigned i = 0; i < r.vlen; ++i) varr[i] = vec[i];
r.varr = varr;
}
} else {
r.type = AdditionalResultUnknown;
r.sval = tracedup(v.type().name());
}
}
// Payoff has exactly three pure virtuals (ql/payoff.hpp), so a Haskell-defined one needs only
// one callback plus two strings. Unlike qlFdmRollback's whole-grid callbacks, operator() is
// genuinely per scalar price everywhere upstream -- DiscretizedVanillaOption loops it node by
// node, FdmCellAveragingInnerValue calls it inside a per-cell Simpson integral, AmericanPathPricer
// calls it per path per exercise index -- and nothing batches an Array. The per-value callback
// is therefore unavoidable, as it is for HsFdmInnerValueCalculator (qlPricingEngine.cpp).
using PayoffFun = QlCallback;
using BasketAccumulateFun = QlCallback;
class HsPayoff : public Payoff {
public:
HsPayoff(std::string name, std::string description, PayoffFun fn)
: name_(std::move(name)), description_(std::move(description)), fn_(fn) {}
std::string name() const override {return name_;}
std::string description() const override {return description_;}
Real operator()(Real price) const override {return fn_->scalar(price);}
private:
std::string name_, description_;
PayoffFun fn_;
};
// Same callback, but derived from StrikedTypePayoff instead of Payoff, carrying an advisory
// (type, strike) pair. This is what makes a Haskell payoff usable with the FD vanilla engines:
// FdBlackScholesVanillaEngine/FdHestonVanillaEngine dynamic_pointer_cast the payoff to
// StrikedTypePayoff and call ->strike(), so they reject a plain HsPayoff -- and QuantLib <= 1.43,
// which omits the QL_REQUIRE, null-derefs there. They need
// the strike only for mesher geometry -- grid extent and the node-concentration point -- and
// hand the payoff itself to FdmLogInnerValue, which takes a generic Payoff. So supplying a real
// strike makes the cast succeed and the engine price the Haskell payoff correctly, rather than
// being a guard bolted on around a crash. StrikedTypePayoff adds no pure virtuals over Payoff
// (it supplies description(), and TypePayoff supplies optionType()), so only operator() and
// name() are overridden here.
class HsStrikedPayoff : public StrikedTypePayoff {
public:
HsStrikedPayoff(Option::Type type, Real strike, std::string name, PayoffFun fn)
: StrikedTypePayoff(type, strike), name_(std::move(name)), fn_(fn) {}
std::string name() const override {return name_;}
Real operator()(Real price) const override {return fn_->scalar(price);}
private:
std::string name_;
PayoffFun fn_;
};
// BasketPayoff's only pure virtual is accumulate(const Array&) -- the whole underlying-state
// vector per call -- so this hook is already the coarsened shape; name()/description()/
// operator()(Real) all delegate to the base payoff upstream and need no override.
class HsBasketPayoff : public BasketPayoff {
public:
HsBasketPayoff(const shared_ptr<Payoff>& base, BasketAccumulateFun fn)
: BasketPayoff(base), fn_(fn) {}
Real accumulate(const Array& a) const override {
return fn_->array(a.begin(), (unsigned)a.size());
}
private:
BasketAccumulateFun fn_;
};
// Shared by RendistatoCalculator's plain-Real-vector getters (yields/durations/swapLengths/
// swapRates/swapYields/swapDurations).
void copyRealVector(const std::vector<Real>& v, unsigned *len, double **out) {
double *xs = qlAllocateDoubles(v.size());
std::copy(v.begin(), v.end(), xs);
*len = v.size(); *out = xs;
}
// Stages QlAdditionalResult structs until commit(); their owned fields require the matching
// aggregate finalizer.
class OutAdditionalResultArray {
unsigned *outLen_;
QlAdditionalResult **out_;
unsigned len_ = 0;
QlAdditionalResult *value_ = nullptr;
public:
OutAdditionalResultArray(unsigned *outLen, QlAdditionalResult **out) : outLen_(outLen), out_(out) {
*outLen_ = 0;
*out_ = nullptr;
}
OutAdditionalResultArray(const OutAdditionalResultArray&) = delete;
OutAdditionalResultArray& operator=(const OutAdditionalResultArray&) = delete;
~OutAdditionalResultArray() {if (value_) qlFreeAdditionalResults(len_, value_);}
QlAdditionalResult* allocate(unsigned len) {
// Value-initialisation makes every entry safe for the aggregate finalizer after a partial fill.
value_ = alloc(new QlAdditionalResult[len]());
len_ = len;
return value_;
}
void commit() noexcept {*outLen_ = len_; *out_ = value_; value_ = nullptr;}
};
// Every fixing a cash flow needs, as (index name, fixing date) pairs, for dependency
// extraction. QuantLib 1.43 has no requiredFixings() API, so its acyclic visitor supplies the
// concrete coupon type after a Leg has erased it to CashFlow.
// A cash flow that carries no index -- a redemption, a fixed-rate coupon, a plain payment --
// needs no fixing and contributes nothing; that is not an error.
void collectIndexFixing(const ext::shared_ptr<Index>& index, const Date& date,
std::vector<std::pair<std::string, Date> >& out) {
if (!index || date == Date()) return;
// A spread index holds no fixings of its own: SwapSpreadIndex::pastFixing reads both
// underlying swap indexes, so those are the names the store must carry. Index has no
// accept() or dependency virtual, and generic IndexedCashFlow accepts a base Index, making
// this the one upstream-forced downcast in the walk.
if (auto spread = ext::dynamic_pointer_cast<SwapSpreadIndex>(index)) {
collectIndexFixing(spread->swapIndex1(), date, out);
collectIndexFixing(spread->swapIndex2(), date, out);
return;
}
#if QL_HEX_VERSION >= 0x01440000
// The composite is erased to Index; its components own the actual fixing histories.
if (auto weighted = ext::dynamic_pointer_cast<StubIborCoupon::WeightedIndex>(index)) {
for (const auto& component : weighted->components())
collectIndexFixing(component.first, date, out);
return;
}
#endif
out.emplace_back(index->name(), date);
}
// The CPI fixings CPI::laggedFixing reads for a date d (inflationindex.cpp): the start of the
// index period holding d - lag, and under Linear the next period's start too, unless d is
// itself a period start. QuantLib's store is read at period starts only
// (ZeroInflationIndex::pastFixing), so these are the keys a fixing must be filed under.
void collectLaggedFixing(const ext::shared_ptr<ZeroInflationIndex>& index, const Date& d,
const Period& lag, CPI::InterpolationType interpolation,
std::vector<std::pair<std::string, Date> >& out) {
if (!index || d == Date()) return;
std::pair<Date, Date> period = inflationPeriod(d - lag, index->frequency());
out.emplace_back(index->name(), period.first);
if (interpolation == CPI::Linear && d != inflationPeriod(d, index->frequency()).first)
out.emplace_back(index->name(), period.second + 1);
}
// CPICashFlow keeps a given base CPI in a protected member and answers baseFixing() from it
// without saying whether it was given; a pointer to the member, taken in a derived scope, reads
// it (upstream offers no accessor).
struct CpiCashFlowBase : CPICashFlow {
static Real of(const CPICashFlow& c) {return c.*(&CpiCashFlowBase::baseFixing_);}
};
class FixingDependencyVisitor : public AcyclicVisitor,
public Visitor<CashFlow>,
#if QL_HEX_VERSION >= 0x01440000
public Visitor<FxResetCoupon>,
#endif
public Visitor<CappedFlooredOvernightIndexedCoupon>,
public Visitor<StrippedCappedFlooredCoupon>,
public Visitor<DigitalCoupon>,
public Visitor<CappedFlooredCoupon>,
public Visitor<AverageBMACoupon>,
public Visitor<MultipleResetsCoupon>,
public Visitor<OvernightIndexedCoupon>,
public Visitor<CmsSpreadCoupon>,
public Visitor<FloatingRateCoupon>,
public Visitor<CPICoupon>,
public Visitor<YoYInflationCoupon>,
public Visitor<InflationCoupon>,
public Visitor<ZeroInflationCashFlow>,
public Visitor<IndexedCashFlow> {
std::vector<std::pair<std::string, Date> >& out_;
void accept(const ext::shared_ptr<CashFlow>& cf) {
if (cf) cf->accept(*this);
}
public:
explicit FixingDependencyVisitor(std::vector<std::pair<std::string, Date> >& out)
: out_(out) {}
void visit(CashFlow&) override {}
#if QL_HEX_VERSION >= 0x01440000
void visit(FxResetCoupon& c) override {accept(c.underlying());}
#endif
void visit(CappedFlooredOvernightIndexedCoupon& c) override {accept(c.underlying());}
// StrippedCappedFlooredCoupon::accept visits its underlying before visiting itself.
void visit(StrippedCappedFlooredCoupon&) override {}
void visit(DigitalCoupon& c) override {accept(c.underlying());}
void visit(CappedFlooredCoupon& c) override {accept(c.underlying());}
void visit(AverageBMACoupon& c) override {
for (const Date& d : c.fixingDates()) collectIndexFixing(c.index(), d, out_);
}
void visit(MultipleResetsCoupon& c) override {
for (const Date& d : c.fixingDates()) collectIndexFixing(c.index(), d, out_);
}
void visit(OvernightIndexedCoupon& c) override {
for (const Date& d : c.fixingDates()) collectIndexFixing(c.index(), d, out_);
}
void visit(CmsSpreadCoupon& c) override {
const ext::shared_ptr<SwapSpreadIndex>& spread = c.swapSpreadIndex();
if (!spread || c.fixingDate() == Date()) return;
collectIndexFixing(spread->swapIndex1(), c.fixingDate(), out_);
collectIndexFixing(spread->swapIndex2(), c.fixingDate(), out_);
}
void visit(FloatingRateCoupon& c) override {
collectIndexFixing(c.index(), c.fixingDate(), out_);
}
// CPICoupon::indexRatio: the accrual end through the lag, and a base read only when no base
// CPI is given, at baseDate() + lag (cpicoupon.cpp)
void visit(CPICoupon& c) override {
collectLaggedFixing(c.cpiIndex(), c.accrualEndDate(), c.observationLag(), c.observationInterpolation(), out_);
if (c.baseCPI() == Null<Real>())
collectLaggedFixing(c.cpiIndex(), c.baseDate() + c.observationLag(), c.observationLag(), c.observationInterpolation(), out_);
}
// CPI::laggedYoYRate: a quoted index's own fixings; a ratio index reads its underlying zero
// index a year apart (YoYInflationIndex::fixing, or interpolated first under Linear)
void visit(YoYInflationCoupon& c) override {
const ext::shared_ptr<YoYInflationIndex>& index = c.yoyIndex();
if (!index) return;
const Date d = c.accrualEndDate();
if (index->ratio()) {
const ext::shared_ptr<ZeroInflationIndex> underlying = index->underlyingIndex();
if (c.interpolation() == CPI::Linear) {
collectLaggedFixing(underlying, d, c.observationLag(), CPI::Linear, out_);
collectLaggedFixing(underlying, d - 1 * Years, c.observationLag(), CPI::Linear, out_);
} else {
const Date start = inflationPeriod(d - c.observationLag(), index->frequency()).first;
collectLaggedFixing(underlying, start, 0 * Months, CPI::Flat, out_);
collectLaggedFixing(underlying, start - 1 * Years, 0 * Months, CPI::Flat, out_);
}
} else {
std::pair<Date, Date> period = inflationPeriod(d - c.observationLag(), index->frequency());
out_.emplace_back(index->name(), period.first);
if (c.interpolation() == CPI::Linear && d != inflationPeriod(d, index->frequency()).first)
out_.emplace_back(index->name(), period.second + 1);
}
}
void visit(InflationCoupon& c) override {
collectIndexFixing(c.index(), c.fixingDate(), out_);
}
// ZeroInflationCashFlow reads laggedFixing at its start and end dates, which it keeps private;
// IndexedCashFlow's base and fixing dates are those less the lag, so their period starts are
// the keys, and under Linear the next ones unless the dates fall on a month's first day
void visit(ZeroInflationCashFlow& c) override {
const ext::shared_ptr<ZeroInflationIndex>& index = c.zeroInflationIndex();
if (!index) return;
for (const Date& lagged : {c.baseDate(), c.fixingDate()}) {
std::pair<Date, Date> period = inflationPeriod(lagged, index->frequency());
out_.emplace_back(index->name(), period.first);
if (c.observationInterpolation() == CPI::Linear && lagged.dayOfMonth() != 1)
out_.emplace_back(index->name(), period.second + 1);
}
}
void visit(IndexedCashFlow& c) override {
// CPICashFlow has no accept() of its own, so it arrives here: a downcast is the only way
// to read its lag and interpolation (CPICashFlow::indexFixing, ::baseFixing)
if (auto* cpi = dynamic_cast<CPICashFlow*>(&c)) {
collectLaggedFixing(cpi->cpiIndex(), cpi->observationDate(), cpi->observationLag(), cpi->interpolation(), out_);
if (CpiCashFlowBase::of(*cpi) == Null<Real>())
collectLaggedFixing(cpi->cpiIndex(), cpi->baseDate(), 0 * Months, cpi->interpolation(), out_);
return;
}
collectIndexFixing(c.index(), c.fixingDate(), out_);
try {collectIndexFixing(c.index(), c.baseDate(), out_);} catch (const std::exception&) {}
}
};
void collectFixingDependencies(const ext::shared_ptr<CashFlow>& cf,
std::vector<std::pair<std::string, Date> >& out) {
if (!cf) return;
FixingDependencyVisitor visitor(out);
cf->accept(visitor);
}
void collectLegFixingDependencies(const Leg& leg,
std::vector<std::pair<std::string, Date> >& out) {
for (const auto& cf : leg) collectFixingDependencies(cf, out);
}
void collectSwapFixingDependencies(const Swap& swap,
std::vector<std::pair<std::string, Date> >& out) {
for (Size j = 0; j < swap.numberOfLegs(); ++j)
collectLegFixingDependencies(swap.leg(j), out);
}
class RateHelperFixingDependencyVisitor : public AcyclicVisitor,
public Visitor<RateHelper>,
public Visitor<DepositRateHelper>,
public Visitor<FixedDateDepositRateHelper>,
public Visitor<FraRateHelper>,
public Visitor<FixedDateFraRateHelper>,
public Visitor<FuturesRateHelper>,
public Visitor<FxSwapRateHelper>,
public Visitor<SwapRateHelper>,
public Visitor<OISRateHelper>,
public Visitor<IborIborBasisSwapRateHelper>,
public Visitor<OvernightIborBasisSwapRateHelper>,
#if QL_HEX_VERSION >= 0x01440000
public Visitor<OvernightOvernightBasisSwapRateHelper>,
public Visitor<OvernightIndexedFundingRateHelper>,
#endif
public Visitor<BondHelper>,
public Visitor<BMASwapRateHelper>,
public Visitor<MultipleResetsSwapRateHelper>,
public Visitor<OvernightIndexFutureRateHelper>,
public Visitor<ConstNotionalCrossCurrencyBasisSwapRateHelper>,
public Visitor<MtMCrossCurrencyBasisSwapRateHelper>,
public Visitor<ConstNotionalCrossCurrencySwapRateHelper> {
std::vector<std::pair<std::string, Date> >& out_;
bool opaque_;
// Helpers that keep their instrument in a protected member: a derived class may name it through
// a pointer to member, which reaches it without touching QuantLib.
#if QL_HEX_VERSION < 0x01440000
struct BMAPeek : BMASwapRateHelper {
static const ext::shared_ptr<BMASwap>& swap(BMASwapRateHelper& h) {return h.*(&BMAPeek::swap_);}
};
struct MultipleResetsPeek : MultipleResetsSwapRateHelper {
static const ext::shared_ptr<MultipleResetsSwap>& swap(MultipleResetsSwapRateHelper& h) {
return h.*(&MultipleResetsPeek::swap_);}
};
struct CrossCurrencySwapPeek : ConstNotionalCrossCurrencySwapRateHelper {
static const ext::shared_ptr<ConstNotionalCrossCurrencyFixedVsFloatingSwap>& swap(
ConstNotionalCrossCurrencySwapRateHelper& h) {return h.*(&CrossCurrencySwapPeek::xccySwap_);}
};
#endif
// The basis helpers price these legs; the swap() later versions expose is a unit-notional mirror.
struct CrossCurrencyBasisPeek : CrossCurrencyBasisSwapRateHelperBase {
static const Leg& baseLeg(CrossCurrencyBasisSwapRateHelperBase& h) {
return h.*(&CrossCurrencyBasisPeek::baseCcyIborLeg_);}
static const Leg& quoteLeg(CrossCurrencyBasisSwapRateHelperBase& h) {
return h.*(&CrossCurrencyBasisPeek::quoteCcyIborLeg_);}
};
void collectPastFixing(const std::string& name, const Date& d) {
if (d < Settings::instance().evaluationDate()) out_.emplace_back(name, d);
}
void collectCrossCurrencyBasis(CrossCurrencyBasisSwapRateHelperBase& h) {
collectLegFixingDependencies(CrossCurrencyBasisPeek::baseLeg(h), out_);
collectLegFixingDependencies(CrossCurrencyBasisPeek::quoteLeg(h), out_);
}
public:
explicit RateHelperFixingDependencyVisitor(
std::vector<std::pair<std::string, Date> >& out) : out_(out), opaque_(false) {}
// True when the helper's instrument is one this walk cannot see, so an empty answer is not "needs nothing".
bool opaque() const {return opaque_;}
// A helper with no case below may read stored fixings, so it is "cannot see it" until given one.
void visit(RateHelper&) override {opaque_ = true;}
// The relative-date deposit and FRA forms read no stored fixing: they adjust the evaluation date
// to a business day before advancing to spot, so they fix on or after it, and fixing(d, true)
// forecasts from the evaluation date on.
void visit(DepositRateHelper&) override {}
void visit(FraRateHelper&) override {}
// The fixed-date forms read the store once their fixing date has passed, and not on it, where
// fixing(d, true) still forecasts. The FRA reads it only with an indexed coupon.
void visit(FixedDateDepositRateHelper& h) override {collectPastFixing(h.indexName(), h.fixingDate());}
void visit(FixedDateFraRateHelper& h) override {
if (h.useIndexedCoupon()) collectPastFixing(h.indexName(), h.fixingDate());
}
void visit(FuturesRateHelper&) override {}
void visit(FxSwapRateHelper&) override {}
void visit(SwapRateHelper& h) override {collectSwapFixingDependencies(*h.swap(), out_);}
void visit(OISRateHelper& h) override {collectSwapFixingDependencies(*h.swap(), out_);}
void visit(IborIborBasisSwapRateHelper& h) override {
collectSwapFixingDependencies(*h.swap(), out_);
}
void visit(OvernightIborBasisSwapRateHelper& h) override {
collectSwapFixingDependencies(*h.swap(), out_);
}
#if QL_HEX_VERSION >= 0x01440000
void visit(OvernightOvernightBasisSwapRateHelper& h) override {
collectSwapFixingDependencies(*h.swap(), out_);
}
void visit(OvernightIndexedFundingRateHelper& h) override {
collectSwapFixingDependencies(*h.swap(), out_);
}
#endif
void visit(BondHelper& h) override {collectLegFixingDependencies(h.bond()->cashflows(), out_);}
#if QL_HEX_VERSION >= 0x01440000
void visit(BMASwapRateHelper& h) override {collectSwapFixingDependencies(*h.swap(), out_);}
void visit(MultipleResetsSwapRateHelper& h) override {collectSwapFixingDependencies(*h.swap(), out_);}
// OvernightIndexFuture's rate reads the stored fixing of each business day from its value date,
// adjusted Preceding, up to today, today's only if present; an expired future reads none.
void visit(OvernightIndexFutureRateHelper& h) override {
const ext::shared_ptr<OvernightIndexFuture> future = h.future();
if (future->isExpired()) return;
const ext::shared_ptr<OvernightIndex>& index = future->overnightIndex();
const Calendar calendar = index->fixingCalendar();
const Date today = Settings::instance().evaluationDate();
Date d = future->valueDate();
for (Date fixingDate = calendar.adjust(d, Preceding);
d < future->maturityDate() && fixingDate <= today; fixingDate = d = calendar.advance(d, 1, Days))
out_.emplace_back(index->name(), fixingDate);
}
void visit(ConstNotionalCrossCurrencySwapRateHelper& h) override {
collectSwapFixingDependencies(*h.swap(), out_);
}
#else
void visit(BMASwapRateHelper& h) override {collectSwapFixingDependencies(*BMAPeek::swap(h), out_);}
void visit(MultipleResetsSwapRateHelper& h) override {
collectSwapFixingDependencies(*MultipleResetsPeek::swap(h), out_);
}
// The future is private, and reads past fixings from its value date adjusted Preceding on a calendar
// it also hides; two weeks before the start covers any holiday run, and before that it reads none.
void visit(OvernightIndexFutureRateHelper& h) override {
if (h.earliestDate() - 14 <= Settings::instance().evaluationDate()) opaque_ = true;
}
void visit(ConstNotionalCrossCurrencySwapRateHelper& h) override {
collectSwapFixingDependencies(*CrossCurrencySwapPeek::swap(h), out_);
}
#endif
void visit(ConstNotionalCrossCurrencyBasisSwapRateHelper& h) override {collectCrossCurrencyBasis(h);}
void visit(MtMCrossCurrencyBasisSwapRateHelper& h) override {collectCrossCurrencyBasis(h);}
};
}
#ifdef QLTRACK_ALLOCATIONS
// Same reason as qlPricingEngine.cpp's Hs* labels: these live in the anonymous namespace above and
// so cannot be named in qlaux.h's table, and without a specialization ObjClassName falls back to
// typeid().name(). All three are shared_ptr payloads -- alloc() only, never freed.
QL_TRACE_NAME(HsPayoff)
QL_TRACE_NAME(HsStrikedPayoff)
QL_TRACE_NAME(HsBasketPayoff)
#endif
extern "C" {
QlInstrument* qlPerpetualFutures(int payoffType, int fundingType,
int fundingFrequencyLength, int fundingFrequencyUnit,
Calendar* cal, DayCounter* dc, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlInstrument(alloc(new PerpetualFutures(
(PerpetualFutures::PayoffType)payoffType,
(PerpetualFutures::FundingType)fundingType,
Period(fundingFrequencyLength, (TimeUnit)fundingFrequencyUnit), *arg(cal), *arg(dc)))));
} catch (std::exception& er) {return handleException<QlInstrument*>(e, er);}}
double qlInstrumentNPV(QlInstrument *instr, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(instr))->NPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlInstrumentSetPricingEngine(QlInstrument *instr, QlPricingEngine *eng, QlError **e) { QlCallScope callbackScope(e);try {(*arg(instr))->setPricingEngine(*arg(eng));} catch (std::exception& er) {(void)handleException<int>(e, er);}}
void qlFreeInstrument(QlInstrument *instr) {del(instr);}
void qlInstrumentAdditionalResults(QlInstrument *instr, unsigned *len,
struct QlAdditionalResult **out, QlError **e) { QlCallScope callbackScope(e);
OutAdditionalResultArray result(len, out);
try {
const std::map<std::string, any> &res = (*arg(instr))->additionalResults();
if (res.empty()) return;
QlAdditionalResult *arr = result.allocate(static_cast<unsigned>(res.size()));
unsigned i = 0;
for (std::map<std::string, any>::const_iterator it = res.begin(); it != res.end(); ++it, ++i) {
arr[i].key = tracedup(it->first.c_str());
fillResult(arr[i], it->second);
}
result.commit();
} catch (std::exception& er) {qlSetError(e, er.what());}
}
void qlFreeAdditionalResults(unsigned len, struct QlAdditionalResult *out) {
if (!out) return;
for (unsigned i = 0; i < len; ++i) {
qlFreeString(out[i].key);
if (out[i].sval) qlFreeString(out[i].sval);
delArray(out[i].varr);
}
delArray(out);
}
QlInstrument* qlCompositeInstrument(unsigned instrLen, QlInstrument **instrs, unsigned, double *coeff, QlError **e) { QlCallScope callbackScope(e);
try {auto ci = ext::make_shared<CompositeInstrument>();
for (unsigned i = 0; i < instrLen; ++i)
ci->add(*(instrs[i]), coeff[i]);
alloc(ci.get());
return ret(new QlInstrument(ci));
} catch (std::exception& er) {return handleException<QlInstrument*>(e, er);}}
double qlInstrumentErrorEstimate(QlInstrument* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->errorEstimate();} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlInstrumentIsExpired(QlInstrument* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->isExpired();} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlInstrumentValuationDate(QlInstrument* o, QlError **e) { QlCallScope callbackScope(e);try {return ((*arg(o))->valuationDate()).serialNumber();} catch (std::exception& er) {return handleException<int>(e, er);}}
void qlFreePayoff(QlPayoff *o) {del(o);}
void qlFreeBasketPayoff(QlBasketPayoff *o) {del(o);}
QlPayoff* qlBasketPayoffAsPayoff(QlBasketPayoff *o) {return ret(new QlPayoff(*arg(o)));}
void qlFreeTypePayoff(QlTypePayoff *o) {del(o);}
QlPayoff* qlTypePayoffAsPayoff(QlTypePayoff *o) {return ret(new QlPayoff(*arg(o)));}
void qlFreeStrikedTypePayoff(QlStrikedTypePayoff *o) {del(o);}
QlTypePayoff* qlStrikedTypePayoffAsTypePayoff(QlStrikedTypePayoff *o) {return ret(new QlTypePayoff(*arg(o)));}
void qlFreePercentageStrikePayoff(QlPercentageStrikePayoff *o) {del(o);}
QlStrikedTypePayoff* qlPercentageStrikePayoffAsStrikedTypePayoff(QlPercentageStrikePayoff *o) {return ret(new QlStrikedTypePayoff(*arg(o)));}
void qlFreePlainVanillaPayoff(QlPlainVanillaPayoff *o) {del(o);}
QlStrikedTypePayoff* qlPlainVanillaPayoffAsStrikedTypePayoff(QlPlainVanillaPayoff *o) {return ret(new QlStrikedTypePayoff(*arg(o)));}
QlPayoff* qlPayoffFromFunction(const char* name, const char* description, QlCallback* fn, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlPayoff(alloc(new HsPayoff(name, description, *arg(fn)))));
} catch (std::exception& er) {return handleException<QlPayoff*>(e, er);}}
QlStrikedTypePayoff* qlStrikedPayoffFromFunction(int type, double strike, const char* name, QlCallback* fn, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlStrikedTypePayoff(alloc(new HsStrikedPayoff((Option::Type)type, strike, name, *arg(fn)))));
} catch (std::exception& er) {return handleException<QlStrikedTypePayoff*>(e, er);}}
QlBasketPayoff* qlBasketPayoffFromFunction(QlPayoff* base, QlCallback* fn, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlBasketPayoff(alloc(new HsBasketPayoff(*arg(base), *arg(fn)))));
} catch (std::exception& er) {return handleException<QlBasketPayoff*>(e, er);}}
QlStrikedTypePayoff* qlAssetOrNothingPayoff(int type, double strike, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlStrikedTypePayoff(alloc(new AssetOrNothingPayoff((Option::Type)type, strike))));
} catch (std::exception& er) {return handleException<QlStrikedTypePayoff*>(e, er);}}
QlBasketPayoff* qlAverageBasketPayoff(QlPayoff* p, unsigned n, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlBasketPayoff(alloc(new AverageBasketPayoff(*arg(p), n))));
} catch (std::exception& er) {return handleException<QlBasketPayoff*>(e, er);}}
QlBasketPayoff* qlAverageBasketPayoff1(QlPayoff* p, unsigned aLen, double* a, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlBasketPayoff(alloc(new AverageBasketPayoff(*arg(p), Array(a, a+aLen)))));
} catch (std::exception& er) {return handleException<QlBasketPayoff*>(e, er);}}
QlStrikedTypePayoff* qlCashOrNothingPayoff(int type, double strike, double cashPayoff, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlStrikedTypePayoff(alloc(new CashOrNothingPayoff((Option::Type)type, strike, cashPayoff))));
} catch (std::exception& er) {return handleException<QlStrikedTypePayoff*>(e, er);}}
QlPayoff* qlDoubleStickyRatchetPayoff(double type1, double type2, double gearing1, double gearing2, double gearing3, double spread1, double spread2, double spread3, double initialValue1, double initialValue2, double accrualFactor, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlPayoff(alloc(new DoubleStickyRatchetPayoff(type1, type2, gearing1, gearing2, gearing3, spread1, spread2, spread3, initialValue1, initialValue2, accrualFactor))));
} catch (std::exception& er) {return handleException<QlPayoff*>(e, er);}}
QlTypePayoff* qlFloatingTypePayoff(int type, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlTypePayoff(alloc(new FloatingTypePayoff((Option::Type)type))));} catch (std::exception& er) {return handleException<QlTypePayoff*>(e, er);}}
QlPayoff* qlForwardTypePayoff(int type, double strike, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlPayoff(alloc(new ForwardTypePayoff((Position::Type)type, strike))));} catch (std::exception& er) {return handleException<QlPayoff*>(e, er);}}
QlStrikedTypePayoff* qlGapPayoff(int type, double strike, double secondStrike, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlStrikedTypePayoff(alloc(new GapPayoff((Option::Type)type, strike, secondStrike))));} catch (std::exception& er) {return handleException<QlStrikedTypePayoff*>(e, er);}}
QlBasketPayoff* qlMaxBasketPayoff(QlPayoff* p, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlBasketPayoff(alloc(new MaxBasketPayoff(*arg(p)))));} catch (std::exception& er) {return handleException<QlBasketPayoff*>(e, er);}}
QlBasketPayoff* qlMinBasketPayoff(QlPayoff* p, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlBasketPayoff(alloc(new MinBasketPayoff(*arg(p)))));} catch (std::exception& er) {return handleException<QlBasketPayoff*>(e, er);}}
QlPercentageStrikePayoff* qlPercentageStrikePayoff(int type, double moneyness, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlPercentageStrikePayoff(alloc(new PercentageStrikePayoff((Option::Type)type, moneyness))));
} catch (std::exception& er) {return handleException<QlPercentageStrikePayoff*>(e, er);}}
QlPlainVanillaPayoff* qlPlainVanillaPayoff(int type, double strike, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlPlainVanillaPayoff(alloc(new PlainVanillaPayoff((Option::Type)type, strike))));
} catch (std::exception& er) {return handleException<QlPlainVanillaPayoff*>(e, er);}}
QlPayoff* qlRatchetMaxPayoff(double gearing1, double gearing2, double gearing3, double spread1, double spread2, double spread3, double initialValue1, double initialValue2, double accrualFactor, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlPayoff(alloc(new RatchetMaxPayoff(gearing1, gearing2, gearing3, spread1, spread2, spread3, initialValue1, initialValue2, accrualFactor))));
} catch (std::exception& er) {return handleException<QlPayoff*>(e, er);}}
QlPayoff* qlRatchetMinPayoff(double gearing1, double gearing2, double gearing3, double spread1, double spread2, double spread3, double initialValue1, double initialValue2, double accrualFactor, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlPayoff(alloc(new RatchetMinPayoff(gearing1, gearing2, gearing3, spread1, spread2, spread3, initialValue1, initialValue2, accrualFactor))));
} catch (std::exception& er) {return handleException<QlPayoff*>(e, er);}}
QlPayoff* qlRatchetPayoff(double gearing1, double gearing2, double spread1, double spread2, double initialValue, double accrualFactor, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlPayoff(alloc(new RatchetPayoff(gearing1, gearing2, spread1, spread2, initialValue, accrualFactor))));
} catch (std::exception& er) {return handleException<QlPayoff*>(e, er);}}
QlBasketPayoff* qlSpreadBasketPayoff(QlPayoff* p, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlBasketPayoff(alloc(new SpreadBasketPayoff(*arg(p)))));
} catch (std::exception& er) {return handleException<QlBasketPayoff*>(e, er);}}
QlPayoff* qlStickyMaxPayoff(double gearing1, double gearing2, double gearing3, double spread1, double spread2, double spread3, double initialValue1, double initialValue2, double accrualFactor, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlPayoff(alloc(new StickyMaxPayoff(gearing1, gearing2, gearing3, spread1, spread2, spread3, initialValue1, initialValue2, accrualFactor))));
} catch (std::exception& er) {return handleException<QlPayoff*>(e, er);}}
QlPayoff* qlStickyMinPayoff(double gearing1, double gearing2, double gearing3, double spread1, double spread2, double spread3, double initialValue1, double initialValue2, double accrualFactor, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlPayoff(alloc(new StickyMinPayoff(gearing1, gearing2, gearing3, spread1, spread2, spread3, initialValue1, initialValue2, accrualFactor))));
} catch (std::exception& er) {return handleException<QlPayoff*>(e, er);}}
QlPayoff* qlStickyPayoff(double gearing1, double gearing2, double spread1, double spread2, double initialValue, double accrualFactor, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlPayoff(alloc(new StickyPayoff(gearing1, gearing2, spread1, spread2, initialValue, accrualFactor))));
} catch (std::exception& er) {return handleException<QlPayoff*>(e, er);}}
QlStrikedTypePayoff* qlSuperFundPayoff(double strike, double secondStrike, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlStrikedTypePayoff(alloc(new SuperFundPayoff(strike, secondStrike))));
} catch (std::exception& er) {return handleException<QlStrikedTypePayoff*>(e, er);}}
QlStrikedTypePayoff* qlSuperSharePayoff(double strike, double secondStrike, double cashPayoff, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlStrikedTypePayoff(alloc(new SuperSharePayoff(strike, secondStrike, cashPayoff))));
} catch (std::exception& er) {return handleException<QlStrikedTypePayoff*>(e, er);}}
void qlFreeAmericanExercise(QlAmericanExercise *o) {del(o);}
QlExercise* qlAmericanExerciseAsExercise(QlAmericanExercise *o) {return ret(new QlExercise(*arg(o)));}
void qlFreeBermudanExercise(QlBermudanExercise *o) {del(o);}
QlExercise* qlBermudanExerciseAsExercise(QlBermudanExercise *o) {return ret(new QlExercise(*arg(o)));}
void qlFreeEuropeanExercise(QlEuropeanExercise *o) {del(o);}
QlExercise* qlEuropeanExerciseAsExercise(QlEuropeanExercise *o) {return ret(new QlExercise(*arg(o)));}
void qlFreeExercise(QlExercise *o) {del(o);}
QlAmericanExercise* qlAmericanExercise(int earliestDate, int latestDate, int payoffAtExpiry, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlAmericanExercise(alloc(new AmericanExercise(Date(earliestDate), Date(latestDate), payoffAtExpiry))));
} catch (std::exception& er) {return handleException<QlAmericanExercise*>(e, er);}}
QlBermudanExercise* qlBermudanExercise(unsigned datesLen, int *dates, int payoffAtExpiry, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlBermudanExercise(alloc(new BermudanExercise(qlDateVector(dates, datesLen), payoffAtExpiry))));
} catch (std::exception& er) {return handleException<QlBermudanExercise*>(e, er);}}
QlExercise* qlEarlyExercise(int type, int payoffAtExpiry, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlExercise(alloc(new EarlyExercise((Exercise::Type)type, payoffAtExpiry))));
} catch (std::exception& er) {return handleException<QlExercise*>(e, er);}}
QlExercise* qlExercise(int type, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlExercise(alloc(new Exercise((Exercise::Type)type))));
} catch (std::exception& er) {return handleException<QlExercise*>(e, er);}}
QlEuropeanExercise* qlEuropeanExercise(int date, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlEuropeanExercise(alloc(new EuropeanExercise(Date(date)))));} catch (std::exception& er) {return handleException<QlEuropeanExercise*>(e, er);}}
QlSwingExercise* qlSwingExercise(unsigned datesLen, int* dates, unsigned secLen, unsigned* seconds, QlError **e) { QlCallScope callbackScope(e);
try {std::vector<Size> secs(seconds, seconds+secLen);
return ret(new QlSwingExercise(alloc(new SwingExercise(qlDateVector(dates, datesLen), secs))));
} catch (std::exception& er) {return handleException<QlSwingExercise*>(e, er);}}
QlSwingExercise* qlSwingExercise1(int from, int to, unsigned stepSizeSecs, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlSwingExercise(alloc(new SwingExercise(Date(from), Date(to), stepSizeSecs))));
} catch (std::exception& er) {return handleException<QlSwingExercise*>(e, er);}}
QlExercise* qlSwingExerciseAsExercise(QlSwingExercise *o) {return ret(new QlExercise(*arg(o)));}
void qlFreeRebatedExercise(QlRebatedExercise *o) {del(o);}
QlExercise* qlRebatedExerciseAsExercise(QlRebatedExercise *o) {return ret(new QlExercise(*arg(o)));}
QlRebatedExercise* qlRebatedExercise(QlExercise* exercise, double rebate, unsigned rebateSettlementDays, Calendar* rebatePaymentCalendar, int rebatePaymentConvention, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlRebatedExercise(alloc(new RebatedExercise(**arg(exercise), rebate, rebateSettlementDays, *arg(rebatePaymentCalendar), (BusinessDayConvention)rebatePaymentConvention))));
} catch (std::exception& er) {return handleException<QlRebatedExercise*>(e, er);}}
QlAmericanExercise* qlAmericanExercise1(int latestDate, int payoffAtExpiry, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlAmericanExercise(alloc(new AmericanExercise(Date(latestDate), payoffAtExpiry))));
} catch (std::exception& er) {return handleException<QlAmericanExercise*>(e, er);}}
void qlFreeCapFloor(QlCapFloor *o) {del(o);}
QlInstrument* qlCapFloorAsInstrument(QlCapFloor *o) {return ret(new QlInstrument(*arg(o)));}
QlCapFloor* qlCap(Leg* floatingLeg, unsigned exerciseRatesLen, double* exerciseRates, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCapFloor(alloc(new Cap(*arg(floatingLeg), std::vector<double>(exerciseRates, exerciseRates+exerciseRatesLen)))));
} catch (std::exception& er) {return handleException<QlCapFloor*>(e, er);}}
QlCapFloor* qlCollar(Leg* floatingLeg, unsigned capRatesLen, double* capRates, unsigned floorRatesLen, double* floorRates, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCapFloor(alloc(new Collar(*arg(floatingLeg), std::vector<double>(capRates, capRates+capRatesLen), std::vector<double>(floorRates, floorRates+floorRatesLen)))));
} catch (std::exception& er) {return handleException<QlCapFloor*>(e, er);}}
QlCapFloor* qlFloor(Leg* floatingLeg, unsigned exerciseRatesLen, double* exerciseRates, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCapFloor(alloc(new Floor(*arg(floatingLeg), std::vector<double>(exerciseRates, exerciseRates+exerciseRatesLen)))));
} catch (std::exception& er) {return handleException<QlCapFloor*>(e, er);}}
double qlCapFloorAtmRate(QlCapFloor* o, QlYieldTermStructure* discountCurve, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->atmRate(handleRef(arg(discountCurve)));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCapFloorImpliedVolatility(QlCapFloor* o, double price, QlYieldTermStructure* disc, double guess, double accuracy, unsigned maxEvaluations, double minVol, double maxVol, int type, double displacement, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->impliedVolatility(price, *arg(disc), guess, accuracy, maxEvaluations, minVol, maxVol, (VolatilityType)type, displacement);
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlCapFloor* qlCapFloorOptionlet(QlCapFloor* o, unsigned n, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCapFloor(alloc((*arg(o))->optionlet(n))));
} catch (std::exception& er) {return handleException<QlCapFloor*>(e, er);}}
void qlFreeCallability(QlCallability *o) {del(o);}
QlCallability* qlCallability(double price, int priceType, int type, int date, QlError **e) { QlCallScope callbackScope(e);
try {Bond::Price p(price, (Bond::Price::Type)priceType);
return ret(new QlCallability(alloc(new Callability(p, (Callability::Type)type, Date(date)))));
} catch (std::exception& er) {return handleException<QlCallability*>(e, er);}}
void qlFreeForward(QlForward *fwd) {del(fwd);}
void qlFreeForwardRateAgreement(QlForwardRateAgreement *fwd) {del(fwd);}
QlInstrument* qlForwardRateAgreementAsInstrument(QlForwardRateAgreement *fwd) {return ret(new QlInstrument(*arg(fwd)));}
QlInstrument* qlForwardAsInstrument(QlForward *fwd) {return ret(new QlInstrument(*arg(fwd)));}
double qlForwardForwardValue(QlForward* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->forwardValue();} catch (std::exception& er) {return handleException<double>(e, er);}}
InterestRate* qlForwardImpliedYield(QlForward* o, double underlyingSpotValue, double forwardValue, int settlementDate, int compoundingConvention, DayCounter* dayCounter, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new InterestRate((*arg(o))->impliedYield(underlyingSpotValue, forwardValue, Date(settlementDate), (Compounding)compoundingConvention, *arg(dayCounter))));
} catch (std::exception& er) {return handleException<InterestRate*>(e, er);}}
int qlForwardSettlementDate(QlForward* o, QlError **e) { QlCallScope callbackScope(e);try {return ((*arg(o))->settlementDate()).serialNumber();} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlForwardSpotIncome(QlForward* o, QlYieldTermStructure* incomeDiscountCurve, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->spotIncome(*arg(incomeDiscountCurve));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlForwardSpotValue(QlForward* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->spotValue();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlForwardRateAgreement* qlForwardRateAgreement(QlIborIndex* index, int valueDate, int maturityDate, int type, double strikeForwardRate, double notionalAmount, QlYieldTermStructure* discountCurve, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlForwardRateAgreement(alloc(new ForwardRateAgreement(*arg(index), Date(valueDate), Date(maturityDate), (Position::Type)type, strikeForwardRate, notionalAmount, qlNullableHandle(arg(discountCurve))))));
} catch (std::exception& er) {return handleException<QlForwardRateAgreement*>(e, er);}}
void qlFreeBondForward(QlBondForward *fwd) {del(fwd);}
QlForward* qlBondForwardAsForward(QlBondForward *fwd) {return ret(new QlForward(*arg(fwd)));}
QlBondForward* qlBondForward(int valueDate, int maturityDate, int type, double strike, unsigned settlementDays, DayCounter* dayCounter, Calendar* calendar, int businessDayConvention, QlBond* bond, QlYieldTermStructure* discountCurve, QlYieldTermStructure* incomeDiscountCurve, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlBondForward(alloc(new BondForward(Date(valueDate), Date(maturityDate), (Position::Type)type, strike, settlementDays, *arg(dayCounter), *arg(calendar), (BusinessDayConvention)businessDayConvention, *arg(bond), qlNullableHandle(arg(discountCurve)), qlNullableHandle(arg(incomeDiscountCurve))))));
} catch (std::exception& er) {return handleException<QlBondForward*>(e, er);}}
double qlBondForwardCleanForwardPrice(QlBondForward* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->cleanForwardPrice();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondForwardForwardPrice(QlBondForward* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->forwardPrice();} catch (std::exception& er) {return handleException<double>(e, er);}}
InterestRate* qlForwardRateAgreementForwardRate(QlForwardRateAgreement* o, QlError **e) { QlCallScope callbackScope(e);try {return ret(new InterestRate((*arg(o))->forwardRate()));} catch (std::exception& er) {return handleException<InterestRate*>(e, er);}}
double qlForwardRateAgreementAmount(QlForwardRateAgreement* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->amount();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeFxForward(QlFxForward *fwd) {del(fwd);}
QlInstrument* qlFxForwardAsInstrument(QlFxForward *fwd) {return ret(new QlInstrument(*arg(fwd)));}
QlFxForward* qlFxForward(double sourceNominal, Currency* sourceCurrency, double targetNominal, Currency* targetCurrency, int maturityDate, int paySourceCurrency, unsigned settlementDays, Calendar* paymentCalendar, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFxForward(alloc(new FxForward(sourceNominal, *arg(sourceCurrency), targetNominal, *arg(targetCurrency), Date(maturityDate), paySourceCurrency, settlementDays, *arg(paymentCalendar)))));
} catch (std::exception& er) {return handleException<QlFxForward*>(e, er);}}
QlFxForward* qlFxForward1(double sourceNominal, Currency* sourceCurrency, Currency* targetCurrency, double forwardRate, int maturityDate, int paySourceCurrency, unsigned settlementDays, Calendar* paymentCalendar, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFxForward(alloc(new FxForward(sourceNominal, *arg(sourceCurrency), *arg(targetCurrency), forwardRate, Date(maturityDate), paySourceCurrency, settlementDays, *arg(paymentCalendar)))));
} catch (std::exception& er) {return handleException<QlFxForward*>(e, er);}}
double qlFxForwardForwardRate(QlFxForward* o) {return (*arg(o))->forwardRate();}
double qlFxForwardFairForwardRate(QlFxForward* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairForwardRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFxForwardNpvSourceCurrency(QlFxForward* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->npvSourceCurrency();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFxForwardNpvTargetCurrency(QlFxForward* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->npvTargetCurrency();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeSwap(QlSwap *o) {del(o);}
QlInstrument* qlSwapAsInstrument(QlSwap *o) {return ret(new QlInstrument(*arg(o)));}
void qlFreeFixedVsFloatingSwap(QlFixedVsFloatingSwap *o) {del(o);}
QlSwap* qlFixedVsFloatingSwapAsSwap(QlFixedVsFloatingSwap *o) {return ret(new QlSwap(*arg(o)));}
void qlFreeVanillaSwap(QlVanillaSwap *o) {del(o);}
QlFixedVsFloatingSwap* qlVanillaSwapAsFixedVsFloatingSwap(QlVanillaSwap *o) {return ret(new QlFixedVsFloatingSwap(*arg(o)));}
void qlFreeNonstandardSwap(QlNonstandardSwap *o) {del(o);}
QlSwap* qlNonstandardSwapAsSwap(QlNonstandardSwap *o) {return ret(new QlSwap(*arg(o)));}
void qlFreeBMASwap(QlBMASwap *o) {del(o);}
QlSwap* qlBMASwapAsSwap(QlBMASwap *o) {return ret(new QlSwap(*arg(o)));}
void qlFreeOvernightIndexedSwap(QlOvernightIndexedSwap *o) {del(o);}
QlFixedVsFloatingSwap* qlOvernightIndexedSwapAsFixedVsFloatingSwap(QlOvernightIndexedSwap *o) {return ret(new QlFixedVsFloatingSwap(*arg(o)));}
QlSwap* qlSwap1(unsigned legsLen, Leg** legs, unsigned payerLen, int *payer, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlSwap(alloc(new Swap(qlVector(legs, legsLen), std::vector<bool>(payer, payer+payerLen)))));
} catch (std::exception& er) {return handleException<QlSwap*>(e, er);}}
void qlFreeAssetSwap(QlAssetSwap *o) {del(o);}
QlSwap* qlAssetSwapAsSwap(QlAssetSwap *o) {return ret(new QlSwap(*arg(o)));}
QlAssetSwap* qlAssetSwap(int payBondCoupon, QlBond* bond, double bondCleanPrice, QlIborIndex* iborIndex, double spread, Schedule* floatSchedule, DayCounter* floatingDayCount, int parAssetSwap, double gearing, double nonParRepayment, int dealMaturity, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlAssetSwap(alloc(new AssetSwap(payBondCoupon, *arg(bond), bondCleanPrice, *arg(iborIndex), spread, *arg(floatSchedule), *arg(floatingDayCount), parAssetSwap, gearing, nonParRepayment, qlNullableDate(dealMaturity)))));
} catch (std::exception& er) {return handleException<QlAssetSwap*>(e, er);}}
QlBMASwap* qlBMASwap(int type, double nominal, Schedule* liborSchedule, double liborFraction, double liborSpread, QlIborIndex* liborIndex, DayCounter* liborDayCount, Schedule* bmaSchedule, QlBMAIndex* bmaIndex, DayCounter* bmaDayCount, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlBMASwap(alloc(new BMASwap((BMASwap::Type)type, nominal, *arg(liborSchedule), liborFraction, liborSpread, *arg(liborIndex), *arg(liborDayCount), *arg(bmaSchedule), *arg(bmaIndex), *arg(bmaDayCount)))));
} catch (std::exception& er) {return handleException<QlBMASwap*>(e, er);}}
QlVanillaSwap* qlVanillaSwap(int type, double nominal, Schedule* fixedSchedule, double fixedRate, DayCounter* fixedDayCount, Schedule* floatSchedule, QlIborIndex* iborIndex, double spread, DayCounter* floatingDayCount, int paymentConvention, int useIndexedCoupons, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlVanillaSwap(alloc(new VanillaSwap((VanillaSwap::Type)type, nominal, *arg(fixedSchedule), fixedRate, *arg(fixedDayCount), *arg(floatSchedule), *arg(iborIndex), spread, *arg(floatingDayCount), qlOptBusinessDayConvention(paymentConvention), qlOptBool(useIndexedCoupons)))));
} catch (std::exception& er) {return handleException<QlVanillaSwap*>(e, er);}}
// Converts an existing FixedVsFloatingSwap (e.g. a VanillaSwap) into a NonstandardSwap
// (upstream's own conversion ctor, not a delegating convenience overload).
QlNonstandardSwap* qlNonstandardSwap1(QlFixedVsFloatingSwap* v, QlError **e) { QlCallScope callbackScope(e);
if (!qlOvernightUnderlyingSupported(e, *arg(v), "nonstandardSwapFromVanilla")) return nullptr;
try {return ret(new QlNonstandardSwap(alloc(new NonstandardSwap(**arg(v)))));
} catch (std::exception& er) {return handleException<QlNonstandardSwap*>(e, er);}}
// Scalar gearing/spread ctor; fixedNominal/floatingNominal/fixedRate are still per-period vectors
// upstream (see nonstandardswap.hpp).
QlNonstandardSwap* qlNonstandardSwap(int type, unsigned fixedNominalLen, double* fixedNominal, unsigned floatingNominalLen, double* floatingNominal, Schedule* fixedSchedule, unsigned fixedRateLen, double* fixedRate, DayCounter* fixedDayCount, Schedule* floatingSchedule, QlIborIndex* iborIndex, double gearing, double spread, DayCounter* floatingDayCount, int intermediateCapitalExchange, int finalCapitalExchange, int paymentConvention, int paymentLag, Calendar* paymentCalendar, QlError **e) { QlCallScope callbackScope(e);
if (!ql144Default(e, "nonstandardSwap", paymentLag == 0 && !paymentCalendar)) return nullptr;
try {return ret(new QlNonstandardSwap(alloc(new NonstandardSwap((Swap::Type)type, std::vector<double>(fixedNominal, fixedNominal+fixedNominalLen), std::vector<double>(floatingNominal, floatingNominal+floatingNominalLen), *arg(fixedSchedule), std::vector<double>(fixedRate, fixedRate+fixedRateLen), *arg(fixedDayCount), *arg(floatingSchedule), *arg(iborIndex), gearing, spread, *arg(floatingDayCount), intermediateCapitalExchange, finalCapitalExchange, qlOptBusinessDayConvention(paymentConvention) QL144_ARGS(paymentLag, paymentCalendar ? *paymentCalendar : Calendar())))));
} catch (std::exception& er) {return handleException<QlNonstandardSwap*>(e, er);}}
// Vector gearing/spread ctor (full coverage: the example only uses the scalar form above).
QlNonstandardSwap* qlNonstandardSwap2(int type, unsigned fixedNominalLen, double* fixedNominal, unsigned floatingNominalLen, double* floatingNominal, Schedule* fixedSchedule, unsigned fixedRateLen, double* fixedRate, DayCounter* fixedDayCount, Schedule* floatingSchedule, QlIborIndex* iborIndex, unsigned gearingLen, double* gearing, unsigned spreadLen, double* spread, DayCounter* floatingDayCount, int intermediateCapitalExchange, int finalCapitalExchange, int paymentConvention, int paymentLag, Calendar* paymentCalendar, QlError **e) { QlCallScope callbackScope(e);
if (!ql144Default(e, "nonstandardSwapFromGearingsAndSpreads", paymentLag == 0 && !paymentCalendar)) return nullptr;
try {return ret(new QlNonstandardSwap(alloc(new NonstandardSwap((Swap::Type)type, std::vector<double>(fixedNominal, fixedNominal+fixedNominalLen), std::vector<double>(floatingNominal, floatingNominal+floatingNominalLen), *arg(fixedSchedule), std::vector<double>(fixedRate, fixedRate+fixedRateLen), *arg(fixedDayCount), *arg(floatingSchedule), *arg(iborIndex), std::vector<double>(gearing, gearing+gearingLen), std::vector<double>(spread, spread+spreadLen), *arg(floatingDayCount), intermediateCapitalExchange, finalCapitalExchange, qlOptBusinessDayConvention(paymentConvention) QL144_ARGS(paymentLag, paymentCalendar ? *paymentCalendar : Calendar())))));
} catch (std::exception& er) {return handleException<QlNonstandardSwap*>(e, er);}}
void qlNonstandardSwapFixedRate(QlNonstandardSwap* o, unsigned *len, double **out, QlError **e) { QlCallScope callbackScope(e);
try {fillVectorOut([&] {return (*arg(o))->fixedRate();}, len, out);
} catch (std::exception& er) {(void)handleException<double*>(e, er);}}
void qlFreeFloatFloatSwap(QlFloatFloatSwap *o) {del(o);}
QlSwap* qlFloatFloatSwapAsSwap(QlFloatFloatSwap *o) {return ret(new QlSwap(*arg(o)));}
// Scalar-nominal ctor. cappedRate1/flooredRate1/cappedRate2/flooredRate2 take Null<Real>()
// (via fromMaybeDouble's qlNullReal sentinel on the Haskell side) unchanged for "no cap/floor",
// matching upstream's own default -- no separate presence flag needed.
QlFloatFloatSwap* qlFloatFloatSwap(int type, double nominal1, double nominal2, Schedule* schedule1, QlInterestRateIndex* index1, DayCounter* dayCount1, Schedule* schedule2, QlInterestRateIndex* index2, DayCounter* dayCount2, int intermediateCapitalExchange, int finalCapitalExchange, double gearing1, double spread1, double cappedRate1, double flooredRate1, double gearing2, double spread2, double cappedRate2, double flooredRate2, int paymentConvention1, int paymentConvention2, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatFloatSwap(alloc(new FloatFloatSwap((Swap::Type)type, nominal1, nominal2, *arg(schedule1), *arg(index1), *arg(dayCount1), *arg(schedule2), *arg(index2), *arg(dayCount2), intermediateCapitalExchange, finalCapitalExchange, gearing1, spread1, cappedRate1, flooredRate1, gearing2, spread2, cappedRate2, flooredRate2, qlOptBusinessDayConvention(paymentConvention1), qlOptBusinessDayConvention(paymentConvention2)))));
} catch (std::exception& er) {return handleException<QlFloatFloatSwap*>(e, er);}}
// Vector-nominal ctor (full coverage; not used by the upstream example).
QlFloatFloatSwap* qlFloatFloatSwap2(int type, unsigned nominal1Len, double* nominal1, unsigned nominal2Len, double* nominal2, Schedule* schedule1, QlInterestRateIndex* index1, DayCounter* dayCount1, Schedule* schedule2, QlInterestRateIndex* index2, DayCounter* dayCount2, int intermediateCapitalExchange, int finalCapitalExchange, unsigned gearing1Len, double* gearing1, unsigned spread1Len, double* spread1, unsigned cappedRate1Len, double* cappedRate1, unsigned flooredRate1Len, double* flooredRate1, unsigned gearing2Len, double* gearing2, unsigned spread2Len, double* spread2, unsigned cappedRate2Len, double* cappedRate2, unsigned flooredRate2Len, double* flooredRate2, int paymentConvention1, int paymentConvention2, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatFloatSwap(alloc(new FloatFloatSwap((Swap::Type)type, std::vector<double>(nominal1, nominal1+nominal1Len), std::vector<double>(nominal2, nominal2+nominal2Len), *arg(schedule1), *arg(index1), *arg(dayCount1), *arg(schedule2), *arg(index2), *arg(dayCount2), intermediateCapitalExchange, finalCapitalExchange, std::vector<double>(gearing1, gearing1+gearing1Len), std::vector<double>(spread1, spread1+spread1Len), std::vector<double>(cappedRate1, cappedRate1+cappedRate1Len), std::vector<double>(flooredRate1, flooredRate1+flooredRate1Len), std::vector<double>(gearing2, gearing2+gearing2Len), std::vector<double>(spread2, spread2+spread2Len), std::vector<double>(cappedRate2, cappedRate2+cappedRate2Len), std::vector<double>(flooredRate2, flooredRate2+flooredRate2Len), qlOptBusinessDayConvention(paymentConvention1), qlOptBusinessDayConvention(paymentConvention2)))));
} catch (std::exception& er) {return handleException<QlFloatFloatSwap*>(e, er);}}
double qlFloatFloatSwapFairSpread1(QlFloatFloatSwap* o, QlError **e) { QlCallScope callbackScope(e);try {const double value = (*arg(o))->fairSpread1(); QL_REQUIRE(std::isfinite(value), "fair rate/spread is undefined for zero leg BPS"); return value;} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFloatFloatSwapFairSpread2(QlFloatFloatSwap* o, QlError **e) { QlCallScope callbackScope(e);try {const double value = (*arg(o))->fairSpread2(); QL_REQUIRE(std::isfinite(value), "fair rate/spread is undefined for zero leg BPS"); return value;} catch (std::exception& er) {return handleException<double>(e, er);}}
QlSwap* qlSwap(Leg* firstLeg, Leg* secondLeg, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlSwap(alloc(new Swap(*arg(firstLeg), *arg(secondLeg)))));} catch (std::exception& er) {return handleException<QlSwap*>(e, er);} }
double qlSwapEndDiscounts(QlSwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->endDiscounts(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
unsigned qlSwapNumberOfLegs(QlSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (unsigned)(*arg(o))->numberOfLegs();} catch (std::exception& er) {return handleException<unsigned>(e, er);}}
Leg* qlSwapLeg(QlSwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);try {return ret(new Leg((*arg(o))->leg(j)));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlSwapLegBPS(QlSwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->legBPS(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlSwapLegNPV(QlSwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->legNPV(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlSwapMaturityDate(QlSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return qlNullableDate((*arg(o))->maturityDate());} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlSwapNpvDateDiscount(QlSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->npvDateDiscount();} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlSwapStartDate(QlSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return qlNullableDate((*arg(o))->startDate());} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlSwapStartDiscounts(QlSwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->startDiscounts(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFixedVsFloatingSwapFairRate(QlFixedVsFloatingSwap* o, QlError **e) { QlCallScope callbackScope(e);try {const double value = (*arg(o))->fairRate(); QL_REQUIRE(std::isfinite(value), "fair rate/spread is undefined for zero leg BPS"); return value;} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFixedVsFloatingSwapFairSpread(QlFixedVsFloatingSwap* o, QlError **e) { QlCallScope callbackScope(e);try {const double value = (*arg(o))->fairSpread(); QL_REQUIRE(std::isfinite(value), "fair rate/spread is undefined for zero leg BPS"); return value;} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlFixedVsFloatingSwapFixedLeg(QlFixedVsFloatingSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return ret(new Leg((*arg(o))->fixedLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlFixedVsFloatingSwapFixedLegBPS(QlFixedVsFloatingSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fixedLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFixedVsFloatingSwapFixedLegNPV(QlFixedVsFloatingSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fixedLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlFixedVsFloatingSwapFloatingLeg(QlFixedVsFloatingSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return ret(new Leg((*arg(o))->floatingLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlFixedVsFloatingSwapFloatingLegBPS(QlFixedVsFloatingSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->floatingLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFixedVsFloatingSwapFloatingLegNPV(QlFixedVsFloatingSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->floatingLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);} }
void qlFreeEquityTotalReturnSwap(QlEquityTotalReturnSwap *o) {del(o);}
QlSwap* qlEquityTotalReturnSwapAsSwap(QlEquityTotalReturnSwap *o) {return ret(new QlSwap(*arg(o)));}
QlEquityTotalReturnSwap* qlEquityTotalReturnSwapIbor(int type, double nominal, Schedule* schedule, QlEquityIndex* equityIndex, QlIborIndex* interestRateIndex, DayCounter* dayCounter, double margin, double gearing, Calendar* paymentCalendar, int paymentConvention, unsigned paymentDelay, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlEquityTotalReturnSwap(alloc(new EquityTotalReturnSwap((Swap::Type)type, nominal, *arg(schedule), *arg(equityIndex), *arg(interestRateIndex),
*arg(dayCounter), margin, gearing, *arg(paymentCalendar), (BusinessDayConvention)paymentConvention, paymentDelay))));
} catch (std::exception& er) {return handleException<QlEquityTotalReturnSwap*>(e, er);}}
QlEquityTotalReturnSwap* qlEquityTotalReturnSwapOvernight(int type, double nominal, Schedule* schedule, QlEquityIndex* equityIndex, QlOvernightIndex* interestRateIndex, DayCounter* dayCounter, double margin, double gearing, Calendar* paymentCalendar, int paymentConvention, unsigned paymentDelay, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlEquityTotalReturnSwap(alloc(new EquityTotalReturnSwap((Swap::Type)type, nominal, *arg(schedule), *arg(equityIndex), *arg(interestRateIndex),
*arg(dayCounter), margin, gearing, *arg(paymentCalendar), (BusinessDayConvention)paymentConvention, paymentDelay))));
} catch (std::exception& er) {return handleException<QlEquityTotalReturnSwap*>(e, er);}}
double qlEquityTotalReturnSwapEquityLegNPV(QlEquityTotalReturnSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->equityLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlEquityTotalReturnSwapInterestRateLegNPV(QlEquityTotalReturnSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->interestRateLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlEquityTotalReturnSwapFairMargin(QlEquityTotalReturnSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairMargin();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlOvernightIndexedSwap* qlOvernightIndexedSwap(int type, double nominal, Schedule* schedule, double fixedRate, DayCounter* fixedDC, QlOvernightIndex* overnightIndex, double spread, int paymentLag, int paymentAdjustment, Calendar* paymentCalendar, int telescopicValueDates, int averagingMethod, unsigned lookbackDays, unsigned lockoutDays, int applyObservationShift, int roundingPrecision, QlError **e) { QlCallScope callbackScope(e);
if (!ql144Default(e, "overnightIndexedSwap", roundingPrecision == Null<int>())) return nullptr;
try {return ret(new QlOvernightIndexedSwap(alloc(new OvernightIndexedSwap((OvernightIndexedSwap::Type)type, nominal, *arg(schedule), fixedRate, *arg(fixedDC), *arg(overnightIndex), spread, paymentLag, (BusinessDayConvention)paymentAdjustment, *arg(paymentCalendar), telescopicValueDates, (RateAveraging::Type)averagingMethod, lookbackDays, lockoutDays, applyObservationShift QL144_ARGS(roundingPrecision == Null<int>() ? optional<Integer>() : optional<Integer>(roundingPrecision))))));
} catch (std::exception& er) {return handleException<QlOvernightIndexedSwap*>(e, er);}}
QlOvernightIndexedSwap* qlOvernightIndexedSwap1(int type, unsigned nominalsLen, double* nominals, Schedule* schedule, double fixedRate, DayCounter* fixedDC, QlOvernightIndex* overnightIndex, double spread, int paymentLag, int paymentAdjustment, Calendar* paymentCalendar, int telescopicValueDates, int averagingMethod, unsigned lookbackDays, unsigned lockoutDays, int applyObservationShift, int roundingPrecision, QlError **e) { QlCallScope callbackScope(e);
if (!ql144Default(e, "overnightIndexedSwapFromNominals", roundingPrecision == Null<int>())) return nullptr;
try {return ret(new QlOvernightIndexedSwap(alloc(new OvernightIndexedSwap((OvernightIndexedSwap::Type)type, std::vector<double>(nominals, nominals+nominalsLen), *arg(schedule), fixedRate, *arg(fixedDC), *arg(overnightIndex), spread, paymentLag, (BusinessDayConvention)paymentAdjustment, *arg(paymentCalendar), telescopicValueDates, (RateAveraging::Type)averagingMethod, lookbackDays, lockoutDays, applyObservationShift QL144_ARGS(roundingPrecision == Null<int>() ? optional<Integer>() : optional<Integer>(roundingPrecision))))));
} catch (std::exception& er) {return handleException<QlOvernightIndexedSwap*>(e, er);}}
void qlFreeConstNotionalCrossCurrencySwap(QlConstNotionalCrossCurrencySwap *o) {del(o);}
QlSwap* qlConstNotionalCrossCurrencySwapAsSwap(QlConstNotionalCrossCurrencySwap *o) {return ret(new QlSwap(*arg(o)));}
QlConstNotionalCrossCurrencySwap* qlConstNotionalCrossCurrencySwap(Leg* firstLeg, Currency* firstLegCcy, Leg* secondLeg, Currency* secondLegCcy, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlConstNotionalCrossCurrencySwap(alloc(new ConstNotionalCrossCurrencySwap(*arg(firstLeg), *arg(firstLegCcy), *arg(secondLeg), *arg(secondLegCcy)))));
} catch (std::exception& er) {return handleException<QlConstNotionalCrossCurrencySwap*>(e, er);}}
QlConstNotionalCrossCurrencySwap* qlConstNotionalCrossCurrencySwap1(unsigned legsLen, Leg** legs, unsigned payerLen, int* payer, unsigned currenciesLen, Currency** currencies, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlConstNotionalCrossCurrencySwap(alloc(new ConstNotionalCrossCurrencySwap(qlVector(legs, legsLen), std::vector<bool>(payer, payer+payerLen), qlVector(currencies, currenciesLen)))));
} catch (std::exception& er) {return handleException<QlConstNotionalCrossCurrencySwap*>(e, er);}}
Currency* qlConstNotionalCrossCurrencySwapLegCurrency(QlConstNotionalCrossCurrencySwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);try {return alloc(new Currency((*arg(o))->legCurrency(j)));} catch (std::exception& er) {return handleException<Currency*>(e, er);}}
double qlConstNotionalCrossCurrencySwapInCcyLegBPS(QlConstNotionalCrossCurrencySwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->inCcyLegBPS(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlConstNotionalCrossCurrencySwapInCcyLegNPV(QlConstNotionalCrossCurrencySwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->inCcyLegNPV(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlConstNotionalCrossCurrencySwapNpvDateDiscounts(QlConstNotionalCrossCurrencySwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->npvDateDiscounts(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeConstNotionalCrossCurrencyBasisSwap(QlConstNotionalCrossCurrencyBasisSwap *o) {del(o);}
QlConstNotionalCrossCurrencySwap* qlConstNotionalCrossCurrencyBasisSwapAsConstNotionalCrossCurrencySwap(QlConstNotionalCrossCurrencyBasisSwap *o) {return ret(new QlConstNotionalCrossCurrencySwap(*arg(o)));}
QlConstNotionalCrossCurrencyBasisSwap* qlConstNotionalCrossCurrencyBasisSwap(
double payNominal, Currency* payCurrency, Schedule* paySchedule, QlIborIndex* payIndex, double paySpread, double payGearing,
double recNominal, Currency* recCurrency, Schedule* recSchedule, QlIborIndex* recIndex, double recSpread, double recGearing,
int payPaymentLag, int recPaymentLag,
int payCompoundSpread, unsigned payLookbackDays, int payObservationShift, unsigned payLockoutDays, int payAveragingMethod,
int recCompoundSpread, unsigned recLookbackDays, int recObservationShift, unsigned recLockoutDays, int recAveragingMethod,
int telescopicValueDates, int useIndexedCoupons, int paymentLagOnNotionalExchanges, QlStubIndexSelection* payStub, QlStubIndexSelection* recStub, QlError **e) { QlCallScope callbackScope(e);
if (!ql144Default(e, "constNotionalCrossCurrencyBasisSwap", useIndexedCoupons == -1 && !paymentLagOnNotionalExchanges && !payStub && !recStub)) return nullptr;
try {return ret(new QlConstNotionalCrossCurrencyBasisSwap(alloc(new ConstNotionalCrossCurrencyBasisSwap(
payNominal, *arg(payCurrency), *arg(paySchedule), *arg(payIndex), paySpread, payGearing,
recNominal, *arg(recCurrency), *arg(recSchedule), *arg(recIndex), recSpread, recGearing,
payPaymentLag, recPaymentLag,
payCompoundSpread, payLookbackDays, payObservationShift, payLockoutDays, (RateAveraging::Type)payAveragingMethod,
recCompoundSpread, recLookbackDays, recObservationShift, recLockoutDays, (RateAveraging::Type)recAveragingMethod,
telescopicValueDates QL144_ARGS(qlOptBool(useIndexedCoupons), paymentLagOnNotionalExchanges, qlStubSelection(payStub), qlStubSelection(recStub))))));
} catch (std::exception& er) {return handleException<QlConstNotionalCrossCurrencyBasisSwap*>(e, er);}}
double qlConstNotionalCrossCurrencyBasisSwapFairPaySpread(QlConstNotionalCrossCurrencyBasisSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairPaySpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlConstNotionalCrossCurrencyBasisSwapFairRecSpread(QlConstNotionalCrossCurrencyBasisSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairRecSpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeConstNotionalCrossCurrencyFixedVsFloatingSwap(QlConstNotionalCrossCurrencyFixedVsFloatingSwap *o) {del(o);}
QlConstNotionalCrossCurrencySwap* qlConstNotionalCrossCurrencyFixedVsFloatingSwapAsConstNotionalCrossCurrencySwap(QlConstNotionalCrossCurrencyFixedVsFloatingSwap *o) {return ret(new QlConstNotionalCrossCurrencySwap(*arg(o)));}
QlConstNotionalCrossCurrencyFixedVsFloatingSwap* qlConstNotionalCrossCurrencyFixedVsFloatingSwap(
int type, double fixedNominal, Currency* fixedCurrency, Schedule* fixedSchedule, double fixedRate,
DayCounter* fixedDayCount, int fixedPaymentBdc, unsigned fixedPaymentLag, Calendar* fixedPaymentCalendar,
double floatNominal, Currency* floatCurrency, Schedule* floatSchedule, QlIborIndex* floatIndex, double floatSpread,
int floatPaymentBdc, unsigned floatPaymentLag, Calendar* floatPaymentCalendar,
int telescopicValueDates, int floatCompoundSpread, unsigned floatLookbackDays, int floatObservationShift,
unsigned floatLockoutDays, int floatAveragingMethod, int useIndexedCoupons, QlStubIndexSelection* floatStub, QlError **e) { QlCallScope callbackScope(e);
if (!ql144Default(e, "constNotionalCrossCurrencyFixedVsFloatingSwap", useIndexedCoupons == -1 && !floatStub)) return nullptr;
try {return ret(new QlConstNotionalCrossCurrencyFixedVsFloatingSwap(alloc(new ConstNotionalCrossCurrencyFixedVsFloatingSwap(
(Swap::Type)type, fixedNominal, *arg(fixedCurrency), *arg(fixedSchedule), fixedRate, *arg(fixedDayCount),
(BusinessDayConvention)fixedPaymentBdc, fixedPaymentLag, *arg(fixedPaymentCalendar),
floatNominal, *arg(floatCurrency), *arg(floatSchedule), *arg(floatIndex), floatSpread,
(BusinessDayConvention)floatPaymentBdc, floatPaymentLag, *arg(floatPaymentCalendar),
telescopicValueDates, floatCompoundSpread, floatLookbackDays, floatObservationShift,
floatLockoutDays, (RateAveraging::Type)floatAveragingMethod QL144_ARGS(qlOptBool(useIndexedCoupons), qlStubSelection(floatStub))))));
} catch (std::exception& er) {return handleException<QlConstNotionalCrossCurrencyFixedVsFloatingSwap*>(e, er);}}
double qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairRate(QlConstNotionalCrossCurrencyFixedVsFloatingSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairSpread(QlConstNotionalCrossCurrencyFixedVsFloatingSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairSpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlAssetSwapBondLeg(QlAssetSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return ret(new Leg((*arg(o))->bondLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlAssetSwapCleanPrice(QlAssetSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->cleanPrice();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlAssetSwapFairCleanPrice(QlAssetSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairCleanPrice();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlAssetSwapFairNonParRepayment(QlAssetSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairNonParRepayment();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlAssetSwapFairSpread(QlAssetSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairSpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlAssetSwapFloatingLeg(QlAssetSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return ret(new Leg((*arg(o))->floatingLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlAssetSwapFloatingLegBPS(QlAssetSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->floatingLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlAssetSwapFloatingLegNPV(QlAssetSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->floatingLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlAssetSwapNonParRepayment(QlAssetSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->nonParRepayment();} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlAssetSwapParSwap(QlAssetSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->parSwap();} catch (std::exception& er) {return handleException<int>(e, er);}}
void qlFreeZeroCouponInflationSwap(QlZeroCouponInflationSwap *o) {del(o);}
QlSwap* qlZeroCouponInflationSwapAsSwap(QlZeroCouponInflationSwap *o) {return ret(new QlSwap(*arg(o)));}
QlZeroCouponInflationSwap* qlZeroCouponInflationSwap(int type, double nominal, int startDate, int maturity, Calendar* cal, int paymentConvention, DayCounter* dayCounter, double fixedRate, QlZeroInflationIndex* index, int obsLagLen, int obsLagUnit, int observationInterpolation, int adjustInfObsDates, Calendar* infCalendar, int infConvention, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlZeroCouponInflationSwap(alloc(new ZeroCouponInflationSwap((ZeroCouponInflationSwap::Type)type, nominal, Date(startDate), Date(maturity), *arg(cal), (BusinessDayConvention)paymentConvention, *arg(dayCounter), fixedRate, *arg(index), Period(obsLagLen, (TimeUnit)obsLagUnit), (CPI::InterpolationType)observationInterpolation, adjustInfObsDates, infCalendar ? *arg(infCalendar) : Calendar(), (BusinessDayConvention)infConvention))));
} catch (std::exception& er) {return handleException<QlZeroCouponInflationSwap*>(e, er);}}
double qlZeroCouponInflationSwapFairRate(QlZeroCouponInflationSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeYearOnYearInflationSwap(QlYearOnYearInflationSwap *o) {del(o);}
QlSwap* qlYearOnYearInflationSwapAsSwap(QlYearOnYearInflationSwap *o) {return ret(new QlSwap(*arg(o)));}
QlYearOnYearInflationSwap* qlYearOnYearInflationSwap(int type, double nominal, Schedule* fixedSchedule, double fixedRate, DayCounter* fixedDayCount, Schedule* yoySchedule, QlYoYInflationIndex* yoyIndex, int obsLagLen, int obsLagUnit, int interpolation, double spread, DayCounter* yoyDayCount, Calendar* paymentCalendar, int paymentConvention, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlYearOnYearInflationSwap(alloc(new YearOnYearInflationSwap((YearOnYearInflationSwap::Type)type, nominal, *arg(fixedSchedule), fixedRate, *arg(fixedDayCount), *arg(yoySchedule), *arg(yoyIndex), Period(obsLagLen, (TimeUnit)obsLagUnit), (CPI::InterpolationType)interpolation, spread, *arg(yoyDayCount), *arg(paymentCalendar), (BusinessDayConvention)paymentConvention))));
} catch (std::exception& er) {return handleException<QlYearOnYearInflationSwap*>(e, er);}}
double qlYearOnYearInflationSwapFairRate(QlYearOnYearInflationSwap* o, QlError **e) { QlCallScope callbackScope(e);try {const double value = (*arg(o))->fairRate(); QL_REQUIRE(std::isfinite(value), "fair rate/spread is undefined for zero leg BPS"); return value;} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlYearOnYearInflationSwapFairSpread(QlYearOnYearInflationSwap* o, QlError **e) { QlCallScope callbackScope(e);try {const double value = (*arg(o))->fairSpread(); QL_REQUIRE(std::isfinite(value), "fair rate/spread is undefined for zero leg BPS"); return value;} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeCPISwap(QlCPISwap *o) {del(o);}
QlSwap* qlCPISwapAsSwap(QlCPISwap *o) {return ret(new QlSwap(*arg(o)));}
QlCPISwap* qlCPISwap(int type, double nominal, int subtractInflationNominal, double spread, DayCounter* floatDayCount, Schedule* floatSchedule, int floatRoll, unsigned fixingDays, QlIborIndex* floatIndex, double fixedRate, double baseCPI, DayCounter* fixedDayCount, Schedule* fixedSchedule, int fixedRoll, int obsLagLen, int obsLagUnit, QlZeroInflationIndex* fixedIndex, int observationInterpolation, double inflationNominal, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCPISwap(alloc(new CPISwap((CPISwap::Type)type, nominal, subtractInflationNominal, spread, *arg(floatDayCount), *arg(floatSchedule), (BusinessDayConvention)floatRoll, fixingDays, *arg(floatIndex), fixedRate, baseCPI, *arg(fixedDayCount), *arg(fixedSchedule), (BusinessDayConvention)fixedRoll, Period(obsLagLen, (TimeUnit)obsLagUnit), *arg(fixedIndex), (CPI::InterpolationType)observationInterpolation, inflationNominal))));
} catch (std::exception& er) {return handleException<QlCPISwap*>(e, er);}}
double qlCPISwapFairRate(QlCPISwap* o, QlError **e) { QlCallScope callbackScope(e);try {const double value = (*arg(o))->fairRate(); QL_REQUIRE(std::isfinite(value), "fair rate/spread is undefined for zero leg BPS"); return value;} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCPISwapFairSpread(QlCPISwap* o, QlError **e) { QlCallScope callbackScope(e);try {const double value = (*arg(o))->fairSpread(); QL_REQUIRE(std::isfinite(value), "fair rate/spread is undefined for zero leg BPS"); return value;} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeZeroCouponSwap(QlZeroCouponSwap *o) {del(o);}
QlSwap* qlZeroCouponSwapAsSwap(QlZeroCouponSwap *o) {return ret(new QlSwap(*arg(o)));}
QlZeroCouponSwap* qlZeroCouponSwap(int type, double baseNominal, int startDate, int maturityDate, double fixedPayment, QlIborIndex* iborIndex, Calendar* paymentCalendar, int paymentConvention, unsigned paymentDelay, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlZeroCouponSwap(alloc(new ZeroCouponSwap((Swap::Type)type, baseNominal, Date(startDate), Date(maturityDate), fixedPayment, *arg(iborIndex), *arg(paymentCalendar), (BusinessDayConvention)paymentConvention, paymentDelay))));
} catch (std::exception& er) {return handleException<QlZeroCouponSwap*>(e, er);}}
QlZeroCouponSwap* qlZeroCouponSwap1(int type, double baseNominal, int startDate, int maturityDate, double fixedRate, DayCounter* fixedDayCounter, QlIborIndex* iborIndex, Calendar* paymentCalendar, int paymentConvention, unsigned paymentDelay, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlZeroCouponSwap(alloc(new ZeroCouponSwap((Swap::Type)type, baseNominal, Date(startDate), Date(maturityDate), fixedRate, *arg(fixedDayCounter), *arg(iborIndex), *arg(paymentCalendar), (BusinessDayConvention)paymentConvention, paymentDelay))));
} catch (std::exception& er) {return handleException<QlZeroCouponSwap*>(e, er);}}
double qlZeroCouponSwapFairFixedPayment(QlZeroCouponSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairFixedPayment();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlZeroCouponSwapFairFixedRate(QlZeroCouponSwap* o, DayCounter* dayCounter, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairFixedRate(*arg(dayCounter));} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlAssetSwapPayBondCoupon(QlAssetSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->payBondCoupon();} catch (std::exception& er) {return handleException<int>(e, er);}}
Leg* qlBMASwapBmaLeg(QlBMASwap* o, QlError **e) { QlCallScope callbackScope(e);try {return ret(new Leg((*arg(o))->bmaLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlBMASwapBmaLegBPS(QlBMASwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->bmaLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBMASwapBmaLegNPV(QlBMASwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->bmaLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBMASwapFairLiborFraction(QlBMASwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairLiborFraction();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBMASwapFairLiborSpread(QlBMASwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairLiborSpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBMASwapLiborFraction(QlBMASwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->liborFraction();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlBMASwapLiborLeg(QlBMASwap* o, QlError **e) { QlCallScope callbackScope(e);try {return ret(new Leg((*arg(o))->liborLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlBMASwapLiborLegBPS(QlBMASwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->liborLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBMASwapLiborLegNPV(QlBMASwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->liborLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlOvernightIndexedSwapOvernightLeg(QlOvernightIndexedSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return ret(new Leg((*arg(o))->overnightLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlOvernightIndexedSwapOvernightLegBPS(QlOvernightIndexedSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->overnightLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOvernightIndexedSwapOvernightLegNPV(QlOvernightIndexedSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->overnightLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeCdsOption(QlCdsOption *o) {del(o);}
QlOption* qlCdsOptionAsOption(QlCdsOption *o) {return ret(new QlOption(*arg(o)));}
void qlFreeCreditDefaultSwap(QlCreditDefaultSwap *o) {del(o);}
QlInstrument* qlCreditDefaultSwapAsInstrument(QlCreditDefaultSwap *o) {return ret(new QlInstrument(*arg(o)));}
void qlFreeClaim(QlClaim *o) {del(o);}
QlClaim* qlFaceValueAccrualClaim(QlBond* referenceSecurity, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlClaim(alloc(new FaceValueAccrualClaim(*arg(referenceSecurity)))));} catch (std::exception& er) {return handleException<QlClaim*>(e, er);}}
QlClaim* qlFaceValueClaim(QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlClaim(alloc(new FaceValueClaim())));} catch (std::exception& er) {return handleException<QlClaim*>(e, er);}}
QlCreditDefaultSwap* qlCreditDefaultSwap1(int side, double notional, double upfront, double spread, Schedule* schedule, int paymentConvention, DayCounter* dayCounter, int settlesAccrual, int paysAtDefaultTime, int protectionStart, int upfrontDate, QlClaim* x11, DayCounter* lastPeriodDayCounter, int rebatesAccrual, int tradeDate, unsigned cashSettlementDays, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCreditDefaultSwap(alloc(new CreditDefaultSwap((Protection::Side)side, notional, upfront, spread, *arg(schedule), (BusinessDayConvention)paymentConvention, *arg(dayCounter), settlesAccrual, paysAtDefaultTime, qlNullableDate(protectionStart), qlNullableDate(upfrontDate), (*arg(x11)),
*arg(lastPeriodDayCounter), rebatesAccrual, qlNullableDate(tradeDate), cashSettlementDays))));
} catch (std::exception& er) {return handleException<QlCreditDefaultSwap*>(e, er);}}
QlCreditDefaultSwap* qlCreditDefaultSwap(int side, double notional, double spread, Schedule* schedule, int paymentConvention, DayCounter* dayCounter, int settlesAccrual, int paysAtDefaultTime, int protectionStart, QlClaim* x9, DayCounter* lastPeriodDayCounter, int rebatesAccrual, int tradeDate, unsigned cashSettlementDays, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCreditDefaultSwap(alloc(new CreditDefaultSwap((Protection::Side)side, notional, spread, *arg(schedule), (BusinessDayConvention)paymentConvention, *arg(dayCounter), settlesAccrual, paysAtDefaultTime, qlNullableDate(protectionStart), (*arg(x9)),
*arg(lastPeriodDayCounter), rebatesAccrual, qlNullableDate(tradeDate), cashSettlementDays))));
} catch (std::exception& er) {return handleException<QlCreditDefaultSwap*>(e, er);}}
double qlCreditDefaultSwapFairSpread(QlCreditDefaultSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairSpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCreditDefaultSwapConventionalSpread(QlCreditDefaultSwap* o, double conventionalRecovery, QlYieldTermStructure* discountCurve, DayCounter* dayCounter, int model, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->conventionalSpread(conventionalRecovery, *arg(discountCurve), *arg(dayCounter), (CreditDefaultSwap::PricingModel)model);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCreditDefaultSwapCouponLegBPS(QlCreditDefaultSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->couponLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCreditDefaultSwapCouponLegNPV(QlCreditDefaultSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->couponLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlCreditDefaultSwapCoupons(QlCreditDefaultSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return alloc(new Leg((*arg(o))->coupons()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlCreditDefaultSwapDefaultLegNPV(QlCreditDefaultSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->defaultLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCreditDefaultSwapFairUpfront(QlCreditDefaultSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairUpfront();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCreditDefaultSwapImpliedHazardRate(QlCreditDefaultSwap* o, double targetNPV, QlYieldTermStructure* discountCurve, DayCounter* dayCounter, double recoveryRate, double accuracy, int model, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->impliedHazardRate(targetNPV, *arg(discountCurve), *arg(dayCounter), recoveryRate, accuracy, (CreditDefaultSwap::PricingModel)model);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCreditDefaultSwapUpfrontBPS(QlCreditDefaultSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->upfrontBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCreditDefaultSwapUpfrontNPV(QlCreditDefaultSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->upfrontNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCreditDefaultSwapAccrualRebateNPV(QlCreditDefaultSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->accrualRebateNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeBarrierOption(QlBarrierOption *o) {del(o);}
QlOneAssetOption* qlBarrierOptionAsOneAssetOption(QlBarrierOption *o) {return ret(new QlOneAssetOption(*arg(o)));}
void qlFreeDoubleBarrierOption(QlDoubleBarrierOption *o) {del(o);}
QlOneAssetOption* qlDoubleBarrierOptionAsOneAssetOption(QlDoubleBarrierOption *o) {return ret(new QlOneAssetOption(*arg(o)));}
void qlFreeSoftBarrierOption(QlSoftBarrierOption *o) {del(o);}
QlOneAssetOption* qlSoftBarrierOptionAsOneAssetOption(QlSoftBarrierOption *o) {return ret(new QlOneAssetOption(*arg(o)));}
void qlFreeMargrabeOption(QlMargrabeOption *o) {del(o);}
QlMultiAssetOption* qlMargrabeOptionAsMultiAssetOption(QlMargrabeOption *o) {return ret(new QlMultiAssetOption(*arg(o)));}
void qlFreeEverestOption(QlEverestOption *o) {del(o);}
QlMultiAssetOption* qlEverestOptionAsMultiAssetOption(QlEverestOption *o) {return ret(new QlMultiAssetOption(*arg(o)));}
void qlFreeMultiAssetOption(QlMultiAssetOption *o) {del(o);}
QlOption* qlMultiAssetOptionAsOption(QlMultiAssetOption *o) {return ret(new QlOption(*arg(o)));}
void qlFreeOneAssetOption(QlOneAssetOption *o) {del(o);}
QlOption* qlOneAssetOptionAsOption(QlOneAssetOption *o) {return ret(new QlOption(*arg(o)));}
void qlFreeOption(QlOption *o) {del(o);}
QlInstrument* qlOptionAsInstrument(QlOption *o) {return ret(new QlInstrument(*arg(o)));}
void qlFreeQuantoVanillaOption(QlQuantoVanillaOption *o) {del(o);}
QlOneAssetOption* qlQuantoVanillaOptionAsOneAssetOption(QlQuantoVanillaOption *o) {return ret(new QlOneAssetOption(*arg(o)));}
void qlFreeSwaption(QlSwaption *o) {del(o);}
QlOption* qlSwaptionAsOption(QlSwaption *o) {return ret(new QlOption(*arg(o)));}
void qlFreeVanillaOption(QlVanillaOption *o) {del(o);}
QlOneAssetOption* qlVanillaOptionAsOneAssetOption(QlVanillaOption *o) {return ret(new QlOneAssetOption(*arg(o)));}
void qlFreeSwingExercise(QlSwingExercise *o) {del(o);}
QlBermudanExercise* qlSwingExerciseAsBermudanExercise(QlSwingExercise *o) {return ret(new QlBermudanExercise(*arg(o)));}
double qlCdsOptionAtmRate(QlCdsOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->atmRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlCdsOption* qlCdsOption(QlCreditDefaultSwap* swap, QlExercise* exercise, int knocksOut, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCdsOption(alloc(new CdsOption(*arg(swap), *arg(exercise), knocksOut))));
} catch (std::exception& er) {return handleException<QlCdsOption*>(e, er);}}
double qlCdsOptionImpliedVolatility(QlCdsOption* o, double price, QlYieldTermStructure* termStructure, QlDefaultProbabilityTermStructure* x3, double recoveryRate, double accuracy, unsigned maxEvaluations, double minVol, double maxVol, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->impliedVolatility(price, *arg(termStructure), Handle<DefaultProbabilityTermStructure>(*arg(x3)), recoveryRate, accuracy, maxEvaluations, minVol, maxVol);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCdsOptionRiskyAnnuity(QlCdsOption* o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->riskyAnnuity();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlSwaptionImpliedVolatility(QlSwaption* o, double price, QlYieldTermStructure* discountCurve, double guess, double accuracy, unsigned maxEvaluations, double minVol, double maxVol, int type, double displacement, int priceType, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->impliedVolatility(price, *arg(discountCurve), guess, accuracy, maxEvaluations, minVol, maxVol, (VolatilityType)type, displacement, (Swaption::PriceType)priceType);
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlSwaption* qlSwaption(QlFixedVsFloatingSwap* swap, QlExercise* exercise, int delivery, int settlementMethod, QlError **e) { QlCallScope callbackScope(e);
if (!qlOvernightUnderlyingSupported(e, *arg(swap), "swaption on OvernightIndexedSwap")) return nullptr;
try {return ret(new QlSwaption(alloc(new Swaption(*arg(swap), *arg(exercise), (Settlement::Type) delivery, (Settlement::Method) settlementMethod))));
} catch (std::exception& er) {return handleException<QlSwaption*>(e, er);}}
void qlFreeIrregularSwaption(QlIrregularSwaption* o) {del(o);}
QlOption* qlIrregularSwaptionAsOption(QlIrregularSwaption* o) {return ret(new QlOption(*arg(o)));}
QlIrregularSwaption* qlIrregularSwaption(QlIrregularSwap* swap, QlExercise* exercise, int settlement, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlIrregularSwaption(alloc(new IrregularSwaption(*arg(swap), *arg(exercise), (IrregularSettlement::Type)settlement))));
} catch (std::exception& er) {return handleException<QlIrregularSwaption*>(e, er);}}
void qlFreeIrregularSwap(QlIrregularSwap* o) {del(o);}
QlSwap* qlIrregularSwapAsSwap(QlIrregularSwap* o) {return ret(new QlSwap(*arg(o)));}
QlIrregularSwap* qlIrregularSwap(int type, Leg* fixedLeg, Leg* floatingLeg, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlIrregularSwap(alloc(new IrregularSwap((Swap::Type)type, *arg(fixedLeg), *arg(floatingLeg)))));
} catch (std::exception& er) {return handleException<QlIrregularSwap*>(e, er);}}
double qlIrregularSwapFairRate(QlIrregularSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlIrregularSwapFairSpread(QlIrregularSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->fairSpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeNonstandardSwaption(QlNonstandardSwaption *o) {del(o);}
QlOption* qlNonstandardSwaptionAsOption(QlNonstandardSwaption *o) {return ret(new QlOption(*arg(o)));}
// Converts an existing Swaption into a NonstandardSwaption (upstream's own conversion ctor).
QlNonstandardSwaption* qlNonstandardSwaption1(QlSwaption* fromSwaption, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlNonstandardSwaption(alloc(new NonstandardSwaption(**arg(fromSwaption)))));
} catch (std::exception& er) {return handleException<QlNonstandardSwaption*>(e, er);}}
QlNonstandardSwaption* qlNonstandardSwaption(QlNonstandardSwap* swap, QlExercise* exercise, int delivery, int settlementMethod, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlNonstandardSwaption(alloc(new NonstandardSwaption(*arg(swap), *arg(exercise), (Settlement::Type) delivery, (Settlement::Method) settlementMethod))));
} catch (std::exception& er) {return handleException<QlNonstandardSwaption*>(e, er);}}
// QuantLib computes the basket according to CalibrationBasketType.
void qlNonstandardSwaptionCalibrationBasket(QlNonstandardSwaption* o, QlSwapIndex* swapBase, QlSwaptionVolatilityStructure* swaptionVol, int basketType, unsigned* len, QlBlackCalibrationHelper*** helpers, QlError **e) { QlCallScope callbackScope(e);
OutPtrArrayResult<QlBlackCalibrationHelper> result(len, helpers);
try {
std::vector<ext::shared_ptr<BlackCalibrationHelper>> basket = (*arg(o))->calibrationBasket(*arg(swapBase), (*arg(swaptionVol)).currentLink(), (BasketGeneratingEngine::CalibrationBasketType)basketType);
const unsigned n = (unsigned)basket.size();
QlBlackCalibrationHelper **hs = result.allocate(n);
for (unsigned i = 0; i < n; ++i) hs[i] = ret(new QlBlackCalibrationHelper(alloc(basket[i])));
result.commit();
} catch (std::exception& er) {handleException<int>(e, er);}}
void qlFreeFloatFloatSwaption(QlFloatFloatSwaption *o) {del(o);}
QlOption* qlFloatFloatSwaptionAsOption(QlFloatFloatSwaption *o) {return ret(new QlOption(*arg(o)));}
QlFloatFloatSwaption* qlFloatFloatSwaption(QlFloatFloatSwap* swap, QlExercise* exercise, int delivery, int settlementMethod, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatFloatSwaption(alloc(new FloatFloatSwaption(*arg(swap), *arg(exercise), (Settlement::Type) delivery, (Settlement::Method) settlementMethod))));
} catch (std::exception& er) {return handleException<QlFloatFloatSwaption*>(e, er);}}
void qlFloatFloatSwaptionCalibrationBasket(QlFloatFloatSwaption* o, QlSwapIndex* swapBase, QlSwaptionVolatilityStructure* swaptionVol, int basketType, unsigned* len, QlBlackCalibrationHelper*** helpers, QlError **e) { QlCallScope callbackScope(e);
OutPtrArrayResult<QlBlackCalibrationHelper> result(len, helpers);
try {
std::vector<ext::shared_ptr<BlackCalibrationHelper>> basket = (*arg(o))->calibrationBasket(*arg(swapBase), (*arg(swaptionVol)).currentLink(), (BasketGeneratingEngine::CalibrationBasketType)basketType);
const unsigned n = (unsigned)basket.size();
QlBlackCalibrationHelper **hs = result.allocate(n);
for (unsigned i = 0; i < n; ++i) hs[i] = ret(new QlBlackCalibrationHelper(alloc(basket[i])));
result.commit();
} catch (std::exception& er) {handleException<int>(e, er);}}
void qlFreeQuantoBarrierOption(QlQuantoBarrierOption *o) {del(o);}
QlOneAssetOption* qlQuantoBarrierOptionAsOneAssetOption(QlQuantoBarrierOption *o) {return ret(new QlOneAssetOption(*arg(o)));}
void qlFreeQuantoDoubleBarrierOption(QlQuantoDoubleBarrierOption *o) {del(o);}
QlOneAssetOption* qlQuantoDoubleBarrierOptionAsOneAssetOption(QlQuantoDoubleBarrierOption *o) {return ret(new QlOneAssetOption(*arg(o)));}
void qlFreeQuantoForwardVanillaOption(QlQuantoForwardVanillaOption *o) {del(o);}
QlOneAssetOption* qlQuantoForwardVanillaOptionAsOneAssetOption(QlQuantoForwardVanillaOption *o) {return ret(new QlOneAssetOption(*arg(o)));}
QlBarrierOption* qlBarrierOption(int barrierType, double barrier, double rebate, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlBarrierOption(alloc(new BarrierOption((Barrier::Type)barrierType, barrier, rebate, *arg(payoff), (*arg(exercise))))));
} catch (std::exception& er) {return handleException<QlBarrierOption*>(e, er);}}
QlInstrument* qlTwoAssetBarrierOption(int barrierType, double barrier, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlInstrument(alloc(new TwoAssetBarrierOption((Barrier::Type)barrierType, barrier, *arg(payoff), (*arg(exercise))))));
} catch (std::exception& er) {return handleException<QlInstrument*>(e, er);}}
double qlBarrierOptionImpliedVolatility(QlBarrierOption* o, double price, QlGeneralizedBlackScholesProcess* process, unsigned dividendsLen, QlDividend** dividends, double accuracy, unsigned maxEvaluations, double minVol, double maxVol, QlError **e) { QlCallScope callbackScope(e);
try {DividendSchedule d = qlVector(dividends, dividendsLen);
return (*arg(o))->impliedVolatility(price, *arg(process), d, accuracy, maxEvaluations, minVol, maxVol);
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlOneAssetOption* qlPartialTimeBarrierOption(int barrierType, int barrierRange, double barrier, double rebate, int coverEventDate, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new PartialTimeBarrierOption((Barrier::Type)barrierType, (PartialBarrier::Range)barrierRange, barrier, rebate, Date(coverEventDate), *arg(payoff), *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlDoubleBarrierOption* qlDoubleBarrierOption(int barrierType, double barrierLo, double barrierHi, double rebate, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlDoubleBarrierOption(alloc(new DoubleBarrierOption((DoubleBarrier::Type)barrierType, barrierLo, barrierHi, rebate, *arg(payoff), (*arg(exercise))))));
} catch (std::exception& er) {return handleException<QlDoubleBarrierOption*>(e, er);}}
double qlDoubleBarrierOptionImpliedVolatility(QlDoubleBarrierOption* o, double price, QlGeneralizedBlackScholesProcess* process, double accuracy, unsigned maxEvaluations, double minVol, double maxVol, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->impliedVolatility(price, *arg(process), accuracy, maxEvaluations, minVol, maxVol);
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlSoftBarrierOption* qlSoftBarrierOption(int barrierType, double barrierLo, double barrierHi, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlSoftBarrierOption(alloc(new SoftBarrierOption((Barrier::Type)barrierType, barrierLo, barrierHi, *arg(payoff), *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlSoftBarrierOption*>(e, er);}}
double qlSoftBarrierOptionImpliedVolatility(QlSoftBarrierOption* o, double price, QlGeneralizedBlackScholesProcess* process, double accuracy, unsigned maxEvaluations, double minVol, double maxVol, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->impliedVolatility(price, *arg(process), accuracy, maxEvaluations, minVol, maxVol);
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlOneAssetOption* qlSimpleChooserOption(int choosingDate, double strike, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new SimpleChooserOption(Date(choosingDate), strike, *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlOneAssetOption* qlComplexChooserOption(int choosingDate, double strikeCall, double strikePut, QlExercise* exerciseCall, QlExercise* exercisePut, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new ComplexChooserOption(Date(choosingDate), strikeCall, strikePut, *arg(exerciseCall), *arg(exercisePut)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlMultiAssetOption* qlTwoAssetCorrelationOption(int type, double strike1, double strike2, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlMultiAssetOption(alloc(new TwoAssetCorrelationOption((Option::Type)type, strike1, strike2, *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlMultiAssetOption*>(e, er);}}
QlOneAssetOption* qlWriterExtensibleOption(QlPlainVanillaPayoff* payoff1, QlExercise* exercise1, QlPlainVanillaPayoff* payoff2, QlExercise* exercise2, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new WriterExtensibleOption(*arg(payoff1), *arg(exercise1), *arg(payoff2), *arg(exercise2)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlOneAssetOption* qlHolderExtensibleOption(int type, double premium, int secondExpiryDate, double secondStrike, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new HolderExtensibleOption((Option::Type)type, premium, Date(secondExpiryDate), secondStrike, *arg(payoff), *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlOneAssetOption* qlForwardVanillaOption(double moneyness, int resetDate, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new ForwardVanillaOption(moneyness, Date(resetDate), *arg(payoff), *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlOneAssetOption* qlCompoundOption(QlStrikedTypePayoff* motherPayoff, QlExercise* motherExercise, QlStrikedTypePayoff* daughterPayoff, QlExercise* daughterExercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new CompoundOption(*arg(motherPayoff), *arg(motherExercise), *arg(daughterPayoff), *arg(daughterExercise)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
double qlMargrabeOptionDelta1(QlMargrabeOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->delta1();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMargrabeOptionDelta2(QlMargrabeOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->delta2();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMargrabeOptionGamma1(QlMargrabeOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->gamma1();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMargrabeOptionGamma2(QlMargrabeOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->gamma2();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlMargrabeOption* qlMargrabeOption(int Q1, int Q2, QlExercise* x2, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlMargrabeOption(alloc(new MargrabeOption(Q1, Q2, (*arg(x2))))));} catch (std::exception& er) {return handleException<QlMargrabeOption*>(e, er);}}
double qlEverestOptionYield(QlEverestOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->yield();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlEverestOption* qlEverestOption(double notional, double guarantee, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlEverestOption(alloc(new EverestOption(notional, guarantee, *arg(exercise)))));} catch (std::exception& er) {return handleException<QlEverestOption*>(e, er);}}
double qlMultiAssetOptionDelta(QlMultiAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->delta();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMultiAssetOptionDividendRho(QlMultiAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->dividendRho();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMultiAssetOptionGamma(QlMultiAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->gamma();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlMultiAssetOption* qlMultiAssetOption(QlPayoff* x0, QlExercise* x1, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlMultiAssetOption(alloc(new MultiAssetOption(*arg(x0), (*arg(x1))))));} catch (std::exception& er) {return handleException<QlMultiAssetOption*>(e, er);}}
double qlMultiAssetOptionRho(QlMultiAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->rho();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMultiAssetOptionTheta(QlMultiAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->theta();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMultiAssetOptionVega(QlMultiAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->vega();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionDelta(QlOneAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->delta();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionDeltaForward(QlOneAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->deltaForward(); } catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionDividendRho(QlOneAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->dividendRho();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionElasticity(QlOneAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->elasticity();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionGamma(QlOneAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->gamma();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionItmCashProbability(QlOneAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->itmCashProbability();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlOneAssetOption* qlOneAssetOption(QlPayoff* x0, QlExercise* x1, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlOneAssetOption(alloc(new OneAssetOption(*arg(x0), (*arg(x1))))));} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
double qlOneAssetOptionRho(QlOneAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->rho();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionStrikeSensitivity(QlOneAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->strikeSensitivity();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionTheta(QlOneAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->theta();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionThetaPerDay(QlOneAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->thetaPerDay();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionVega(QlOneAssetOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->vega();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoBarrierOptionQlambda(QlQuantoBarrierOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->qlambda();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoBarrierOptionQrho(QlQuantoBarrierOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->qrho();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlQuantoBarrierOption* qlQuantoBarrierOption(int barrierType, double barrier, double rebate, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlQuantoBarrierOption(alloc(new QuantoBarrierOption((Barrier::Type)barrierType, barrier, rebate, *arg(payoff), (*arg(exercise))))));
} catch (std::exception& er) {return handleException<QlQuantoBarrierOption*>(e, er);}}
double qlQuantoBarrierOptionQvega(QlQuantoBarrierOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->qvega();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoDoubleBarrierOptionQlambda(QlQuantoDoubleBarrierOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->qlambda();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoDoubleBarrierOptionQrho(QlQuantoDoubleBarrierOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->qrho();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlQuantoDoubleBarrierOption* qlQuantoDoubleBarrierOption(int barrierType, double barrierLo, double barrierHi, double rebate, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlQuantoDoubleBarrierOption(alloc(new QuantoDoubleBarrierOption((DoubleBarrier::Type)barrierType, barrierLo, barrierHi, rebate, *arg(payoff), (*arg(exercise))))));
} catch (std::exception& er) {return handleException<QlQuantoDoubleBarrierOption*>(e, er);}}
double qlQuantoDoubleBarrierOptionQvega(QlQuantoDoubleBarrierOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->qvega();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoForwardVanillaOptionQlambda(QlQuantoForwardVanillaOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->qlambda();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoForwardVanillaOptionQrho(QlQuantoForwardVanillaOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->qrho();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlQuantoForwardVanillaOption* qlQuantoForwardVanillaOption(double moneyness, int resetDate, QlStrikedTypePayoff* x2, QlExercise* x3, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlQuantoForwardVanillaOption(alloc(new QuantoForwardVanillaOption(moneyness, Date(resetDate), *arg(x2), *arg(x3)))));
} catch (std::exception& er) {return handleException<QlQuantoForwardVanillaOption*>(e, er);}}
double qlQuantoForwardVanillaOptionQvega(QlQuantoForwardVanillaOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->qvega();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoVanillaOptionQlambda(QlQuantoVanillaOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->qlambda();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoVanillaOptionQrho(QlQuantoVanillaOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->qrho();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlQuantoVanillaOption* qlQuantoVanillaOption(QlStrikedTypePayoff* x0, QlExercise* x1, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlQuantoVanillaOption(alloc(new QuantoVanillaOption(*arg(x0), (*arg(x1))))));
} catch (std::exception& er) {return handleException<QlQuantoVanillaOption*>(e, er);}}
double qlQuantoVanillaOptionQvega(QlQuantoVanillaOption* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->qvega();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlVanillaOptionImpliedVolatility(QlVanillaOption* o, double price, QlGeneralizedBlackScholesProcess* process, unsigned dividendsLen, QlDividend** dividends, double accuracy, unsigned maxEvaluations, double minVol, double maxVol, QlError **e) { QlCallScope callbackScope(e);
try {DividendSchedule d = qlVector(dividends, dividendsLen);
return (*arg(o))->impliedVolatility(price, *arg(process), d, accuracy, maxEvaluations, minVol, maxVol);
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlVanillaOption* qlVanillaOption(QlStrikedTypePayoff* x0, QlExercise* x1, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlVanillaOption(alloc(new VanillaOption(*arg(x0), (*arg(x1))))));
} catch (std::exception& er) {return handleException<QlVanillaOption*>(e, er);}}
QlMultiAssetOption* qlBasketOption(QlBasketPayoff* x0, QlExercise* x1, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlMultiAssetOption(alloc(new BasketOption(*arg(x0), (*arg(x1))))));
} catch (std::exception& er) {return handleException<QlMultiAssetOption*>(e, er);}}
QlMultiAssetOption* qlHimalayaOption(unsigned fixingDatesLen, int* fixingDates, double strike, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlMultiAssetOption(alloc(new HimalayaOption(qlDateVector(fixingDates, fixingDatesLen), strike))));
} catch (std::exception& er) {return handleException<QlMultiAssetOption*>(e, er);}}
QlMultiAssetOption* qlPagodaOption(unsigned fixingDatesLen, int* fixingDates, double roof, double fraction, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlMultiAssetOption(alloc(new PagodaOption(qlDateVector(fixingDates, fixingDatesLen), roof, fraction))));
} catch (std::exception& er) {return handleException<QlMultiAssetOption*>(e, er);}}
QlOneAssetOption* qlCliquetOption(QlPercentageStrikePayoff* x0, QlEuropeanExercise* maturity, unsigned resetDatesLen, int* resetDates, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new CliquetOption(*arg(x0), *arg(maturity), qlDateVector(resetDates, resetDatesLen)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlOneAssetOption* qlContinuousAveragingAsianOption(int averageType, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new ContinuousAveragingAsianOption((Average::Type)averageType, *arg(payoff), *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlOneAssetOption* qlContinuousFixedLookbackOption(double currentMinmax, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new ContinuousFixedLookbackOption(currentMinmax, *arg(payoff), *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlOneAssetOption* qlContinuousFloatingLookbackOption(double currentMinmax, QlTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new ContinuousFloatingLookbackOption(currentMinmax, *arg(payoff), *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlOneAssetOption* qlContinuousPartialFloatingLookbackOption(double currentMinmax, double lambda, int lookbackPeriodEnd, QlTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new ContinuousPartialFloatingLookbackOption(currentMinmax, lambda, Date(lookbackPeriodEnd), *arg(payoff), *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlOneAssetOption* qlContinuousPartialFixedLookbackOption(int lookbackPeriodStart, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new ContinuousPartialFixedLookbackOption(Date(lookbackPeriodStart), *arg(payoff), *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlOneAssetOption* qlDiscreteAveragingAsianOption(int averageType, double runningAccumulator, unsigned pastFixings, unsigned fixingDatesLen, int* fixingDates, QlStrikedTypePayoff* payoff, QlExercise* exercise, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new DiscreteAveragingAsianOption((Average::Type)averageType, runningAccumulator, pastFixings, qlDateVector(fixingDates, fixingDatesLen), *arg(payoff), *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlOneAssetOption* qlVanillaStorageOption(QlBermudanExercise* ex, double capacity, double load, double changeRate, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new VanillaStorageOption(*arg(ex), capacity, load, changeRate))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlOneAssetOption* qlVanillaSwingOption(QlStrikedTypePayoff* payoff, QlSwingExercise* ex, unsigned minExerciseRights, unsigned maxExerciseRights, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOneAssetOption(alloc(new VanillaSwingOption(*arg(payoff), *arg(ex), minExerciseRights, maxExerciseRights))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlVanillaOption* qlEuropeanOption(QlStrikedTypePayoff* x0, QlExercise* x1, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlVanillaOption(alloc(new EuropeanOption(*arg(x0), (*arg(x1))))));} catch (std::exception& er) {return handleException<QlVanillaOption*>(e, er);}}
QlBond *qlBond(unsigned settlDays, Calendar *calendar, int issueDate, Leg *coupons, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlBond(alloc(new Bond(settlDays, *arg(calendar), qlNullableDate(issueDate), *arg(coupons)))));
} catch (std::exception& er) {return handleException<QlBond *>(e, er);}}
int qlBondMaturityDate(QlBond *bond, QlError **e) { QlCallScope callbackScope(e);
try {return qlNullableDate((*arg(bond))->maturityDate());
} catch (std::exception& er) {return handleException<int>(e, er);}}
void qlFreeBond(QlBond *bond) {del(bond);}
void qlFreeFixedRateBond(QlFixedRateBond *bond) {del(bond);}
QlBond *qlFixedRateBondAsBond(QlFixedRateBond *bond) {return ret(new QlBond(*arg(bond)));}
void qlFreeCPIBond(QlCPIBond *bond) {del(bond);}
QlBond *qlCPIBondAsBond(QlCPIBond *bond) {return ret(new QlBond(*arg(bond)));}
QlCPIBond *qlCPIBond(unsigned settlementDays, double faceAmount, double baseCPI, int obsLagLen, int obsLagUnit, QlZeroInflationIndex* index, int observationInterpolation, Schedule *schedule, unsigned couponsLen, double *coupons, DayCounter *accrualDayCounter, int paymentConvention, int issueDate, Calendar *paymentCalendar, int exCouponPeriodLen, int exCouponPeriodUnit, Calendar* exCouponCalendar, int exCouponConvention, int exCouponEndOfMonth, QlError **e) { QlCallScope callbackScope(e);
try {std::vector<Rate> cpns(coupons, coupons+couponsLen);
return ret(new QlCPIBond(alloc(new CPIBond(settlementDays, faceAmount, baseCPI, Period(obsLagLen, (TimeUnit)obsLagUnit), *arg(index),
(CPI::InterpolationType)observationInterpolation, *arg(schedule), cpns, *arg(accrualDayCounter), (BusinessDayConvention)paymentConvention,
qlNullableDate(issueDate), *arg(paymentCalendar), Period(exCouponPeriodLen, (TimeUnit)exCouponPeriodUnit), *arg(exCouponCalendar),
(BusinessDayConvention)exCouponConvention, exCouponEndOfMonth))));
} catch (std::exception& er) {return handleException<QlCPIBond *>(e, er);}}
QlFixedRateBond *qlFixedRateBond(unsigned settlDays, double face, Schedule *schedule, unsigned cLen, double *coupons, DayCounter *counter,
int payConv, double redemption, int issue, Calendar *payCal, int exCouponPeriodLen, int exCouponPeriodUnit, Calendar* exCouponCalendar, int exCouponConvention, int exCouponEndOfMonth, DayCounter* firstPeriodDayCounter, QlError **e) { QlCallScope callbackScope(e);
try {std::vector<Rate> cpns(coupons, coupons+cLen);
return ret(new QlFixedRateBond(alloc(new FixedRateBond(settlDays, face, *arg(schedule),
cpns, *arg(counter), (BusinessDayConvention) payConv, redemption, qlNullableDate(issue), *arg(payCal),
Period(exCouponPeriodLen, (TimeUnit)exCouponPeriodUnit), *arg(exCouponCalendar), (BusinessDayConvention)exCouponConvention, exCouponEndOfMonth,
*arg(firstPeriodDayCounter)))));
} catch (std::exception& er) {return handleException<QlFixedRateBond *>(e, er);}}
QlBTP *qlBtp(int maturityDate, double fixedRate, int startDate, int issueDate, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlBTP(alloc(new BTP(Date(maturityDate), fixedRate, qlNullableDate(startDate), qlNullableDate(issueDate)))));
} catch (std::exception& er) {return handleException<QlBTP*>(e, er);}}
QlBTP *qlBtpWithRedemption(int maturityDate, double fixedRate, double redemption, int startDate, int issueDate, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlBTP(alloc(new BTP(Date(maturityDate), fixedRate, redemption, qlNullableDate(startDate), qlNullableDate(issueDate)))));
} catch (std::exception& er) {return handleException<QlBTP*>(e, er);}}
void qlFreeBtp(QlBTP *o) {del(o);}
QlFixedRateBond *qlBtpAsFixedRateBond(QlBTP *o) {return ret(new QlFixedRateBond(*arg(o)));}
QlInstrument *qlBondAsInstrument(QlBond *b) {return ret(new QlInstrument(*arg(b)));}
QlBond *qlZeroCouponBond(int settlDays, Calendar *cal, double face, int maturity, int payConv, double redemption, int issue, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlBond(alloc(new ZeroCouponBond(settlDays, *arg(cal), face, Date(maturity), (BusinessDayConvention) payConv, redemption, qlNullableDate(issue)))));
} catch (std::exception& er) {return handleException<QlBond *>(e, er);}}
QlBond *qlFloatingRateBond(unsigned settlDays, double face, Schedule *sched, QlIborIndex *index, DayCounter *dc, int payConv, unsigned fixDays,
unsigned nGearings, double *gearings, unsigned nSpreads, double *spreads, unsigned nCaps, double *caps, unsigned nFloors, double *floors,
int inArrears, double redemption, int issue, int exCouponPeriodLen, int exCouponPeriodUnit, Calendar* exCouponCalendar, int exCouponConvention, int exCouponEndOfMonth, int fixingConvention, QlError **e) { QlCallScope callbackScope(e);
try {std::vector<Real> gs(gearings, gearings+nGearings); std::vector<Spread> sps(spreads, spreads+nSpreads);
std::vector<Rate> cs(caps, caps+nCaps); std::vector<Rate> fs(floors, floors+nFloors);
return ret(new QlBond(alloc(new FloatingRateBond(settlDays, face, *arg(sched), *arg(index), *arg(dc), (BusinessDayConvention) payConv, fixDays, gs,
sps, cs, fs, inArrears, redemption, qlNullableDate(issue),
Period(exCouponPeriodLen, (TimeUnit)exCouponPeriodUnit), *arg(exCouponCalendar), (BusinessDayConvention)exCouponConvention, exCouponEndOfMonth,
(BusinessDayConvention)fixingConvention))));
} catch (std::exception& er) {return handleException<QlBond *>(e, er);}}
QlBond *qlCmsRateBond(unsigned settlDays, double faceAmount, Schedule *sched, QlSwapIndex *index, DayCounter *dc,
int payConv, unsigned fixDays, unsigned nGearings, double *gearings, unsigned nSpreads, double *spreads,
unsigned nCaps, double *caps, unsigned nFloors, double *floors, int inArrears, double redemption, int issue, QlError **e) { QlCallScope callbackScope(e);
try {std::vector<Real> gs(gearings, gearings+nGearings); std::vector<Spread> sps(spreads, spreads+nSpreads);
std::vector<Rate> cs(caps, caps+nCaps); std::vector<Rate> fs(floors, floors+nFloors);
return ret(new QlBond(alloc(new CmsRateBond(settlDays, faceAmount, *arg(sched), *arg(index), *arg(dc),
(BusinessDayConvention)payConv, fixDays, gs, sps, cs, fs, inArrears, redemption, qlNullableDate(issue)))));
} catch (std::exception& er) {return handleException<QlBond *>(e, er);}}
QlBond *qlAmortizingCmsRateBond(unsigned settlementDays, unsigned notionalsLen, double *notionals, Schedule *sched,
QlSwapIndex *index, DayCounter *dc, int payConv, unsigned fixDays, unsigned nGearings, double *gearings,
unsigned nSpreads, double *spreads, unsigned nCaps, double *caps, unsigned nFloors, double *floors,
int inArrears, int issue, unsigned redemptionsLen, double *redemptions, QlError **e) { QlCallScope callbackScope(e);
try {std::vector<Real> ns(notionals, notionals+notionalsLen);
std::vector<Real> gs(gearings, gearings+nGearings); std::vector<Spread> sps(spreads, spreads+nSpreads);
std::vector<Rate> cs(caps, caps+nCaps); std::vector<Rate> fs(floors, floors+nFloors);
std::vector<Real> reds(redemptions, redemptions+redemptionsLen);
return ret(new QlBond(alloc(new AmortizingCmsRateBond(settlementDays, ns, *arg(sched), *arg(index), *arg(dc),
(BusinessDayConvention)payConv, fixDays, gs, sps, cs, fs, inArrears, qlNullableDate(issue), reds))));
} catch (std::exception& er) {return handleException<QlBond *>(e, er);}}
QlBond *qlAmortizingFixedRateBond(unsigned settlementDays, unsigned notionalsLen, double *notionals, Schedule *schedule,
unsigned couponsLen, double *coupons, DayCounter *accrualDayCounter, int paymentConvention, int issueDate,
int exCouponPeriodLen, int exCouponPeriodUnit, Calendar* exCouponCalendar, int exCouponConvention, int exCouponEndOfMonth,
unsigned redemptionsLen, double *redemptions, int paymentLag, QlError **e) { QlCallScope callbackScope(e);
try {std::vector<Real> ns(notionals, notionals+notionalsLen); std::vector<Rate> cpns(coupons, coupons+couponsLen);
std::vector<Real> reds(redemptions, redemptions+redemptionsLen);
return ret(new QlBond(alloc(new AmortizingFixedRateBond(settlementDays, ns, *arg(schedule), cpns, *arg(accrualDayCounter),
(BusinessDayConvention)paymentConvention, qlNullableDate(issueDate),
Period(exCouponPeriodLen, (TimeUnit)exCouponPeriodUnit), *arg(exCouponCalendar), (BusinessDayConvention)exCouponConvention,
exCouponEndOfMonth, reds, paymentLag))));
} catch (std::exception& er) {return handleException<QlBond *>(e, er);}}
QlBond *qlAmortizingFloatingRateBond(unsigned settlementDays, unsigned notionalLen, double *notional, Schedule *schedule,
QlIborIndex *index, DayCounter *accrualDayCounter, int paymentConvention, unsigned fixingDays,
unsigned nGearings, double *gearings, unsigned nSpreads, double *spreads, unsigned nCaps, double *caps, unsigned nFloors, double *floors,
int inArrears, int issueDate, int exCouponPeriodLen, int exCouponPeriodUnit, Calendar* exCouponCalendar, int exCouponConvention,
int exCouponEndOfMonth, unsigned redemptionsLen, double *redemptions, int paymentLag, QlError **e) { QlCallScope callbackScope(e);
try {std::vector<Real> ns(notional, notional+notionalLen);
std::vector<Real> gs(gearings, gearings+nGearings); std::vector<Spread> sps(spreads, spreads+nSpreads);
std::vector<Rate> cs(caps, caps+nCaps); std::vector<Rate> fs(floors, floors+nFloors);
std::vector<Real> reds(redemptions, redemptions+redemptionsLen);
return ret(new QlBond(alloc(new AmortizingFloatingRateBond(settlementDays, ns, *arg(schedule), *arg(index), *arg(accrualDayCounter),
(BusinessDayConvention)paymentConvention, fixingDays, gs, sps, cs, fs, inArrears, qlNullableDate(issueDate),
Period(exCouponPeriodLen, (TimeUnit)exCouponPeriodUnit), *arg(exCouponCalendar), (BusinessDayConvention)exCouponConvention,
exCouponEndOfMonth, reds, paymentLag))));
} catch (std::exception& er) {return handleException<QlBond *>(e, er);}}
Schedule *qlSinkingSchedule(int startDate, int lengthLen, int lengthUnit, int frequency, Calendar *paymentCalendar, QlError **e) { QlCallScope callbackScope(e);
try {return alloc(new Schedule(sinkingSchedule(Date(startDate), Period(lengthLen, (TimeUnit)lengthUnit), (Frequency)frequency, *arg(paymentCalendar))));
} catch (std::exception& er) {return handleException<Schedule *>(e, er);}}
void qlSinkingNotionals(int lengthLen, int lengthUnit, int frequency, double couponRate, double initialNotional,
unsigned *len, double **out, QlError **e) { QlCallScope callbackScope(e);
try {fillVectorOut([&] {return sinkingNotionals(Period(lengthLen, (TimeUnit)lengthUnit), (Frequency)frequency, couponRate, initialNotional);}, len, out);
} catch (std::exception& er) {(void)handleException<double*>(e, er);}}
void qlBondNotionals(QlBond* o, unsigned *len, double **ns, QlError **e) { QlCallScope callbackScope(e);
try {fillVectorOut([&] {return (*arg(o))->notionals();}, len, ns);
} catch (std::exception& er) {(void)handleException<double*>(e, er);}}
double qlBondYield(QlBond* o, DayCounter* dc, int comp, int freq, double accuracy, unsigned maxEvaluations, double guess, int priceType, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->yield(*arg(dc), (Compounding)comp, (Frequency)freq, accuracy, maxEvaluations, guess, (Bond::Price::Type)priceType);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondAccruedAmount(QlBond* o, int d, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->accruedAmount(Date(d));} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondDirtyPrice1(QlBond* o, double yield, DayCounter* dc, int comp, int freq, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->dirtyPrice(yield, *arg(dc), (Compounding)comp, (Frequency)freq, Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlBondNextCashFlowDate(QlBond* o, int d, QlError **e) { QlCallScope callbackScope(e);try {return qlNullableDate((*arg(o))->nextCashFlowDate(Date(d)));} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlBondNextCouponRate(QlBond* o, int d, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->nextCouponRate(Date(d));} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondNotional(QlBond* o, int d, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->notional(Date(d));} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlBondPreviousCashFlowDate(QlBond* o, int d, QlError **e) { QlCallScope callbackScope(e);try {return qlNullableDate((*arg(o))->previousCashFlowDate(Date(d)));} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlBondPreviousCouponRate(QlBond* o, int d, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->previousCouponRate(Date(d));} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondSettlementValue1(QlBond* o, double cleanPrice, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->settlementValue(cleanPrice);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondSettlementValue(QlBond* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->settlementValue();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondYield1(QlBond* o, double price, int priceType, DayCounter* dc, int comp, int freq, int settlementDate, double accuracy, unsigned maxEvaluations, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->yield(Bond::Price(price, (Bond::Price::Type)priceType), *arg(dc), (Compounding)comp, (Frequency)freq, Date(settlementDate), accuracy, maxEvaluations);
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlBondIsTradable(QlBond* o, int d, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->isTradable(Date(d));} catch (std::exception& er) {return handleException<int>(e, er);}}
Leg* qlBondCashflows(QlBond* o, QlError **e) { QlCallScope callbackScope(e);try {return ret(new Leg((*arg(o))->cashflows()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
Leg* qlBondRedemptions(QlBond* o, QlError **e) { QlCallScope callbackScope(e);try {return ret(new Leg((*arg(o))->redemptions()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
int qlBondSettlementDate(QlBond* o, int d, QlError **e) { QlCallScope callbackScope(e);try {return ((*arg(o))->settlementDate(Date(d))).serialNumber();} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlBondStartDate(QlBond* o, QlError **e) { QlCallScope callbackScope(e);try {return ((*arg(o))->startDate()).serialNumber();} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlBondFunctionsAccrualDays(QlBond* bond, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::accrualDays(**arg(bond), Date(settlementDate));
} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlBondFunctionsAccrualEndDate(QlBond* bond, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return qlNullableDate(BondFunctions::accrualEndDate(**arg(bond), Date(settlementDate)));
} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlBondFunctionsAccrualPeriod(QlBond* bond, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::accrualPeriod(**arg(bond), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlBondFunctionsAccrualStartDate(QlBond* bond, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return qlNullableDate(BondFunctions::accrualStartDate(**arg(bond), Date(settlementDate)));
} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlBondFunctionsAccruedDays(QlBond* bond, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::accruedDays(**arg(bond), Date(settlementDate));
} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlBondFunctionsAccruedPeriod(QlBond* bond, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::accruedPeriod(**arg(bond), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsAtmRate(QlBond* bond, QlYieldTermStructure* discountCurve, int settlementDate, double price, int priceType, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::atmRate(**arg(bond), handleRef(arg(discountCurve)), Date(settlementDate), Bond::Price(price, (Bond::Price::Type)priceType));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsBasisPointValue(QlBond* bond, InterestRate* yield, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::basisPointValue(**arg(bond), *arg(yield), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsBps1(QlBond* bond, InterestRate* yield, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::bps(**arg(bond), *arg(yield), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsBps(QlBond* bond, QlYieldTermStructure* discountCurve, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::bps(**arg(bond), handleRef(arg(discountCurve)), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsCleanPrice2(QlBond* bond, QlYieldTermStructure* discountCurve, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::cleanPrice(**arg(bond), handleRef(arg(discountCurve)), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsCleanPrice3(QlBond* bond, QlYieldTermStructure* discount, double zSpread, int compounding, int frequency, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::cleanPrice(**arg(bond), handlePtr(arg(discount)), zSpread, (Compounding)compounding, (Frequency)frequency, Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsCleanPrice4(QlBond* bond, InterestRate* yield, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::cleanPrice(**arg(bond), *arg(yield), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsConvexity(QlBond* bond, InterestRate* yield, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::convexity(**arg(bond), *arg(yield), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsDuration(QlBond* bond, InterestRate* yield, int type, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::duration(**arg(bond), *arg(yield), (Duration::Type)type, Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsNextCashFlowAmount(QlBond* bond, int refDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::nextCashFlowAmount(**arg(bond), Date(refDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsPreviousCashFlowAmount(QlBond* bond, int refDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::previousCashFlowAmount(**arg(bond), Date(refDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlBondFunctionsReferencePeriodEnd(QlBond* bond, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return qlNullableDate(BondFunctions::referencePeriodEnd(**arg(bond), Date(settlementDate)));
} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlBondFunctionsReferencePeriodStart(QlBond* bond, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return qlNullableDate(BondFunctions::referencePeriodStart(**arg(bond), Date(settlementDate)));
} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlBondFunctionsYield2(QlBond* bond, double price, int priceType, DayCounter* dayCounter, int compounding, int frequency, int settlementDate, double accuracy, unsigned maxIterations, double guess, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::yield(**arg(bond), Bond::Price(price, (Bond::Price::Type)priceType), *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, Date(settlementDate), accuracy, maxIterations, guess);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsYieldValueBasisPoint(QlBond* bond, InterestRate* yield, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::yieldValueBasisPoint(**arg(bond), *arg(yield), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsZSpread(QlBond* bond, double price, int priceType, QlYieldTermStructure* x2, int compounding, int frequency, int settlementDate, double accuracy, unsigned maxIterations, double guess, QlError **e) { QlCallScope callbackScope(e);
try {return BondFunctions::zSpread(**arg(bond), Bond::Price(price, (Bond::Price::Type)priceType), handlePtr(arg(x2)), (Compounding)compounding, (Frequency)frequency, Date(settlementDate), accuracy, maxIterations, guess);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondCleanPrice(QlBond* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->cleanPrice();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondDirtyPrice(QlBond* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->dirtyPrice();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeCallableBond(QlCallableBond *o) {del(o);}
QlBond* qlCallableBondAsBond(QlCallableBond *o) {return ret(new QlBond(*arg(o)));}
void qlFreeConvertibleBond(QlConvertibleBond *o) {del(o);}
QlBond* qlConvertibleBondAsBond(QlConvertibleBond *o) {return ret(new QlBond(*arg(o)));}
QlCallableBond* qlCallableFixedRateBond(unsigned settlementDays, double faceAmount, Schedule* schedule, unsigned couponsLen, double* coupons, DayCounter* accrualDayCounter, int paymentConvention, double redemption, int issueDate, unsigned putCallScheduleLen, QlCallability** putCallSchedule, int exCouponPeriodLen, int exCouponPeriodUnit, Calendar* exCouponCalendar, int exCouponConvention, int exCouponEndOfMonth, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCallableBond(alloc(new CallableFixedRateBond(settlementDays, faceAmount, *arg(schedule), std::vector<double>(coupons, coupons+couponsLen), *arg(accrualDayCounter), (BusinessDayConvention)paymentConvention, redemption, qlNullableDate(issueDate), qlVector(putCallSchedule, putCallScheduleLen),
Period(exCouponPeriodLen, (TimeUnit)exCouponPeriodUnit), *arg(exCouponCalendar), (BusinessDayConvention)exCouponConvention, exCouponEndOfMonth))));
} catch (std::exception& er) {return handleException<QlCallableBond*>(e, er);}}
QlCallableBond* qlCallableZeroCouponBond(unsigned settlementDays, double faceAmount, Calendar* calendar, int maturityDate, DayCounter* dayCounter, int paymentConvention, double redemption, int issueDate, unsigned putCallScheduleLen, QlCallability** putCallSchedule, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCallableBond(alloc(new CallableZeroCouponBond(settlementDays, faceAmount, *arg(calendar), Date(maturityDate), *arg(dayCounter), (BusinessDayConvention)paymentConvention, redemption, qlNullableDate(issueDate), qlVector(putCallSchedule, putCallScheduleLen)))));
} catch (std::exception& er) {return handleException<QlCallableBond*>(e, er);}}
QlConvertibleBond* qlConvertibleFixedCouponBond(QlExercise* exercise, double conversionRatio, unsigned callabilityLen, QlCallability** callability, int issueDate, unsigned settlementDays, unsigned couponsLen, double* coupons, DayCounter* dayCounter, Schedule* schedule, double redemption, int exCouponPeriodLen, int exCouponPeriodUnit, Calendar* exCouponCalendar, int exCouponConvention, int exCouponEndOfMonth, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlConvertibleBond(alloc(new ConvertibleFixedCouponBond(*arg(exercise), conversionRatio, qlVector(callability, callabilityLen), Date(issueDate), settlementDays, std::vector<double>(coupons, coupons+couponsLen), *arg(dayCounter), *arg(schedule), redemption,
Period(exCouponPeriodLen, (TimeUnit)exCouponPeriodUnit), *arg(exCouponCalendar), (BusinessDayConvention)exCouponConvention, exCouponEndOfMonth))));
} catch (std::exception& er) {return handleException<QlConvertibleBond*>(e, er);}}
QlConvertibleBond* qlConvertibleFloatingRateBond(QlExercise* exercise, double conversionRatio, unsigned callabilityLen, QlCallability** callability, int issueDate, unsigned settlementDays, QlIborIndex* index, unsigned fixingDays, unsigned spreadsLen, double* spreads, DayCounter* dayCounter, Schedule* schedule, double redemption, int exCouponPeriodLen, int exCouponPeriodUnit, Calendar* exCouponCalendar, int exCouponConvention, int exCouponEndOfMonth, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlConvertibleBond(alloc(new ConvertibleFloatingRateBond(*arg(exercise), conversionRatio, qlVector(callability, callabilityLen), Date(issueDate), settlementDays, (*arg(index)), fixingDays, std::vector<double>(spreads, spreads+spreadsLen), *arg(dayCounter), *arg(schedule), redemption,
Period(exCouponPeriodLen, (TimeUnit)exCouponPeriodUnit), *arg(exCouponCalendar), (BusinessDayConvention)exCouponConvention, exCouponEndOfMonth))));
} catch (std::exception& er) {return handleException<QlConvertibleBond*>(e, er);}}
QlConvertibleBond* qlConvertibleZeroCouponBond(QlExercise* exercise, double conversionRatio, unsigned callabilityLen, QlCallability** callability, int issueDate, unsigned settlementDays, DayCounter* dayCounter, Schedule* schedule, double redemption, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlConvertibleBond(alloc(new ConvertibleZeroCouponBond(*arg(exercise), conversionRatio, qlVector(callability, callabilityLen), Date(issueDate), settlementDays, *arg(dayCounter), *arg(schedule), redemption))));
} catch (std::exception& er) {return handleException<QlConvertibleBond*>(e, er);}}
QlCallability* qlSoftCallability(double price, int priceType, int date, double trigger, QlError **e) { QlCallScope callbackScope(e);
try {Bond::Price p(price, (Bond::Price::Type)priceType); return ret(new QlCallability(alloc(new SoftCallability(p, Date(date), trigger))));
} catch (std::exception& er) {return handleException<QlCallability*>(e, er);}}
Leg *qlLeg(unsigned len, double *amounts, int *dates, QlError **e) { QlCallScope callbackScope(e);
try {std::unique_ptr<Leg> leg(new Leg()); leg->reserve(len);
for (unsigned i = 0; i < len; ++i)
leg->push_back(shared_ptr<CashFlow>(new SimpleCashFlow(amounts[i], Date(dates[i]))));
return alloc(leg.release());
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
void qlFreeCashFlow(QlCashFlow *o) {del(o);}
double qlCashFlowAmount(QlCashFlow *o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->amount();} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlCashFlowDate(QlCashFlow *o) {return (*arg(o))->date().serialNumber();}
QlCashFlow *qlSimpleCashFlow(double amount, int date, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCashFlow(alloc(new SimpleCashFlow(amount, Date(date)))));
} catch (std::exception& er) {return handleException<QlCashFlow*>(e, er);}}
void qlFreeIndexedCashFlow(QlIndexedCashFlow *o) {del(o);}
QlCashFlow *qlIndexedCashFlowAsCashFlow(QlIndexedCashFlow *o) {return ret(new QlCashFlow(*arg(o)));}
QlIndexedCashFlow *qlIndexedCashFlow(double notional, QlIndex *index, int baseDate, int fixingDate, int paymentDate, int growthOnly, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlIndexedCashFlow(alloc(new IndexedCashFlow(notional, *arg(index), Date(baseDate), Date(fixingDate), Date(paymentDate), growthOnly))));
} catch (std::exception& er) {return handleException<QlIndexedCashFlow*>(e, er);}}
double qlIndexedCashFlowBaseFixing(QlIndexedCashFlow *o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->baseFixing();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlIndexedCashFlowIndexFixing(QlIndexedCashFlow *o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->indexFixing();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlFixedRateCoupon *qlFixedRateCoupon(int paymentDate, double nominal, double rate, DayCounter *dayCounter, int accrualStartDate, int accrualEndDate, int refPeriodStart, int refPeriodEnd, int exCouponDate, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFixedRateCoupon(alloc(new FixedRateCoupon(Date(paymentDate), nominal, rate, *arg(dayCounter), Date(accrualStartDate), Date(accrualEndDate), qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), qlNullableDate(exCouponDate)))));
} catch (std::exception& er) {return handleException<QlFixedRateCoupon*>(e, er);}}
void qlFreeCoupon(QlCoupon *o) {del(o);}
QlCashFlow* qlCouponAsCashFlow(QlCoupon *o) {return ret(new QlCashFlow(*arg(o)));}
double qlCouponRate(QlCoupon *o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->rate();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCouponAccruedAmount(QlCoupon *o, int d, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->accruedAmount(Date(d));} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeFixedRateCoupon(QlFixedRateCoupon *o) {del(o);}
QlCoupon* qlFixedRateCouponAsCoupon(QlFixedRateCoupon *o) {return ret(new QlCoupon(*arg(o)));}
InterestRate* qlFixedRateCouponInterestRate(QlFixedRateCoupon *o) {return ret(new InterestRate((*arg(o))->interestRate()));}
QlFloatingRateCoupon *qlFloatingRateCoupon(int paymentDate, double nominal, int startDate, int endDate, unsigned fixingDays, QlInterestRateIndex *index, double gearing, double spread, int refPeriodStart, int refPeriodEnd, DayCounter *dayCounter, int inArrears, int exCouponDate, int fixingConvention, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatingRateCoupon(alloc(new FloatingRateCoupon(Date(paymentDate), nominal, Date(startDate), Date(endDate), fixingDays, *arg(index), gearing, spread, qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), *arg(dayCounter), inArrears, qlNullableDate(exCouponDate), (BusinessDayConvention)fixingConvention))));
} catch (std::exception& er) {return handleException<QlFloatingRateCoupon*>(e, er);}}
Leg *qlCashFlowLeg(unsigned len, QlCashFlow **cashFlows, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new Leg(qlVector(cashFlows, len)));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
int qlLegStartDate(Leg *leg, QlError **e) { QlCallScope callbackScope(e);try {Date d = CashFlows::startDate(*arg(leg)); return d.serialNumber();} catch (std::exception& er) {return handleException<int>(e, er);}}
void qlFreeLeg(Leg *leg) {del(leg);}
Leg *qlNextCashFlows(Leg *leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {const Leg &l = *arg(leg);
Leg::const_iterator i = CashFlows::nextCashFlow(l,
includeSettlementDateFlows, qlNullableDate(settlementDate));
return alloc(new Leg(i, l.end()));
} catch (std::exception& er) {return handleException<Leg *>(e, er);}}
Leg *qlPreviousCashFlows(Leg *leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {const Leg &l = *arg(leg);
Leg::const_reverse_iterator i = CashFlows::previousCashFlow(l,
includeSettlementDateFlows, qlNullableDate(settlementDate));
return alloc(new Leg(l.begin(), i.base()));
} catch (std::exception& er) {return handleException<Leg *>(e, er);}}
// Every fixing the cash flows of this leg need, as parallel (index name, fixing date) arrays in
// leg order. QuantLib exposes no such query, so this walks the leg itself; see
// collectFixingDependencies above for the cast cascade and why its order matters. Names are
// Index::name(), the same key QuantLib's process-global fixing store uses. Duplicates are left
// in: two coupons may legitimately fix the same index on the same date, and the caller decides
// whether that matters.
void qlLegFixingDependencies(Leg *leg, unsigned *nameLen, char ***names, unsigned *dateLen, int **dates, QlError **e) { QlCallScope callbackScope(e);
OutStringArrayResult nameResult(nameLen, names);
OutArrayResult<int> dateResult(dateLen, dates);
try {const Leg& l = *arg(leg);
std::vector<std::pair<std::string, Date> > deps;
collectLegFixingDependencies(l, deps);
const unsigned n = (unsigned)deps.size();
char **ns = nameResult.allocate(n);
int *ds = dateResult.allocate(n);
for (unsigned i = 0; i < n; ++i) {
ns[i] = tracedup(deps[i].first.c_str());
ds[i] = deps[i].second.serialNumber();
}
nameResult.commit(); dateResult.commit();
} catch (std::exception& er) {qlSetError(e, er.what());}}
// The same walk for one of the rate helpers a curve was bootstrapped from. A bootstrapped curve
// cannot be asked what it was built from: PiecewiseYieldCurve is a template whose only accessors
// are maxDate/times/dates/data/nodes, and Observer does not expose the observables it registered
// with, so the helper list stays the caller's. A helper whose underlying instrument QuantLib
// hands back owns Legs, and a Leg is qlLegFixingDependencies' walk -- the underlying is reached
// through the only accessors 1.43 gives: SwapRateHelper::swap, OISRateHelper::swap,
// BondHelper::bond, and the two basis-swap helpers' swap; BMA, multiple-resets and cross-currency
// helpers keep theirs protected, which a derived-class pointer-to-member reaches.
//
// A futures or FX swap helper contributes nothing, and neither does a relative-date deposit or FRA,
// and that is an answer rather than a gap: the convention forms of the last two build their index
// with a "no-fix" name, and every relative form fixes on or after the evaluation date, where
// fixing(d, true) forecasts rather than reading the store. The fixed-date deposit and FRA forms
// read a fixing once its date has passed, and QuantLib keeps that date private, so hasquant builds
// them as FixedDateDepositRateHelper and FixedDateFraRateHelper (qlTermStructureAux.h), which keep
// a copy for this walk and report it from the day after it. An overnight-index (or SOFR) futures helper reads past fixings once
// its reference period is about to start and keeps its future private, so from then *reachable is
// set to 0 for it: an empty answer with reachable == 0 is "cannot see it". So is a helper type
// the visitor has no case for, which is how a newly bound helper fails until it gets one.
//
// The dates follow Settings::evaluationDate, because a relative-date helper re-initialises its
// schedule when that date moves. Call it on the date whose fixings are being asked about.
//
// The alias is local for the reason qlTermStructure.cpp gives where it declares its own:
// RateHelper is a typedef, so qlaux.h cannot alias it from a forward declaration.
using QlRateHelper = shared_ptr<RateHelper>;
void qlRateHelperFixingDependencies(QlRateHelper *helper, unsigned *nameLen, char ***names, unsigned *dateLen, int **dates, int *reachable, QlError **e) { QlCallScope callbackScope(e);
OutStringArrayResult nameResult(nameLen, names);
OutArrayResult<int> dateResult(dateLen, dates);
try {const ext::shared_ptr<RateHelper>& h = *arg(helper);
std::vector<std::pair<std::string, Date> > deps;
RateHelperFixingDependencyVisitor visitor(deps);
h->accept(visitor);
*reachable = !visitor.opaque();
const unsigned n = (unsigned)deps.size();
char **ns = nameResult.allocate(n);
int *ds = dateResult.allocate(n);
for (unsigned i = 0; i < n; ++i) {
ns[i] = tracedup(deps[i].first.c_str());
ds[i] = deps[i].second.serialNumber();
}
nameResult.commit(); dateResult.commit();
} catch (std::exception& er) {qlSetError(e, er.what());}}
void qlLegCashFlows(Leg *leg, int includeSettlementDateFlows, int settlementDate,
unsigned *al, double **amount, unsigned *dl, int **date, unsigned *hl, int **hasOccurred, QlError **e) { QlCallScope callbackScope(e);
OutArrayResult<double> amountResult(al, amount);
OutArrayResult<int> dateResult(dl, date);
OutArrayResult<int> occurredResult(hl, hasOccurred);
try {const Leg& l = *arg(leg);
double *amounts = amountResult.allocate((unsigned)l.size());
int *dates = dateResult.allocate((unsigned)l.size());
int *occurred = occurredResult.allocate((unsigned)l.size());
for (unsigned i = 0; i < l.size(); ++i) {
amounts[i] = l[i]->amount();
dates[i] = l[i]->date().serialNumber();
occurred[i] = l[i]->hasOccurred(qlNullableDate(settlementDate), qlOptBool(includeSettlementDateFlows));
}
amountResult.commit(); dateResult.commit(); occurredResult.commit();
} catch (std::exception& er) {qlSetError(e, er.what());}}
double qlCashFlowsDuration(Leg* leg, InterestRate* yield, int type, int includeSettlementDateFlows, int settlementDate, int npvDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::duration(*arg(leg), *arg(yield), (Duration::Type)type, includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlCashFlowsAccrualDays(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::accrualDays(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate));
} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlCashFlowsAccrualEndDate(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return qlNullableDate(CashFlows::accrualEndDate(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate)));
} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlCashFlowsAccrualPeriod(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::accrualPeriod(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlCashFlowsAccrualStartDate(Leg* leg, int includeSettlementDateFlows, int settlDate, QlError **e) { QlCallScope callbackScope(e);
try {return qlNullableDate(CashFlows::accrualStartDate(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlDate)));
} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlCashFlowsAccruedAmount(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::accruedAmount(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlCashFlowsAccruedDays(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::accruedDays(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate));
} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlCashFlowsAccruedPeriod(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::accruedPeriod(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsAtmRate(Leg* leg, QlYieldTermStructure* discountCurve, int includeSettlementDateFlows, int settlementDate, int npvDate, double npv, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::atmRate(*arg(leg), handleRef(arg(discountCurve)), includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate), npv);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsBasisPointValue(Leg* leg, InterestRate* yield, int includeSettlementDateFlows, int settlementDate, int npvDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::basisPointValue(*arg(leg), *arg(yield), includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsBps1(Leg* leg, InterestRate* yield, int includeSettlementDateFlows, int settlementDate, int npvDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::bps(*arg(leg), *arg(yield), includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsBps(Leg* leg, QlYieldTermStructure* discountCurve, int includeSettlementDateFlows, int settlementDate, int npvDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::bps(*arg(leg), handleRef(arg(discountCurve)), includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsConvexity(Leg* leg, InterestRate* yield, int includeSettlementDateFlows, int settlementDate, int npvDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::convexity(*arg(leg), *arg(yield), includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlCashFlowsIsExpired(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::isExpired(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate));
} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlCashFlowsMaturityDate(Leg* leg, QlError **e) { QlCallScope callbackScope(e);
try {return (CashFlows::maturityDate(*arg(leg))).serialNumber();
} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlCashFlowsNextCashFlowAmount(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::nextCashFlowAmount(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlCashFlowsNextCashFlowDate(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return qlNullableDate(CashFlows::nextCashFlowDate(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate)));
} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlCashFlowsNextCouponRate(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::nextCouponRate(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsNominal(Leg* leg, int includeSettlementDateFlows, int settlDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::nominal(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsNpv1(Leg* leg, InterestRate* yield, int includeSettlementDateFlows, int settlementDate, int npvDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::npv(*arg(leg), *arg(yield), includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsNpv3(Leg* leg, QlYieldTermStructure* discount, double zSpread, int compounding, int frequency, int includeSettlementDateFlows, int settlementDate, int npvDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::npv(*arg(leg), handlePtr(arg(discount)), zSpread, (Compounding)compounding, (Frequency)frequency, includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsNpv(Leg* leg, QlYieldTermStructure* discountCurve, int includeSettlementDateFlows, int settlementDate, int npvDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::npv(*arg(leg), handleRef(arg(discountCurve)), includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlCashFlowsNpvbps(Leg* leg, QlYieldTermStructure* discountCurve, int includeSettlementDateFlows, int settlementDate, int npvDate, double *npv, double *bps, QlError **e) { QlCallScope callbackScope(e);
try {
auto r = CashFlows::npvbps(*arg(leg), handleRef(arg(discountCurve)), includeSettlementDateFlows, Date(settlementDate), Date(npvDate));
*npv = r.first; *bps = r.second;
} catch (std::exception& er) {(void)handleException<int>(e, er);}}
double qlCashFlowsPreviousCashFlowAmount(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::previousCashFlowAmount(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlCashFlowsPreviousCashFlowDate(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return qlNullableDate(CashFlows::previousCashFlowDate(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate)));
} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlCashFlowsPreviousCouponRate(Leg* leg, int includeSettlementDateFlows, int settlementDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::previousCouponRate(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlCashFlowsReferencePeriodEnd(Leg* leg, int includeSettlementDateFlows, int settlDate, QlError **e) { QlCallScope callbackScope(e);
try {return qlNullableDate(CashFlows::referencePeriodEnd(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlDate)));
} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlCashFlowsReferencePeriodStart(Leg* leg, int includeSettlementDateFlows, int settlDate, QlError **e) { QlCallScope callbackScope(e);
try {return qlNullableDate(CashFlows::referencePeriodStart(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlDate)));
} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlCashFlowsYield(Leg* leg, double npv, DayCounter* dayCounter, int compounding, int frequency, int includeSettlementDateFlows, int settlementDate, int npvDate, double accuracy, unsigned maxIterations, double guess, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::yield(*arg(leg), npv, *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate), accuracy, maxIterations, guess);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsYieldValueBasisPoint(Leg* leg, InterestRate* yield, int includeSettlementDateFlows, int settlementDate, int npvDate, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::yieldValueBasisPoint(*arg(leg), *arg(yield), includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsZSpread(Leg* leg, double npv, QlYieldTermStructure* x2, int compounding, int frequency, int includeSettlementDateFlows, int settlementDate, int npvDate, double accuracy, unsigned maxIterations, double guess, QlError **e) { QlCallScope callbackScope(e);
try {return CashFlows::zSpread(*arg(leg), npv, handlePtr(arg(x2)), (Compounding)compounding, (Frequency)frequency, includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate), accuracy, maxIterations, guess);
} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlQuantLibSetCouponPricer(Leg* leg, QlFloatingRateCouponPricer* x1, QlError **e) { QlCallScope callbackScope(e);try {return setCouponPricer(*arg(leg), *arg(x1));} catch (std::exception& er) {(void)handleException<int>(e, er);} }
void qlQuantLibSetCouponPricers(Leg* leg, unsigned x1Len, QlFloatingRateCouponPricer** x1, QlError **e) { QlCallScope callbackScope(e);try {return setCouponPricers(*arg(leg), qlVector(x1, x1Len));} catch (std::exception& er) {(void)handleException<int>(e, er);}}
void qlCouponAccrualStartDates(CouponLeg* o, unsigned *len, int **days, QlError **e) { QlCallScope callbackScope(e);
OutArrayResult<int> result(len, days);
try {
int *out = result.allocate((unsigned)o->size());
for (unsigned i = 0; i < o->size(); ++i)
out[i] = ((*o)[i]->accrualStartDate()).serialNumber();
result.commit();
} catch (std::exception& er) {handleException<int*>(e, er);}}
void qlCouponLegCoupons(CouponLeg* o, unsigned *len, QlCoupon ***out, QlError **e) { QlCallScope callbackScope(e);
OutPtrArrayResult<QlCoupon> result(len, out);
try {
QlCoupon **cs = result.allocate((unsigned)o->size());
for (unsigned i = 0; i < o->size(); ++i)
cs[i] = ret(new QlCoupon((*o)[i]));
result.commit();
} catch (std::exception& er) {handleException<int>(e, er);}}
void qlFreeDividend(QlDividend *o) {del(o);}
void qlFreeCouponLeg(CouponLeg *o) {del(o);}
Leg* qlCouponLegAsLeg(CouponLeg *o) {return alloc(new Leg(o->begin(), o->end()));}
void qlFreeFloatingCouponPricer(QlFloatingRateCouponPricer *p) {del(p);}
QlDividend* qlFixedDividend(double amount, int date, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlDividend(alloc(new FixedDividend(amount, Date(date)))));} catch (std::exception& er) {return handleException<QlDividend*>(e, er);} }
QlDividend* qlFractionalDividend1(double rate, double nominal, int date, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlDividend(alloc(new FractionalDividend(rate, nominal, Date(date)))));
} catch (std::exception& er) {return handleException<QlDividend*>(e, er);}}
QlDividend* qlFractionalDividend(double rate, int date, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlDividend(alloc(new FractionalDividend(rate, Date(date)))));
} catch (std::exception& er) {return handleException<QlDividend*>(e, er);}}
Leg* qlAverageBMALeg(Schedule* schedule, QlBMAIndex* index, unsigned notionalsLen, double* notionals, DayCounter* paymentDayCounter, int paymentAdjustment, unsigned gearingsLen, double* gearings, unsigned spreadsLen, double* spreads, QlError **e) { QlCallScope callbackScope(e);
try {return alloc(new Leg(AverageBMALeg(*arg(schedule), *arg(index)).withNotionals(std::vector<double>(notionals, notionals+notionalsLen)).withPaymentDayCounter(*arg(paymentDayCounter))
.withPaymentAdjustment((BusinessDayConvention)paymentAdjustment).withGearings(std::vector<double>(gearings, gearings+gearingsLen)).withSpreads(std::vector<double>(spreads, spreads+spreadsLen))));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
Leg* qlFixedRateLeg(Schedule* schedule, unsigned NotionalsLen, double* Notionals, unsigned couponRatesLen, InterestRate** couponRates, int paymentAdjustment, DayCounter* firstPeriodDayCounter, Calendar* paymentCalendar, QlError **e) { QlCallScope callbackScope(e);
try {return alloc(new Leg(FixedRateLeg(*arg(schedule)).withNotionals(std::vector<double>(Notionals, Notionals+NotionalsLen)).withCouponRates(qlVector(couponRates, couponRatesLen))
.withPaymentAdjustment((BusinessDayConvention)paymentAdjustment).withFirstPeriodDayCounter(*arg(firstPeriodDayCounter)).withPaymentCalendar(*arg(paymentCalendar))));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
Leg* qlIborLeg(Schedule* schedule, QlIborIndex* index, unsigned notionalsLen, double* notionals, DayCounter* paymentDayCounter, int paymentAdjustment, unsigned fixingDaysLen, unsigned* fixingDays, unsigned gearingsLen, double* gearings, unsigned spreadsLen, double* spreads, unsigned capsLen, double* caps, unsigned floorsLen, double* floors, int inArrears, int zeroPayments,
int paymentLag, Calendar* paymentCalendar, int exCouponPeriodLen, int exCouponPeriodUnit, Calendar* exCouponCalendar, int exCouponConvention, int exCouponEndOfMonth, int fixingConvention, int useIndexedCoupons, QlStubIndexSelection* stub, QlError **e) { QlCallScope callbackScope(e);
if (!ql144Default(e, "iborLegWithOptions", !stub)) return nullptr;
try {return alloc(new Leg(IborLeg(*arg(schedule), *arg(index)).withNotionals(std::vector<double>(notionals, notionals+notionalsLen)).withPaymentDayCounter(*arg(paymentDayCounter))
.withPaymentAdjustment((BusinessDayConvention)paymentAdjustment).withFixingDays(std::vector<unsigned>(fixingDays, fixingDays+fixingDaysLen))
.withGearings(std::vector<double>(gearings, gearings+gearingsLen)).withSpreads(std::vector<double>(spreads, spreads+spreadsLen))
.withCaps(std::vector<double>(caps, caps+capsLen)).withFloors(std::vector<double>(floors, floors+floorsLen)).inArrears(inArrears).withZeroPayments(zeroPayments)
.withPaymentLag(paymentLag).withPaymentCalendar(*arg(paymentCalendar))
.withExCouponPeriod(Period(exCouponPeriodLen, (TimeUnit)exCouponPeriodUnit), *arg(exCouponCalendar), (BusinessDayConvention)exCouponConvention, exCouponEndOfMonth)
.withFixingConvention((BusinessDayConvention)fixingConvention).withIndexedCoupons(qlOptBool(useIndexedCoupons))
#if QL_HEX_VERSION >= 0x01440000
.withStubIndexSelection(qlStubSelection(stub))
#endif
));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
Leg* qlCmsLeg(Schedule* schedule, QlSwapIndex* swapIndex, unsigned notionalsLen, double* notionals, DayCounter* paymentDayCounter, int paymentAdjustment, unsigned fixingDaysLen, unsigned* fixingDays, unsigned gearingsLen, double* gearings, unsigned spreadsLen, double* spreads, unsigned capsLen, double* caps, unsigned floorsLen, double* floors, int inArrears, int zeroPayments,
int exCouponPeriodLen, int exCouponPeriodUnit, Calendar* exCouponCalendar, int exCouponConvention, int exCouponEndOfMonth, int fixingConvention, QlError **e) { QlCallScope callbackScope(e);
try {return alloc(new Leg(CmsLeg(*arg(schedule), *arg(swapIndex)).withNotionals(std::vector<double>(notionals, notionals+notionalsLen)).withPaymentDayCounter(*arg(paymentDayCounter))
.withPaymentAdjustment((BusinessDayConvention)paymentAdjustment).withFixingDays(std::vector<unsigned>(fixingDays, fixingDays+fixingDaysLen))
.withGearings(std::vector<double>(gearings, gearings+gearingsLen)).withSpreads(std::vector<double>(spreads, spreads+spreadsLen))
.withCaps(std::vector<double>(caps, caps+capsLen)).withFloors(std::vector<double>(floors, floors+floorsLen)).inArrears(inArrears).withZeroPayments(zeroPayments)
.withExCouponPeriod(Period(exCouponPeriodLen, (TimeUnit)exCouponPeriodUnit), *arg(exCouponCalendar), (BusinessDayConvention)exCouponConvention, exCouponEndOfMonth)
.withFixingConvention((BusinessDayConvention)fixingConvention)));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
Leg* qlOvernightLeg(Schedule* schedule, QlOvernightIndex* overnightIndex, unsigned notionalsLen, double* notionals, DayCounter* paymentDayCounter, int paymentAdjustment, unsigned gearingsLen, double* gearings, unsigned spreadsLen, double* spreads, QlError **e) { QlCallScope callbackScope(e);
try {return alloc(new Leg(OvernightLeg(*arg(schedule), *arg(overnightIndex)).withNotionals(std::vector<double>(notionals, notionals+notionalsLen)).withPaymentDayCounter(*arg(paymentDayCounter))
.withPaymentAdjustment((BusinessDayConvention)paymentAdjustment).withGearings(std::vector<double>(gearings, gearings+gearingsLen)).withSpreads(std::vector<double>(spreads, spreads+spreadsLen))));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
Leg* qlRangeAccrualLeg(Schedule* schedule, QlIborIndex* index, unsigned notionalsLen, double* notionals, DayCounter* paymentDayCounter, int paymentAdjustment, unsigned fixingDaysLen, unsigned* fixingDays, unsigned gearingsLen, double* gearings, unsigned spreadsLen, double* spreads, unsigned lowerTriggersLen, double* lowerTriggers, unsigned upperTriggersLen, double* upperTriggers, int l, int u, int observationConvention, QlError **e) { QlCallScope callbackScope(e);
try {return alloc(new Leg(RangeAccrualLeg(*arg(schedule), *arg(index)).withNotionals(std::vector<double>(notionals, notionals+notionalsLen)).withPaymentDayCounter(*arg(paymentDayCounter))
.withPaymentAdjustment((BusinessDayConvention)paymentAdjustment).withFixingDays(std::vector<unsigned>(fixingDays, fixingDays+fixingDaysLen))
.withGearings(std::vector<double>(gearings, gearings+gearingsLen)).withSpreads(std::vector<double>(spreads, spreads+spreadsLen)).
withLowerTriggers(std::vector<double>(lowerTriggers, lowerTriggers+lowerTriggersLen)).withUpperTriggers(std::vector<double>(upperTriggers, upperTriggers+upperTriggersLen))
.withObservationTenor(Period(l, (TimeUnit)u)).withObservationConvention((BusinessDayConvention)observationConvention)));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
Leg* qlCPILeg(Schedule* schedule, QlZeroInflationIndex* index, double baseCPI, int obsLagLen, int obsLagUnit, unsigned notionalsLen, double* notionals, unsigned fixedRatesLen, double* fixedRates, DayCounter* paymentDayCounter, int paymentAdjustment, Calendar* paymentCalendar, int observationInterpolation, int subtractInflationNominal, QlError **e) { QlCallScope callbackScope(e);
try {return alloc(new Leg(CPILeg(*arg(schedule), *arg(index), baseCPI, Period(obsLagLen, (TimeUnit)obsLagUnit))
.withNotionals(std::vector<double>(notionals, notionals+notionalsLen)).withFixedRates(std::vector<double>(fixedRates, fixedRates+fixedRatesLen))
.withPaymentDayCounter(*arg(paymentDayCounter)).withPaymentAdjustment((BusinessDayConvention)paymentAdjustment).withPaymentCalendar(*arg(paymentCalendar))
.withObservationInterpolation((CPI::InterpolationType)observationInterpolation).withSubtractInflationNominal(subtractInflationNominal)));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
Leg* qlYoYInflationLeg(Schedule* schedule, Calendar* cal, QlYoYInflationIndex* index, int obsLagLen, int obsLagUnit, int interpolation, unsigned notionalsLen, double* notionals, DayCounter* paymentDayCounter, int paymentAdjustment, unsigned fixingDaysLen, unsigned* fixingDays, unsigned gearingsLen, double* gearings, unsigned spreadsLen, double* spreads, unsigned capsLen, double* caps, unsigned floorsLen, double* floors, QlError **e) { QlCallScope callbackScope(e);
try {return alloc(new Leg(yoyInflationLeg(*arg(schedule), *arg(cal), *arg(index), Period(obsLagLen, (TimeUnit)obsLagUnit), (CPI::InterpolationType)interpolation)
.withNotionals(std::vector<double>(notionals, notionals+notionalsLen)).withPaymentDayCounter(*arg(paymentDayCounter))
.withPaymentAdjustment((BusinessDayConvention)paymentAdjustment).withFixingDays(std::vector<Natural>(fixingDays, fixingDays+fixingDaysLen))
.withGearings(std::vector<double>(gearings, gearings+gearingsLen)).withSpreads(std::vector<double>(spreads, spreads+spreadsLen))
.withCaps(std::vector<double>(caps, caps+capsLen)).withFloors(std::vector<double>(floors, floors+floorsLen))));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
/* YoYInflationCouponPricer -- all 3 concrete pricers share this ctor shape (caplet vol handle,
nominal discount curve handle); mirrors the 3 YoY cap/floor engines in qlInflationVol.cpp. */
QlYoYInflationCouponPricer *qlBlackYoYInflationCouponPricer(QlYoYOptionletVolatilitySurface *vol, QlYieldTermStructure *nominalTs, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlYoYInflationCouponPricer(alloc(new BlackYoYInflationCouponPricer(*arg(vol), *arg(nominalTs)))));
} catch (std::exception& er) {return handleException<QlYoYInflationCouponPricer*>(e, er);}}
QlYoYInflationCouponPricer *qlUnitDisplacedBlackYoYInflationCouponPricer(QlYoYOptionletVolatilitySurface *vol, QlYieldTermStructure *nominalTs, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlYoYInflationCouponPricer(alloc(new UnitDisplacedBlackYoYInflationCouponPricer(*arg(vol), *arg(nominalTs)))));
} catch (std::exception& er) {return handleException<QlYoYInflationCouponPricer*>(e, er);}}
QlYoYInflationCouponPricer *qlBachelierYoYInflationCouponPricer(QlYoYOptionletVolatilitySurface *vol, QlYieldTermStructure *nominalTs, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlYoYInflationCouponPricer(alloc(new BachelierYoYInflationCouponPricer(*arg(vol), *arg(nominalTs)))));
} catch (std::exception& er) {return handleException<QlYoYInflationCouponPricer*>(e, er);}}
void qlFreeYoYInflationCouponPricer(QlYoYInflationCouponPricer *p) {del(p);}
void qlSetYoYInflationCouponPricer(Leg* leg, QlYoYInflationCouponPricer* pricer, QlError **e) { QlCallScope callbackScope(e);
try {return setCouponPricer(*arg(leg), *arg(pricer));} catch (std::exception& er) {(void)handleException<int>(e, er);}}
void qlFreeZeroInflationCashFlow(QlZeroInflationCashFlow *o) {del(o);}
QlIndexedCashFlow *qlZeroInflationCashFlowAsIndexedCashFlow(QlZeroInflationCashFlow *o) {return ret(new QlIndexedCashFlow(*arg(o)));}
QlZeroInflationCashFlow* qlZeroInflationCashFlow(double notional, QlZeroInflationIndex* index, int observationInterpolation, int startDate, int endDate, int obsLagLen, int obsLagUnit, int paymentDate, int growthOnly, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlZeroInflationCashFlow(alloc(new ZeroInflationCashFlow(notional, *arg(index), (CPI::InterpolationType)observationInterpolation,
Date(startDate), Date(endDate), Period(obsLagLen, (TimeUnit)obsLagUnit), Date(paymentDate), growthOnly))));
} catch (std::exception& er) {return handleException<QlZeroInflationCashFlow*>(e, er);}}
void qlFreeCPICashFlow(QlCPICashFlow *o) {del(o);}
QlIndexedCashFlow *qlCPICashFlowAsIndexedCashFlow(QlCPICashFlow *o) {return ret(new QlIndexedCashFlow(*arg(o)));}
QlCPICashFlow* qlCPICashFlow(double notional, QlZeroInflationIndex* index, int baseDate, double baseFixing, int observationDate, int obsLagLen, int obsLagUnit, int interpolation, int paymentDate, int growthOnly, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCPICashFlow(alloc(new CPICashFlow(notional, *arg(index), qlNullableDate(baseDate), baseFixing,
Date(observationDate), Period(obsLagLen, (TimeUnit)obsLagUnit), (CPI::InterpolationType)interpolation, Date(paymentDate), growthOnly))));
} catch (std::exception& er) {return handleException<QlCPICashFlow*>(e, er);}}
void qlFreeEquityCashFlow(QlEquityCashFlow *o) {del(o);}
QlIndexedCashFlow *qlEquityCashFlowAsIndexedCashFlow(QlEquityCashFlow *o) {return ret(new QlIndexedCashFlow(*arg(o)));}
QlEquityCashFlow* qlEquityCashFlow(double notional, QlEquityIndex* index, int baseDate, int fixingDate, int paymentDate, int growthOnly, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlEquityCashFlow(alloc(new EquityCashFlow(notional, *arg(index),
Date(baseDate), Date(fixingDate), Date(paymentDate), growthOnly))));
} catch (std::exception& er) {return handleException<QlEquityCashFlow*>(e, er);}}
void qlEquityCashFlowSetPricer(QlEquityCashFlow* o, QlEquityCashFlowPricer* pricer, QlError **e) { QlCallScope callbackScope(e);
try {(*arg(o))->setPricer(*arg(pricer));
} catch (std::exception& er) {(void)handleException<int>(e, er);}}
void qlFreeEquityCashFlowPricer(QlEquityCashFlowPricer *o) {del(o);}
QlEquityCashFlowPricer* qlEquityQuantoCashFlowPricer(QlYieldTermStructure* quantoCurrencyTermStructure, QlBlackVolTermStructure* equityVolatility, QlBlackVolTermStructure* fxVolatility, QlQuote* correlation, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlEquityCashFlowPricer(alloc(new EquityQuantoCashFlowPricer(*arg(quantoCurrencyTermStructure),
*arg(equityVolatility), *arg(fxVolatility), *arg(correlation)))));
} catch (std::exception& er) {return handleException<QlEquityCashFlowPricer*>(e, er);}}
void qlQuantLibSetEquityCashFlowPricer(Leg* leg, QlEquityCashFlowPricer* pricer, QlError **e) { QlCallScope callbackScope(e);
try {setCouponPricer(*arg(leg), *arg(pricer));
} catch (std::exception& er) {(void)handleException<int>(e, er);}}
CouponLeg* qlLegToCouponLeg(Leg *o, QlError **e) { QlCallScope callbackScope(e);
try {std::unique_ptr<CouponLeg> cl(new CouponLeg()); cl->reserve(o->size());
for (unsigned i = 0; i < o->size(); ++i) {
shared_ptr<Coupon> c = coupon_cast((*o)[i]);
if (c != nullptr) cl->push_back(c);
else QL_FAIL("Cash flow #" << i << " is not a coupon");
}
return alloc(cl.release());
} catch (std::exception& er) {return handleException<CouponLeg*>(e, er);}}
QlFloatingRateCouponPricer *qlBlackIborCouponPricer(QlOptionletVolatilityStructure *vol, int timingAdjustment, QlQuote *correlation, int useIndexedCoupon, QlError **e) { QlCallScope callbackScope(e);
try {Handle<Quote> corr = qlNullableHandleOr(correlation, [] { return shared_ptr<Quote>(alloc(new SimpleQuote(1.0))); });
return ret(new QlFloatingRateCouponPricer(alloc(new BlackIborCouponPricer(*arg(vol), (BlackIborCouponPricer::TimingAdjustment)timingAdjustment, corr, qlOptBool(useIndexedCoupon)))));
} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer *>(e, er);}}
QlFloatingRateCouponPricer *qlBlackIborQuantoCouponPricer(QlBlackVolTermStructure *fxRateBlackVolatility, QlQuote *underlyingFxCorrelation, QlOptionletVolatilityStructure *capletVolatility, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatingRateCouponPricer(alloc(new BlackIborQuantoCouponPricer(*arg(fxRateBlackVolatility), *arg(underlyingFxCorrelation), *arg(capletVolatility)))));
} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer *>(e, er);}}
void qlFreeCmsCouponPricer(QlCmsCouponPricer *p) {del(p);}
QlFloatingRateCouponPricer* qlCmsCouponPricerAsFloatingRateCouponPricer(QlCmsCouponPricer* p) {return ret(new QlFloatingRateCouponPricer(*arg(p)));}
QlCmsCouponPricer* qlAnalyticHaganPricer(QlSwaptionVolatilityStructure* swaptionVol, int modelOfYieldCurve, QlQuote* meanReversion, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCmsCouponPricer(alloc(new AnalyticHaganPricer(*arg(swaptionVol), (GFunctionFactory::YieldCurveModel)modelOfYieldCurve, *arg(meanReversion)))));
} catch (std::exception& er) {return handleException<QlCmsCouponPricer*>(e, er);}}
QlCmsCouponPricer* qlNumericHaganPricer(QlSwaptionVolatilityStructure* swaptionVol, int modelOfYieldCurve, QlQuote* meanReversion, double lowerLimit, double upperLimit, double precision, double hardUpperLimit, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCmsCouponPricer(alloc(new NumericHaganPricer(*arg(swaptionVol), (GFunctionFactory::YieldCurveModel)modelOfYieldCurve, *arg(meanReversion), lowerLimit, upperLimit, precision, hardUpperLimit))));
} catch (std::exception& er) {return handleException<QlCmsCouponPricer*>(e, er);}}
QlCmsCouponPricer* qlLinearTsrPricer(QlSwaptionVolatilityStructure* swaptionVol, QlQuote* meanReversion, QlYieldTermStructure* couponDiscountCurve, int strategy, double param, int haveBounds, double lowerBound, double upperBound, QlError **e) { QlCallScope callbackScope(e);
try {
LinearTsrPricer::Settings settings;
switch (strategy) {
case hasquant::LinearTsrPricerRateBound: haveBounds ? settings.withRateBound(lowerBound, upperBound) : settings.withRateBound(); break;
case hasquant::LinearTsrPricerVegaRatio: haveBounds ? settings.withVegaRatio(param, lowerBound, upperBound) : settings.withVegaRatio(param); break;
case hasquant::LinearTsrPricerPriceThreshold: haveBounds ? settings.withPriceThreshold(param, lowerBound, upperBound) : settings.withPriceThreshold(param); break;
case hasquant::LinearTsrPricerBSStdDevs: haveBounds ? settings.withBSStdDevs(param, lowerBound, upperBound) : settings.withBSStdDevs(param); break;
default: QL_FAIL("unknown LinearTsrPricer strategy " << strategy);
}
return ret(new QlCmsCouponPricer(alloc(new LinearTsrPricer(*arg(swaptionVol), *arg(meanReversion),
qlNullableHandle(couponDiscountCurve), settings))));
} catch (std::exception& er) {return handleException<QlCmsCouponPricer*>(e, er);}}
QlFloatingRateCouponPricer* qlRangeAccrualPricerByBgm(double correlation, QlSmileSection* smilesOnExpiry, QlSmileSection* smilesOnPayment, int withSmile, int byCallSpread, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatingRateCouponPricer(alloc(new RangeAccrualPricerByBgm(correlation, *arg(smilesOnExpiry), *arg(smilesOnPayment), withSmile, byCallSpread))));
} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer*>(e, er);}}
void qlFreeFloatingRateCoupon(QlFloatingRateCoupon *o) {del(o);}
void qlFreeIborCoupon(QlIborCoupon *o) {del(o);}
QlFloatingRateCoupon* qlIborCouponAsFloatingRateCoupon(QlIborCoupon* o) {return ret(new QlFloatingRateCoupon(*arg(o)));}
QlIborCoupon* qlIborCouponExact(int paymentDate, double nominal, int startDate, int endDate, unsigned fixingDays, QlIborIndex *index, double gearing, double spread, int refPeriodStart, int refPeriodEnd, DayCounter *dayCounter, int inArrears, int exCouponDate, int fixingConvention, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlIborCoupon(alloc(new IborCoupon(Date(paymentDate), nominal, Date(startDate), Date(endDate), fixingDays, *arg(index), gearing, spread, qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), *arg(dayCounter), inArrears, qlNullableDate(exCouponDate), (BusinessDayConvention)fixingConvention))));
} catch (std::exception& er) {return handleException<QlIborCoupon*>(e, er);}}
void qlFreeAverageBMACoupon(QlAverageBMACoupon *o) {del(o);}
QlFloatingRateCoupon* qlAverageBMACouponAsFloatingRateCoupon(QlAverageBMACoupon* o) {return ret(new QlFloatingRateCoupon(*arg(o)));}
QlAverageBMACoupon* qlAverageBMACoupon(int paymentDate, double nominal, int startDate, int endDate, QlBMAIndex *index, double gearing, double spread, int refPeriodStart, int refPeriodEnd, DayCounter *dayCounter, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlAverageBMACoupon(alloc(new AverageBMACoupon(Date(paymentDate), nominal, Date(startDate), Date(endDate), *arg(index), gearing, spread, qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), *arg(dayCounter)))));
} catch (std::exception& er) {return handleException<QlAverageBMACoupon*>(e, er);}}
void qlAverageBMACouponFixingDates(QlAverageBMACoupon *o, unsigned *len, int **ds, QlError **e) { QlCallScope callbackScope(e);
OutArrayResult<int> result(len, ds);
try {const std::vector<Date>& d = (*arg(o))->fixingDates(); int *out = result.allocate((unsigned)d.size());
std::transform(d.begin(), d.end(), out, [](const Date& x) {return (int)x.serialNumber();});
result.commit();
} catch (std::exception& er) {(void)handleException<int*>(e, er);}}
void qlAverageBMACouponIndexFixings(QlAverageBMACoupon *o, unsigned *len, double **fs, QlError **e) { QlCallScope callbackScope(e);
try {fillVectorOut([&] {return (*arg(o))->indexFixings();}, len, fs);
} catch (std::exception& er) {(void)handleException<double*>(e, er);}}
QlFloatingRateCoupon* qlCappedFlooredCoupon(QlFloatingRateCoupon *underlying, double cap, double floor, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatingRateCoupon(alloc(new CappedFlooredCoupon(*arg(underlying), cap, floor))));
} catch (std::exception& er) {return handleException<QlFloatingRateCoupon*>(e, er);}}
void qlFreeStrippedCappedFlooredCoupon(QlStrippedCappedFlooredCoupon *o) {del(o);}
QlFloatingRateCoupon* qlStrippedCappedFlooredCouponAsFloatingRateCoupon(QlStrippedCappedFlooredCoupon* o) {return ret(new QlFloatingRateCoupon(*arg(o)));}
QlStrippedCappedFlooredCoupon* qlStrippedCappedFlooredCoupon(QlFloatingRateCoupon *underlying, double cap, double floor, QlError **e) { QlCallScope callbackScope(e);
try {auto capped = ext::make_shared<CappedFlooredCoupon>(*arg(underlying), cap, floor);
return ret(new QlStrippedCappedFlooredCoupon(alloc(new StrippedCappedFlooredCoupon(capped))));
} catch (std::exception& er) {return handleException<QlStrippedCappedFlooredCoupon*>(e, er);}}
double qlStrippedCappedFlooredCouponCap(QlStrippedCappedFlooredCoupon *o) {return (*arg(o))->cap();}
double qlStrippedCappedFlooredCouponFloor(QlStrippedCappedFlooredCoupon *o) {return (*arg(o))->floor();}
double qlStrippedCappedFlooredCouponEffectiveCap(QlStrippedCappedFlooredCoupon *o) {return (*arg(o))->effectiveCap();}
double qlStrippedCappedFlooredCouponEffectiveFloor(QlStrippedCappedFlooredCoupon *o) {return (*arg(o))->effectiveFloor();}
int qlStrippedCappedFlooredCouponIsCap(QlStrippedCappedFlooredCoupon *o) {return (*arg(o))->isCap();}
int qlStrippedCappedFlooredCouponIsFloor(QlStrippedCappedFlooredCoupon *o) {return (*arg(o))->isFloor();}
int qlStrippedCappedFlooredCouponIsCollar(QlStrippedCappedFlooredCoupon *o) {return (*arg(o))->isCollar();}
QlFloatingRateCoupon* qlCappedFlooredIborCoupon(int paymentDate, double nominal, int startDate, int endDate, unsigned fixingDays, QlIborIndex *index, double gearing, double spread, double cap, double floor, int refPeriodStart, int refPeriodEnd, DayCounter *dayCounter, int inArrears, int exCouponDate, int fixingConvention, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatingRateCoupon(alloc(new CappedFlooredIborCoupon(Date(paymentDate), nominal, Date(startDate), Date(endDate), fixingDays, *arg(index), gearing, spread, cap, floor, qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), *arg(dayCounter), inArrears, qlNullableDate(exCouponDate), (BusinessDayConvention)fixingConvention))));
} catch (std::exception& er) {return handleException<QlFloatingRateCoupon*>(e, er);}}
QlDigitalCoupon* qlDigitalIborCoupon(QlIborCoupon *underlying, double callStrike, int callPosition, int callATM, double callPayoff, double putStrike, int putPosition, int putATM, double putPayoff, QlDigitalReplication *replication, int nakedOption, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlDigitalCoupon(alloc(new DigitalIborCoupon(*arg(underlying), callStrike, (Position::Type)callPosition, callATM, callPayoff, putStrike, (Position::Type)putPosition, putATM, putPayoff, replication ? *arg(replication) : shared_ptr<DigitalReplication>(), nakedOption))));
} catch (std::exception& er) {return handleException<QlDigitalCoupon*>(e, er);}}
void qlFreeDigitalCoupon(QlDigitalCoupon* o) {del(o);}
QlFloatingRateCoupon* qlDigitalCouponAsFloatingRateCoupon(QlDigitalCoupon* o) {return ret(new QlFloatingRateCoupon(*arg(o)));}
QlDigitalCoupon* qlDigitalCoupon(QlFloatingRateCoupon *underlying, double callStrike, int callPosition, int callATM, double callPayoff, double putStrike, int putPosition, int putATM, double putPayoff, QlDigitalReplication *replication, int nakedOption, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlDigitalCoupon(alloc(new DigitalCoupon(*arg(underlying), callStrike, (Position::Type)callPosition, callATM, callPayoff, putStrike, (Position::Type)putPosition, putATM, putPayoff, replication ? *arg(replication) : shared_ptr<DigitalReplication>(), nakedOption))));
} catch (std::exception& er) {return handleException<QlDigitalCoupon*>(e, er);}}
double qlDigitalCouponCallOptionRate(QlDigitalCoupon* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->callOptionRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlDigitalCouponPutOptionRate(QlDigitalCoupon* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->putOptionRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeMultipleResetsCoupon(QlMultipleResetsCoupon *o) {del(o);}
QlFloatingRateCoupon* qlMultipleResetsCouponAsFloatingRateCoupon(QlMultipleResetsCoupon* o) {return ret(new QlFloatingRateCoupon(*arg(o)));}
QlMultipleResetsCoupon* qlMultipleResetsCoupon(int paymentDate, double nominal, Schedule *schedule, unsigned fixingDays, QlIborIndex *index, double gearing, double couponSpread, double rateSpread, int refPeriodStart, int refPeriodEnd, DayCounter *dayCounter, int exCouponDate, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlMultipleResetsCoupon(alloc(new MultipleResetsCoupon(Date(paymentDate), nominal, *arg(schedule), fixingDays, *arg(index), gearing, couponSpread, rateSpread, qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), *arg(dayCounter), qlNullableDate(exCouponDate)))));
} catch (std::exception& er) {return handleException<QlMultipleResetsCoupon*>(e, er);}}
void qlMultipleResetsCouponFixingDates(QlMultipleResetsCoupon *o, unsigned *len, int **dates, QlError **e) { QlCallScope callbackScope(e);
OutArrayResult<int> result(len, dates);
try {const std::vector<Date>& ds = (*arg(o))->fixingDates();
int *out = result.allocate((unsigned)ds.size());
for (unsigned i = 0; i < ds.size(); ++i) out[i] = ds[i].serialNumber();
result.commit();
} catch (std::exception& er) {(void)handleException<int*>(e, er);}}
void qlFreeRangeAccrualFloatersCoupon(QlRangeAccrualFloatersCoupon* o) {del(o);}
QlFloatingRateCoupon* qlRangeAccrualFloatersCouponAsFloatingRateCoupon(QlRangeAccrualFloatersCoupon* o) {return ret(new QlFloatingRateCoupon(*arg(o)));}
QlRangeAccrualFloatersCoupon* qlRangeAccrualFloatersCoupon(int paymentDate, double nominal, QlIborIndex* index, int startDate, int endDate, unsigned fixingDays, DayCounter* dayCounter, double gearing, double spread, int refStart, int refEnd, Schedule* observations, double lower, double upper, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlRangeAccrualFloatersCoupon(alloc(new RangeAccrualFloatersCoupon(Date(paymentDate), nominal, *arg(index), Date(startDate), Date(endDate), fixingDays, *arg(dayCounter), gearing, spread, qlNullableDate(refStart), qlNullableDate(refEnd), *arg(observations), lower, upper))));
} catch (std::exception& er) {return handleException<QlRangeAccrualFloatersCoupon*>(e, er);}}
double qlRangeAccrualFloatersCouponPriceWithoutOptionality(QlRangeAccrualFloatersCoupon* o, QlYieldTermStructure* curve, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->priceWithoutOptionality(*arg(curve));} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeYoYInflationCoupon(QlYoYInflationCoupon* o) {del(o);}
QlCoupon* qlYoYInflationCouponAsCoupon(QlYoYInflationCoupon* o) {return ret(new QlCoupon(*arg(o)));}
QlYoYInflationCoupon* qlYoYInflationCoupon(int paymentDate, double nominal, int startDate, int endDate, unsigned fixingDays, QlYoYInflationIndex* index, int lagLen, int lagUnit, int interpolation, DayCounter* dayCounter, double gearing, double spread, int refStart, int refEnd, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlYoYInflationCoupon(alloc(new YoYInflationCoupon(Date(paymentDate), nominal, Date(startDate), Date(endDate), fixingDays, *arg(index), Period(lagLen, (TimeUnit)lagUnit), (CPI::InterpolationType)interpolation, *arg(dayCounter), gearing, spread, qlNullableDate(refStart), qlNullableDate(refEnd)))));
} catch (std::exception& er) {return handleException<QlYoYInflationCoupon*>(e, er);}}
double qlYoYInflationCouponAdjustedFixing(QlYoYInflationCoupon* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->adjustedFixing();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlFloatingRateCouponPricer* qlAveragingMultipleResetsPricer(QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlFloatingRateCouponPricer(alloc(new AveragingMultipleResetsPricer())));} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer*>(e, er);}}
QlFloatingRateCouponPricer* qlCompoundingMultipleResetsPricer(QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlFloatingRateCouponPricer(alloc(new CompoundingMultipleResetsPricer())));} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer*>(e, er);}}
void qlFreeOvernightIndexedCoupon(QlOvernightIndexedCoupon *o) {del(o);}
QlFloatingRateCoupon* qlOvernightIndexedCouponAsFloatingRateCoupon(QlOvernightIndexedCoupon* o) {return ret(new QlFloatingRateCoupon(*arg(o)));}
QlOvernightIndexedCoupon* qlOvernightIndexedCoupon(int paymentDate, double nominal, int startDate, int endDate, QlOvernightIndex *index, double gearing, double spread, int refPeriodStart, int refPeriodEnd, DayCounter *dayCounter, int telescopic, int averaging, unsigned lookback, unsigned lockout, int observationShift, int compoundSpread, int rateStart, int rateEnd, int exCouponDate, int rounding, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlOvernightIndexedCoupon(alloc(new OvernightIndexedCoupon(Date(paymentDate), nominal, Date(startDate), Date(endDate), *arg(index), gearing, spread, qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), *arg(dayCounter), telescopic, (RateAveraging::Type)averaging, lookback, lockout, observationShift, compoundSpread, qlNullableDate(rateStart), qlNullableDate(rateEnd), qlNullableDate(exCouponDate), rounding == Null<Integer>() ? optional<Integer>() : optional<Integer>(rounding)))));
} catch (std::exception& er) {return handleException<QlOvernightIndexedCoupon*>(e, er);}}
QlFloatingRateCoupon* qlCappedFlooredOvernightIndexedCoupon(QlOvernightIndexedCoupon *underlying, double cap, double floor, int naked, int daily, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatingRateCoupon(alloc(new CappedFlooredOvernightIndexedCoupon(*arg(underlying), cap, floor, naked, daily))));
} catch (std::exception& er) {return handleException<QlFloatingRateCoupon*>(e, er);}}
void qlOvernightIndexedCouponFixingDates(QlOvernightIndexedCoupon *o, unsigned *len, int **dates, QlError **e) { QlCallScope callbackScope(e);
OutArrayResult<int> result(len, dates);
try {const std::vector<Date>& ds = (*arg(o))->fixingDates();
int *out = result.allocate((unsigned)ds.size());
for (unsigned i = 0; i < ds.size(); ++i) out[i] = ds[i].serialNumber();
result.commit();
} catch (std::exception& er) {(void)handleException<int*>(e, er);}}
void qlOvernightIndexedCouponIndexFixings(QlOvernightIndexedCoupon *o, unsigned *len, double **fixings, QlError **e) { QlCallScope callbackScope(e);
try {fillVectorOut([&] {return (*arg(o))->indexFixings();}, len, fixings);
} catch (std::exception& er) {(void)handleException<double*>(e, er);}}
QlFloatingRateCouponPricer* qlCompoundingOvernightIndexedCouponPricer(QlOptionletVolatilityStructure *vol, int effective, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlFloatingRateCouponPricer(alloc(new CompoundingOvernightIndexedCouponPricer(qlNullableHandle(vol), effective))));} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer*>(e, er);}}
QlFloatingRateCouponPricer* qlArithmeticAveragedOvernightIndexedCouponPricer(double mr, double volatility, int byApprox, QlOptionletVolatilityStructure *vol, int effective, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlFloatingRateCouponPricer(alloc(new ArithmeticAveragedOvernightIndexedCouponPricer(mr, volatility, byApprox, qlNullableHandle(vol), effective))));} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer*>(e, er);}}
QlFloatingRateCouponPricer* qlBlackCompoundingOvernightIndexedCouponPricer(QlOptionletVolatilityStructure *vol, int effective, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlFloatingRateCouponPricer(alloc(new BlackCompoundingOvernightIndexedCouponPricer(qlNullableHandle(vol), effective))));} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer*>(e, er);}}
QlFloatingRateCouponPricer* qlBlackAveragingOvernightIndexedCouponPricer(QlOptionletVolatilityStructure *vol, int effective, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlFloatingRateCouponPricer(alloc(new BlackAveragingOvernightIndexedCouponPricer(qlNullableHandle(vol), effective))));} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer*>(e, er);}}
void qlFreeCPICoupon(QlCPICoupon *o) {del(o);}
QlCPICoupon* qlCPICoupon(double baseCPI, int paymentDate, double nominal, int startDate, int endDate, QlZeroInflationIndex *index, int lagLen, int lagUnit, int interpolation, DayCounter *dc, double fixedRate, int refStart, int refEnd, int exCoupon, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlCPICoupon(alloc(new CPICoupon(baseCPI, Date(paymentDate), nominal, Date(startDate), Date(endDate), *arg(index), Period(lagLen, (TimeUnit)lagUnit), (CPI::InterpolationType)interpolation, *arg(dc), fixedRate, qlNullableDate(refStart), qlNullableDate(refEnd), qlNullableDate(exCoupon)))));} catch (std::exception& er) {return handleException<QlCPICoupon*>(e, er);}}
QlCPICoupon* qlCPICouponFromBaseDate(int baseDate, int paymentDate, double nominal, int startDate, int endDate, QlZeroInflationIndex *index, int lagLen, int lagUnit, int interpolation, DayCounter *dc, double fixedRate, int refStart, int refEnd, int exCoupon, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlCPICoupon(alloc(new CPICoupon(Date(baseDate), Date(paymentDate), nominal, Date(startDate), Date(endDate), *arg(index), Period(lagLen, (TimeUnit)lagUnit), (CPI::InterpolationType)interpolation, *arg(dc), fixedRate, qlNullableDate(refStart), qlNullableDate(refEnd), qlNullableDate(exCoupon)))));} catch (std::exception& er) {return handleException<QlCPICoupon*>(e, er);}}
QlCPICoupon* qlCPICouponWithBaseDate(double baseCPI, int baseDate, int paymentDate, double nominal, int startDate, int endDate, QlZeroInflationIndex *index, int lagLen, int lagUnit, int interpolation, DayCounter *dc, double fixedRate, int refStart, int refEnd, int exCoupon, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlCPICoupon(alloc(new CPICoupon(baseCPI, Date(baseDate), Date(paymentDate), nominal, Date(startDate), Date(endDate), *arg(index), Period(lagLen, (TimeUnit)lagUnit), (CPI::InterpolationType)interpolation, *arg(dc), fixedRate, qlNullableDate(refStart), qlNullableDate(refEnd), qlNullableDate(exCoupon)))));} catch (std::exception& er) {return handleException<QlCPICoupon*>(e, er);}}
void qlFreeCPICouponPricer(QlCPICouponPricer *o) {del(o);}
QlCPICouponPricer* qlCPICouponPricer(QlYieldTermStructure *nominal, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlCPICouponPricer(alloc(new CPICouponPricer(qlNullableHandle(nominal)))));} catch (std::exception& er) {return handleException<QlCPICouponPricer*>(e, er);}}
QlCPICouponPricer* qlCPICouponPricerWithVol(QlCPIVolatilitySurface *vol, QlYieldTermStructure *nominal, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlCPICouponPricer(alloc(new CPICouponPricer(*arg(vol), qlNullableHandle(nominal)))));} catch (std::exception& er) {return handleException<QlCPICouponPricer*>(e, er);}}
QlCoupon* qlCPICouponAsCoupon(QlCPICoupon* o) {return ret(new QlCoupon(*arg(o)));}
void qlCPICouponSetPricer(QlCPICoupon *coupon, QlCPICouponPricer *pricer, QlError **e) { QlCallScope callbackScope(e);try {(*arg(coupon))->setPricer(*arg(pricer));} catch (std::exception& er) {(void)handleException<int>(e, er);}}
QlCashFlow* qlRedemption(double amount, int date, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlCashFlow(alloc(new Redemption(amount, Date(date)))));} catch (std::exception& er) {return handleException<QlCashFlow*>(e, er);}}
QlCashFlow* qlAmortizingPayment(double amount, int date, QlError **e) { QlCallScope callbackScope(e);try {return ret(new QlCashFlow(alloc(new AmortizingPayment(amount, Date(date)))));} catch (std::exception& er) {return handleException<QlCashFlow*>(e, er);}}
QlCoupon* qlFloatingRateCouponAsCoupon(QlFloatingRateCoupon* o) {return ret(new QlCoupon(*arg(o)));}
void qlFloatingRateCouponSetPricer(QlFloatingRateCoupon* o, QlFloatingRateCouponPricer* pricer, QlError **e) { QlCallScope callbackScope(e);
try {(*arg(o))->setPricer(*arg(pricer));
} catch (std::exception& er) {(void)handleException<int>(e, er);}}
double qlFloatingRateCouponPrice(QlFloatingRateCoupon* o, QlYieldTermStructure* discountingCurve, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->price(qlNullableHandle(discountingCurve));} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFloatingRateCouponConvexityAdjustment(QlFloatingRateCoupon* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->convexityAdjustment();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCPICouponIndexRatio(QlCPICoupon* o, int d, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->indexRatio(Date(d));} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFloatingRateCouponPricerSwapletRate(QlFloatingRateCouponPricer* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->swapletRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFloatingRateCouponPricerSwapletPrice(QlFloatingRateCouponPricer* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->swapletPrice();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFloatingRateCouponPricerCapletPrice(QlFloatingRateCouponPricer* o, double effectiveCap, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->capletPrice(effectiveCap);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFloatingRateCouponPricerCapletRate(QlFloatingRateCouponPricer* o, double effectiveCap, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->capletRate(effectiveCap);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFloatingRateCouponPricerFloorletPrice(QlFloatingRateCouponPricer* o, double effectiveFloor, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->floorletPrice(effectiveFloor);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFloatingRateCouponPricerFloorletRate(QlFloatingRateCouponPricer* o, double effectiveFloor, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->floorletRate(effectiveFloor);} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeCmsCoupon(QlCmsCoupon *o) {del(o);}
QlFloatingRateCoupon* qlCmsCouponAsFloatingRateCoupon(QlCmsCoupon* o) {return ret(new QlFloatingRateCoupon(*arg(o)));}
QlCmsCoupon* qlCmsCoupon(int paymentDate, double nominal, int startDate, int endDate, unsigned fixingDays, QlSwapIndex* index, double gearing, double spread, int refPeriodStart, int refPeriodEnd, DayCounter* dayCounter, int inArrears, int exCouponDate, int fixingConvention, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCmsCoupon(alloc(new CmsCoupon(Date(paymentDate), nominal, Date(startDate), Date(endDate), fixingDays,
*arg(index), gearing, spread, qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), *arg(dayCounter), inArrears,
qlNullableDate(exCouponDate), (BusinessDayConvention)fixingConvention))));
} catch (std::exception& er) {return handleException<QlCmsCoupon*>(e, er);}}
QlFloatingRateCoupon* qlCmsSpreadCoupon(int paymentDate, double nominal, int startDate, int endDate, unsigned fixingDays, QlSwapSpreadIndex* index, double gearing, double spread, int refPeriodStart, int refPeriodEnd, DayCounter* dayCounter, int inArrears, int exCouponDate, int fixingConvention, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatingRateCoupon(alloc(new CmsSpreadCoupon(Date(paymentDate), nominal, Date(startDate), Date(endDate), fixingDays,
*arg(index), gearing, spread, qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), *arg(dayCounter), inArrears, qlNullableDate(exCouponDate), (BusinessDayConvention)fixingConvention))));
} catch (std::exception& er) {return handleException<QlFloatingRateCoupon*>(e, er);}}
QlFloatingRateCoupon* qlCappedFlooredCmsSpreadCoupon(int paymentDate, double nominal, int startDate, int endDate, unsigned fixingDays, QlSwapSpreadIndex* index, double gearing, double spread, double cap, double floor, int refPeriodStart, int refPeriodEnd, DayCounter* dayCounter, int inArrears, int exCouponDate, int fixingConvention, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatingRateCoupon(alloc(new CappedFlooredCmsSpreadCoupon(Date(paymentDate), nominal, Date(startDate), Date(endDate), fixingDays,
*arg(index), gearing, spread, cap, floor, qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), *arg(dayCounter), inArrears, qlNullableDate(exCouponDate), (BusinessDayConvention)fixingConvention))));
} catch (std::exception& er) {return handleException<QlFloatingRateCoupon*>(e, er);}}
QlFloatingRateCouponPricer* qlLognormalCmsSpreadPricer(QlCmsCouponPricer* cmsPricer, QlQuote* correlation, QlYieldTermStructure* couponDiscountCurve, unsigned integrationPoints, int haveVolatilityType, int volatilityType, double shift1, double shift2, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatingRateCouponPricer(alloc(new LognormalCmsSpreadPricer(*arg(cmsPricer), *arg(correlation), qlNullableHandle(couponDiscountCurve), integrationPoints,
haveVolatilityType ? optional<VolatilityType>((VolatilityType)volatilityType) : nullopt, shift1, shift2))));
} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer*>(e, er);}}
Leg* qlCmsSpreadLeg(Schedule* schedule, QlSwapSpreadIndex* swapSpreadIndex, unsigned notionalsLen, double* notionals, DayCounter* paymentDayCounter, int paymentAdjustment, unsigned fixingDaysLen, unsigned* fixingDays, unsigned gearingsLen, double* gearings, unsigned spreadsLen, double* spreads, unsigned capsLen, double* caps, unsigned floorsLen, double* floors, int inArrears, int zeroPayments, QlError **e) { QlCallScope callbackScope(e);
try {return alloc(new Leg(CmsSpreadLeg(*arg(schedule), *arg(swapSpreadIndex)).withNotionals(std::vector<double>(notionals, notionals+notionalsLen)).withPaymentDayCounter(*arg(paymentDayCounter))
.withPaymentAdjustment((BusinessDayConvention)paymentAdjustment).withFixingDays(std::vector<unsigned>(fixingDays, fixingDays+fixingDaysLen))
.withGearings(std::vector<double>(gearings, gearings+gearingsLen)).withSpreads(std::vector<double>(spreads, spreads+spreadsLen))
.withCaps(std::vector<double>(caps, caps+capsLen)).withFloors(std::vector<double>(floors, floors+floorsLen)).inArrears(inArrears).withZeroPayments(zeroPayments)));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
void qlFreeDigitalCmsSpreadCoupon(QlDigitalCmsSpreadCoupon *o) {del(o);}
QlDigitalCoupon* qlDigitalCmsSpreadCouponAsDigitalCoupon(QlDigitalCmsSpreadCoupon* o) {return ret(new QlDigitalCoupon(*arg(o)));}
QlDigitalCmsSpreadCoupon* qlDigitalCmsSpreadCoupon(int paymentDate, double nominal, int startDate, int endDate, unsigned fixingDays, QlSwapSpreadIndex* index, double gearing, double spread, int refPeriodStart, int refPeriodEnd, DayCounter* dayCounter, int inArrears, int exCouponDate, int fixingConvention, double callStrike, int callPosition, int callATM, double callPayoff, double putStrike, int putPosition, int putATM, double putPayoff, QlDigitalReplication* replication, int nakedOption, QlError **e) { QlCallScope callbackScope(e);
try {auto underlying = ext::make_shared<CmsSpreadCoupon>(Date(paymentDate), nominal, Date(startDate), Date(endDate), fixingDays,
*arg(index), gearing, spread, qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), *arg(dayCounter), inArrears, qlNullableDate(exCouponDate), (BusinessDayConvention)fixingConvention);
return ret(new QlDigitalCmsSpreadCoupon(alloc(new DigitalCmsSpreadCoupon(underlying, callStrike, (Position::Type)callPosition, callATM,
callPayoff, putStrike, (Position::Type)putPosition, putATM, putPayoff, replication ? *arg(replication) : shared_ptr<DigitalReplication>(), nakedOption))));
} catch (std::exception& er) {return handleException<QlDigitalCmsSpreadCoupon*>(e, er);}}
Leg* qlDigitalCmsSpreadLeg(Schedule* schedule, QlSwapSpreadIndex* index, unsigned notionalsLen, double* notionals, DayCounter* paymentDayCounter, int paymentAdjustment, unsigned fixingDaysLen, unsigned* fixingDays, unsigned gearingsLen, double* gearings, unsigned spreadsLen, double* spreads, int inArrears, unsigned callStrikesLen, double* callStrikes, int callPosition, int callATM, unsigned callPayoffsLen, double* callPayoffs, unsigned putStrikesLen, double* putStrikes, int putPosition, int putATM, unsigned putPayoffsLen, double* putPayoffs, QlDigitalReplication* replication, int nakedOption, QlError **e) { QlCallScope callbackScope(e);
try {DigitalCmsSpreadLeg builder(*arg(schedule), *arg(index));
builder.withNotionals(std::vector<Real>(notionals, notionals + notionalsLen))
.withPaymentDayCounter(*arg(paymentDayCounter)).withPaymentAdjustment((BusinessDayConvention)paymentAdjustment)
.withFixingDays(std::vector<Natural>(fixingDays, fixingDays + fixingDaysLen))
.withGearings(std::vector<Real>(gearings, gearings + gearingsLen)).withSpreads(std::vector<Spread>(spreads, spreads + spreadsLen))
.inArrears(inArrears).withCallStrikes(std::vector<Rate>(callStrikes, callStrikes + callStrikesLen))
.withLongCallOption((Position::Type)callPosition).withCallATM(callATM)
.withCallPayoffs(std::vector<Rate>(callPayoffs, callPayoffs + callPayoffsLen))
.withPutStrikes(std::vector<Rate>(putStrikes, putStrikes + putStrikesLen)).withLongPutOption((Position::Type)putPosition)
.withPutATM(putATM).withPutPayoffs(std::vector<Rate>(putPayoffs, putPayoffs + putPayoffsLen))
.withReplication(replication ? *arg(replication) : shared_ptr<DigitalReplication>()).withNakedOption(nakedOption);
return ret(new Leg(builder));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
void qlFreeSwapSpreadIndex(QlSwapSpreadIndex *o) {del(o);}
QlInterestRateIndex* qlSwapSpreadIndexAsInterestRateIndex(QlSwapSpreadIndex* o) {return ret(new QlInterestRateIndex(*arg(o)));}
QlSwapSpreadIndex* qlSwapSpreadIndex(const char* familyName, QlSwapIndex* swapIndex1, QlSwapIndex* swapIndex2, double gearing1, double gearing2, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlSwapSpreadIndex(alloc(new SwapSpreadIndex(familyName, *arg(swapIndex1), *arg(swapIndex2), gearing1, gearing2))));
} catch (std::exception& er) {return handleException<QlSwapSpreadIndex*>(e, er);}}
QlFloatingRateCoupon* qlCappedFlooredCmsCoupon(int paymentDate, double nominal, int startDate, int endDate, unsigned fixingDays, QlSwapIndex* index, double gearing, double spread, double cap, double floor, int refPeriodStart, int refPeriodEnd, DayCounter* dayCounter, int inArrears, int exCouponDate, int fixingConvention, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatingRateCoupon(alloc(new CappedFlooredCmsCoupon(Date(paymentDate), nominal, Date(startDate), Date(endDate), fixingDays,
*arg(index), gearing, spread, cap, floor, qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), *arg(dayCounter), inArrears,
qlNullableDate(exCouponDate), (BusinessDayConvention)fixingConvention))));
} catch (std::exception& er) {return handleException<QlFloatingRateCoupon*>(e, er);}}
void qlFreeDigitalReplication(QlDigitalReplication *o) {del(o);}
QlDigitalReplication* qlDigitalReplication(int type, double gap, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlDigitalReplication(alloc(new DigitalReplication(qlReplicationType(type), gap))));
} catch (std::exception& er) {return handleException<QlDigitalReplication*>(e, er);}}
int qlDigitalReplicationType(QlDigitalReplication* o) {return qlReplicationTypeOut((*arg(o))->replicationType());}
double qlDigitalReplicationGap(QlDigitalReplication* o) {return (*arg(o))->gap();}
void qlFreeDigitalCmsCoupon(QlDigitalCmsCoupon *o) {del(o);}
QlDigitalCoupon* qlDigitalCmsCouponAsDigitalCoupon(QlDigitalCmsCoupon* o) {return ret(new QlDigitalCoupon(*arg(o)));}
QlDigitalCmsCoupon* qlDigitalCmsCoupon(QlCmsCoupon* underlying, double callStrike, int callPosition, int callATM, double callPayoff, double putStrike, int putPosition, int putATM, double putPayoff, QlDigitalReplication* replication, int nakedOption, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlDigitalCmsCoupon(alloc(new DigitalCmsCoupon(*arg(underlying), callStrike, (Position::Type)callPosition, callATM,
callPayoff, putStrike, (Position::Type)putPosition, putATM, putPayoff, replication ? *arg(replication) : shared_ptr<DigitalReplication>(), nakedOption))));
} catch (std::exception& er) {return handleException<QlDigitalCmsCoupon*>(e, er);}}
Leg* qlDigitalCmsLeg(Schedule* schedule, QlSwapIndex* index, unsigned notionalsLen, double* notionals, DayCounter* paymentDayCounter, int paymentAdjustment, unsigned fixingDaysLen, unsigned* fixingDays, unsigned gearingsLen, double* gearings, unsigned spreadsLen, double* spreads, int inArrears, unsigned callStrikesLen, double* callStrikes, int callPosition, int callATM, unsigned callPayoffsLen, double* callPayoffs, unsigned putStrikesLen, double* putStrikes, int putPosition, int putATM, unsigned putPayoffsLen, double* putPayoffs, QlDigitalReplication* replication, int nakedOption, QlError **e) { QlCallScope callbackScope(e);
try {DigitalCmsLeg builder(*arg(schedule), *arg(index));
builder.withNotionals(std::vector<Real>(notionals, notionals + notionalsLen))
.withPaymentDayCounter(*arg(paymentDayCounter)).withPaymentAdjustment((BusinessDayConvention)paymentAdjustment)
.withFixingDays(std::vector<Natural>(fixingDays, fixingDays + fixingDaysLen))
.withGearings(std::vector<Real>(gearings, gearings + gearingsLen)).withSpreads(std::vector<Spread>(spreads, spreads + spreadsLen))
.inArrears(inArrears).withCallStrikes(std::vector<Rate>(callStrikes, callStrikes + callStrikesLen))
.withLongCallOption((Position::Type)callPosition).withCallATM(callATM)
.withCallPayoffs(std::vector<Rate>(callPayoffs, callPayoffs + callPayoffsLen))
.withPutStrikes(std::vector<Rate>(putStrikes, putStrikes + putStrikesLen)).withLongPutOption((Position::Type)putPosition)
.withPutATM(putATM).withPutPayoffs(std::vector<Rate>(putPayoffs, putPayoffs + putPayoffsLen))
.withReplication(replication ? *arg(replication) : shared_ptr<DigitalReplication>()).withNakedOption(nakedOption);
return ret(new Leg(builder));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
Leg* qlDigitalIborLeg(Schedule* schedule, QlIborIndex* index, unsigned notionalsLen, double* notionals, DayCounter* paymentDayCounter, int paymentAdjustment, unsigned fixingDaysLen, unsigned* fixingDays, unsigned gearingsLen, double* gearings, unsigned spreadsLen, double* spreads, int inArrears, unsigned callStrikesLen, double* callStrikes, int callPosition, int callATM, unsigned callPayoffsLen, double* callPayoffs, unsigned putStrikesLen, double* putStrikes, int putPosition, int putATM, unsigned putPayoffsLen, double* putPayoffs, QlDigitalReplication* replication, int nakedOption, QlError **e) { QlCallScope callbackScope(e);
try {DigitalIborLeg builder(*arg(schedule), *arg(index));
builder.withNotionals(std::vector<Real>(notionals, notionals + notionalsLen)).withPaymentDayCounter(*arg(paymentDayCounter)).withPaymentAdjustment((BusinessDayConvention)paymentAdjustment)
.withFixingDays(std::vector<Natural>(fixingDays, fixingDays + fixingDaysLen)).withGearings(std::vector<Real>(gearings, gearings + gearingsLen)).withSpreads(std::vector<Spread>(spreads, spreads + spreadsLen)).inArrears(inArrears)
.withCallStrikes(std::vector<Rate>(callStrikes, callStrikes + callStrikesLen)).withLongCallOption((Position::Type)callPosition).withCallATM(callATM).withCallPayoffs(std::vector<Rate>(callPayoffs, callPayoffs + callPayoffsLen))
.withPutStrikes(std::vector<Rate>(putStrikes, putStrikes + putStrikesLen)).withLongPutOption((Position::Type)putPosition).withPutATM(putATM).withPutPayoffs(std::vector<Rate>(putPayoffs, putPayoffs + putPayoffsLen)).withReplication(replication ? *arg(replication) : shared_ptr<DigitalReplication>()).withNakedOption(nakedOption);
return ret(new Leg(builder));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
Leg* qlMultipleResetsLeg(Schedule* schedule, QlIborIndex* index, unsigned resetsPerCoupon, unsigned notionalsLen, double* notionals, DayCounter* dc, int adjustment, Calendar* calendar, int lag, unsigned fixingDaysLen, unsigned* fixingDays, unsigned gearingsLen, double* gearings, unsigned couponSpreadsLen, double* couponSpreads, unsigned rateSpreadsLen, double* rateSpreads, int exLen, int exUnit, Calendar* exCalendar, int exConvention, int exEom, int averaging, QlError **e) { QlCallScope callbackScope(e);
try {MultipleResetsLeg builder(*arg(schedule), *arg(index), resetsPerCoupon);
builder.withNotionals(std::vector<Real>(notionals, notionals + notionalsLen)).withPaymentDayCounter(*arg(dc)).withPaymentAdjustment((BusinessDayConvention)adjustment).withPaymentCalendar(*arg(calendar)).withPaymentLag(lag)
.withFixingDays(std::vector<Natural>(fixingDays, fixingDays + fixingDaysLen)).withGearings(std::vector<Real>(gearings, gearings + gearingsLen)).withCouponSpreads(std::vector<Spread>(couponSpreads, couponSpreads + couponSpreadsLen)).withRateSpreads(std::vector<Spread>(rateSpreads, rateSpreads + rateSpreadsLen))
.withExCouponPeriod(Period(exLen, (TimeUnit)exUnit), *arg(exCalendar), (BusinessDayConvention)exConvention, exEom).withAveragingMethod((RateAveraging::Type)averaging);
return ret(new Leg(builder));
} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
void qlFreeVarianceSwap(QlVarianceSwap *o) {del(o);}
QlInstrument* qlVarianceSwapAsInstrument(QlVarianceSwap *o) {return ret(new QlInstrument(*arg(o)));}
QlVarianceSwap* qlVarianceSwap(int position, double strike, double notional, int startDate, int maturityDate, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlVarianceSwap(alloc(new VarianceSwap((Position::Type)position, strike, notional, Date(startDate), Date(maturityDate)))));
} catch (std::exception& er) {return handleException<QlVarianceSwap*>(e, er);}}
double qlVarianceSwapVariance(QlVarianceSwap* o, QlError **e) { QlCallScope callbackScope(e);try {return (*arg(o))->variance();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeVarianceOption(QlVarianceOption *o) {del(o);}
QlInstrument* qlVarianceOptionAsInstrument(QlVarianceOption *o) {return ret(new QlInstrument(*arg(o)));}
QlVarianceOption* qlVarianceOption(QlPayoff* payoff, double notional, int startDate, int maturityDate, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlVarianceOption(alloc(new VarianceOption(*arg(payoff), notional, Date(startDate), Date(maturityDate)))));
} catch (std::exception& er) {return handleException<QlVarianceOption*>(e, er);}}
// Commodity and EnergyCommodity are abstract binding roots reached through their concrete leaves.
// Their constructor-echo getters are intentionally not bound.
void qlFreeCommodity(QlCommodity *o) {del(o);}
QlInstrument* qlCommodityAsInstrument(QlCommodity *o) {return ret(new QlInstrument(*arg(o)));}
void qlFreeEnergyCommodity(QlEnergyCommodity *o) {del(o);}
QlCommodity* qlEnergyCommodityAsCommodity(QlEnergyCommodity *o) {return ret(new QlCommodity(*arg(o)));}
/* Commodity base-level operations shared by every leaf. */
void qlCommodityAddPricingError(QlCommodity *o, int level, char *error, char *detail) {
(*arg(o))->addPricingError((PricingError::Level)level, arg(error), arg(detail));
}
void qlCommoditySecondaryCostAmounts(QlCommodity *o, unsigned *len, char ***keys,
unsigned *len2, double **amounts, unsigned *len3, Currency ***currencies, QlError **e) { QlCallScope callbackScope(e);
OutStringArrayResult keyResult(len, keys);
OutArrayResult<double> amountResult(len2, amounts);
OutPtrArrayResult<Currency> currencyResult(len3, currencies);
try {
const SecondaryCostAmounts &m = (*arg(o))->secondaryCostAmounts();
const unsigned n = (unsigned)m.size();
char **ks = keyResult.allocate(n);
double *am = amountResult.allocate(n);
Currency **cs = currencyResult.allocate(n);
unsigned i = 0;
for (SecondaryCostAmounts::const_iterator it = m.begin(); it != m.end(); ++it, ++i) {
ks[i] = tracedup(it->first.c_str());
am[i] = it->second.value();
cs[i] = ret(new Currency(it->second.currency()));
}
keyResult.commit(); amountResult.commit(); currencyResult.commit();
} catch (std::exception& er) {handleException<int>(e, er);}
}
void qlCommodityPricingErrors(QlCommodity *o, unsigned *len, int **levels,
unsigned *len2, char ***errors, unsigned *len3, char ***details, QlError **e) { QlCallScope callbackScope(e);
OutArrayResult<int> levelResult(len, levels);
OutStringArrayResult errorResult(len2, errors);
OutStringArrayResult detailResult(len3, details);
try {
const PricingErrors &errs = (*arg(o))->pricingErrors();
const unsigned n = (unsigned)errs.size();
int *lv = levelResult.allocate(n);
char **errs2 = errorResult.allocate(n);
char **dets = detailResult.allocate(n);
for (unsigned i = 0; i < n; ++i) {
lv[i] = errs[i].errorLevel;
errs2[i] = tracedup(errs[i].error.c_str());
dets[i] = tracedup(errs[i].detail.c_str());
}
levelResult.commit(); errorResult.commit(); detailResult.commit();
} catch (std::exception& er) {handleException<int>(e, er);}
}
/* EnergyCommodity -- quantity() is pure virtual upstream; one shim, dispatched virtually, covers
every leaf (EnergyFuture's own override is a plain echo of its constructor argument, but
EnergySwap's is a real computed sum -- see energyswap.cpp). */
double qlEnergyCommodityQuantity(QlEnergyCommodity *o, CommodityType **outCt, UnitOfMeasure **outUom, QlError **e) { QlCallScope callbackScope(e);
*outCt = 0; *outUom = 0;
try {
Quantity q = (*arg(o))->quantity();
// unique_ptr until both allocations have succeeded, so a throw from the second one releases
// the first without any cleanup in the catch -- and ret() runs only on the pointers actually
// handed out, so nothing half-built is ever traced as returned.
std::unique_ptr<CommodityType> ct(new CommodityType(q.commodityType()));
std::unique_ptr<UnitOfMeasure> uom(new UnitOfMeasure(q.unitOfMeasure()));
*outCt = ret(ct.release());
*outUom = ret(uom.release());
return q.amount();
} catch (std::exception& er) {
return handleException<double>(e, er);
}
}
/* tradePrice()/index() are constructor echoes and intentionally not bound. quantity() is exposed
once through the EnergyCommodity base. */
void qlFreeEnergyFuture(QlEnergyFuture *o) {del(o);}
QlEnergyCommodity* qlEnergyFutureAsEnergyCommodity(QlEnergyFuture *o) {return ret(new QlEnergyCommodity(*arg(o)));}
QlEnergyFuture* qlEnergyFuture(int buySell,
CommodityType *qCt, UnitOfMeasure *qUom, double qAmount,
double tpAmount, Currency *tpCcy, UnitOfMeasure *tpUom,
QlCommodityIndex *index, CommodityType *commodityType,
unsigned scLen, char **scKeys, unsigned, int *scIsUnitCost, unsigned, double *scAmounts,
unsigned, Currency **scCurrencies, unsigned, UnitOfMeasure **scUoms,
QlError **e) { QlCallScope callbackScope(e);
try {
return ret(new QlEnergyFuture(alloc(new EnergyFuture(
buySell,
Quantity(*arg(qCt), *arg(qUom), qAmount),
CommodityUnitCost(Money(*arg(tpCcy), tpAmount), *arg(tpUom)),
*arg(index),
*arg(commodityType),
qlBuildSecondaryCosts(scLen, scKeys, scIsUnitCost, scAmounts, scCurrencies, scUoms)))));
} catch (std::exception& er) {return handleException<QlEnergyFuture*>(e, er);}}
/* EnergySwap -- binds no constructor (falls through to Instrument's null-engine QL_REQUIRE, see
qlaux.h); calendar/payCurrency/receiveCurrency/pricingPeriods/commodityType are all plain,
never-mutated echoes of (or, for commodityType/quantity, pure functions of) each leaf's own
constructor arguments -- not bound. dailyPositions/paymentCashFlows are genuinely computed
during performCalculations, so those are the two worth binding, generalized over both leaves. */
void qlFreeEnergySwap(QlEnergySwap *o) {del(o);}
QlEnergyCommodity* qlEnergySwapAsEnergyCommodity(QlEnergySwap *o) {return ret(new QlEnergyCommodity(*arg(o)));}
void qlEnergySwapDailyPositions(QlEnergySwap *o, unsigned *len, int **dates,
unsigned *len2, double **quantityAmounts, unsigned *len3, double **payLegPrices,
unsigned *len4, double **receiveLegPrices, unsigned *len5, double **riskDeltas,
unsigned *len6, int **unrealized, QlError **e) { QlCallScope callbackScope(e);
OutArrayResult<int> dateResult(len, dates), unrealizedResult(len6, unrealized);
OutArrayResult<double> quantityResult(len2, quantityAmounts), payResult(len3, payLegPrices),
receiveResult(len4, receiveLegPrices), deltaResult(len5, riskDeltas);
try {
const EnergyDailyPositions &m = (*arg(o))->dailyPositions();
const unsigned n = (unsigned)m.size();
int *ds = dateResult.allocate(n), *ur = unrealizedResult.allocate(n);
double *qa = quantityResult.allocate(n), *plp = payResult.allocate(n),
*rlp = receiveResult.allocate(n), *rd = deltaResult.allocate(n);
unsigned i = 0;
for (EnergyDailyPositions::const_iterator it = m.begin(); it != m.end(); ++it, ++i) {
ds[i] = it->first.serialNumber();
qa[i] = it->second.quantityAmount;
plp[i] = it->second.payLegPrice;
rlp[i] = it->second.receiveLegPrice;
rd[i] = it->second.riskDelta;
ur[i] = it->second.unrealized;
}
dateResult.commit(); quantityResult.commit(); payResult.commit();
receiveResult.commit(); deltaResult.commit(); unrealizedResult.commit();
} catch (std::exception& er) {handleException<int>(e, er);}
}
void qlEnergySwapPaymentCashFlows(QlEnergySwap *o, unsigned *len, QlCommodityCashFlow ***out, QlError **e) { QlCallScope callbackScope(e);
OutPtrArrayResult<QlCommodityCashFlow> result(len, out);
try {
const CommodityCashFlows &m = (*arg(o))->paymentCashFlows();
QlCommodityCashFlow **cs = result.allocate((unsigned)m.size());
unsigned i = 0;
for (CommodityCashFlows::const_iterator it = m.begin(); it != m.end(); ++it, ++i)
cs[i] = ret(new QlCommodityCashFlow(alloc(it->second)));
result.commit();
} catch (std::exception& er) {handleException<int>(e, er);}
}
/* EnergyVanillaSwap -- payReceive()/fixedPrice()/fixedPriceUnitOfMeasure()/index() are all plain,
never-mutated echoes of this constructor's own arguments -- not bound (payReceive_ is a trivial
`payer ? 1 : 0` of the ctor's own bool, reproducible in Haskell with no C++ call at all). */
void qlFreeEnergyVanillaSwap(QlEnergyVanillaSwap *o) {del(o);}
QlEnergySwap* qlEnergyVanillaSwapAsEnergySwap(QlEnergyVanillaSwap *o) {return ret(new QlEnergySwap(*arg(o)));}
QlEnergyVanillaSwap* qlEnergyVanillaSwap(int payer, Calendar *calendar,
double fixedPriceAmount, Currency *fixedPriceCurrency, UnitOfMeasure *fixedPriceUnitOfMeasure,
QlCommodityIndex *index, Currency *payCurrency, Currency *receiveCurrency,
unsigned ppLen, int *ppStartDates, unsigned, int *ppEndDates, unsigned, int *ppPaymentDates,
unsigned, CommodityType **ppTypes, unsigned, UnitOfMeasure **ppUoms, unsigned, double *ppAmounts,
CommodityType *commodityType,
unsigned scLen, char **scKeys, unsigned, int *scIsUnitCost, unsigned, double *scAmounts,
unsigned, Currency **scCurrencies, unsigned, UnitOfMeasure **scUoms,
QlYieldTermStructure *payLegTS, QlYieldTermStructure *receiveLegTS, QlYieldTermStructure *discountTS,
QlError **e) { QlCallScope callbackScope(e);
try {
return ret(new QlEnergyVanillaSwap(alloc(new EnergyVanillaSwap(
payer,
*arg(calendar),
Money(*arg(fixedPriceCurrency), fixedPriceAmount),
*arg(fixedPriceUnitOfMeasure),
*arg(index),
*arg(payCurrency),
*arg(receiveCurrency),
qlPricingPeriodVector(ppLen, ppStartDates, ppEndDates, ppPaymentDates, ppTypes, ppUoms, ppAmounts),
*arg(commodityType),
qlBuildSecondaryCosts(scLen, scKeys, scIsUnitCost, scAmounts, scCurrencies, scUoms),
*arg(payLegTS), *arg(receiveLegTS), *arg(discountTS)))));
} catch (std::exception& er) {return handleException<QlEnergyVanillaSwap*>(e, er);}}
/* EnergyBasisSwap -- payIndex()/receiveIndex()/basis() are likewise plain constructor-argument
echoes -- not bound. */
void qlFreeEnergyBasisSwap(QlEnergyBasisSwap *o) {del(o);}
QlEnergySwap* qlEnergyBasisSwapAsEnergySwap(QlEnergyBasisSwap *o) {return ret(new QlEnergySwap(*arg(o)));}
QlEnergyBasisSwap* qlEnergyBasisSwap(Calendar *calendar,
QlCommodityIndex *spreadIndex, QlCommodityIndex *payIndex, QlCommodityIndex *receiveIndex,
int spreadToPayLeg, Currency *payCurrency, Currency *receiveCurrency,
unsigned ppLen, int *ppStartDates, unsigned, int *ppEndDates, unsigned, int *ppPaymentDates,
unsigned, CommodityType **ppTypes, unsigned, UnitOfMeasure **ppUoms, unsigned, double *ppAmounts,
double basisAmount, Currency *basisCurrency, UnitOfMeasure *basisUnitOfMeasure,
CommodityType *commodityType,
unsigned scLen, char **scKeys, unsigned, int *scIsUnitCost, unsigned, double *scAmounts,
unsigned, Currency **scCurrencies, unsigned, UnitOfMeasure **scUoms,
QlYieldTermStructure *payLegTS, QlYieldTermStructure *receiveLegTS, QlYieldTermStructure *discountTS,
QlError **e) { QlCallScope callbackScope(e);
try {
return ret(new QlEnergyBasisSwap(alloc(new EnergyBasisSwap(
*arg(calendar),
*arg(spreadIndex), *arg(payIndex), *arg(receiveIndex),
spreadToPayLeg,
*arg(payCurrency), *arg(receiveCurrency),
qlPricingPeriodVector(ppLen, ppStartDates, ppEndDates, ppPaymentDates, ppTypes, ppUoms, ppAmounts),
CommodityUnitCost(Money(*arg(basisCurrency), basisAmount), *arg(basisUnitOfMeasure)),
*arg(commodityType),
qlBuildSecondaryCosts(scLen, scKeys, scIsUnitCost, scAmounts, scCurrencies, scUoms),
*arg(payLegTS), *arg(receiveLegTS), *arg(discountTS)))));
} catch (std::exception& er) {return handleException<QlEnergyBasisSwap*>(e, er);}}
/* CommodityCashFlow -- a standalone CashFlow leaf, never Haskell-constructed (only ever produced
by EnergySwap::paymentCashFlows() above). The upstream field reads themselves can't throw, but
each shim also does `ret(new Currency(...))`, which is a bad_alloc-only throw point -- QlError **e
guards that, not the upstream call. */
void qlFreeCommodityCashFlow(QlCommodityCashFlow *o) {del(o);}
QlCashFlow *qlCommodityCashFlowAsCashFlow(QlCommodityCashFlow *o) {return ret(new QlCashFlow(*arg(o)));}
double qlCommodityCashFlowDiscountedAmount(QlCommodityCashFlow *o, Currency **outCcy, QlError **e) { QlCallScope callbackScope(e);
*outCcy = 0;
try {
const Money &m = (*arg(o))->discountedAmount();
*outCcy = ret(new Currency(m.currency()));
return m.value();
} catch (std::exception& er) {return handleException<double>(e, er);}
}
double qlCommodityCashFlowUndiscountedAmount(QlCommodityCashFlow *o, Currency **outCcy, QlError **e) { QlCallScope callbackScope(e);
*outCcy = 0;
try {
const Money &m = (*arg(o))->undiscountedAmount();
*outCcy = ret(new Currency(m.currency()));
return m.value();
} catch (std::exception& er) {return handleException<double>(e, er);}
}
double qlCommodityCashFlowDiscountedPaymentAmount(QlCommodityCashFlow *o, Currency **outCcy, QlError **e) { QlCallScope callbackScope(e);
*outCcy = 0;
try {
const Money &m = (*arg(o))->discountedPaymentAmount();
*outCcy = ret(new Currency(m.currency()));
return m.value();
} catch (std::exception& er) {return handleException<double>(e, er);}
}
double qlCommodityCashFlowUndiscountedPaymentAmount(QlCommodityCashFlow *o, Currency **outCcy, QlError **e) { QlCallScope callbackScope(e);
*outCcy = 0;
try {
const Money &m = (*arg(o))->undiscountedPaymentAmount();
*outCcy = ret(new Currency(m.currency()));
return m.value();
} catch (std::exception& er) {return handleException<double>(e, er);}
}
double qlCommodityCashFlowDiscountFactor(QlCommodityCashFlow *o) {return (*arg(o))->discountFactor();}
double qlCommodityCashFlowPaymentDiscountFactor(QlCommodityCashFlow *o) {return (*arg(o))->paymentDiscountFactor();}
int qlCommodityCashFlowFinalized(QlCommodityCashFlow *o) {return (*arg(o))->finalized();}
/* The other CommodityPricingHelper static methods duplicate conversion APIs already bound. */
void qlCreatePricingPeriods(int startDate, int endDate, CommodityType *qCt, UnitOfMeasure *qUom, double qAmount,
int deliverySchedule, int qtyPeriodicity, PaymentTerm *paymentTerm,
unsigned *len, int **ppStartDates, unsigned *len2, int **ppEndDates, unsigned *len3, int **ppPaymentDates,
unsigned *len4, CommodityType ***ppTypes, unsigned *len5, UnitOfMeasure ***ppUoms, unsigned *len6, double **ppAmounts,
QlError **e) { QlCallScope callbackScope(e);
OutArrayResult<int> startResult(len, ppStartDates), endResult(len2, ppEndDates), payResult(len3, ppPaymentDates);
OutPtrArrayResult<CommodityType> typeResult(len4, ppTypes);
OutPtrArrayResult<UnitOfMeasure> uomResult(len5, ppUoms);
OutArrayResult<double> amountResult(len6, ppAmounts);
try {
PricingPeriods pps;
CommodityPricingHelper::createPricingPeriods(Date(startDate), Date(endDate),
Quantity(*arg(qCt), *arg(qUom), qAmount),
(EnergyCommodity::DeliverySchedule)deliverySchedule,
(EnergyCommodity::QuantityPeriodicity)qtyPeriodicity,
*arg(paymentTerm), pps);
const unsigned n = (unsigned)pps.size();
int *starts = startResult.allocate(n), *ends = endResult.allocate(n), *pays = payResult.allocate(n);
double *amounts = amountResult.allocate(n);
CommodityType **types = typeResult.allocate(n);
UnitOfMeasure **uoms = uomResult.allocate(n);
for (unsigned i = 0; i < n; ++i) {
starts[i] = pps[i]->startDate().serialNumber();
ends[i] = pps[i]->endDate().serialNumber();
pays[i] = pps[i]->paymentDate().serialNumber();
types[i] = ret(new CommodityType(pps[i]->quantity().commodityType()));
uoms[i] = ret(new UnitOfMeasure(pps[i]->quantity().unitOfMeasure()));
amounts[i] = pps[i]->quantity().amount();
}
startResult.commit(); endResult.commit(); payResult.commit();
typeResult.commit(); uomResult.commit(); amountResult.commit();
} catch (std::exception& er) {handleException<int>(e, er);}
}
void qlFreeYoYInflationCapFloor(QlYoYInflationCapFloor *o) {del(o);}
QlInstrument *qlYoYInflationCapFloorAsInstrument(QlYoYInflationCapFloor *o) {return ret(new QlInstrument(*arg(o)));}
QlYoYInflationCapFloor *qlYoYInflationCap(Leg *yoyLeg, unsigned exerciseRatesLen, double *exerciseRates, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlYoYInflationCapFloor(alloc(new YoYInflationCapFloor(YoYInflationCapFloor::Cap, *arg(yoyLeg),
std::vector<double>(exerciseRates, exerciseRates+exerciseRatesLen), std::vector<double>()))));
} catch (std::exception& er) {return handleException<QlYoYInflationCapFloor*>(e, er);}}
QlYoYInflationCapFloor *qlYoYInflationFloor(Leg *yoyLeg, unsigned exerciseRatesLen, double *exerciseRates, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlYoYInflationCapFloor(alloc(new YoYInflationCapFloor(YoYInflationCapFloor::Floor, *arg(yoyLeg),
std::vector<double>(), std::vector<double>(exerciseRates, exerciseRates+exerciseRatesLen)))));
} catch (std::exception& er) {return handleException<QlYoYInflationCapFloor*>(e, er);}}
QlYoYInflationCapFloor *qlYoYInflationCollar(Leg *yoyLeg, unsigned capRatesLen, double *capRates,
unsigned floorRatesLen, double *floorRates, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlYoYInflationCapFloor(alloc(new YoYInflationCapFloor(YoYInflationCapFloor::Collar, *arg(yoyLeg),
std::vector<double>(capRates, capRates+capRatesLen), std::vector<double>(floorRates, floorRates+floorRatesLen)))));
} catch (std::exception& er) {return handleException<QlYoYInflationCapFloor*>(e, er);}}
// atmRate takes a plain YieldTermStructure& (not a Handle), same reasoning as qlCapFloorAtmRate.
double qlYoYInflationCapFloorAtmRate(QlYoYInflationCapFloor *o, QlYieldTermStructure *discountCurve, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->atmRate(handleRef(arg(discountCurve)));
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlYoYInflationCapFloor *qlYoYInflationCapFloorOptionlet(QlYoYInflationCapFloor *o, unsigned n, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlYoYInflationCapFloor(alloc((*arg(o))->optionlet(n))));
} catch (std::exception& er) {return handleException<QlYoYInflationCapFloor*>(e, er);}}
void qlFreeCPICapFloor(QlCPICapFloor *o) {del(o);}
QlInstrument *qlCPICapFloorAsInstrument(QlCPICapFloor *o) {return ret(new QlInstrument(*arg(o)));}
QlCPICapFloor *qlCPICapFloor(int type, double nominal, int startDate, double baseCPI, int maturity,
Calendar *fixCalendar, int fixConvention, Calendar *payCalendar, int payConvention, double strike,
QlZeroInflationIndex *index, int observationLagLen, int observationLagUnit, int observationInterpolation,
QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCPICapFloor(alloc(new CPICapFloor((Option::Type)type, nominal, Date(startDate), baseCPI,
Date(maturity), *arg(fixCalendar), (BusinessDayConvention)fixConvention, *arg(payCalendar),
(BusinessDayConvention)payConvention, strike, *arg(index),
Period(observationLagLen, (TimeUnit)observationLagUnit), (CPI::InterpolationType)observationInterpolation))));
} catch (std::exception& er) {return handleException<QlCPICapFloor*>(e, er);}}
DefaultProbKey* qlNorthAmericaCorpDefaultKey(Currency* currency, int seniority, int graceFailureToPayLen, int graceFailureToPayUnit, double amountFailure, int restructuringType, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new DefaultProbKey(NorthAmericaCorpDefaultKey(*arg(currency), (Seniority)seniority,
Period(graceFailureToPayLen, (TimeUnit)graceFailureToPayUnit), amountFailure, (Restructuring::Type)restructuringType)));
} catch (std::exception& er) {return handleException<DefaultProbKey*>(e, er);}}
void qlFreeDefaultProbKey(DefaultProbKey *o) {del(o);}
Issuer* qlIssuer(unsigned probabilitiesLen, DefaultProbKey** keys, QlDefaultProbabilityTermStructure** curves, QlError **e) { QlCallScope callbackScope(e);
try {
std::vector<Issuer::key_curve_pair> probs;
probs.reserve(probabilitiesLen);
for (unsigned i = 0; i < probabilitiesLen; ++i)
probs.emplace_back(*keys[i], Handle<DefaultProbabilityTermStructure>(*curves[i]));
return ret(new Issuer(probs));
} catch (std::exception& er) {return handleException<Issuer*>(e, er);}}
void qlFreeIssuer(Issuer *o) {del(o);}
QlPool* qlPool(unsigned namesLen, char** names, Issuer** issuers, DefaultProbKey** keys, QlError **e) { QlCallScope callbackScope(e);
try {
auto p = allocShared(new Pool());
for (unsigned i = 0; i < namesLen; ++i) p->add(names[i], *issuers[i], *keys[i]);
return ret(new QlPool(p));
} catch (std::exception& er) {return handleException<QlPool*>(e, er);}}
void qlFreePool(QlPool *o) {del(o);}
QlBasket* qlBasket(int refDate, unsigned namesLen, char** names, double* notionals, QlPool* pool, double attachmentRatio, double detachmentRatio, QlClaim* claim, QlDefaultLossModel* lossModel, QlError **e) { QlCallScope callbackScope(e);
try {
std::vector<std::string> nm(names, names + namesLen);
auto b = allocShared(new Basket(Date(refDate), nm, std::vector<double>(notionals, notionals + namesLen),
*arg(pool), attachmentRatio, detachmentRatio, *arg(claim)));
b->setLossModel(*arg(lossModel));
return ret(new QlBasket(b));
} catch (std::exception& er) {return handleException<QlBasket*>(e, er);}}
void qlFreeBasket(QlBasket *o) {del(o);}
double qlBasketNotional(QlBasket* o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->notional();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBasketExpectedTrancheLoss(QlBasket* o, int d, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->expectedTrancheLoss(Date(d));
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlBasket* qlDigitalBasket(int refDate, unsigned namesLen, char** names, double* notionals, QlPool* pool, double attachmentRatio, double detachmentRatio, QlClaim* claim, QlDefaultLossModel* lossModel, QlError **e) { QlCallScope callbackScope(e);
return qlBasket(refDate, namesLen, names, notionals, pool, attachmentRatio, detachmentRatio, claim, lossModel, e);
}
double qlBasketRemainingNotional(QlBasket* o, int d, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->remainingNotional(Date(d));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBasketRecoveryRate(QlBasket* o, int d, unsigned iName, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->recoveryRate(Date(d), iName);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBasketProbOverLoss(QlBasket* o, int d, double lossFraction, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->probOverLoss(Date(d), lossFraction);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBasketPercentile(QlBasket* o, int d, double prob, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->percentile(Date(d), prob);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBasketExpectedShortfall(QlBasket* o, int d, double prob, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->expectedShortfall(Date(d), prob);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBasketDefaultCorrelation(QlBasket* o, int d, unsigned iName, unsigned jName, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->defaultCorrelation(Date(d), iName, jName);
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBasketProbAtLeastNEvents(QlBasket* o, unsigned n, int d, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->probAtLeastNEvents(n, Date(d));
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlDefaultLossModel* qlGaussianLHPLossModel(QlQuote* correlQuote, unsigned recoveriesLen, double* recoveries, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlDefaultLossModel(shared_ptr<DefaultLossModel>(allocAs<DefaultLossModel>(
new GaussianLHPLossModel(*arg(correlQuote), std::vector<double>(recoveries, recoveries + recoveriesLen))))));
} catch (std::exception& er) {return handleException<QlDefaultLossModel*>(e, er);}}
void qlFreeDefaultLossModel(QlDefaultLossModel *o) {del(o);}
QlSyntheticCDO* qlSyntheticCDO(QlBasket* basket, int side, Schedule* schedule, double upfrontRate, double runningRate, DayCounter* dayCounter, int paymentConvention, int haveNotional, double notional, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlSyntheticCDO(alloc(new SyntheticCDO(*arg(basket), (Protection::Side)side, *arg(schedule), upfrontRate, runningRate,
*arg(dayCounter), (BusinessDayConvention)paymentConvention, haveNotional ? optional<Real>(notional) : nullopt))));
} catch (std::exception& er) {return handleException<QlSyntheticCDO*>(e, er);}}
void qlFreeSyntheticCDO(QlSyntheticCDO *o) {del(o);}
QlInstrument* qlSyntheticCDOAsInstrument(QlSyntheticCDO *o) {return ret(new QlInstrument(*arg(o)));}
double qlSyntheticCDOFairPremium(QlSyntheticCDO* o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->fairPremium();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlSyntheticCDOFairUpfrontPremium(QlSyntheticCDO* o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->fairUpfrontPremium();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlSyntheticCDOPremiumValue(QlSyntheticCDO* o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->premiumValue();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlSyntheticCDOProtectionValue(QlSyntheticCDO* o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->protectionValue();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlSyntheticCDOPremiumLegNPV(QlSyntheticCDO* o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->premiumLegNPV();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlSyntheticCDOProtectionLegNPV(QlSyntheticCDO* o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->protectionLegNPV();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlSyntheticCDORemainingNotional(QlSyntheticCDO* o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->remainingNotional();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlSyntheticCDOImplicitCorrelation(QlSyntheticCDO* o, unsigned recoveriesLen, double* recoveries, QlYieldTermStructure* discountCurve, double targetNPV, double accuracy, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->implicitCorrelation(std::vector<double>(recoveries, recoveries + recoveriesLen), *arg(discountCurve), targetNPV, accuracy);
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlDefaultLossModel* qlConstantLossModel(QlQuote* correlQuote, unsigned recoveriesLen, double* recoveries, int integralType, unsigned tOrdersLen, int* tOrders, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlDefaultLossModel(alloc(qlConstantLossModelAux(*arg(correlQuote),
std::vector<double>(recoveries, recoveries + recoveriesLen),
(LatentModelIntegrationType::LatentModelIntegrationType)integralType, recoveriesLen,
std::vector<Integer>(tOrders, tOrders + tOrdersLen)))));
} catch (std::exception& er) {return handleException<QlDefaultLossModel*>(e, er);}}
QlNthToDefault* qlNthToDefault(QlBasket* basket, unsigned n, int side, Schedule* premiumSchedule, double upfrontRate, double premiumRate, DayCounter* dayCounter, double nominal, int settlePremiumAccrual, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlNthToDefault(alloc(new NthToDefault(*arg(basket), n, (Protection::Side)side,
*arg(premiumSchedule), upfrontRate, premiumRate, *arg(dayCounter), nominal, settlePremiumAccrual != 0))));
} catch (std::exception& er) {return handleException<QlNthToDefault*>(e, er);}}
void qlFreeNthToDefault(QlNthToDefault *o) {del(o);}
QlInstrument* qlNthToDefaultAsInstrument(QlNthToDefault *o) {return ret(new QlInstrument(*arg(o)));}
double qlNthToDefaultFairPremium(QlNthToDefault* o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->fairPremium();
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlRendistatoBasket *qlRendistatoBasket(unsigned btpsLen, QlBTP **btps, unsigned outstandingsLen, double *outstandings, unsigned quotesLen, QlQuote **cleanPriceQuotes, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlRendistatoBasket(alloc(new RendistatoBasket(qlVector(btps, btpsLen),
std::vector<double>(outstandings, outstandings+outstandingsLen), qlHandleVector(cleanPriceQuotes, quotesLen)))));
} catch (std::exception& er) {return handleException<QlRendistatoBasket*>(e, er);}}
void qlFreeRendistatoBasket(QlRendistatoBasket *o) {del(o);}
QlRendistatoCalculator *qlRendistatoCalculator(QlRendistatoBasket *basket, int euriborTenorLen, int euriborTenorUnit,
QlYieldTermStructure *euriborForwardCurve, QlYieldTermStructure *discountCurve, QlError **e) { QlCallScope callbackScope(e);
try {
auto idx = ext::make_shared<Euribor>(Period(euriborTenorLen, (TimeUnit)euriborTenorUnit), qlNullableHandle(euriborForwardCurve));
return ret(new QlRendistatoCalculator(alloc(new RendistatoCalculator(*arg(basket), idx, *arg(discountCurve)))));
} catch (std::exception& er) {return handleException<QlRendistatoCalculator*>(e, er);}}
void qlFreeRendistatoCalculator(QlRendistatoCalculator *o) {del(o);}
double qlRendistatoCalculatorYield(QlRendistatoCalculator *o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->yield();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlRendistatoCalculatorDuration(QlRendistatoCalculator *o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->duration();
} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlRendistatoCalculatorYields(QlRendistatoCalculator *o, unsigned *len, double **out, QlError **e) { QlCallScope callbackScope(e);
*len = 0; *out = 0;
try {copyRealVector((*arg(o))->yields(), len, out);
} catch (std::exception& er) {(void)handleException<double*>(e, er);}}
void qlRendistatoCalculatorDurations(QlRendistatoCalculator *o, unsigned *len, double **out, QlError **e) { QlCallScope callbackScope(e);
*len = 0; *out = 0;
try {copyRealVector((*arg(o))->durations(), len, out);
} catch (std::exception& er) {(void)handleException<double*>(e, er);}}
void qlRendistatoCalculatorSwapLengths(QlRendistatoCalculator *o, unsigned *len, double **out, QlError **e) { QlCallScope callbackScope(e);
*len = 0; *out = 0;
try {copyRealVector((*arg(o))->swapLengths(), len, out);
} catch (std::exception& er) {(void)handleException<double*>(e, er);}}
void qlRendistatoCalculatorSwapRates(QlRendistatoCalculator *o, unsigned *len, double **out, QlError **e) { QlCallScope callbackScope(e);
*len = 0; *out = 0;
try {copyRealVector((*arg(o))->swapRates(), len, out);
} catch (std::exception& er) {(void)handleException<double*>(e, er);}}
void qlRendistatoCalculatorSwapYields(QlRendistatoCalculator *o, unsigned *len, double **out, QlError **e) { QlCallScope callbackScope(e);
*len = 0; *out = 0;
try {copyRealVector((*arg(o))->swapYields(), len, out);
} catch (std::exception& er) {(void)handleException<double*>(e, er);}}
void qlRendistatoCalculatorSwapDurations(QlRendistatoCalculator *o, unsigned *len, double **out, QlError **e) { QlCallScope callbackScope(e);
*len = 0; *out = 0;
try {copyRealVector((*arg(o))->swapDurations(), len, out);
} catch (std::exception& er) {(void)handleException<double*>(e, er);}}
QlVanillaSwap *qlRendistatoCalculatorEquivalentSwap(QlRendistatoCalculator *o, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlVanillaSwap((*arg(o))->equivalentSwap()));
} catch (std::exception& er) {return handleException<QlVanillaSwap*>(e, er);}}
double qlRendistatoCalculatorEquivalentSwapRate(QlRendistatoCalculator *o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->equivalentSwapRate();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlRendistatoCalculatorEquivalentSwapYield(QlRendistatoCalculator *o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->equivalentSwapYield();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlRendistatoCalculatorEquivalentSwapDuration(QlRendistatoCalculator *o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->equivalentSwapDuration();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlRendistatoCalculatorEquivalentSwapLength(QlRendistatoCalculator *o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->equivalentSwapLength();
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlRendistatoCalculatorEquivalentSwapSpread(QlRendistatoCalculator *o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->equivalentSwapSpread();
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlQuote *qlRendistatoEquivalentSwapLengthQuote(QlRendistatoCalculator *o, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlQuote(shared_ptr<Quote>(alloc(new RendistatoEquivalentSwapLengthQuote(*arg(o))))));
} catch (std::exception& er) {return handleException<QlQuote*>(e, er);}}
QlQuote *qlRendistatoEquivalentSwapSpreadQuote(QlRendistatoCalculator *o, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlQuote(shared_ptr<Quote>(alloc(new RendistatoEquivalentSwapSpreadQuote(*arg(o))))));
} catch (std::exception& er) {return handleException<QlQuote*>(e, er);}}
QlFixedVsFloatingSwap* qlSwaptionUnderlying(QlSwaption* o, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFixedVsFloatingSwap((*arg(o))->underlying()));}
catch (std::exception& er) {return handleException<QlFixedVsFloatingSwap*>(e, er);}}
QlNonstandardSwap* qlNonstandardSwaptionUnderlyingSwap(QlNonstandardSwaption* o, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlNonstandardSwap((*arg(o))->underlyingSwap()));}
catch (std::exception& er) {return handleException<QlNonstandardSwap*>(e, er);}}
QlFloatFloatSwap* qlFloatFloatSwaptionUnderlyingSwap(QlFloatFloatSwaption* o, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlFloatFloatSwap((*arg(o))->underlyingSwap()));}
catch (std::exception& er) {return handleException<QlFloatFloatSwap*>(e, er);}}
QlIrregularSwap* qlIrregularSwaptionUnderlyingSwap(QlIrregularSwaption* o, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlIrregularSwap((*arg(o))->underlyingSwap()));}
catch (std::exception& er) {return handleException<QlIrregularSwap*>(e, er);}}
QlCreditDefaultSwap* qlCdsOptionUnderlyingSwap(QlCdsOption* o, QlError **e) { QlCallScope callbackScope(e);
try {return ret(new QlCreditDefaultSwap((*arg(o))->underlyingSwap()));}
catch (std::exception& er) {return handleException<QlCreditDefaultSwap*>(e, er);}}
void qlFreeMtMCrossCurrencyBasisSwap(QlMtMCrossCurrencyBasisSwap* o) {del(o);}
QlSwap* qlMtMCrossCurrencyBasisSwapAsSwap(QlMtMCrossCurrencyBasisSwap* o) {
#if QL_HEX_VERSION >= 0x01440000
return ret(new QlSwap(*arg(o)));
#else
(void)o; return nullptr;
#endif
}
QlMtMCrossCurrencyBasisSwap* qlMtMCrossCurrencyBasisSwap(int type, double fxBaseNominal, Currency* fxBaseCurrency, Schedule* fxBaseSchedule, QlIborIndex* fxBaseIndex, double fxBaseSpread, double fxBaseGearing, double fxQuoteNominal, Currency* fxQuoteCurrency, Schedule* fxQuoteSchedule, QlIborIndex* fxQuoteIndex, double fxQuoteSpread, double fxQuoteGearing, int resetBase, unsigned fxResetFixingDays, Calendar* fxResetFixingCalendar, int fxBasePaymentLag, int fxQuotePaymentLag, int fxBasePaymentConvention, int fxQuotePaymentConvention, int fxBaseCompoundSpread, unsigned fxBaseLookbackDays, int fxBaseObservationShift, unsigned fxBaseLockoutDays, int fxBaseAveragingMethod, int fxQuoteCompoundSpread, unsigned fxQuoteLookbackDays, int fxQuoteObservationShift, unsigned fxQuoteLockoutDays, int fxQuoteAveragingMethod, int telescopicValueDates, int useIndexedCoupons, QlStubIndexSelection* fxBaseStubIndexSelection, QlStubIndexSelection* fxQuoteStubIndexSelection, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {return ret(new QlMtMCrossCurrencyBasisSwap(alloc(new MtMCrossCurrencyBasisSwap((MtMCrossCurrencyBasisSwap::Type)type, fxBaseNominal, *arg(fxBaseCurrency), *arg(fxBaseSchedule), *arg(fxBaseIndex), fxBaseSpread, fxBaseGearing, fxQuoteNominal, *arg(fxQuoteCurrency), *arg(fxQuoteSchedule), *arg(fxQuoteIndex), fxQuoteSpread, fxQuoteGearing, resetBase, fxResetFixingDays, fxResetFixingCalendar ? *arg(fxResetFixingCalendar) : Calendar(), fxBasePaymentLag, fxQuotePaymentLag, (BusinessDayConvention)fxBasePaymentConvention, (BusinessDayConvention)fxQuotePaymentConvention, fxBaseCompoundSpread, fxBaseLookbackDays, fxBaseObservationShift, fxBaseLockoutDays, (RateAveraging::Type)fxBaseAveragingMethod, fxQuoteCompoundSpread, fxQuoteLookbackDays, fxQuoteObservationShift, fxQuoteLockoutDays, (RateAveraging::Type)fxQuoteAveragingMethod, telescopicValueDates, qlOptBool(useIndexedCoupons), qlStubSelection(fxBaseStubIndexSelection), qlStubSelection(fxQuoteStubIndexSelection)))));} catch (std::exception& er) {return handleException<QlMtMCrossCurrencyBasisSwap*>(e, er);}
#else
(void)type; (void)fxBaseNominal; (void)fxBaseCurrency; (void)fxBaseSchedule; (void)fxBaseIndex; (void)fxBaseSpread; (void)fxBaseGearing; (void)fxQuoteNominal; (void)fxQuoteCurrency; (void)fxQuoteSchedule; (void)fxQuoteIndex; (void)fxQuoteSpread; (void)fxQuoteGearing; (void)resetBase; (void)fxResetFixingDays; (void)fxResetFixingCalendar; (void)fxBasePaymentLag; (void)fxQuotePaymentLag; (void)fxBasePaymentConvention; (void)fxQuotePaymentConvention; (void)fxBaseCompoundSpread; (void)fxBaseLookbackDays; (void)fxBaseObservationShift; (void)fxBaseLockoutDays; (void)fxBaseAveragingMethod; (void)fxQuoteCompoundSpread; (void)fxQuoteLookbackDays; (void)fxQuoteObservationShift; (void)fxQuoteLockoutDays; (void)fxQuoteAveragingMethod; (void)telescopicValueDates; (void)useIndexedCoupons; (void)fxBaseStubIndexSelection; (void)fxQuoteStubIndexSelection;
qlUnsupportedVersion(e, "mtmCrossCurrencyBasisSwap", "1.44"); return nullptr;
#endif
}
Currency* qlMtMLegCurrency(QlMtMCrossCurrencyBasisSwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {return ret(new Currency((*arg(o))->legCurrency(j)));} catch (std::exception& er) {return handleException<Currency*>(e, er);}
#else
(void)o; (void)j;
qlUnsupportedVersion(e, "legCurrency", "1.44"); return nullptr;
#endif
}
double qlMtMInCcyLegBPS(QlMtMCrossCurrencyBasisSwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {return (*arg(o))->inCcyLegBPS(j);} catch (std::exception& er) {return handleException<double>(e, er);}
#else
(void)o; (void)j;
qlUnsupportedVersion(e, "inCcyLegBps", "1.44"); return 0;
#endif
}
double qlMtMInCcyLegNPV(QlMtMCrossCurrencyBasisSwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {return (*arg(o))->inCcyLegNPV(j);} catch (std::exception& er) {return handleException<double>(e, er);}
#else
(void)o; (void)j;
qlUnsupportedVersion(e, "inCcyLegNpv", "1.44"); return 0;
#endif
}
double qlMtMNpvDateDiscounts(QlMtMCrossCurrencyBasisSwap* o, unsigned j, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {return (*arg(o))->npvDateDiscounts(j);} catch (std::exception& er) {return handleException<double>(e, er);}
#else
(void)o; (void)j;
qlUnsupportedVersion(e, "npvDateDiscounts", "1.44"); return 0;
#endif
}
double qlMtMFairFxBaseSpread(QlMtMCrossCurrencyBasisSwap* o, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {const double value = (*arg(o))->fairFxBaseSpread(); QL_REQUIRE(std::isfinite(value), "fair spread is undefined for zero leg BPS"); return value;} catch (std::exception& er) {return handleException<double>(e, er);}
#else
(void)o;
qlUnsupportedVersion(e, "fairFxBaseSpread", "1.44"); return 0;
#endif
}
double qlMtMFairFxQuoteSpread(QlMtMCrossCurrencyBasisSwap* o, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {const double value = (*arg(o))->fairFxQuoteSpread(); QL_REQUIRE(std::isfinite(value), "fair spread is undefined for zero leg BPS"); return value;} catch (std::exception& er) {return handleException<double>(e, er);}
#else
(void)o;
qlUnsupportedVersion(e, "fairFxQuoteSpread", "1.44"); return 0;
#endif
}
double qlMtMFairPaySpread(QlMtMCrossCurrencyBasisSwap* o, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {const double value = (*arg(o))->fairPaySpread(); QL_REQUIRE(std::isfinite(value), "fair spread is undefined for zero leg BPS"); return value;} catch (std::exception& er) {return handleException<double>(e, er);}
#else
(void)o;
qlUnsupportedVersion(e, "fairPaySpread", "1.44"); return 0;
#endif
}
double qlMtMFairRecSpread(QlMtMCrossCurrencyBasisSwap* o, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {const double value = (*arg(o))->fairRecSpread(); QL_REQUIRE(std::isfinite(value), "fair spread is undefined for zero leg BPS"); return value;} catch (std::exception& er) {return handleException<double>(e, er);}
#else
(void)o;
qlUnsupportedVersion(e, "fairRecSpread", "1.44"); return 0;
#endif
}
void qlMtMFxResetRates(QlMtMCrossCurrencyBasisSwap* o, unsigned* len, double** out, QlError **e) { QlCallScope callbackScope(e);
*len = 0; *out = nullptr;
#if QL_HEX_VERSION >= 0x01440000
try {fillVectorOut([&] {return (*arg(o))->fxResetRates();}, len, out);} catch (std::exception& er) {qlSetError(e, er.what());}
#else
(void)o; (void)len; (void)out;
qlUnsupportedVersion(e, "fxResetRates", "1.44");
#endif
}
void qlMtMFxResetNotionals(QlMtMCrossCurrencyBasisSwap* o, unsigned* len, double** out, QlError **e) { QlCallScope callbackScope(e);
*len = 0; *out = nullptr;
#if QL_HEX_VERSION >= 0x01440000
try {fillVectorOut([&] {return (*arg(o))->fxResetNotionals();}, len, out);} catch (std::exception& er) {qlSetError(e, er.what());}
#else
(void)o; (void)len; (void)out;
qlUnsupportedVersion(e, "fxResetNotionals", "1.44");
#endif
}
void qlFxResetConventionReset(unsigned fixingDays, Calendar* calendar, int date, int* fixing, int* value, QlError **e) { QlCallScope callbackScope(e);
*fixing = 0; *value = 0;
#if QL_HEX_VERSION >= 0x01440000
try {auto reset = FxResetConvention(fixingDays, calendar ? *arg(calendar) : Calendar()).reset(Date(date)); *fixing = reset.fixingDate().serialNumber(); *value = reset.valueDate().serialNumber();} catch (std::exception& er) {qlSetError(e, er.what());}
#else
(void)fixingDays; (void)calendar; (void)date; (void)fixing; (void)value;
qlUnsupportedVersion(e, "fxResetObservation", "1.44");
#endif
}
int qlFxResetConventionValueDate(unsigned fixingDays, Calendar* calendar, int date, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {return FxResetConvention(fixingDays, calendar ? *arg(calendar) : Calendar()).valueDate(Date(date)).serialNumber();} catch (std::exception& er) {return handleException<int>(e, er);}
#else
(void)fixingDays; (void)calendar; (void)date;
qlUnsupportedVersion(e, "fxResetValueDate", "1.44"); return 0;
#endif
}
void qlFreeFxResetPricer(QlFxResetPricer* o) {del(o);}
QlFxResetPricer* qlDiscountingFxResetPricer(Currency* constantCcy, Currency* resetCcy, QlYieldTermStructure* constantCurve, QlYieldTermStructure* resetCurve, QlQuote* spotFx, int spotIsResettablePerConstant, int spotFxSettleDate, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {return ret(new QlFxResetPricer(alloc(new DiscountingFxResetPricer(*arg(constantCcy), *arg(resetCcy), *arg(constantCurve), *arg(resetCurve), *arg(spotFx), spotIsResettablePerConstant, qlNullableDate(spotFxSettleDate)))));} catch (std::exception& er) {return handleException<QlFxResetPricer*>(e, er);}
#else
(void)constantCcy; (void)resetCcy; (void)constantCurve; (void)resetCurve; (void)spotFx; (void)spotIsResettablePerConstant; (void)spotFxSettleDate;
qlUnsupportedVersion(e, "discountingFxResetPricer", "1.44"); return nullptr;
#endif
}
double qlFxResetRate(QlFxResetPricer* o, int fixing, int value, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {return (*arg(o))->fxRate(FxReset(Date(fixing), Date(value)));} catch (std::exception& er) {return handleException<double>(e, er);}
#else
(void)o; (void)fixing; (void)value;
qlUnsupportedVersion(e, "fxResetRate", "1.44"); return 0;
#endif
}
void qlFreeFxResetCoupon(QlFxResetCoupon* o) {del(o);}
QlFloatingRateCoupon* qlFxResetCouponAsFloatingRateCoupon(QlFxResetCoupon* o) {
#if QL_HEX_VERSION >= 0x01440000
return ret(new QlFloatingRateCoupon(*arg(o)));
#else
(void)o; return nullptr;
#endif
}
void qlFreeFxResetNotionalExchange(QlFxResetNotionalExchange* o) {del(o);}
QlCashFlow* qlFxResetNotionalExchangeAsCashFlow(QlFxResetNotionalExchange* o) {
#if QL_HEX_VERSION >= 0x01440000
return ret(new QlCashFlow(*arg(o)));
#else
(void)o; return nullptr;
#endif
}
QlFxResetCoupon* qlFxResetCoupon(QlFloatingRateCoupon* underlying, double notional, int fixing, int value, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {return ret(new QlFxResetCoupon(alloc(new FxResetCoupon(*arg(underlying), notional, FxReset(Date(fixing), Date(value))))));} catch (std::exception& er) {return handleException<QlFxResetCoupon*>(e, er);}
#else
(void)underlying; (void)notional; (void)fixing; (void)value;
qlUnsupportedVersion(e, "fxResetCoupon", "1.44"); return nullptr;
#endif
}
QlFxResetNotionalExchange* qlFxResetNotionalExchange(int payment, double notional, int previousFixing, int previousValue, int currentFixing, int currentValue, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {optional<FxReset> previous, current; if (previousFixing) previous.emplace(Date(previousFixing), Date(previousValue)); if (currentFixing) current.emplace(Date(currentFixing), Date(currentValue)); return ret(new QlFxResetNotionalExchange(alloc(new FxResetNotionalExchange(Date(payment), notional, previous, current))));} catch (std::exception& er) {return handleException<QlFxResetNotionalExchange*>(e, er);}
#else
(void)payment; (void)notional; (void)previousFixing; (void)previousValue; (void)currentFixing; (void)currentValue;
qlUnsupportedVersion(e, "fxResetNotionalExchange", "1.44"); return nullptr;
#endif
}
void qlFxResetCouponSetFxResetPricer(QlFxResetCoupon* o, QlFxResetPricer* pricer, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {(*arg(o))->setFxResetPricer(*arg(pricer));} catch (std::exception& er) {qlSetError(e, er.what());}
#else
(void)o; (void)pricer;
qlUnsupportedVersion(e, "setFxResetPricer", "1.44");
#endif
}
void qlFxResetNotionalExchangeSetFxResetPricer(QlFxResetNotionalExchange* o, QlFxResetPricer* pricer, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {(*arg(o))->setFxResetPricer(*arg(pricer));} catch (std::exception& er) {qlSetError(e, er.what());}
#else
(void)o; (void)pricer;
qlUnsupportedVersion(e, "setFxResetPricer", "1.44");
#endif
}
void qlSetFxResetLegPricer(Leg* leg, QlFxResetPricer* pricer, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {QuantLib::setFxResetPricer(*arg(leg), *arg(pricer));} catch (std::exception& er) {qlSetError(e, er.what());}
#else
(void)leg; (void)pricer;
qlUnsupportedVersion(e, "setFxResetLegPricer", "1.44");
#endif
}
QlIborCoupon* qlStubIborCoupon(int paymentDate, double nominal, int startDate, int endDate, unsigned fixingDays, QlStubIndexSelection* selection, double gearing, double spread, int refPeriodStart, int refPeriodEnd, DayCounter* dayCounter, int inArrears, int exCouponDate, int fixingConvention, QlError **e) { QlCallScope callbackScope(e);
#if QL_HEX_VERSION >= 0x01440000
try {return ret(new QlIborCoupon(alloc(new StubIborCoupon(Date(paymentDate), nominal, Date(startDate), Date(endDate), fixingDays, qlStubSelection(selection), gearing, spread, qlNullableDate(refPeriodStart), qlNullableDate(refPeriodEnd), dayCounter ? *arg(dayCounter) : DayCounter(), inArrears, qlNullableDate(exCouponDate), (BusinessDayConvention)fixingConvention))));} catch (std::exception& er) {return handleException<QlIborCoupon*>(e, er);}
#else
(void)paymentDate; (void)nominal; (void)startDate; (void)endDate; (void)fixingDays; (void)selection; (void)gearing; (void)spread; (void)refPeriodStart; (void)refPeriodEnd; (void)dayCounter; (void)inArrears; (void)exCouponDate; (void)fixingConvention;
qlUnsupportedVersion(e, "stubIborCoupon", "1.44"); return nullptr;
#endif
}
double qlCouponNominal(QlCoupon* o, QlError **e) { QlCallScope callbackScope(e);
try {return (*arg(o))->nominal();} catch (std::exception& er) {return handleException<double>(e, er);}}
}
/* vim: set ft=cpp ff=unix ts=8 sts=2 sw=2 et: */