本文整理汇总了C++中QL_FAIL函数的典型用法代码示例。如果您正苦于以下问题:C++ QL_FAIL函数的具体用法?C++ QL_FAIL怎么用?C++ QL_FAIL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QL_FAIL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
void BarrierOption::arguments::validate() const {
OneAssetOption::arguments::validate();
switch (barrierType) {
case Barrier::DownIn:
case Barrier::UpIn:
case Barrier::DownOut:
case Barrier::UpOut:
break;
default:
QL_FAIL("unknown type");
}
QL_REQUIRE(barrier != Null<Real>(), "no barrier given");
QL_REQUIRE(rebate != Null<Real>(), "no rebate given");
}
示例2: underlyingPriceDate
// gets a price that can include an arbitrary number of basis curves
inline Real CommodityCurve::price(
const Date& d,
const boost::shared_ptr<ExchangeContracts>& exchangeContracts,
Integer nearbyOffset) const {
Date date = nearbyOffset > 0 ?
underlyingPriceDate(d, exchangeContracts, nearbyOffset) : d;
Time t = timeFromReference(date);
Real priceValue = 0;
try {
priceValue = priceImpl(t);
} catch (const std::exception& e) {
QL_FAIL("error retrieving price for curve [" << name() << "]: "
<< e.what());
}
return priceValue + basisOfPriceImpl(t);
}
示例3: cap_floor
std::vector<Real> cap_floor(Date evaluationDate,
CapFloor::Type type,
Real strike,
Real nominal,
Schedule schedule,
Natural fixingDays,
BusinessDayConvention convention,
boost::shared_ptr<IborIndex> index,
boost::shared_ptr<YieldTermStructure> termStructure,
Volatility volatility) {
Date todaysDate = evaluationDate;
Settings::instance().evaluationDate() = todaysDate;
std::vector<Real> nominals = std::vector<Real>(1, nominal);
/*Make Leg*/
Leg leg = IborLeg(schedule, index)
.withNotionals(nominals)
.withPaymentDayCounter(index->dayCounter())
.withPaymentAdjustment(convention)
.withFixingDays(fixingDays);
/*Make Engine*/
Handle<Quote> vol(boost::shared_ptr<Quote>(new SimpleQuote(volatility)));
boost::shared_ptr<PricingEngine> engine =
boost::shared_ptr<PricingEngine>(new BlackCapFloorEngine(Handle<YieldTermStructure>(termStructure), vol));
/*Pricing*/
boost::shared_ptr<CapFloor> testProduct;
switch (type) {
case CapFloor::Cap:
testProduct = boost::shared_ptr<CapFloor>(new Cap(leg, std::vector<Rate>(1, strike)));
break;
case CapFloor::Floor:
testProduct = boost::shared_ptr<CapFloor>(new Floor(leg, std::vector<Rate>(1, strike)));
break;
default:
QL_FAIL("unknown cap/floor type");
}
testProduct->setPricingEngine(engine);
std::vector<Real> rst;
rst.push_back(testProduct->NPV());
return rst;
}
示例4: switch
Date Date::advance(const Date& date, Integer n, TimeUnit units) {
switch (units) {
case Days:
return date + n;
case Weeks:
return date + 7*n;
case Months: {
Day d = date.dayOfMonth();
Integer m = Integer(date.month())+n;
Year y = date.year();
while (m > 12) {
m -= 12;
y += 1;
}
while (m < 1) {
m += 12;
y -= 1;
}
QL_ENSURE(y >= 1900 && y <= 2199,
"year " << y << " out of bounds. "
<< "It must be in [1901,2199]");
Integer length = monthLength(Month(m), isLeap(y));
if (d > length)
d = length;
return Date(d, Month(m), y);
}
case Years: {
Day d = date.dayOfMonth();
Month m = date.month();
Year y = date.year()+n;
QL_ENSURE(y >= 1900 && y <= 2199,
"year " << y << " out of bounds. "
<< "It must be in [1901,2199]");
if (d == 29 && m == February && !isLeap(y))
d = 28;
return Date(d,m,y);
}
default:
QL_FAIL("undefined time units");
}
}
示例5: if
Decimal operator/(const Money& m1, const Money& m2) {
if (m1.currency() == m2.currency()) {
return m1.value()/m2.value();
} else if (Money::conversionType == Money::BaseCurrencyConversion) {
Money tmp1 = m1;
convertToBase(tmp1);
Money tmp2 = m2;
convertToBase(tmp2);
return tmp1/tmp2;
} else if (Money::conversionType == Money::AutomatedConversion) {
Money tmp = m2;
convertTo(tmp, m1.currency());
return m1/tmp;
} else {
QL_FAIL("currency mismatch and no conversion specified");
}
}
示例6: close_enough
bool close_enough(const Money& m1, const Money& m2, Size n) {
if (m1.currency() == m2.currency()) {
return close_enough(m1.value(),m2.value(),n);
} else if (Money::conversionType == Money::BaseCurrencyConversion) {
Money tmp1 = m1;
convertToBase(tmp1);
Money tmp2 = m2;
convertToBase(tmp2);
return close_enough(tmp1,tmp2,n);
} else if (Money::conversionType == Money::AutomatedConversion) {
Money tmp = m2;
convertTo(tmp, m1.currency());
return close_enough(m1,tmp,n);
} else {
QL_FAIL("currency mismatch and no conversion specified");
}
}
示例7: switch
void BlackCalculator::Calculator::visit(CashOrNothingPayoff& payoff) {
black_.alpha_ = black_.DalphaDd1_ = 0.0;
black_.x_ = payoff.cashPayoff();
black_.DxDstrike_ = 0.0;
switch (payoff.optionType()) {
case Option::Call:
black_.beta_ = black_.cum_d2_;
black_.DbetaDd2_ = black_.n_d2_;
break;
case Option::Put:
black_.beta_ = 1.0-black_.cum_d2_;
black_.DbetaDd2_ = -black_.n_d2_;
break;
default:
QL_FAIL("invalid option type");
}
}
示例8: switch
std::vector<boost::function1<Real, Real> >
LsmBasisSystem::pathBasisSystem(Size order, PolynomType polynomType) {
std::vector<boost::function1<Real, Real> > ret;
for (Size i=0; i<=order; ++i) {
switch (polynomType) {
case Monomial:
ret.push_back(MonomialFct(i));
break;
case Laguerre:
ret.push_back(
bind(&GaussianOrthogonalPolynomial::weightedValue,
GaussLaguerrePolynomial(), i, _1));
break;
case Hermite:
ret.push_back(
bind(&GaussianOrthogonalPolynomial::weightedValue,
GaussHermitePolynomial(), i, _1));
break;
case Hyperbolic:
ret.push_back(
bind(&GaussianOrthogonalPolynomial::weightedValue,
GaussHyperbolicPolynomial(), i, _1));
break;
case Legendre:
ret.push_back(
bind(&GaussianOrthogonalPolynomial::weightedValue,
GaussLegendrePolynomial(), i, _1));
break;
case Chebyshev:
ret.push_back(
bind(&GaussianOrthogonalPolynomial::weightedValue,
GaussChebyshevPolynomial(), i, _1));
break;
case Chebyshev2nd:
ret.push_back(
bind(&GaussianOrthogonalPolynomial::weightedValue,
GaussChebyshev2ndPolynomial(), i, _1));
break;
default:
QL_FAIL("unknown regression type");
}
}
return ret;
}
示例9: switch
std::ostream& operator<<(std::ostream& out,
SwapIndex::FixingType t) {
switch (t) {
case SwapIndex::IsdaFixA:
return out << "IsdaFixA";
case SwapIndex::IsdaFixB:
return out << "IsdaFixB";
case SwapIndex::IfrFix:
return out << "IfrFix";
case SwapIndex::IsdaFixAm:
return out << "IsdaFixAm";
case SwapIndex::IsdaFixPm:
return out << "IsdaFixPm";
default:
QL_FAIL("unknown SwapIndex::FixingType(" << QuantLib::Integer(t) << ")");
}
}
示例10: switch
boost::shared_ptr<DayCounter::Impl>
ActualActual::implementation(ActualActual::Convention c) {
switch (c) {
case ISMA:
case Bond:
return boost::shared_ptr<DayCounter::Impl>(new ISMA_Impl);
case ISDA:
case Historical:
case Actual365:
return boost::shared_ptr<DayCounter::Impl>(new ISDA_Impl);
case AFB:
case Euro:
return boost::shared_ptr<DayCounter::Impl>(new AFB_Impl);
default:
QL_FAIL("unknown act/act convention");
}
}
示例11: settlementImpl
SouthKorea::SouthKorea(Market market) {
// all calendar instances share the same implementation instance
static boost::shared_ptr<Calendar::Impl> settlementImpl(
new SouthKorea::SettlementImpl);
static boost::shared_ptr<Calendar::Impl> krxImpl(
new SouthKorea::KrxImpl);
switch (market) {
case Settlement:
impl_ = settlementImpl;
break;
case KRX:
impl_ = krxImpl;
break;
default:
QL_FAIL("unknown market");
}
}
示例12: x
Real FilonIntegral::integrate(const ext::function<Real (Real)>& f,
Real a, Real b) const {
const Real h = (b-a)/(2*n_);
Array x(2*n_+1, a, h);
const Real theta = t_*h;
const Real theta2 = theta*theta;
const Real theta3 = theta2*theta;
const Real alpha = 1/theta + std::sin(2*theta)/(2*theta2)
- 2*square<Real>()(std::sin(theta))/theta3;
const Real beta = 2*( (1+square<Real>()(std::cos(theta)))/theta2
- std::sin(2*theta)/theta3);
const Real gamma = 4*(std::sin(theta)/theta3 - std::cos(theta)/theta2);
Array v(x.size());
std::transform(x.begin(), x.end(), v.begin(), f);
ext::function<Real(Real)> f1, f2;
switch(type_) {
case Cosine:
f1 = static_cast<Real(*)(Real)>(std::sin);
f2 = static_cast<Real(*)(Real)>(std::cos);
break;
case Sine:
f1 = static_cast<Real(*)(Real)>(std::cos);
f2 = static_cast<Real(*)(Real)>(std::sin);
break;
default:
QL_FAIL("unknown integration type");
}
Real c_2n_1 = 0.0;
Real c_2n = v[0]*f2(t_*a)
- 0.5*(v[2*n_]*f2(t_*b) + v[0]*f2(t_*a));
for (Size i=1; i <= n_; ++i) {
c_2n += v[2*i] *f2(t_*x[2*i]);
c_2n_1 += v[2*i-1]*f2(t_*x[2*i-1]);
}
return h*(alpha*(v[2*n_]*f1(t_*x[2*n_]) - v[0]*f1(t_*x[0]))
*((type_ == Cosine) ? 1.0 : -1.0)
+ beta*c_2n + gamma*c_2n_1);
}
示例13: if
boost::shared_ptr<QuantLib::OperatorND> qlOperatorFactory::operatorND(const boost::shared_ptr<FpmlSerialized::OperatorND>& xml_serial)
{
boost::shared_ptr<QuantLib::OperatorND> ql_oper;
std::string operNDType = xml_serial->getType()->SValue();
if ( operNDType == "additionOperND" )
{
const boost::shared_ptr<FpmlSerialized::AdditionOperND>& xml_operND
= xml_serial->getAdditionOperND();
ql_oper = this->additionOperND(xml_operND);
}
else if ( operNDType == "multipleOperND" )
{
const boost::shared_ptr<FpmlSerialized::MultipleOperND>& xml_operND
= xml_serial->getMultipleOperND();
ql_oper = this->multipleOperND(xml_operND);
}
else if ( operNDType == "maximumOperND" )
{
const boost::shared_ptr<FpmlSerialized::MaximumOperND>& xml_operND
= xml_serial->getMaximumOperND();
ql_oper = this->maximumOperND(xml_operND);
}
else if ( operNDType == "divisionOperND" )
{
const boost::shared_ptr<FpmlSerialized::DivisionOperND>& xml_operND
= xml_serial->getDivisionOperND();
ql_oper = this->divisionOperND(xml_operND);
}
else if ( operNDType == "identityOperND" )
{
ql_oper = this->identityOperND();
}
else
{
QL_FAIL("unknown operNDType : " << operNDType);
}
return ql_oper;
}
示例14: businessDayConvention
QuantLib::BusinessDayConvention businessDayConvention(const std::string& typeStr)
{
QuantLib::BusinessDayConvention bdc;
std::string upperStr = boost::to_upper_copy(typeStr);
if(upperStr=="FOLLOWING")
{
bdc = QuantLib::Following;
}
else
{
QL_FAIL("unknown type calendar string");
}
return bdc;
}
示例15: N
/*! The constructor takes as inputs
- rateTimes the libor grid points
- mode the parametrization mode, see below which are available
- parameters generic parameters describing the parameterization, see below for their meaning for each mode
The following values for mode are possible and the following parameters must be given:
- mode=0: N (N=number of libors) parameters must be given. The first parameter is the skew for the next libor not yet expired,
the second one for the libor after that and so on.
- mode=1: 2 Parameters \f$ (b_0, lambda) \f$ must be given. The skew for the ith not expired libor (i starting with 0) is
\f$ 1.0 - b_0 e^{-\lambda i}\f$
*/
PiecewiseConstantBeta(std::vector<Time>& rateTimes,
int mode,
std::vector<Real>& parameters
) : rateTimes_(rateTimes), N_(rateTimes.size()-1), parameters_(parameters), mode_(mode) {
// set number of parameters
switch(mode_) {
case 0: P_=N_;
break;
case 1: P_=2;
break;
default: QL_FAIL("mode " << mode_ << " not supported.");
}
// initialize beta
beta_=std::vector<double>(N_,0.0);
setParameters();
}