Stock Market Simulator main e8c3612
A game that provides a realistic stock buying experience with unpredictable trends to test investment strategies.
|
Implements event-related data structures and (declarations of) such functions. More...
#include <istream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
Go to the source code of this file.
Classes | |
struct | Stock_event |
The data structure of an event that will be applied to the stocks. More... | |
Typedefs | |
typedef std::map< decltype(Stock_event::event_id), std::vector< decltype(Stock_event::event_id)> > | mutuallyExclusiveMap |
Enumerations | |
enum | event_type { all_stocks , category , pick_random_stock } |
The type of event that will be applied to the stocks. More... | |
enum | stock_modifiers { standard_deviation , mean , lower_limit , upper_limit } |
The attributes of a stock that Events will modify are hardcoded here. More... | |
Functions | |
bool | assertion_check_mutual_exclusivity (void) |
Check if there are mutual exclusivity violations in all_stock_events. | |
void | assertion_check_uniq_events (void) |
mutuallyExclusiveMap | build_mutual_exclusivity_map (const std::vector< Stock_event > &all_events) |
mutuallyExclusiveMap | check_mutual_exclusivity (const std::vector< Stock_event > &all_events) |
If A is mutually exclusive with B, then B is mutually exclusive with A. | |
Stock_event | getStockSplitEvent (void) |
std::vector< Stock_event > | pick_events (const std::vector< Stock_event > &all_events, unsigned int num_events) |
Pick a random event from the list of events. | |
void | print_map (const std::map< unsigned int, std::vector< unsigned int > > &map) |
Print a map to std::cout. | |
std::vector< Stock_event > | uniq_events (std::vector< Stock_event > picked_events, const std::vector< Stock_event > &all_events) |
Filter out the events that are mutually exclusive with each other, or events that are identical (except for event_type::pick_random_stock). | |
Variables | |
const std::vector< Stock_event > | all_stock_events |
The list of all events that will be applied to the stocks. | |
const float | defaultLowerLimit = -5 |
Default lower limit. | |
constexpr float | defaultMean = 0.5f / meanMultiplier |
Default mean. | |
const float | defaultUpperLimit = 5 |
Default upper limit. | |
const unsigned int | durationDecreaseMultiplier = 2 |
Rate of decrease of duration. | |
const float | lowerLimitMultiplier = 0.2 |
Lower limit multiplier. | |
constexpr float | meanMultiplier = 0.6f |
Multiplier for mean. | |
const float | sdMultiplier = 7.5f |
Multiplier for standard deviation. | |
const float | upperLimitMultiplier = 0.2 |
Upper limit multiplier. | |
Implements event-related data structures and (declarations of) such functions.
Definition in file events.h.
typedef std::map<decltype(Stock_event::event_id), std::vector<decltype(Stock_event::event_id)> > mutuallyExclusiveMap |
enum event_type |
The type of event that will be applied to the stocks.
Definition at line 88 of file events.h.
enum stock_modifiers |
The attributes of a stock that Events will modify are hardcoded here.
std::map<stock_modifiers, float>
. Definition at line 30 of file events.h.
bool assertion_check_mutual_exclusivity | ( | void | ) |
Check if there are mutual exclusivity violations in all_stock_events.
Definition at line 1331 of file events.cpp.
References all_stock_events, check_mutual_exclusivity(), and print_map().
Referenced by main().
void assertion_check_uniq_events | ( | void | ) |
Definition at line 1416 of file events.cpp.
References all_stocks, lower_limit, mean, pick_random_stock, standard_deviation, uniq_events(), and upper_limit.
Referenced by main().
mutuallyExclusiveMap build_mutual_exclusivity_map | ( | const std::vector< Stock_event > & | all_events | ) |
Definition at line 1293 of file events.cpp.
Referenced by check_mutual_exclusivity(), and uniq_events().
mutuallyExclusiveMap check_mutual_exclusivity | ( | const std::vector< Stock_event > & | all_events | ) |
If A is mutually exclusive with B, then B is mutually exclusive with A.
Check if these two events specifies each other as mutually exclusive in mutually_exclusive_events.
all_events | The list of all events |
Definition at line 1307 of file events.cpp.
References build_mutual_exclusivity_map().
Referenced by assertion_check_mutual_exclusivity().
Stock_event getStockSplitEvent | ( | void | ) |
Definition at line 1453 of file events.cpp.
References lower_limit, mean, pick_random_stock, standard_deviation, and upper_limit.
Referenced by Stock::setup_STOCK_SPLIT_EVENT().
std::vector< Stock_event > pick_events | ( | const std::vector< Stock_event > & | all_events, |
unsigned int | num_events ) |
Pick a random event from the list of events.
all_events | The list of all events |
num_events | The number of events to pick |
When picking the event, consider event.probability_permille. E.g. if there are 3 events with probability_permille 10, 20, 30. total_permille = 60; random_permille = 0 to 59; If random_permille is 0 to 9, pick the first event; If random_permille is 10 to 29, pick the second event; If random_permille is 30 to 59, pick the third event.
Definition at line 1348 of file events.cpp.
References all_stock_events, random_integer(), and uniq_events().
Referenced by new_events_next_round().
void print_map | ( | const std::map< unsigned int, std::vector< unsigned int > > & | map | ) |
Print a map to std::cout.
map | The std::map object you want to print. |
Definition at line 1269 of file events.cpp.
Referenced by assertion_check_mutual_exclusivity().
std::vector< Stock_event > uniq_events | ( | std::vector< Stock_event > | picked_events, |
const std::vector< Stock_event > & | all_events ) |
Filter out the events that are mutually exclusive with each other, or events that are identical (except for event_type::pick_random_stock).
picked_events | The list of events to filter. |
all_events | The list of all events to consider. |
Definition at line 1380 of file events.cpp.
References build_mutual_exclusivity_map(), and pick_random_stock.
Referenced by assertion_check_uniq_events(), and pick_events().
|
extern |
The list of all events that will be applied to the stocks.
The list of all events that will be applied to the stocks.
Event ID Range | Affected Category |
---|---|
0 to 7 | All Stocks |
8 to 11 | Adv&Market |
12 to 16 | Aero&Def |
17 to 22 | Airlines |
23 to 27 | RenewEnergy |
28 to 31 | Auto |
32 to 34 | Banks |
35 to 37 | Biotech |
38 to 40 | Broadcast |
41 to 46 | Casinos&Gaming |
47 to 51 | E-Commerce |
52 to 55 | FinServices |
56 to 61 | Food&Beverage |
62 to 66 | Healthcare |
67 to 74 | Tech |
75 to 79 | RealEstate |
80 to 85 | Retail |
86 to 91 | Telecom |
92 to 98 | pick_random_stock |
Definition at line 49 of file events.cpp.
Referenced by assertion_check_mutual_exclusivity(), new_events_next_round(), and pick_events().
const float defaultLowerLimit = -5 |
Default lower limit.
Definition at line 64 of file events.h.
Referenced by Stock::Stock(), and getProcessedModifiers().
|
constexpr |
const float defaultUpperLimit = 5 |
Default upper limit.
Definition at line 67 of file events.h.
Referenced by Stock::Stock(), and getProcessedModifiers().
const unsigned int durationDecreaseMultiplier = 2 |
Rate of decrease of duration.
Definition at line 73 of file events.h.
Referenced by Stock::next_round().
const float lowerLimitMultiplier = 0.2 |
Lower limit multiplier.
Definition at line 58 of file events.h.
Referenced by getProcessedModifiers().
|
constexpr |
const float sdMultiplier = 7.5f |
Multiplier for standard deviation.
Definition at line 55 of file events.h.
Referenced by getProcessedModifiers().
const float upperLimitMultiplier = 0.2 |
Upper limit multiplier.
Definition at line 61 of file events.h.
Referenced by getProcessedModifiers().