From 64c0ffee5c8aa02dc7fdb297f6b8588bae8f78b6 Mon Sep 17 00:00:00 2001 From: Lev Date: Sat, 3 Jul 2021 04:42:08 -0500 Subject: [PATCH] Update fixed getMean not returning correct value --- .../Merkelrex-TradingBot/TradingBot.cpp | 41 +++++++++++-------- .../Midterm/Merkelrex-TradingBot/TradingBot.h | 10 ++++- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/CM2005 Object Oriented Programming/Midterm/Merkelrex-TradingBot/TradingBot.cpp b/CM2005 Object Oriented Programming/Midterm/Merkelrex-TradingBot/TradingBot.cpp index 1bf4dcb..5c528f3 100644 --- a/CM2005 Object Oriented Programming/Midterm/Merkelrex-TradingBot/TradingBot.cpp +++ b/CM2005 Object Oriented Programming/Midterm/Merkelrex-TradingBot/TradingBot.cpp @@ -26,6 +26,7 @@ void TradingBot::printMenu() // 1 print help std::cout << "1: Retrieve current orders" << std::endl; std::cout << "2: Predict ask and bid rates" << std::endl; + std::cout << "3: Print predictions" << std::endl;; std::cout << "8: Exit bot" << std::endl; std::cout << spacer << std::endl; std::cout << "Enter an option: "; @@ -111,6 +112,7 @@ void TradingBot::predictRates() for (const std::string &product : products) { askMap[product] = getMean(bookAsks, product); + std::cout << askMap[product] << std::endl; } askHistory.push_back(askMap); @@ -143,17 +145,23 @@ void TradingBot::predictRates() double TradingBot::getMean(std::vector orders, std::string product) { double sum = 0; + int count = 0; for (const OrderBookEntry &order : orders) { if (order.product == product) + { sum += order.price; + ++count; + } } - return sum / orders.size(); + if (count == 0) return 0.0; + return sum / count; } // Print predictions if they have been made void TradingBot::printPredictions() { + std::cout.precision(8); std::cout << "Asks" << std::endl; if (predictedAsks.size() == 0) std::cout << "No ask predictions have been made yet" << std::endl; @@ -173,21 +181,7 @@ void TradingBot::printPredictions() void TradingBot::testFunc() { - std::cout << "Asks" << std::endl; - for (auto const &ask : predictedAsks) - { - std::cout << ask.first << " - " << ask.second << std::endl; - } - - std::cout << "Bids" << std::endl; - for (auto const &bid : predictedBids) - { - std::cout << bid.first << " - " << bid.second << std::endl; - } - - //std::cout << "Ask: " << askHistory[0] << std::endl; - return; - std::cout << "Asks" << std::endl; + std::cout << "Asks" << std::endl; for (int i = 0; i < bookAsks.size(); ++i) { std::cout << "Entry: " << bookAsks[i].timestamp << " - " @@ -210,6 +204,21 @@ void TradingBot::testFunc() } return; + std::cout << "Asks" << std::endl; + for (auto const &ask : predictedAsks) + { + std::cout << ask.first << " - " << ask.second << std::endl; + } + + std::cout << "Bids" << std::endl; + for (auto const &bid : predictedBids) + { + std::cout << bid.first << " - " << bid.second << std::endl; + } + + //std::cout << "Ask: " << askHistory[0] << std::endl; + return; + std::vector currentAsks = merkel->getCurrentAsks(); std::cout.precision(8); for (int i = 0; i < currentAsks.size(); ++i) diff --git a/CM2005 Object Oriented Programming/Midterm/Merkelrex-TradingBot/TradingBot.h b/CM2005 Object Oriented Programming/Midterm/Merkelrex-TradingBot/TradingBot.h index 96afd90..f1ee128 100644 --- a/CM2005 Object Oriented Programming/Midterm/Merkelrex-TradingBot/TradingBot.h +++ b/CM2005 Object Oriented Programming/Midterm/Merkelrex-TradingBot/TradingBot.h @@ -21,12 +21,18 @@ private: void printMenu(); int getUserOption(); void processUserOption(int userOption); + void printPredictions(); // Exchange functions void retrieveOrders(); // Retrieves current orders from Merkel and stores them in bookBids and BookAsks - + void predictRates(); + // Helper functions + static double getMean(std::vector orders, std::string product); // ===== Variables ===== MerkelMain *merkel; std::vector bookBids; std::vector bookAsks; - double bidHistory = {}; + std::vector> bidHistory; + std::vector> askHistory; + std::map predictedBids; + std::map predictedAsks; }; \ No newline at end of file