diff --git a/include/events.h b/include/events.h index 8918dfd..b85888e 100644 --- a/include/events.h +++ b/include/events.h @@ -49,7 +49,7 @@ enum stock_modifiers { }; /// @brief Multiplier for mean -const float meanMultiplier = 0.3; +constexpr float meanMultiplier = 0.3f; /// @brief Multiplier for standard deviation const float sdMultiplier = 15.0; @@ -67,7 +67,7 @@ const float defaultLowerLimit = -5; const float defaultUpperLimit = 5; /// @brief Default mean -const float defaultMean = 0.1; +constexpr float defaultMean = 0.5f / meanMultiplier; /// @brief Rate of decrease of duration const unsigned int durationDecreaseMultiplier = 2; diff --git a/include/stock.h b/include/stock.h index 18ab18f..e362c2a 100644 --- a/include/stock.h +++ b/include/stock.h @@ -49,7 +49,7 @@ const float STOCK_PRICE_LIMIT = 1000.0f; * // What is the name of the stock? * std::string name = stock.get_name(); * // Get the upper limit of the percentage change of the stock price: - * float upper_limit = stock.getTotalAttribute(stock_modifiers::upper_limit); + * float upper_limit = stock.get_total_attribute(stock_modifiers::upper_limit); * @endcode */ class Stock { @@ -123,13 +123,13 @@ class Stock { /** * @brief Get the total change of attribute of the stock due to events only. * Getter function. \n Example usage: @code {.cpp} - * stock.get_attribute(stock_modifiers::standard_deviation); + * stock.get_base_attribute(stock_modifiers::standard_deviation); * @endcode * @param attribute The attribute to get. * @return Total change of attribute due to Stock_event. Does not include the * base value. */ - float sum_attribute(stock_modifiers attribute); + float get_event_attribute(stock_modifiers attribute); /** * @brief Call this when the game proceed to next round. @@ -188,7 +188,9 @@ class Stock { * lower_limit, upper_limit * @return Base value of stock_attributes as float. */ - float get_attribute(stock_modifiers attribute) { return attributes[attribute]; } + float get_base_attribute(stock_modifiers attribute) { + return attributes[attribute]; + } /** * @brief Get size of the history. @@ -233,11 +235,11 @@ class Stock { bool can_add_event(const Stock_event & event); /** - * @brief Sums up get_attribute() and sum_attribute(). + * @brief Sums up get_base_attribute() and get_event_attribute(). * @param attribute The attribute to get. * @return Total value of the attribute. `float` type. */ - float getTotalAttribute(stock_modifiers attribute); + float get_total_attribute(stock_modifiers attribute); /** * @brief Calculate the total value of the stocks the player is holding. diff --git a/src/events.cpp b/src/events.cpp index 65a97ef..7b5dc25 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -74,11 +74,11 @@ const std::vector all_stock_events = { /** mutually_exclusive_events */ {}, /** text */ "Economic Recession: Market Downturn Signals Investor Concerns", /** duration */ 7, - /** percentage_permille */ 4, + /** percentage_permille */ 2, /** type_of_event */ all_stocks, /** category */ 0, /** modifiers*/ - {{standard_deviation, 0.2}, {mean, -50}, {lower_limit, -50}, {upper_limit, 0}}, + {{standard_deviation, 0.2}, {mean, -30}, {lower_limit, -30}, {upper_limit, 0}}, }, { /** event_id */ 3, diff --git a/src/random_price.cpp b/src/random_price.cpp index 8289ddf..b51fa1c 100644 --- a/src/random_price.cpp +++ b/src/random_price.cpp @@ -52,8 +52,8 @@ unsigned int random_integer(unsigned int max_integer) { } std::map getProcessedModifiers(Stock stock) { - float trueMean = meanMultiplier * (stock.getTotalAttribute(mean)); - float trueSD = sdMultiplier * (stock.getTotalAttribute(standard_deviation)); + float trueMean = meanMultiplier * (stock.get_total_attribute(mean)); + float trueSD = sdMultiplier * (stock.get_total_attribute(standard_deviation)); unsigned int rounds_passed = stock.get_history_size(); if (stock.get_price() < stock.get_initial_price() / 10) { // Force the return of a significantly higher mean normal dist, by a bit over @@ -74,11 +74,11 @@ std::map getProcessedModifiers(Stock stock) { // of the stock. float temp = 100 * std::abs(stock.get_initial_price() - stock.get_price()) / stock.get_price(); - float upper_lim = stock.get_attribute(upper_limit) + - stock.sum_attribute(upper_limit) * upperLimitMultiplier + + float upper_lim = stock.get_base_attribute(upper_limit) + + stock.get_event_attribute(upper_limit) * upperLimitMultiplier + std::min(static_cast(rounds_passed / 3), 10) + temp; - float lower_lim = stock.get_attribute(lower_limit) + - stock.sum_attribute(lower_limit) * lowerLimitMultiplier - + float lower_lim = stock.get_base_attribute(lower_limit) + + stock.get_event_attribute(lower_limit) * lowerLimitMultiplier - std::min(static_cast(rounds_passed / 3), 10) - temp; // Standardize the upper and lower limit float zScoreUpLimit = (upper_limit - trueMean) / trueSD; diff --git a/src/stock.cpp b/src/stock.cpp index 968e7fe..104f1b0 100644 --- a/src/stock.cpp +++ b/src/stock.cpp @@ -256,7 +256,7 @@ void Stock::remove_obselete_event(void) { } } -float Stock::sum_attribute(stock_modifiers attribute) { +float Stock::get_event_attribute(stock_modifiers attribute) { float sum = 0; std::list::iterator event_itr = events.begin(); while (event_itr != events.end()) { @@ -314,8 +314,8 @@ std::vector Stock::get_event_ids(void) { return event_ids; } -float Stock::getTotalAttribute(stock_modifiers attribute) { - return attributes[attribute] + sum_attribute(attribute); +float Stock::get_total_attribute(stock_modifiers attribute) { + return attributes[attribute] + get_event_attribute(attribute); } void sortStocksList(std::vector & stocks_list, SortingMethods sortMethod, @@ -339,25 +339,25 @@ void sortStocksList(std::vector & stocks_list, SortingMethods sortMethod, break; case by_sd: std::sort(stocks_list.begin(), stocks_list.end(), [](Stock a, Stock b) { - return a.getTotalAttribute(standard_deviation) < - b.getTotalAttribute(standard_deviation); + return a.get_total_attribute(standard_deviation) < + b.get_total_attribute(standard_deviation); }); break; case by_mean: std::sort(stocks_list.begin(), stocks_list.end(), [](Stock a, Stock b) { - return a.getTotalAttribute(mean) < b.getTotalAttribute(mean); + return a.get_total_attribute(mean) < b.get_total_attribute(mean); }); break; case by_lower_limit: std::sort(stocks_list.begin(), stocks_list.end(), [](Stock a, Stock b) { - return a.getTotalAttribute(lower_limit) < - b.getTotalAttribute(lower_limit); + return a.get_total_attribute(lower_limit) < + b.get_total_attribute(lower_limit); }); break; case by_upper_limit: std::sort(stocks_list.begin(), stocks_list.end(), [](Stock a, Stock b) { - return a.getTotalAttribute(upper_limit) < - b.getTotalAttribute(upper_limit); + return a.get_total_attribute(upper_limit) < + b.get_total_attribute(upper_limit); }); break; default: