本文整理汇总了C++中Flag::isUp方法的典型用法代码示例。如果您正苦于以下问题:C++ Flag::isUp方法的具体用法?C++ Flag::isUp怎么用?C++ Flag::isUp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Flag
的用法示例。
在下文中一共展示了Flag::isUp方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testObservable
void InstrumentTest::testObservable() {
BOOST_TEST_MESSAGE("Testing observability of instruments...");
boost::shared_ptr<SimpleQuote> me1(new SimpleQuote(0.0));
RelinkableHandle<Quote> h(me1);
boost::shared_ptr<Instrument> s(new Stock(h));
Flag f;
f.registerWith(s);
s->NPV();
me1->setValue(3.14);
if (!f.isUp())
BOOST_FAIL("Observer was not notified of instrument change");
s->NPV();
f.lower();
boost::shared_ptr<SimpleQuote> me2(new SimpleQuote(0.0));
h.linkTo(me2);
if (!f.isUp())
BOOST_FAIL("Observer was not notified of instrument change");
f.lower();
s->freeze();
s->NPV();
me2->setValue(2.71);
if (f.isUp())
BOOST_FAIL("Observer was notified of frozen instrument change");
s->NPV();
s->unfreeze();
if (!f.isUp())
BOOST_FAIL("Observer was not notified of instrument change");
}
示例2: testDiscardingNotifications
void LazyObjectTest::testDiscardingNotifications() {
BOOST_TEST_MESSAGE(
"Testing that lazy object discards notifications after the first...");
boost::shared_ptr<SimpleQuote> q(new SimpleQuote(0.0));
boost::shared_ptr<Instrument> s(new Stock(Handle<Quote>(q)));
Flag f;
f.registerWith(s);
s->NPV();
q->setValue(1.0);
if (!f.isUp())
BOOST_FAIL("Observer was not notified of change");
f.lower();
q->setValue(2.0);
if (f.isUp())
BOOST_FAIL("Observer was notified of second change");
f.lower();
s->NPV();
q->setValue(3.0);
if (!f.isUp())
BOOST_FAIL("Observer was not notified of change after recalculation");
}
示例3: testObservableHandle
void QuoteTest::testObservableHandle() {
BOOST_MESSAGE("Testing observability of quote handles...");
boost::shared_ptr<SimpleQuote> me1(new SimpleQuote(0.0));
RelinkableHandle<Quote> h(me1);
Flag f;
f.registerWith(h);
me1->setValue(3.14);
if (!f.isUp())
BOOST_FAIL("Observer was not notified of quote change");
f.lower();
boost::shared_ptr<SimpleQuote> me2(new SimpleQuote(0.0));
h.linkTo(me2);
if (!f.isUp())
BOOST_FAIL("Observer was not notified of quote change");
}
示例4: testZSpreadedObs
void TermStructureTest::testZSpreadedObs() {
BOOST_TEST_MESSAGE("Testing observability of zero-spreaded term structure...");
CommonVars vars;
ext::shared_ptr<SimpleQuote> me(new SimpleQuote(0.01));
Handle<Quote> mh(me);
RelinkableHandle<YieldTermStructure> h(vars.dummyTermStructure);
ext::shared_ptr<YieldTermStructure> spreaded(
new ZeroSpreadedTermStructure(h,mh));
Flag flag;
flag.registerWith(spreaded);
h.linkTo(vars.termStructure);
if (!flag.isUp())
BOOST_ERROR("Observer was not notified of term structure change");
flag.lower();
me->setValue(0.005);
if (!flag.isUp())
BOOST_ERROR("Observer was not notified of spread change");
}
示例5: testObservable
void QuoteTest::testObservable() {
BOOST_MESSAGE("Testing observability of quotes...");
boost::shared_ptr<SimpleQuote> me(new SimpleQuote(0.0));
Flag f;
f.registerWith(me);
me->setValue(3.14);
if (!f.isUp())
BOOST_FAIL("Observer was not notified of quote change");
}
示例6: testForwardingNotifications
void LazyObjectTest::testForwardingNotifications() {
BOOST_TEST_MESSAGE(
"Testing that lazy object forwards all notifications when told...");
boost::shared_ptr<SimpleQuote> q(new SimpleQuote(0.0));
boost::shared_ptr<Instrument> s(new Stock(Handle<Quote>(q)));
s->alwaysForwardNotifications();
Flag f;
f.registerWith(s);
s->NPV();
q->setValue(1.0);
if (!f.isUp())
BOOST_FAIL("Observer was not notified of change");
f.lower();
q->setValue(2.0);
if (!f.isUp())
BOOST_FAIL("Observer was not notified of second change");
}
示例7: testImpliedObs
void TermStructureTest::testImpliedObs() {
BOOST_TEST_MESSAGE("Testing observability of implied term structure...");
CommonVars vars;
Date today = Settings::instance().evaluationDate();
Date newToday = today + 3*Years;
Date newSettlement = vars.calendar.advance(newToday,
vars.settlementDays,Days);
RelinkableHandle<YieldTermStructure> h;
ext::shared_ptr<YieldTermStructure> implied(
new ImpliedTermStructure(h, newSettlement));
Flag flag;
flag.registerWith(implied);
h.linkTo(vars.termStructure);
if (!flag.isUp())
BOOST_ERROR("Observer was not notified of term structure change");
}
示例8: testForwardValueQuoteAndImpliedStdevQuote
void QuoteTest::testForwardValueQuoteAndImpliedStdevQuote() {
BOOST_MESSAGE(
"Testing forward-value and implied-standard-deviation quotes...");
Real forwardRate = .05;
DayCounter dc = ActualActual();
Calendar calendar = TARGET();
boost::shared_ptr<SimpleQuote> forwardQuote(new SimpleQuote(forwardRate));
Handle<Quote> forwardHandle(forwardQuote);
Date evaluationDate = Settings::instance().evaluationDate();
boost::shared_ptr<YieldTermStructure>yc (new FlatForward(
evaluationDate, forwardHandle, dc));
Handle<YieldTermStructure> ycHandle(yc);
Period euriborTenor(1,Years);
boost::shared_ptr<Index> euribor(new Euribor(euriborTenor, ycHandle));
Date fixingDate = calendar.advance(evaluationDate, euriborTenor);
boost::shared_ptr<ForwardValueQuote> forwardValueQuote( new
ForwardValueQuote(euribor, fixingDate));
Rate forwardValue = forwardValueQuote->value();
Rate expectedForwardValue = euribor->fixing(fixingDate, true);
// we test if the forward value given by the quote is consistent
// with the one directly given by the index
if (std::fabs(forwardValue-expectedForwardValue) > 1.0e-15)
BOOST_FAIL("Foward Value Quote quote yields " << forwardValue << "\n"
<< "expected result is " << expectedForwardValue);
// then we test the observer/observable chain
Flag f;
f.registerWith(forwardValueQuote);
forwardQuote->setValue(0.04);
if (!f.isUp())
BOOST_FAIL("Observer was not notified of quote change");
// and we retest if the values are still matching
forwardValue = forwardValueQuote->value();
expectedForwardValue = euribor->fixing(fixingDate, true);
if (std::fabs(forwardValue-expectedForwardValue) > 1.0e-15)
BOOST_FAIL("Foward Value Quote quote yields " << forwardValue << "\n"
<< "expected result is " << expectedForwardValue);
// we test the ImpliedStdevQuote class
f.unregisterWith(forwardValueQuote);
f.lower();
Real price = 0.02;
Rate strike = 0.04;
Volatility guess = .15;
Real accuracy = 1.0e-6;
Option::Type optionType = Option::Call;
boost::shared_ptr<SimpleQuote> priceQuote(new SimpleQuote(price));
Handle<Quote> priceHandle(priceQuote);
boost::shared_ptr<ImpliedStdDevQuote> impliedStdevQuote(new
ImpliedStdDevQuote(optionType, forwardHandle, priceHandle,
strike, guess, accuracy));
Real impliedStdev = impliedStdevQuote->value();
Real expectedImpliedStdev =
blackFormulaImpliedStdDev(optionType, strike,
forwardQuote->value(), price,
1.0, 0.0, guess, 1.0e-6);
if (std::fabs(impliedStdev-expectedImpliedStdev) > 1.0e-15)
BOOST_FAIL("\nimpliedStdevQuote yields :" << impliedStdev <<
"\nexpected result is :" << expectedImpliedStdev);
// then we test the observer/observable chain
boost::shared_ptr<Quote> quote = impliedStdevQuote;
f.registerWith(quote);
forwardQuote->setValue(0.05);
if (!f.isUp())
BOOST_FAIL("Observer was not notified of quote change");
quote->value();
f.lower();
quote->value();
priceQuote->setValue(0.11);
if (!f.isUp())
BOOST_FAIL("Observer was not notified of quote change");
}