double print_total(std::ostream& os, const Quote& item, size_t n) { double ret = item.net_price(n); os << "ISBN:" << item.isbn() << "# sold: " << n << "total due: " <<ret << std::endl; return ret; }
int main() { Quote q("aaa", 10.60); Bulk_quote bq("bbb", 111, 10, 0.3); Limit_quote lq("ccc", 222, 10, 0.3); /** @note Not dynamic binding! * The codes below are not dynamic binding. The compiler has known what the * r refering to at compile time. As a result, the virtual function debug of * the subobject is called. */ Quote *r = &q; r->debug(); std::cout << "\n"; r = &bq; r->debug(); std::cout << "\n"; r = &lq; r->debug(); std::cout << "\n"; std::cout << "====================\n"; q.debug(); bq.debug(); lq.debug(); print_debug(q); print_debug(bq); print_debug(lq); return 0; }
int main() { Bulk_quote bulk_quote("bulk_quote_1", 10.10, 10, 0.5); // The pointer is of static type Quote, but it's dynamic type is Bulk Quote // Because of polymorphism the Bulk Quote implementation of the net_price() // method gets called. Quote *quote_pointer = &bulk_quote; quote_pointer->net_price(5); // The reference is of static type Quote, but it's dynamic type is Bulk Quote // Like with the pointer, the Bulk Quote implementation of the net_price() // method gets called. Quote "e_reference = bulk_quote; quote_reference.net_price(5); // The static type of this variable is Quote. Here the Bulk Quote object // gets upcasted. The Quote part of bulk_quote gets copied into quote, but // the rest is not handled. Because of the cast the Quote implementation of // the net_price() method gets called. Quote quote = bulk_quote; quote.net_price(5); return 0; }
double print_total(ostream& os, const Quote& item, size_t number){ double ret = item.net_price(number); os << "ISBN: " << item.isbn() << " # sold: " << number << " total due: " << ret << endl; return ret; }
double print_total(std::ostream& out, const Quote& item, std::size_t n) { // depending on the type of the object bound to the item parameter // call corresponding functuon either Quote::net_price or Bulk_quote::net_price double ret = item.net_price(n); out << "IBSN: " << item.isbn() << " # sold: " << n << " total due: " << ret << std::endl; return ret; }
double print_total(ostream& os, Quote const& item, size_t sold) { double net_price = item.net_price(sold); os << "isbn: " << item.isbn() << ", sold: " << sold << ", total due: " << net_price << endl; return net_price; }
// non-member double print_total(std::ostream &os, const Quote &item, size_t n) { // depending on the type of the object bound to the item parameter // calls either Quote::net_price or Bulk_quote::net_price double ret = item.net_price(n); os << "ISBN: " << item.isbn() // calls Quote::isbn << " # sold: " << n << " total due: " << ret << std::endl; return ret; }
int main() { Bulk_quote bulk; Bulk_quote *bulkP = &bulk; // static and dynamic types are the same Quote *itemP = &bulk; // static and dynamic types differ bulkP->discount_policy(); // ok: bulkP has type Bulk_quote* itemP->discount_policy(); // error: itemP has type Quote* return 0; }
int main() { Quote base("000111", 50); print_total(cout, base, 10); //calls Quote::net_price Bulk_quote bulk("000111", 50, 5, 0.19); print_total(cout, bulk, 10); //calls Bulk_quote::net_price Quote *baseP = &bulk; cout << baseP->net_price(10) << endl; //calls Bulk_quote::net_price cout << baseP->Quote::net_price(10) << endl; //calls Quote::net_price system("pause"); }
// for test int main(int argc, char **argv) { Quote q("asd", 10.5); Bulk_Quote b_q("f**k", 10.5, 20, 0.2); Quote *p; p = &q; cout << "20本asd的总价格为:" << p->net_price(20) << endl; p->debug(); p = &b_q; cout << "20本f**k的总价格为:" << p->net_price(20) << endl; p->debug(); system("pause"); return 0; }
int main(int argc, char* argv[]) { /// Take file input either from command line or from console string fileName; cout << "profile name: "; if(argc > 1 ) { fileName = argv[1]; } else { cin >> fileName; } cout << fileName << endl; /// Read the file till the end string inputData, line; /// Open the file stream ifstream inputFile (fileName); /// If file stream succeeds if(inputFile) { while( getline (inputFile, line) ) { inputData.append(line); } } else { cout << "Error to open the profile file. Please check the file path." << endl; return -1; } /// Deserialized JSON fileName is represented in "pofile" object Profile profile; CJsonDeserializer::Deserialize( &profile, inputData ); /// Generates quote with generated profile Quote q; cout << "Quote: " << std::fixed << std::setprecision(2) << q.GetQuote(profile) << endl; return 0; }
void Board::setQuote(Quote& quote){ deleteQuoteFields(); const vector<QuoteLine>& lines = quote.getLines(); for(vector<QuoteLine>::const_iterator itr = lines.begin(); itr != lines.end(); ++itr){ mQuoteFields += new QuoteField( mGrid->getCell(itr->getIndices().front())->getCenter(), Rand::randInt(QUOTE_FIELD_NUM_DIVERS_MIN, QUOTE_FIELD_NUM_DIVERS_MAX), *itr ); } mQuoteCurrent = "e; }
void quote_test() { zmq::context_t context(1); zmq::socket_t pub(context, ZMQ_PUB); pub.bind("tcp://*:5556"); Quote quote; zmq::message_t message; timestamp start; timestamp stop; timestamp diff; while (run) { double q_price = 150.0 + within(50) + within(100) / 100.0; uint64_t q_size = 30 + within(1000); uint8_t q_type = within(3); quote.set_price(q_price); quote.set_size(q_size); quote.set_type(wave::Quote_QuoteType(q_type)); int size = quote.ByteSize(); message.rebuild(size); start = timestamp::now(); quote.SerializeToArray(message.data(), size); stop = timestamp::now(); diff = stop - start; log::debug << "msg pack time = " << diff.total_usecs() << " us"; if (pub.send(message) == -1) log::error << "error while sending: " << strerror(errno); sleep(1); } }
void print_debug(const Quote &q) { q.debug(); }
// copy version void add_item(Quote const& item) { cout << "basket::add_item(Quote const&)" << endl; items_.insert(std::shared_ptr<Quote>( item.clone())); }
void GUIWidget::createGUI () { QVBoxLayout *vbox = new QVBoxLayout; vbox->setSpacing(2); vbox->setMargin(5); setLayout(vbox); QFormLayout *form = new QFormLayout; form->setSpacing(2); form->setMargin(0); vbox->addLayout(form); // csv file _csvButton = new FileButton(0); connect(_csvButton, SIGNAL(signalSelectionChanged(QStringList)), this, SLOT(buttonStatus())); // _csvButton->setFiles(QStringList() << "/tmp/yahoo.csv"); form->addRow (tr("CSV File"), _csvButton); // format _format = new QLineEdit; form->addRow (tr("Format"), _format); // date format _dateFormat = new QLineEdit; form->addRow (tr("Date Format"), _dateFormat); // delimiter Delimiter d; _delimiter = new QComboBox; _delimiter->addItems(d.list()); _delimiter->setCurrentIndex(Delimiter::_SEMICOLON); form->addRow (tr("Delimiter"), _delimiter); // type Quote q; _type = new QComboBox; _type->addItems(q.list()); _type->setCurrentIndex(Quote::_STOCK); form->addRow (tr("Quote Type"), _type); // exchange _exchange = new QLineEdit; form->addRow (tr("Exchange Override"), _exchange); // filename as symbol _filename = new QCheckBox; form->addRow (tr("Use Filename As Symbol"), _filename); // log _log = new QTextEdit; _log->setReadOnly(TRUE); vbox->addWidget(_log); // buttonbox QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Help); vbox->addWidget(bb); // ok button _okButton = bb->addButton(QDialogButtonBox::Ok); _okButton->setText(tr("&OK")); connect(_okButton, SIGNAL(clicked()), this, SLOT(importThread())); // cancel button _cancelButton = bb->addButton(QDialogButtonBox::Cancel); _cancelButton->setText(tr("&Cancel")); _cancelButton->setDefault(TRUE); _cancelButton->setFocus(); _cancelButton->setEnabled(TRUE); // help button QPushButton *b = bb->button(QDialogButtonBox::Help); b->setText(tr("&Help")); connect(b, SIGNAL(clicked()), this, SIGNAL(signalHelp())); }
void Process::HandleTSTrading( const Quote& quote ) { // m_dblCallPrice = m_iterOILatestGammaSelectCall->Call()->Ask(); m_dblPutPrice = m_iterOILatestGammaSelectPut->second.Put()->Ask(); ptime dt = ou::TimeSource::Instance().Internal(); if ( dt.time_of_day() >= m_dtMarketClosingOrder ) { m_ss.str( "" ); m_ss << dt; m_ss << " State: Close Orders." << std::endl; OutputDebugString( m_ss.str().c_str() ); m_TradingState = ETSCloseOrders; } else { double dblMidQuote = ( quote.Bid() + quote.Ask() ) / 2.0; double dblDeltaPut = m_iterOILatestGammaSelectPut->second.Put()->Delta() * m_posPut->GetRow().nPositionActive * 100; //double dblDeltaCall = m_iterOILatestGammaSelectCall->second.Call()->Delta() * m_nCalls * 100; bool bTraded = false; if ( ( 0.0 != dblDeltaPut ) && !m_posUnderlying->OrdersPending() && !m_posPut->OrdersPending() ) { try { // todo: while implied volatility is rising, hold back on exiting? // todo: while implied volatility is falling, hold back on entering? double dblDeltaTotalUnderlying = m_posUnderlying->GetRow().nPositionActive; if ( ou::tf::OrderSide::Sell == m_posUnderlying->GetRow().eOrderSideActive ) { dblDeltaTotalUnderlying *= -1.0; } double dblDeltaDif = dblDeltaPut + dblDeltaTotalUnderlying; if ( dblDeltaDif > m_dblBaseDeltaIncrement ) { // sell underlying to get closer to put delta //m_posUnderlying->PlaceOrder( OrderType::Market, OrderSide::Sell, m_dblBaseDeltaIncrement / 100 ); // <<=== temporary fix for this simulation set m_posUnderlying->PlaceOrder( OrderType::Market, OrderSide::Sell, m_dblBaseDeltaIncrement ); bTraded = true; m_ss.str( "" ); m_ss << dt; m_ss << " Underlying Sell " << m_dblBaseDeltaIncrement << ", trigger @" << dblMidQuote << std::endl; OutputDebugString( m_ss.str().c_str() ); } else { if ( dblDeltaDif < -m_dblBaseDeltaIncrement ) { // buy underlying to get closer to put delta //m_posUnderlying->PlaceOrder( OrderType::Market, OrderSide::Buy, m_dblBaseDeltaIncrement / 100 ); // <<=== temporary fix for this simulation set m_posUnderlying->PlaceOrder( OrderType::Market, OrderSide::Buy, m_dblBaseDeltaIncrement ); bTraded = true; m_ss.str( "" ); m_ss << dt; m_ss << " Underlying Buy " << m_dblBaseDeltaIncrement << ", trigger @" << dblMidQuote << std::endl; OutputDebugString( m_ss.str().c_str() ); } } } catch ( std::logic_error &e ) { // just catch, don't do anything } if ( bTraded ) { PrintGreeks(); } } } }
void Process::HandleTSMarketOpened( const Quote& quote ) { double dblOpenValue = ( quote.Bid() + quote.Ask() ) / 2.0; // comment our starting trade of the day m_ss.str( "" ); m_ss << ou::TimeSource::Instance().Internal(); m_ss << " Opening mid quote: " << dblOpenValue << std::endl; OutputDebugString( m_ss.str().c_str() ); // set iterators for center of the pack (crossovers are above and below trade): m_iterAboveCrossOver = m_vCrossOverPoints.begin(); while ( dblOpenValue >= *m_iterAboveCrossOver ) { ++m_iterAboveCrossOver; } m_iterBelowCrossOver = m_iterAboveCrossOver; while ( dblOpenValue <= *m_iterBelowCrossOver ) { --m_iterBelowCrossOver; } // comment our crossover points m_ss.str( "" ); m_ss << "Trade start " << *m_iterBelowCrossOver << ", " << dblOpenValue << ", " << *m_iterAboveCrossOver << std::endl; OutputDebugString( m_ss.str().c_str() ); // calculate where to have put/call option watches, // have a range of strikes above and below current trade (have maximum 100 watches available) m_iterOIHighestWatch = m_mapStrikeInfo.begin(); while ( (m_iterOIHighestWatch->first) <= dblOpenValue ) { ++m_iterOIHighestWatch; } m_iterOILowestWatch = m_iterOIHighestWatch; --m_iterOILowestWatch; for ( int i = 0; i < 15; ++i ) { if ( m_mapStrikeInfo.begin() != m_iterOILowestWatch ) { --m_iterOILowestWatch; } if ( m_mapStrikeInfo.end() != m_iterOIHighestWatch ) { ++m_iterOIHighestWatch; } } // set the actual watches m_bWatchingOptions = true; if ( keytypes::EProviderSimulator != m_pDataProvider->ID() ) { for ( mapStrikeInfo_iter_t iter = m_iterOILowestWatch; iter != m_iterOIHighestWatch; ++iter ) { StrikeInfo& oi = iter->second; m_pDataProvider->AddQuoteHandler( oi.Call()->GetInstrument(), MakeDelegate( oi.Call(), &CNakedCall::HandleQuote ) ); m_pDataProvider->AddTradeHandler( oi.Call()->GetInstrument(), MakeDelegate( oi.Call(), &CNakedCall::HandleTrade ) ); m_pDataProvider->AddGreekHandler( oi.Call()->GetInstrument(), MakeDelegate( oi.Call(), &CNakedCall::HandleGreek ) ); m_pDataProvider->AddQuoteHandler( oi.Put()->GetInstrument(), MakeDelegate( oi.Put(), &CNakedPut::HandleQuote ) ); m_pDataProvider->AddTradeHandler( oi.Put()->GetInstrument(), MakeDelegate( oi.Put(), &CNakedPut::HandleTrade ) ); m_pDataProvider->AddGreekHandler( oi.Put()->GetInstrument(), MakeDelegate( oi.Put(), &CNakedPut::HandleGreek ) ); } } m_TradingState = ETSFirstTrade; }
void TSReturns::Append( const Quote& quote ) { price_t price_ = std::log( quote.LogarithmicMidPointA() ); if ( m_bFirstAppend ) m_bFirstAppend = false; else Prices::Append( Price( quote.DateTime(), price_ - m_priceLast ) ); m_priceLast = price_; }
void printTotal(ostream& os, const Quote& book, const size_t bookNum) { os << book.isbn() <<":" <<book.net_price(bookNum); }
void add_item(const Quote& sale) { items.insert(std::shared_ptr<Quote>(sale.clone())); }
void print_debug(const Quote& item) { item.debug(); }