int main() { using std::cout; using std::ios_base; // create an array of initialized objects Stock stocks[STKS] = { Stock("NanoSmart", 12, 20.0), Stock("Boffo Objects", 200, 2.0), Stock("Monolithic Obelisks", 130, 3.25), Stock("Fleep Enterprises", 60, 6.5) }; cout.precision(2); // #.## format cout.setf(ios_base::fixed, ios_base::floatfield);// #.## format cout.setf(ios_base::showpoint); // #.## format cout << "Stock holdings:\n"; int st; for (st = 0; st < STKS; st++) stocks[st].show(); Stock top = stocks[0]; for (st = 1; st < STKS; st++) top = top.topval(stocks[st]); cout << "\nMost valuable holding:\n"; top.show(); return 0; }
Stock PgsqlDataProvider::getStock(uint32_t id) { nontransaction command(*conn); string query = "SELECT id, price FROM get_stock(" + to_string(id) + ");"; result queryResult(command.exec(query)); if (verbose) cout << "Result of " << query << ": " << endl; if (queryResult.size() != 1) { cerr << "getStock: Incorrect number of results: " << queryResult.size() << endl; throw invalid_argument("getStock: Incorrect number of results."); } if (queryResult[0][0].is_null()) { cerr << "getStock: Stock id = " << id << " does not exist." << endl; throw invalid_argument("getStock: Stock does not exist."); } Stock stock; stock.setId(queryResult[0][0].as<int>()); stock.setPrice(Decimal(queryResult[0][1].as<string>())); if (verbose) cout << "Stock: id = " << stock.getId() << ", price = " << stock.getPrice() << endl; return stock; }
template <class numericType> numericType calculatePERatio<numericType>::operator() (const Stock<numericType>& stock) { if ((stock.getTickerPrice() == 0) || (stock.getLastDividend() == 0)) { return (numericType)0; } return (numericType)(stock.getTickerPrice()/stock.getLastDividend()); }
Stock* Stock::create(int stockCode, String* stockName,int nowPrice,int makedealprice,float percent,int storeNumber ) { Stock* stock = new Stock(stockCode,stockName,nowPrice,makedealprice,percent,storeNumber); stock->init(); stock->autorelease(); return stock; }
static void moveTest(){ ostringstream oss; Stock stock = Stock(); Draw draw = Draw(); int size; try { draw.move(stock, size = 26); assert(stock.getSize() == 26); draw.move(stock, size = 5); } catch(std::logic_error & e){ oss << "Failure while trying to take " << size << " cards!"; } assert(oss.str() == "Failure while trying to take 5 cards!"); oss.str(""); oss.clear(); Build build = Build(); stock += 3; try { stock.move(build); assert(false); } catch(std::exception & e){ oss << e.what(); } assert(oss.str() == "Can't add card - not in sequence!\n"); }
HKU_API std::ostream & operator<<(std::ostream& os, const TradeRecord& record) { Stock stock = record.stock; string market_code(""), name(""); if(!stock.isNull()){ market_code = stock.market_code(); #if defined(BOOST_WINDOWS) && (PY_VERSION_HEX >= 0x03000000) name = utf8_to_gb(stock.name()); #else name = stock.name(); #endif } string strip(", "); os << std::fixed; os.precision(4); os << "Trade(" << record.datetime << strip << market_code << strip << name << strip << getBusinessName(record.business) << strip << record.planPrice << strip << record.realPrice; if (record.goalPrice == Null<price_t>()) { os << strip << "NULL"; } else { os << strip << record.goalPrice; } os << strip << record.number << strip << record.cost.commission << strip << record.cost.stamptax << strip << record.cost.transferfee << strip << record.cost.others << strip << record.cost.total << strip << record.stoploss << strip << record.cash << strip << getSystemPartName(record.from) << ")"; os.unsetf(std::ostream::floatfield); os.precision(); return os; }
int main(void) { using std::cout; using std::ios_base; Stock stocks[STKS] = { Stock("NanoSmart", 12, 20.0), Stock("Boffo Objects", 200, 2.0), Stock("Obelisk blue", 130, 3.2), Stock("Fleep Enterprise", 60, 6.5) }; cout.precision(2); // *.** format cout.setf(ios_base::fixed, ios_base::floatfield);// *.** format cout.setf(ios_base::showpoint); cout << "Stock holdings:\n"; int st; for (st = 0; st < STKS; st++) stocks[st].show(); Stock top = stocks[0]; for (st = 1; st < STKS; st++) top = top.topval(stocks[st]); cout << "\nMost valuable holding:\n"; top.show(); return 0; }
void SetStockImgType::revert(ObjectsContainer* objects, UndoersCollector* redoers) { Stock* stock = objects->getObjectT<Stock>(m_stockId); // Push another SetStockImgType as redoer redoers->pushUndoer(new SetStockImgType(objects, stock)); stock->setImgType(m_imgtype); }
void SetStockPixelFormat::revert(ObjectsContainer* objects, UndoersCollector* redoers) { Stock* stock = objects->getObjectT<Stock>(m_stockId); // Push another SetStockPixelFormat as redoer redoers->pushUndoer(new SetStockPixelFormat(objects, stock)); stock->setPixelFormat(static_cast<PixelFormat>(m_format)); }
void RemoveImage::revert(ObjectsContainer* objects, UndoersCollector* redoers) { Stock* stock = objects->getObjectT<Stock>(m_stockId); Image* image = read_object<Image>(objects, m_stream, raster::read_image); // Push an AddImage as redoer redoers->pushUndoer(new AddImage(objects, stock, m_imageIndex)); stock->replaceImage(m_imageIndex, image); }
DatetimeList StockManager:: getTradingCalendar(const KQuery& query, const string& market) { Stock stock = getStock("SH000001"); size_t start_ix = 0, end_ix = 0; DatetimeList result; if (stock.getIndexRange(query, start_ix, end_ix)) { result = stock.getDatetimeList(start_ix, end_ix, query.kType()); } return result; }
static void opsTest() { Stock s = Stock(); vector<int> list; ostringstream oss; for(int i = 1; i < 13; i++){ list.push_back(i); } int num = 1; try { s += list; num++; s += list; num++; s += list; num++; //this num++ should not be executed } catch (std::invalid_argument & e){ oss << "Failed at num = " << num; } assert(oss.str() == "Failed at num = 3"); oss.str(""); oss.clear(); //assert Stock pile has 24 cards now assert(s.getSize() == 24); try { s += 13; } catch (std::invalid_argument & e){ oss << e.what(); } //assert exception is caught assert(oss.str() == "Invalid card value.\n"); oss.str(""); oss.clear(); vector<int> list2 = {5, 3, 2, 1, 0, 1}; try{ s += list2; } catch(std::invalid_argument & e){ assert(false); //should not be executed } assert(s.getSize() == 30); try { s += 1; }catch(std::logic_error & e){ oss << e.what(); } assert(oss.str() == "Can't have more than 30 cards in Stock pile!\n"); }
void AddImage::revert(ObjectsContainer* objects, UndoersCollector* redoers) { Stock* stock = objects->getObjectT<Stock>(m_stockId); Image* image = stock->getImage(m_imageIndex); if (image == NULL) throw UndoException("One image was not found in the stock"); redoers->pushUndoer(new RemoveImage(objects, stock, m_imageIndex)); stock->removeImage(image); delete image; }
double StockUtil::DividendYield(Stock stock, double marketPrice) { if(marketPrice == 0.0){return 0;} switch(stock.getStockType() ) { case COMMON: return (stock.getLastDividend() / marketPrice); case PREFFERED: return (stock.getFixedDividend() * stock.getParValue())/ marketPrice; default: return 0; } }
bool Stock::operator!=(const Stock& stock) const { if (this == &stock) return false; if (m_data == stock.m_data) return false; if (!m_data || !stock.m_data) return true; if( m_data->m_code != stock.code() || m_data->m_market != stock.market()) return true; return false; }
int main() { cout << "Enter the first share (name, num_holding, share_price): "; string line; getline(cin, line); Stock s0(line); cout << "Enter the second share (name, num_holding, share_price): "; getline(cin, line); Stock s1(line); Stock top = s0.topval(s1); cout << top.getName() << " with total value of " << top.getTotalVal() << " is more valuable." << endl; return 0; }
double StockUtil::PERatio(Stock stock, double marketPrice) { double div = stock.getLastDividend(); if(div == 0.0){return 0;} return marketPrice/div; }
void ReplaceImage::revert(ObjectsContainer* objects, UndoersCollector* redoers) { Stock* stock = objects->getObjectT<Stock>(m_stockId); // Read the image to be restored from the stream Image* image = read_object<Image>(objects, m_stream, raster::read_image); // Save the current image in the redoers redoers->pushUndoer(new ReplaceImage(objects, stock, m_imageIndex)); Image* oldImage = stock->getImage(m_imageIndex); // Replace the image in the stock stock->replaceImage(m_imageIndex, image); // Destroy the old image delete oldImage; }
vector <Stock> stockUtility:: createStocks (vector <std::string> stringList){ Stock stock; vector <Stock> stockList; stockUtility util; cout<<"HERE"<<endl; //TODO: Investigate why this first pop_back is stringList.pop_back(); while(stringList.size()>6){ stock.setAverageDailyVolume(util.filterStockList_MarketCap(stringList.back())); stringList.pop_back(); stock.setMarketCap(util.filterStockList_MarketCap(stringList.back())); stringList.pop_back(); stock.setLastTrade(ofToFloat(stringList.back())); stringList.pop_back(); stock.setLastTradeDate(stringList.back()); stringList.pop_back(); stock.setName(stringList.back()); stringList.pop_back(); stock.setCode(stringList.back()); stringList.pop_back(); stockList.push_back(stock); } return stockList; }
bool LaminatTask::form2Entity(Entity *task) { Process *process = Process::getInstance(); task->fields["task_process"] = processId; task->fields["task_weight"] = process->getWeight(processId); task->fields["equipment_id"] = ui->equip->getEquip()->getId(); Stock *stock = ui->product->getParam(); if (stock == NULL) { return false; } task->fields["product_id"] = stock->fields["product_id"]; task->fields["stock_id"] = stock->getId(); task->fields["task_total"] = ui->totalInput->getMoney().cents; return true; }
Image* Cel::image() const { ASSERT(m_layer != NULL); ASSERT(m_image >= 0); ASSERT(m_image < m_layer->sprite()->stock()->size()); if (m_layer) { Stock* stock = m_layer->sprite()->stock(); ASSERT(stock); ASSERT(m_image >= 0 && m_image < stock->size()); if (m_image >= 0 && m_image < stock->size()) { Image* image = stock->getImage(m_image); ASSERT((m_image == 0 && !image) || (m_image != 0 && image)); return image; } } return NULL; }
static void takeCardTest(){ ostringstream oss; Stock stock = Stock(); vector<int> list(30,5); stock += list; int size = stock.getSize(); for(int i = 0; i < 30; i++){ assert(stock.takeCard() == 5); assert(stock.getSize() == --size); } assert(stock.isEmpty()); try { stock.takeCard(); } catch(std::logic_error & e){ oss << e.what(); } cout << oss.str(); }
bool StockManager::addStock(const Stock& stock) { string market_code(stock.market_code()); boost::to_upper(market_code); if(m_stockDict.find(market_code) != m_stockDict.end()) { HKU_ERROR("The stock had exist! " << market_code << " [StockManager::addStock]"); return false; } m_stockDict[market_code] = stock; return true; }
void BiggestChangeRecorder::onPriceChanged ( Stock & _s, double _oldPrice ) { double priceChange = _s.getCurrentPrice() - _oldPrice; if ( priceChange > 0 ) { if ( m_maxPositiveChange < priceChange ) m_maxPositiveChange = priceChange; } else { priceChange = -priceChange; if ( m_maxNegativeChange < priceChange ) m_maxNegativeChange = priceChange; } }
// This function recieves arrayObjects as a parameter and prints each object to the report.txt file. void output(Stock arrayObjects) { ofstream outData; // an output filestream variable // Open report.txt to write data to outData.open("iofiles\\report.txt", ios::app); // If report.txt cannot be opened display an error message if(!outData) { cout<<"Can't open output file\n"; } // Write data to report.txt using accessor methods outData<<"==============================="<<"\nTitle... "<<arrayObjects.getTitle()<<endl<<"Barcode... "<<arrayObjects.getBarcode()<<endl<<"Wholesale Price... "<<arrayObjects.getWholesalePrice()<<endl<<"Retail Price... "<<arrayObjects.getRetailPrice()<<endl<<"Stock Level... "<<arrayObjects.getStockLevel()<<endl<<"==============================="<<endl; // Close report.txt outData.close(); }
int main() { srand(time(NULL)); Stock stock; vector<Buddy*> buddies{ new CentralBank(stock) }; for (int i = 0; i < 10; i++) { buddies.push_back(new Player(stock)); buddies.push_back(new Client(stock)); } // спекулятивные заявки stock.CreateBuyBet(1, 1e9); stock.CreateSellBet(1.8, 1e9); stock.CreateBuyBet(1.24, 1e7); stock.CreateSellBet(1.26, 1e7); stock.CreateBuyBet(1.239, 1e5); stock.CreateSellBet(1.261, 1e5); ofstream fs("result.csv"); fs.imbue(locale("")); // чтобы интерпретировать в винде точки правильно (регионалные настройки по умолчанию) fs << "time;buy rate;sell rate\n"; for (int time = 0; time < 10000; time++) { for (auto b : buddies) // (b->begin(); b != b->end(); b++) b->Act(); fs << time << ";"; fs << stock.GetBuyRate() << ";"; fs << stock.GetSellRate() << "\n"; //cout << time << ' '; } fs.close(); cout << "end" << endl; _getch(); return 0; }
HKU_API std::ostream & operator<<(std::ostream& os, const PositionRecord& record) { Stock stock = record.stock; int precision = 2; std::string market(""), code(""), name(""); if(!stock.isNull()){ market = stock.market(); code = stock.code(); #if defined(BOOST_WINDOWS) && (PY_VERSION_HEX >= 0x03000000) name = utf8_to_gb(stock.name()); #else name = stock.name(); #endif } else { precision = stock.precision(); } price_t costPrice = 0.0; if (record.number != 0.0) { costPrice = roundEx((record.buyMoney - record.sellMoney) / record.number, precision); } string strip(", "); os << std::fixed; os.precision(precision); os << "Position(" << market << strip << code << strip << name << strip << record.takeDatetime << strip << record.cleanDatetime << strip << record.number << strip << costPrice << strip << record.stoploss << strip << record.goalPrice << strip << record.totalNumber << strip << record.buyMoney << strip << record.totalCost << strip << record.totalRisk << strip << record.sellMoney << ")"; os.unsetf(std::ostream::floatfield); os.precision(); return os; }
void SetStockPricesEqual( Stock & s1, Stock & s2 ) { s1.setPrice( s2.getPrice() ); }
/************************************************ * STOCKS BUY SELL * The interactive function allowing the user to * buy and sell stocks ***********************************************/ void stocksBuySell() { // instructions cout << "This program will allow you to buy and sell stocks. " << "The actions are:\n"; cout << " buy 200 $1.57 - Buy 200 shares at $1.57\n"; cout << " sell 150 $2.15 - Sell 150 shares at $2.15\n"; cout << " display - Display your current stock portfolio\n"; cout << " quit - Display a final report and quit the program\n"; // your code here... string command; //check the command int amount = 0; //bought stock amount Dollars price; //bought stock price int sAmount = 0;//sold stock price Dollars sPrice; //sold stock price Dollars total; //bought stock total Dollars sTotal; //sold stock total Stock bStock; //one element of the bought stocks Stock sStock; //one element of the sold stocks //the check if we have bought or sold at all bool buy = false; bool sell = false; Queue <Stock> bStocks; //one queue for bought stocks Queue <Stock> sStocks; //one queue for sold stocks Queue <Dollars> profit; //one queue for profits do { //create a copy for bought stocks Queue <Stock> stocks1(bStocks); //create a copy for sold stocks Queue <Stock> stocks2(sStocks); cout << "> "; cin >> command; if (command == "quit" || command == "display") { if (buy && sell) { int i; int j; cout << "Currently held:\n"; for (i = 0; !stocks1.empty(); i++) { bStock = stocks1.front(); cout << "\tBought " << bStock.getAmount() << " shares at " << bStock.getPrice() << endl; stocks1.pop(); } cout << "Sell History:\n"; for (j = 0; !stocks2.empty(); j++) { sStock = stocks2.front(); cout << "\tSold " << sStock.getAmount() << " shares at " << sStock.getPrice() << " for a profit of "; cout << (sTotal - total) << endl; stocks2.pop(); } } else if(buy) { int i; cout << "Currently held:\n"; for (i = 0; !stocks1.empty(); i++) { bStock = stocks1.front(); cout << "\tBought " << bStock.getAmount() << " shares at " << bStock.getPrice() << endl; stocks1.pop(); } } else if(sell) sStock = stocks2.front(); cout << "\nProceeds: " << (sTotal - total) << endl; } else if (command == "buy") { //get bought amount and price from user cin >> amount >> price; //add to bought total total += (price * amount); //amount and price of current bought stock transaction bStock.setAmount(amount); bStock.setPrice(price); //we did buy stock buy = true; //add to the bought stock queue bStocks.push(bStock); } else if (command == "sell") { //get sell amount and price from user cin >> sAmount >> sPrice; //add to sell total sTotal += (sPrice * sAmount); //amount and price of current sold stock transaction sStock.setAmount(sAmount); sStock.setPrice(sPrice); //we did sell stock sell = true; //add sold stock to queue sStocks.push(sStock); //to allow us to go into the loop to find total sold stocks int tmp = 1; // should to handle the selling of stocks for (; tmp != 0;) { //if there are no more bought stocks left leave if (bStocks.empty()) break; bStock = bStocks.front(); tmp = (sStock.getAmount() - bStock.getAmount()); Dollars tmpD = sStock.getPrice() - bStock.getPrice(); //if we didn't finish selling one bought transaction //we save that number into bought stock if (tmp < 0) { tmp *= -1; bStock.setAmount(tmp); bStocks.front() = bStock; tmp = 0; } else if (tmp > 0) { bStocks.pop(); } Dollars Profit = tmpD * bStock.getAmount(); profit.push(Profit); } //while (tmp == 0); }
void DisplayStock( Stock & s ) //NOTE(SighPhy): took out const { cout << "\nStock: " << s.getStockSymbol() << " Shares: " << s.getShares() << " Price: " << s.getPrice() << endl; }