hasquant-0.6.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/softbarrieroption.hpp>
#include <ql/instruments/twoassetcorrelationoption.hpp>
#include <ql/instruments/writerextensibleoption.hpp>
#include <ql/instruments/forward.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/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/credit/cdsoption.hpp>
#include <ql/instruments/bonds/all.hpp>
#include <ql/cashflows/couponpricer.hpp>
#include <ql/pricingengines/bond/bondfunctions.hpp>
#include <ql/experimental/callablebonds/callablebond.hpp>
#include <ql/instruments/bonds/convertiblebonds.hpp>
#include <ql/cashflows/cashflows.hpp>
#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/overnightindexedcoupon.hpp>
#include <ql/cashflows/rangeaccrual.hpp>
#include <ql/cashflows/simplecashflow.hpp>
#include <ql/cashflows/cpicoupon.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/cashflows/equitycashflow.hpp>
#include <ql/indexes/equityindex.hpp>
#include <ql/instruments/inflationcapfloor.hpp>
#include <ql/instruments/cpicapfloor.hpp>
#include "qlaux.h"
using namespace QuantLib;
#include "qlInstrument.h"
#include "qlMisc.h"
#include <cstring>
#include <any>
#include <typeinfo>
#ifdef QLTRACK_ALLOCATIONS
template <> class ObjClassName<Leg*> {public: static void output(std::ostream& os) {os << "Leg";}};
template <> class ObjClassName<QlAdditionalResult*> {public: static void output(std::ostream& os) {os << "QlAdditionalResult";}};
#endif
// 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;
}
// ext::any is std::any in the Homebrew build and boost::any in the Docker build; both expose
// .type() returning a std::type_info-compatible name, so we classify by typeid equality rather
// than by a string name (which differs between the two).
//
// 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 ext::any &v) {
if (v.type() == typeid(double)) {
r.type = AdditionalResultDouble;
r.dval = ext::any_cast<double>(v);
} else if (v.type() == typeid(std::string)) {
r.type = AdditionalResultString;
r.sval = DUP(ext::any_cast<std::string>(v).c_str());
} else if (v.type() == typeid(std::vector<double>)) {
r.type = AdditionalResultDoubleVector;
const std::vector<double> &vec = ext::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 = DUP(v.type().name());
}
}
extern "C" {
double qlInstrumentNPV(QlInstrument *instr, char **e) {try {return (*arg(instr))->NPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlInstrumentSetPricingEngine(QlInstrument *instr, QlPricingEngine *eng, char **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, char **e) {
*out = 0;
*len = 0;
QlAdditionalResult *arr = 0;
unsigned n = 0;
try {
const std::map<std::string, ext::any> &res = (*arg(instr))->additionalResults();
if (res.empty()) return;
n = static_cast<unsigned>(res.size());
// Value-initialised (the trailing `()`): every field, including the pointers, starts at
// zero/null, so a not-yet-filled or half-filled entry is always safe to free -- this is what
// lets the catch below release partial work without tracking how far the loop got.
arr = alloc(new QlAdditionalResult[n]());
unsigned i = 0;
for (std::map<std::string, ext::any>::const_iterator it = res.begin(); it != res.end(); ++it, ++i) {
arr[i].key = DUP(it->first.c_str());
fillResult(arr[i], it->second);
}
*out = arr;
*len = n;
} catch (std::exception& er) {
qlFreeAdditionalResults(n, arr);
*e = DUP(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);
if (out[i].varr) {
TP2("deleting", out[i].varr);
delete[] out[i].varr;
TP2("deleted", out[i].varr);
}
}
TP2("deleting", out);
delete[] out;
TP2("deleted", out);
}
QlInstrument* qlCompositeInstrument(unsigned instrLen, QlInstrument **instrs, unsigned, double *coeff, char **e) {
CompositeInstrument *ci = 0;
try {ci = new CompositeInstrument();
for (unsigned i = 0; i < instrLen; ++i)
ci->add(*(instrs[i]), coeff[i]);
return ret(new QlInstrument(alloc(ci)));
} catch (std::exception& er) {delete ci; return handleException<QlInstrument*>(e, er);}}
double qlInstrumentErrorEstimate(QlInstrument* o, char **e) {try {return (*arg(o))->errorEstimate();} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlInstrumentIsExpired(QlInstrument* o, char **e) {try {return (*arg(o))->isExpired();} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlInstrumentValuationDate(QlInstrument* o, char **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)));}
QlStrikedTypePayoff* qlAssetOrNothingPayoff(int type, double strike, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **e) {try {return ret(new QlBasketPayoff(alloc(new MaxBasketPayoff(*arg(p)))));} catch (std::exception& er) {return handleException<QlBasketPayoff*>(e, er);}}
QlBasketPayoff* qlMinBasketPayoff(QlPayoff* p, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **e) {try {return ((*arg(o))->settlementDate()).serialNumber();} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlForwardSpotIncome(QlForward* o, QlYieldTermStructure* incomeDiscountCurve, char **e) {
try {return (*arg(o))->spotIncome(*arg(incomeDiscountCurve));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlForwardSpotValue(QlForward* o, char **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, char **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, char **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, char **e) {try {return (*arg(o))->cleanForwardPrice();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondForwardForwardPrice(QlBondForward* o, char **e) {try {return (*arg(o))->forwardPrice();} catch (std::exception& er) {return handleException<double>(e, er);}}
InterestRate* qlForwardRateAgreementForwardRate(QlForwardRateAgreement* o, char **e) {try {return ret(new InterestRate((*arg(o))->forwardRate()));} catch (std::exception& er) {return handleException<InterestRate*>(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, char **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, char **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 qlFxForwardFairForwardRate(QlFxForward* o, char **e) {try {return (*arg(o))->fairForwardRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFxForwardNpvSourceCurrency(QlFxForward* o, char **e) {try {return (*arg(o))->npvSourceCurrency();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFxForwardNpvTargetCurrency(QlFxForward* o, char **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);}
QlSwap* qlOvernightIndexedSwapAsSwap(QlOvernightIndexedSwap *o) {return ret(new QlSwap(*arg(o)));}
QlSwap* qlSwap1(unsigned legsLen, Leg** legs, unsigned payerLen, int *payer, char **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, char **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, char **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, char **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, char **e) {
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, char **e) {
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)))));
} 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, char **e) {
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)))));
} catch (std::exception& er) {return handleException<QlNonstandardSwap*>(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, char **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, char **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, char **e) {try {return (*arg(o))->fairSpread1();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFloatFloatSwapFairSpread2(QlFloatFloatSwap* o, char **e) {try {return (*arg(o))->fairSpread2();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlSwap* qlSwap(Leg* firstLeg, Leg* secondLeg, char **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, char **e) {try {return (*arg(o))->endDiscounts(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlSwapLeg(QlSwap* o, unsigned j, char **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, char **e) {try {return (*arg(o))->legBPS(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlSwapLegNPV(QlSwap* o, unsigned j, char **e) {try {return (*arg(o))->legNPV(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlSwapMaturityDate(QlSwap* o, char **e) {try {return qlNullableDate((*arg(o))->maturityDate());} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlSwapNpvDateDiscount(QlSwap* o, char **e) {try {return (*arg(o))->npvDateDiscount();} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlSwapStartDate(QlSwap* o, char **e) {try {return qlNullableDate((*arg(o))->startDate());} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlSwapStartDiscounts(QlSwap* o, unsigned j, char **e) {try {return (*arg(o))->startDiscounts(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFixedVsFloatingSwapFairRate(QlFixedVsFloatingSwap* o, char **e) {try {return (*arg(o))->fairRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFixedVsFloatingSwapFairSpread(QlFixedVsFloatingSwap* o, char **e) {try {return (*arg(o))->fairSpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlFixedVsFloatingSwapFixedLeg(QlFixedVsFloatingSwap* o, char **e) {try {return ret(new Leg((*arg(o))->fixedLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlFixedVsFloatingSwapFixedLegBPS(QlFixedVsFloatingSwap* o, char **e) {try {return (*arg(o))->fixedLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFixedVsFloatingSwapFixedLegNPV(QlFixedVsFloatingSwap* o, char **e) {try {return (*arg(o))->fixedLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlFixedVsFloatingSwapFloatingLeg(QlFixedVsFloatingSwap* o, char **e) {try {return ret(new Leg((*arg(o))->floatingLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlFixedVsFloatingSwapFloatingLegBPS(QlFixedVsFloatingSwap* o, char **e) {try {return (*arg(o))->floatingLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlFixedVsFloatingSwapFloatingLegNPV(QlFixedVsFloatingSwap* o, char **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, char **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, char **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, char **e) {try {return (*arg(o))->equityLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlEquityTotalReturnSwapInterestRateLegNPV(QlEquityTotalReturnSwap* o, char **e) {try {return (*arg(o))->interestRateLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlEquityTotalReturnSwapFairMargin(QlEquityTotalReturnSwap* o, char **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, char **e) {
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))));
} 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, char **e) {
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))));
} 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, char **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, char **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, char **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, char **e) {try {return (*arg(o))->inCcyLegBPS(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlConstNotionalCrossCurrencySwapInCcyLegNPV(QlConstNotionalCrossCurrencySwap* o, unsigned j, char **e) {try {return (*arg(o))->inCcyLegNPV(j);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlConstNotionalCrossCurrencySwapNpvDateDiscounts(QlConstNotionalCrossCurrencySwap* o, unsigned j, char **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, char **e) {
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))));
} catch (std::exception& er) {return handleException<QlConstNotionalCrossCurrencyBasisSwap*>(e, er);}}
double qlConstNotionalCrossCurrencyBasisSwapFairPaySpread(QlConstNotionalCrossCurrencyBasisSwap* o, char **e) {try {return (*arg(o))->fairPaySpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlConstNotionalCrossCurrencyBasisSwapFairRecSpread(QlConstNotionalCrossCurrencyBasisSwap* o, char **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, char **e) {
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))));
} catch (std::exception& er) {return handleException<QlConstNotionalCrossCurrencyFixedVsFloatingSwap*>(e, er);}}
double qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairRate(QlConstNotionalCrossCurrencyFixedVsFloatingSwap* o, char **e) {try {return (*arg(o))->fairRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlConstNotionalCrossCurrencyFixedVsFloatingSwapFairSpread(QlConstNotionalCrossCurrencyFixedVsFloatingSwap* o, char **e) {try {return (*arg(o))->fairSpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlAssetSwapBondLeg(QlAssetSwap* o, char **e) {try {return ret(new Leg((*arg(o))->bondLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlAssetSwapCleanPrice(QlAssetSwap* o, char **e) {try {return (*arg(o))->cleanPrice();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlAssetSwapFairCleanPrice(QlAssetSwap* o, char **e) {try {return (*arg(o))->fairCleanPrice();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlAssetSwapFairNonParRepayment(QlAssetSwap* o, char **e) {try {return (*arg(o))->fairNonParRepayment();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlAssetSwapFairSpread(QlAssetSwap* o, char **e) {try {return (*arg(o))->fairSpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlAssetSwapFloatingLeg(QlAssetSwap* o, char **e) {try {return ret(new Leg((*arg(o))->floatingLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlAssetSwapFloatingLegBPS(QlAssetSwap* o, char **e) {try {return (*arg(o))->floatingLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlAssetSwapFloatingLegNPV(QlAssetSwap* o, char **e) {try {return (*arg(o))->floatingLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlAssetSwapNonParRepayment(QlAssetSwap* o, char **e) {try {return (*arg(o))->nonParRepayment();} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlAssetSwapParSwap(QlAssetSwap* o, char **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, char **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, char **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, char **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, char **e) {try {return (*arg(o))->fairRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlYearOnYearInflationSwapFairSpread(QlYearOnYearInflationSwap* o, char **e) {try {return (*arg(o))->fairSpread();} 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, char **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, char **e) {try {return (*arg(o))->fairRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCPISwapFairSpread(QlCPISwap* o, char **e) {try {return (*arg(o))->fairSpread();} 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, char **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, char **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, char **e) {try {return (*arg(o))->fairFixedPayment();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlZeroCouponSwapFairFixedRate(QlZeroCouponSwap* o, DayCounter* dayCounter, char **e) {try {return (*arg(o))->fairFixedRate(*arg(dayCounter));} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlAssetSwapPayBondCoupon(QlAssetSwap* o, char **e) {try {return (*arg(o))->payBondCoupon();} catch (std::exception& er) {return handleException<int>(e, er);}}
Leg* qlBMASwapBmaLeg(QlBMASwap* o, char **e) {try {return ret(new Leg((*arg(o))->bmaLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlBMASwapBmaLegBPS(QlBMASwap* o, char **e) {try {return (*arg(o))->bmaLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBMASwapBmaLegNPV(QlBMASwap* o, char **e) {try {return (*arg(o))->bmaLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBMASwapFairLiborFraction(QlBMASwap* o, char **e) {try {return (*arg(o))->fairLiborFraction();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBMASwapFairLiborSpread(QlBMASwap* o, char **e) {try {return (*arg(o))->fairLiborSpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBMASwapLiborFraction(QlBMASwap* o, char **e) {try {return (*arg(o))->liborFraction();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlBMASwapLiborLeg(QlBMASwap* o, char **e) {try {return ret(new Leg((*arg(o))->liborLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlBMASwapLiborLegBPS(QlBMASwap* o, char **e) {try {return (*arg(o))->liborLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBMASwapLiborLegNPV(QlBMASwap* o, char **e) {try {return (*arg(o))->liborLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOvernightIndexedSwapFairRate(QlOvernightIndexedSwap* o, char **e) {try {return (*arg(o))->fairRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOvernightIndexedSwapFairSpread(QlOvernightIndexedSwap* o, char **e) {try {return (*arg(o))->fairSpread();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlOvernightIndexedSwapFixedLeg(QlOvernightIndexedSwap* o, char **e) {try {return ret(new Leg((*arg(o))->fixedLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlOvernightIndexedSwapFixedLegBPS(QlOvernightIndexedSwap* o, char **e) {try {return (*arg(o))->fixedLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOvernightIndexedSwapFixedLegNPV(QlOvernightIndexedSwap* o, char **e) {try {return (*arg(o))->fixedLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlOvernightIndexedSwapOvernightLeg(QlOvernightIndexedSwap* o, char **e) {try {return ret(new Leg((*arg(o))->overnightLeg()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlOvernightIndexedSwapOvernightLegBPS(QlOvernightIndexedSwap* o, char **e) {try {return (*arg(o))->overnightLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOvernightIndexedSwapOvernightLegNPV(QlOvernightIndexedSwap* o, char **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, char **e) {try {return ret(new QlClaim(alloc(new FaceValueAccrualClaim(*arg(referenceSecurity)))));} catch (std::exception& er) {return handleException<QlClaim*>(e, er);}}
QlClaim* qlFaceValueClaim(char **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, char **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, char **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, char **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, char **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, char **e) {try {return (*arg(o))->couponLegBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCreditDefaultSwapCouponLegNPV(QlCreditDefaultSwap* o, char **e) {try {return (*arg(o))->couponLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
Leg* qlCreditDefaultSwapCoupons(QlCreditDefaultSwap* o, char **e) {try {return alloc(new Leg((*arg(o))->coupons()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
double qlCreditDefaultSwapDefaultLegNPV(QlCreditDefaultSwap* o, char **e) {try {return (*arg(o))->defaultLegNPV();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCreditDefaultSwapFairUpfront(QlCreditDefaultSwap* o, char **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, char **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, char **e) {try {return (*arg(o))->upfrontBPS();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCreditDefaultSwapUpfrontNPV(QlCreditDefaultSwap* o, char **e) {try {return (*arg(o))->upfrontNPV();} 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 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, char **e) {try {return (*arg(o))->atmRate();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlCdsOption* qlCdsOption(QlCreditDefaultSwap* swap, QlExercise* exercise, int knocksOut, char **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, char **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, char **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, char **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, char **e) {
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 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, char **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, char **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);}}
// Basket is computed internally by QuantLib's calibration-basket algorithm (per CalibrationBasketType);
// *helpers is written before anything can throw so a mid-loop exception still leaves a safe, freeable array.
void qlNonstandardSwaptionCalibrationBasket(QlNonstandardSwaption* o, QlSwapIndex* swapBase, QlSwaptionVolatilityStructure* swaptionVol, int basketType, unsigned* len, QlBlackCalibrationHelper*** helpers, char **e) {
*len = 0; *helpers = nullptr;
unsigned n = 0;
QlBlackCalibrationHelper **hs = 0;
try {
std::vector<ext::shared_ptr<BlackCalibrationHelper>> basket = (*arg(o))->calibrationBasket(*arg(swapBase), (*arg(swaptionVol)).currentLink(), (BasketGeneratingEngine::CalibrationBasketType)basketType);
n = (unsigned)basket.size();
// Value-initialised, like qlInstrumentAdditionalResults above: a mid-loop exception leaves
// every not-yet-filled slot null, so the catch below can free exactly `n` slots regardless of
// how far the loop got.
hs = new QlBlackCalibrationHelper*[n]();
for (unsigned i = 0; i < n; ++i) hs[i] = ret(new QlBlackCalibrationHelper(alloc(basket[i])));
*helpers = hs;
*len = n;
} catch (std::exception& er) {
if (hs) { for (unsigned i = 0; i < n; ++i) delete hs[i]; delete[] hs; }
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, char **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);}}
// Same shape as qlNonstandardSwaptionCalibrationBasket above, retargeted to FloatFloatSwaption.
void qlFloatFloatSwaptionCalibrationBasket(QlFloatFloatSwaption* o, QlSwapIndex* swapBase, QlSwaptionVolatilityStructure* swaptionVol, int basketType, unsigned* len, QlBlackCalibrationHelper*** helpers, char **e) {
*len = 0; *helpers = nullptr;
unsigned n = 0;
QlBlackCalibrationHelper **hs = 0;
try {
std::vector<ext::shared_ptr<BlackCalibrationHelper>> basket = (*arg(o))->calibrationBasket(*arg(swapBase), (*arg(swaptionVol)).currentLink(), (BasketGeneratingEngine::CalibrationBasketType)basketType);
n = (unsigned)basket.size();
// Same idiom as qlNonstandardSwaptionCalibrationBasket above.
hs = new QlBlackCalibrationHelper*[n]();
for (unsigned i = 0; i < n; ++i) hs[i] = ret(new QlBlackCalibrationHelper(alloc(basket[i])));
*helpers = hs;
*len = n;
} catch (std::exception& er) {
if (hs) { for (unsigned i = 0; i < n; ++i) delete hs[i]; delete[] hs; }
handleException<int>(e, er);
}}
void qlFreeQuantoBarrierOption(QlQuantoBarrierOption *o) {del(o);}
QlOneAssetOption* qlQuantoBarrierOptionAsOneAssetOption(QlQuantoBarrierOption *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, char **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);}}
double qlBarrierOptionImpliedVolatility(QlBarrierOption* o, double price, QlGeneralizedBlackScholesProcess* process, unsigned dividendsLen, QlDividend** dividends, double accuracy, unsigned maxEvaluations, double minVol, double maxVol, char **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, char **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, char **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, char **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, char **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, char **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, char **e) {
try {return ret(new QlOneAssetOption(alloc(new SimpleChooserOption(Date(choosingDate), strike, *arg(exercise)))));
} catch (std::exception& er) {return handleException<QlOneAssetOption*>(e, er);}}
QlMultiAssetOption* qlTwoAssetCorrelationOption(int type, double strike1, double strike2, QlExercise* exercise, char **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, char **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* qlForwardVanillaOption(double moneyness, int resetDate, QlStrikedTypePayoff* payoff, QlExercise* exercise, char **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, char **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, char **e) {try {return (*arg(o))->delta1();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMargrabeOptionDelta2(QlMargrabeOption* o, char **e) {try {return (*arg(o))->delta2();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMargrabeOptionGamma1(QlMargrabeOption* o, char **e) {try {return (*arg(o))->gamma1();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMargrabeOptionGamma2(QlMargrabeOption* o, char **e) {try {return (*arg(o))->gamma2();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlMargrabeOption* qlMargrabeOption(int Q1, int Q2, QlExercise* x2, char **e) {try {return ret(new QlMargrabeOption(alloc(new MargrabeOption(Q1, Q2, (*arg(x2))))));} catch (std::exception& er) {return handleException<QlMargrabeOption*>(e, er);}}
double qlMultiAssetOptionDelta(QlMultiAssetOption* o, char **e) {try {return (*arg(o))->delta();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMultiAssetOptionDividendRho(QlMultiAssetOption* o, char **e) {try {return (*arg(o))->dividendRho();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMultiAssetOptionGamma(QlMultiAssetOption* o, char **e) {try {return (*arg(o))->gamma();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlMultiAssetOption* qlMultiAssetOption(QlPayoff* x0, QlExercise* x1, char **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, char **e) {try {return (*arg(o))->rho();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMultiAssetOptionTheta(QlMultiAssetOption* o, char **e) {try {return (*arg(o))->theta();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlMultiAssetOptionVega(QlMultiAssetOption* o, char **e) {try {return (*arg(o))->vega();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionDelta(QlOneAssetOption* o, char **e) {try {return (*arg(o))->delta();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionDeltaForward(QlOneAssetOption* o, char **e) {try {return (*arg(o))->deltaForward(); } catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionDividendRho(QlOneAssetOption* o, char **e) {try {return (*arg(o))->dividendRho();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionElasticity(QlOneAssetOption* o, char **e) {try {return (*arg(o))->elasticity();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionGamma(QlOneAssetOption* o, char **e) {try {return (*arg(o))->gamma();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionItmCashProbability(QlOneAssetOption* o, char **e) {try {return (*arg(o))->itmCashProbability();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlOneAssetOption* qlOneAssetOption(QlPayoff* x0, QlExercise* x1, char **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, char **e) {try {return (*arg(o))->rho();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionStrikeSensitivity(QlOneAssetOption* o, char **e) {try {return (*arg(o))->strikeSensitivity();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionTheta(QlOneAssetOption* o, char **e) {try {return (*arg(o))->theta();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionThetaPerDay(QlOneAssetOption* o, char **e) {try {return (*arg(o))->thetaPerDay();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlOneAssetOptionVega(QlOneAssetOption* o, char **e) {try {return (*arg(o))->vega();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoBarrierOptionQlambda(QlQuantoBarrierOption* o, char **e) {try {return (*arg(o))->qlambda();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoBarrierOptionQrho(QlQuantoBarrierOption* o, char **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, char **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, char **e) {try {return (*arg(o))->qvega();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoForwardVanillaOptionQlambda(QlQuantoForwardVanillaOption* o, char **e) {try {return (*arg(o))->qlambda();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoForwardVanillaOptionQrho(QlQuantoForwardVanillaOption* o, char **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, char **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, char **e) {try {return (*arg(o))->qvega();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoVanillaOptionQlambda(QlQuantoVanillaOption* o, char **e) {try {return (*arg(o))->qlambda();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlQuantoVanillaOptionQrho(QlQuantoVanillaOption* o, char **e) {try {return (*arg(o))->qrho();} catch (std::exception& er) {return handleException<double>(e, er);}}
QlQuantoVanillaOption* qlQuantoVanillaOption(QlStrikedTypePayoff* x0, QlExercise* x1, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **e) {
try {return ret(new QlOneAssetOption(alloc(new ContinuousFloatingLookbackOption(currentMinmax, *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, char **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, char **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, char **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, char **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, char **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);}}
QlBond *qlBond1(unsigned settlDays, Calendar *calendar, double faceAmount, int maturityDate, int issueDate, Leg *cashFlows, char **e) {
try {return ret(new QlBond(alloc(new Bond(settlDays, *arg(calendar), faceAmount, qlNullableDate(maturityDate), qlNullableDate(issueDate), *arg(cashFlows)))));
} catch (std::exception& er) {return handleException<QlBond *>(e, er);}}
int qlBondMaturityDate(QlBond *bond, char **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, char **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, char **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);}}
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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **e) {
try {const std::vector<Real>& ns = sinkingNotionals(Period(lengthLen, (TimeUnit)lengthUnit), (Frequency)frequency, couponRate, initialNotional);
*len = ns.size(); *out = qlAllocateDoubles(*len); std::copy(ns.begin(), ns.end(), *out);
} catch (std::exception& er) {(void)handleException<double*>(e, er);}}
void qlBondNotionals(QlBond* o, unsigned *len, double **ns, char **e) {
try {const std::vector<double>& notionals = (*arg(o))->notionals(); *len = notionals.size(); *ns = qlAllocateDoubles(*len); std::copy(notionals.begin(), notionals.end(), *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, char **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, char **e) {try {return (*arg(o))->accruedAmount(Date(d));} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondCleanPrice1(QlBond* o, double yield, DayCounter* dc, int comp, int freq, int settlementDate, char **e) {
try {return (*arg(o))->cleanPrice(yield, *arg(dc), (Compounding)comp, (Frequency)freq, Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondDirtyPrice1(QlBond* o, double yield, DayCounter* dc, int comp, int freq, int settlementDate, char **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, char **e) {try {return qlNullableDate((*arg(o))->nextCashFlowDate(Date(d)));} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlBondNextCouponRate(QlBond* o, int d, char **e) {try {return (*arg(o))->nextCouponRate(Date(d));} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondNotional(QlBond* o, int d, char **e) {try {return (*arg(o))->notional(Date(d));} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlBondPreviousCashFlowDate(QlBond* o, int d, char **e) {try {return qlNullableDate((*arg(o))->previousCashFlowDate(Date(d)));} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlBondPreviousCouponRate(QlBond* o, int d, char **e) {try {return (*arg(o))->previousCouponRate(Date(d));} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondSettlementValue1(QlBond* o, double cleanPrice, char **e) {try {return (*arg(o))->settlementValue(cleanPrice);} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondSettlementValue(QlBond* o, char **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, char **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, char **e) {try {return (*arg(o))->isTradable(Date(d));} catch (std::exception& er) {return handleException<int>(e, er);}}
Leg* qlBondCashflows(QlBond* o, char **e) {try {return ret(new Leg((*arg(o))->cashflows()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
Leg* qlBondRedemptions(QlBond* o, char **e) {try {return ret(new Leg((*arg(o))->redemptions()));} catch (std::exception& er) {return handleException<Leg*>(e, er);}}
int qlBondSettlementDate(QlBond* o, int d, char **e) {try {return ((*arg(o))->settlementDate(Date(d))).serialNumber();} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlBondStartDate(QlBond* o, char **e) {try {return ((*arg(o))->startDate()).serialNumber();} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlBondFunctionsAccrualDays(QlBond* bond, int settlementDate, char **e) {
try {return BondFunctions::accrualDays(**arg(bond), Date(settlementDate));
} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlBondFunctionsAccrualEndDate(QlBond* bond, int settlementDate, char **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, char **e) {
try {return BondFunctions::accrualPeriod(**arg(bond), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlBondFunctionsAccrualStartDate(QlBond* bond, int settlementDate, char **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, char **e) {
try {return BondFunctions::accruedDays(**arg(bond), Date(settlementDate));
} catch (std::exception& er) {return handleException<int>(e, er);}}
double qlBondFunctionsAccruedPeriod(QlBond* bond, int settlementDate, char **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, char **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 qlBondFunctionsBasisPointValue1(QlBond* bond, double yield, DayCounter* dayCounter, int compounding, int frequency, int settlementDate, char **e) {
try {return BondFunctions::basisPointValue(**arg(bond), yield, *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsBasisPointValue(QlBond* bond, InterestRate* yield, int settlementDate, char **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, char **e) {
try {return BondFunctions::bps(**arg(bond), *arg(yield), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsBps2(QlBond* bond, double yield, DayCounter* dayCounter, int compounding, int frequency, int settlementDate, char **e) {
try {return BondFunctions::bps(**arg(bond), yield, *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsBps(QlBond* bond, QlYieldTermStructure* discountCurve, int settlementDate, char **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, char **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, char **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, char **e) {
try {return BondFunctions::cleanPrice(**arg(bond), *arg(yield), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsConvexity1(QlBond* bond, double yield, DayCounter* dayCounter, int compounding, int frequency, int settlementDate, char **e) {
try {return BondFunctions::convexity(**arg(bond), yield, *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsConvexity(QlBond* bond, InterestRate* yield, int settlementDate, char **e) {
try {return BondFunctions::convexity(**arg(bond), *arg(yield), Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsDuration1(QlBond* bond, double yield, DayCounter* dayCounter, int compounding, int frequency, int type, int settlementDate, char **e) {
try {return BondFunctions::duration(**arg(bond), yield, *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, (Duration::Type)type, Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsDuration(QlBond* bond, InterestRate* yield, int type, int settlementDate, char **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, char **e) {
try {return BondFunctions::nextCashFlowAmount(**arg(bond), Date(refDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsPreviousCashFlowAmount(QlBond* bond, int refDate, char **e) {
try {return BondFunctions::previousCashFlowAmount(**arg(bond), Date(refDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlBondFunctionsReferencePeriodEnd(QlBond* bond, int settlementDate, char **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, char **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, char **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 qlBondFunctionsYieldValueBasisPoint1(QlBond* bond, double yield, DayCounter* dayCounter, int compounding, int frequency, int settlementDate, char **e) {
try {return BondFunctions::yieldValueBasisPoint(**arg(bond), yield, *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, Date(settlementDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondFunctionsYieldValueBasisPoint(QlBond* bond, InterestRate* yield, int settlementDate, char **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, char **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, char **e) {try {return (*arg(o))->cleanPrice();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlBondDirtyPrice(QlBond* o, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **e) {
Leg *leg = 0;
try {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);
} catch (std::exception& er) {return handleException(e, er, leg);}}
int qlLegStartDate(Leg *leg, char **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, char **e) {
try {const Leg &l = *arg(leg);
Leg::const_iterator i = CashFlows::nextCashFlow(l,
includeSettlementDateFlows, qlNullableDate(settlementDate));
return new Leg(i, l.end());
} catch (std::exception& er) {return handleException<Leg *>(e, er);}}
Leg *qlPreviousCashFlows(Leg *leg, int includeSettlementDateFlows, int settlementDate, char **e) {
try {const Leg &l = *arg(leg);
Leg::const_reverse_iterator i = CashFlows::previousCashFlow(l,
includeSettlementDateFlows, qlNullableDate(settlementDate));
return new Leg(l.begin(), i.base());
} catch (std::exception& er) {return handleException<Leg *>(e, er);}}
void qlLegCashFlows(Leg *leg, int includeSettlementDateFlows, int settlementDate,
unsigned *al, double **amount, unsigned *dl, int **date, unsigned *hl, int **hasOccurred, char **e) {
*amount = 0; *date = 0; *hasOccurred = 0;
try {const Leg& l = *arg(leg); *amount = qlAllocateDoubles(l.size()); *date = qlAllocateInts(l.size()); *hasOccurred = qlAllocateInts(l.size());
for (unsigned i = 0; i < l.size(); ++i) {
(*amount)[i] = l[i]->amount();
(*date)[i] = l[i]->date().serialNumber();
(*hasOccurred)[i] = l[i]->hasOccurred(qlNullableDate(settlementDate), qlOptBool(includeSettlementDateFlows));
}
*al = l.size(); *dl = l.size(); *hl = l.size();
} catch (std::exception& er) {qlFreeDoubles(*amount); qlFreeInts(*date); qlFreeInts(*hasOccurred); *e = DUP(er.what());}}
double qlCashFlowsDuration(Leg* leg, InterestRate* yield, int type, int includeSettlementDateFlows, int settlementDate, int npvDate, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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 qlCashFlowsBasisPointValue1(Leg* leg, double yield, DayCounter* dayCounter, int compounding, int frequency, int includeSettlementDateFlows, int settlementDate, int npvDate, char **e) {
try {return CashFlows::basisPointValue(*arg(leg), yield, *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsBasisPointValue(Leg* leg, InterestRate* yield, int includeSettlementDateFlows, int settlementDate, int npvDate, char **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, char **e) {
try {return CashFlows::bps(*arg(leg), *arg(yield), includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsBps2(Leg* leg, double yield, DayCounter* dayCounter, int compounding, int frequency, int includeSettlementDateFlows, int settlementDate, int npvDate, char **e) {
try {return CashFlows::bps(*arg(leg), yield, *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, 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, char **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 qlCashFlowsConvexity1(Leg* leg, double yield, DayCounter* dayCounter, int compounding, int frequency, int includeSettlementDateFlows, int settlementDate, int npvDate, char **e) {
try {return CashFlows::convexity(*arg(leg), yield, *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, 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, char **e) {
try {return CashFlows::convexity(*arg(leg), *arg(yield), includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsDuration1(Leg* leg, double yield, DayCounter* dayCounter, int compounding, int frequency, int type, int includeSettlementDateFlows, int settlementDate, int npvDate, char **e) {
try {return CashFlows::duration(*arg(leg), yield, *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, (Duration::Type)type, includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
int qlCashFlowsIsExpired(Leg* leg, int includeSettlementDateFlows, int settlementDate, char **e) {
try {return CashFlows::isExpired(*arg(leg), includeSettlementDateFlows, qlNullableDate(settlementDate));
} catch (std::exception& er) {return handleException<int>(e, er);}}
int qlCashFlowsMaturityDate(Leg* leg, char **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, char **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, char **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, char **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, char **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, char **e) {
try {return CashFlows::npv(*arg(leg), *arg(yield), includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsNpv2(Leg* leg, double yield, DayCounter* dayCounter, int compounding, int frequency, int includeSettlementDateFlows, int settlementDate, int npvDate, char **e) {
try {return CashFlows::npv(*arg(leg), yield, *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, 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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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 qlCashFlowsYieldValueBasisPoint1(Leg* leg, double yield, DayCounter* dayCounter, int compounding, int frequency, int includeSettlementDateFlows, int settlementDate, int npvDate, char **e) {
try {return CashFlows::yieldValueBasisPoint(*arg(leg), yield, *arg(dayCounter), (Compounding)compounding, (Frequency)frequency, includeSettlementDateFlows, qlNullableDate(settlementDate), qlNullableDate(npvDate));
} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCashFlowsYieldValueBasisPoint(Leg* leg, InterestRate* yield, int includeSettlementDateFlows, int settlementDate, int npvDate, char **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, char **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, char **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, char **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, char **e) {
*len = 0; *days = 0;
try {*days = qlAllocateInts(o->size()); *len = o->size();
for (unsigned i = 0; i < o->size(); ++i)
(*days)[i] = ((*o)[i]->accrualStartDate()).serialNumber();
} catch (std::exception& er) {
qlFreeInts(*days); *days = 0; *len = 0;
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, char **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, char **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, char **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, char **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, char **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, char **e) {
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))));
} 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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **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, char **e) {
try {return setCouponPricer(*arg(leg), *arg(pricer));} catch (std::exception& er) {(void)handleException<int>(e, er);}}
void qlFreeZeroInflationCashFlow(QlZeroInflationCashFlow *o) {del(o);}
QlZeroInflationCashFlow* qlZeroInflationCashFlow(double notional, QlZeroInflationIndex* index, int observationInterpolation, int startDate, int endDate, int obsLagLen, int obsLagUnit, int paymentDate, int growthOnly, char **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);}}
double qlZeroInflationCashFlowAmount(QlZeroInflationCashFlow* o, char **e) {try {return (*arg(o))->amount();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlZeroInflationCashFlowBaseFixing(QlZeroInflationCashFlow* o, char **e) {try {return (*arg(o))->baseFixing();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlZeroInflationCashFlowIndexFixing(QlZeroInflationCashFlow* o, char **e) {try {return (*arg(o))->indexFixing();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeCPICashFlow(QlCPICashFlow *o) {del(o);}
QlCPICashFlow* qlCPICashFlow(double notional, QlZeroInflationIndex* index, int baseDate, double baseFixing, int observationDate, int obsLagLen, int obsLagUnit, int interpolation, int paymentDate, int growthOnly, char **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);}}
double qlCPICashFlowAmount(QlCPICashFlow* o, char **e) {try {return (*arg(o))->amount();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCPICashFlowBaseFixing(QlCPICashFlow* o, char **e) {try {return (*arg(o))->baseFixing();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlCPICashFlowIndexFixing(QlCPICashFlow* o, char **e) {try {return (*arg(o))->indexFixing();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlFreeEquityCashFlow(QlEquityCashFlow *o) {del(o);}
QlEquityCashFlow* qlEquityCashFlow(double notional, QlEquityIndex* index, int baseDate, int fixingDate, int paymentDate, int growthOnly, char **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);}}
double qlEquityCashFlowAmount(QlEquityCashFlow* o, char **e) {try {return (*arg(o))->amount();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlEquityCashFlowBaseFixing(QlEquityCashFlow* o, char **e) {try {return (*arg(o))->baseFixing();} catch (std::exception& er) {return handleException<double>(e, er);}}
double qlEquityCashFlowIndexFixing(QlEquityCashFlow* o, char **e) {try {return (*arg(o))->indexFixing();} catch (std::exception& er) {return handleException<double>(e, er);}}
void qlEquityCashFlowSetPricer(QlEquityCashFlow* o, QlEquityCashFlowPricer* pricer, char **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, char **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, char **e) {
try {setCouponPricer(*arg(leg), *arg(pricer));
} catch (std::exception& er) {(void)handleException<int>(e, er);}}
CouponLeg* qlLegToCouponLeg(Leg *o, char **e) {
CouponLeg *cl = 0;
try {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);
} catch (std::exception& er) {return handleException(e, er, cl);}}
QlFloatingRateCouponPricer *qlBlackIborCouponPricer(QlOptionletVolatilityStructure *vol, int timingAdjustment, QlQuote *correlation, int useIndexedCoupon, char **e) {
try {Handle<Quote> corr = qlNullableHandleOr(correlation, [] { return shared_ptr<Quote>(new SimpleQuote(1.0)); });
return ret(new QlFloatingRateCouponPricer(new BlackIborCouponPricer(*arg(vol), (BlackIborCouponPricer::TimingAdjustment)timingAdjustment, corr, qlOptBool(useIndexedCoupon))));
} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer *>(e, er);}}
QlFloatingRateCouponPricer* qlAnalyticHaganPricer(QlSwaptionVolatilityStructure* swaptionVol, int modelOfYieldCurve, QlQuote* meanReversion, char **e) {
try {return ret(new QlFloatingRateCouponPricer(alloc(new AnalyticHaganPricer(*arg(swaptionVol), (GFunctionFactory::YieldCurveModel)modelOfYieldCurve, *arg(meanReversion)))));
} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer*>(e, er);}}
QlFloatingRateCouponPricer* qlNumericHaganPricer(QlSwaptionVolatilityStructure* swaptionVol, int modelOfYieldCurve, QlQuote* meanReversion, double lowerLimit, double upperLimit, double precision, double hardUpperLimit, char **e) {
try {return ret(new QlFloatingRateCouponPricer(alloc(new NumericHaganPricer(*arg(swaptionVol), (GFunctionFactory::YieldCurveModel)modelOfYieldCurve, *arg(meanReversion), lowerLimit, upperLimit, precision, hardUpperLimit))));
} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer*>(e, er);}}
QlFloatingRateCouponPricer* qlLinearTsrPricer(QlSwaptionVolatilityStructure* swaptionVol, QlQuote* meanReversion, QlYieldTermStructure* couponDiscountCurve, int strategy, double param, int haveBounds, double lowerBound, double upperBound, char **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 QlFloatingRateCouponPricer(alloc(new LinearTsrPricer(*arg(swaptionVol), *arg(meanReversion),
qlNullableHandle(couponDiscountCurve), settings))));
} catch (std::exception& er) {return handleException<QlFloatingRateCouponPricer*>(e, er);}}
QlFloatingRateCouponPricer* qlRangeAccrualPricerByBgm(double correlation, QlSmileSection* smilesOnExpiry, QlSmileSection* smilesOnPayment, int withSmile, int byCallSpread, char **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 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, char **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, char **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, char **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/EnergyCommodity bind no constructor -- both are abstract-here (Commodity is never
// constructed directly upstream; EnergyCommodity::quantity() is pure virtual). They're reachable
// only as upcast targets once a Stage-6 leaf (EnergyFuture, EnergyVanillaSwap, EnergyBasisSwap)
// exists. secondaryCosts()/commodityType() are plain, never-mutated echoes of each class's own
// constructor argument -- not bound, per CLAUDE.md's trivial-getter rule.
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 getters generalized over any leaf (Stage 6). Neither can throw: both
are plain reads of (or, for addPricingError, a push_back onto) already-computed mutable state. */
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, char **e) {
*len = 0; *len2 = 0; *len3 = 0; *keys = 0; *amounts = 0; *currencies = 0;
unsigned n = 0;
char **ks = 0;
double *am = 0;
Currency **cs = 0;
try {
const SecondaryCostAmounts &m = (*arg(o))->secondaryCostAmounts();
n = (unsigned)m.size();
// Value-initialised, like qlInstrumentAdditionalResults above: a mid-loop exception leaves
// every not-yet-filled slot null, so the catch below can free exactly `n` slots regardless of
// how far the loop got.
ks = new char*[n]();
am = qlAllocateDoubles(n);
cs = new Currency*[n]();
unsigned i = 0;
for (SecondaryCostAmounts::const_iterator it = m.begin(); it != m.end(); ++it, ++i) {
ks[i] = DUP(it->first.c_str());
am[i] = it->second.value();
cs[i] = ret(new Currency(it->second.currency()));
}
*keys = ks; *amounts = am; *currencies = cs;
*len = n; *len2 = n; *len3 = n;
} catch (std::exception& er) {
if (ks) { for (unsigned i = 0; i < n; ++i) qlFreeString(ks[i]); delete[] ks; }
delete[] am;
if (cs) { for (unsigned i = 0; i < n; ++i) delete cs[i]; delete[] cs; }
handleException<int>(e, er);
}
}
void qlCommodityPricingErrors(QlCommodity *o, unsigned *len, int **levels,
unsigned *len2, char ***errors, unsigned *len3, char ***details, char **e) {
*len = 0; *len2 = 0; *len3 = 0; *levels = 0; *errors = 0; *details = 0;
unsigned n = 0;
int *lv = 0;
char **errs2 = 0, **dets = 0;
try {
const PricingErrors &errs = (*arg(o))->pricingErrors();
n = (unsigned)errs.size();
lv = qlAllocateInts(n);
// Value-initialised, like qlInstrumentAdditionalResults above: a mid-loop exception leaves
// every not-yet-filled slot null, so the catch below can free exactly `n` slots regardless of
// how far the loop got.
errs2 = new char*[n]();
dets = new char*[n]();
for (unsigned i = 0; i < n; ++i) {
lv[i] = errs[i].errorLevel;
errs2[i] = DUP(errs[i].error.c_str());
dets[i] = DUP(errs[i].detail.c_str());
}
*levels = lv; *errors = errs2; *details = dets;
*len = n; *len2 = n; *len3 = n;
} catch (std::exception& er) {
delete[] lv;
if (errs2) { for (unsigned i = 0; i < n; ++i) qlFreeString(errs2[i]); delete[] errs2; }
if (dets) { for (unsigned i = 0; i < n; ++i) qlFreeString(dets[i]); delete[] dets; }
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, char **e) {
*outCt = 0; *outUom = 0;
CommodityType *ct = 0;
try {
Quantity q = (*arg(o))->quantity();
ct = ret(new CommodityType(q.commodityType()));
UnitOfMeasure *uom = ret(new UnitOfMeasure(q.unitOfMeasure()));
*outCt = ct; *outUom = uom;
return q.amount();
} catch (std::exception& er) {
delete ct;
return handleException<double>(e, er);
}
}
/* EnergyFuture -- tradePrice()/index() are plain, never-mutated echoes of this constructor's own
arguments (energyfuture.hpp's inline getters each just `return foo_;`) -- not bound, per
CLAUDE.md's trivial-getter rule (the same call Stage 4 made for CommodityIndex's own
constructor-echo getters). quantity() is bound once, generically, above. */
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,
char **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, char **e) {
*len = 0; *len2 = 0; *len3 = 0; *len4 = 0; *len5 = 0; *len6 = 0;
*dates = 0; *quantityAmounts = 0; *payLegPrices = 0; *receiveLegPrices = 0; *riskDeltas = 0; *unrealized = 0;
int *ds = 0, *ur = 0;
double *qa = 0, *plp = 0, *rlp = 0, *rd = 0;
try {
const EnergyDailyPositions &m = (*arg(o))->dailyPositions();
unsigned n = (unsigned)m.size();
ds = qlAllocateInts(n);
qa = qlAllocateDoubles(n);
plp = qlAllocateDoubles(n);
rlp = qlAllocateDoubles(n);
rd = qlAllocateDoubles(n);
ur = qlAllocateInts(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;
}
*dates = ds; *quantityAmounts = qa; *payLegPrices = plp; *receiveLegPrices = rlp; *riskDeltas = rd; *unrealized = ur;
*len = n; *len2 = n; *len3 = n; *len4 = n; *len5 = n; *len6 = n;
} catch (std::exception& er) {
delete[] ds; delete[] qa; delete[] plp; delete[] rlp; delete[] rd; delete[] ur;
handleException<int>(e, er);
}
}
void qlEnergySwapPaymentCashFlows(QlEnergySwap *o, unsigned *len, QlCommodityCashFlow ***out, char **e) {
*len = 0; *out = 0;
unsigned n = 0;
QlCommodityCashFlow **cs = 0;
try {
const CommodityCashFlows &m = (*arg(o))->paymentCashFlows();
n = (unsigned)m.size();
// Value-initialised, like qlInstrumentAdditionalResults above: a mid-loop exception leaves
// every not-yet-filled slot null, so the catch below can free exactly `n` slots regardless of
// how far the loop got.
cs = new QlCommodityCashFlow*[n]();
unsigned i = 0;
for (CommodityCashFlows::const_iterator it = m.begin(); it != m.end(); ++it, ++i)
cs[i] = ret(new QlCommodityCashFlow(alloc(it->second)));
*out = cs;
*len = n;
} catch (std::exception& er) {
if (cs) { for (unsigned i = 0; i < n; ++i) delete cs[i]; delete[] cs; }
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,
char **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,
char **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 -- char **e
guards that, not the upstream call. */
void qlFreeCommodityCashFlow(QlCommodityCashFlow *o) {del(o);}
int qlCommodityCashFlowDate(QlCommodityCashFlow *o) {return (*arg(o))->date().serialNumber();}
double qlCommodityCashFlowDiscountedAmount(QlCommodityCashFlow *o, Currency **outCcy, char **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, char **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, char **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, char **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();}
/* CommodityPricingHelper::createPricingPeriods -- the one static method worth binding (the other
three -- calculateFxConversionFactor/calculateUomConversionFactor/calculateUnitCost -- duplicate
logic already reachable via lookupUomConversion/lookupExchangeRate (Stage 2) and are skipped per
minimalism, per the plan). */
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,
char **e) {
*len = 0; *len2 = 0; *len3 = 0; *len4 = 0; *len5 = 0; *len6 = 0;
*ppStartDates = 0; *ppEndDates = 0; *ppPaymentDates = 0; *ppTypes = 0; *ppUoms = 0; *ppAmounts = 0;
unsigned n = 0;
int *starts = 0, *ends = 0, *pays = 0;
CommodityType **types = 0;
UnitOfMeasure **uoms = 0;
double *amounts = 0;
try {
PricingPeriods pps;
CommodityPricingHelper::createPricingPeriods(Date(startDate), Date(endDate),
Quantity(*arg(qCt), *arg(qUom), qAmount),
(EnergyCommodity::DeliverySchedule)deliverySchedule,
(EnergyCommodity::QuantityPeriodicity)qtyPeriodicity,
*arg(paymentTerm), pps);
n = (unsigned)pps.size();
starts = qlAllocateInts(n); ends = qlAllocateInts(n); pays = qlAllocateInts(n);
amounts = qlAllocateDoubles(n);
// Value-initialised, like qlInstrumentAdditionalResults above: a mid-loop exception leaves
// every not-yet-filled slot null, so the catch below can free exactly `n` slots regardless of
// how far the loop got.
types = new CommodityType*[n]();
uoms = new UnitOfMeasure*[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();
}
*ppStartDates = starts; *ppEndDates = ends; *ppPaymentDates = pays;
*ppTypes = types; *ppUoms = uoms; *ppAmounts = amounts;
*len = n; *len2 = n; *len3 = n; *len4 = n; *len5 = n; *len6 = n;
} catch (std::exception& er) {
delete[] starts; delete[] ends; delete[] pays; delete[] amounts;
if (types) { for (unsigned i = 0; i < n; ++i) delete types[i]; delete[] types; }
if (uoms) { for (unsigned i = 0; i < n; ++i) delete uoms[i]; delete[] uoms; }
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, char **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, char **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, char **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, char **e) {
try {return (*arg(o))->atmRate(handleRef(arg(discountCurve)));
} catch (std::exception& er) {return handleException<double>(e, er);}}
QlYoYInflationCapFloor *qlYoYInflationCapFloorOptionlet(QlYoYInflationCapFloor *o, unsigned n, char **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,
char **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);}}
}
/* vim: set ft=cpp ff=unix ts=8 sts=2 sw=2 et: */