264 friend std::ostream &
operator<<(std::ostream & fout,
const Stock & stock);
A class that represents a stock object in the game.
std::string category_name(void) const
Return the name of the category the stock belongs to.
unsigned int split_count
Contains the spliting count of a stock.
float sell(float &balance, unsigned int amount, float trading_fees_percent)
Sell a given number of stocks.
float calculateStockValue(const float &trading_fees_percent) const
Calculate the total value of the stocks the player is holding.
void add_event(const Stock_event &event)
Add an event to the stock.
unsigned int num_stocks_affordable(float balance, float trading_fees_percent) const
std::vector< float > history
Contains the stock price history.
friend std::ostream & operator<<(std::ostream &fout, const Stock &stock)
unsigned int get_category(void)
Get the category of the stock.
std::map< stock_modifiers, float > attributes
Stores the initial value of the stock_modifiers (e.g.
unsigned int category
Use numbers to represent the category of the stock.
unsigned int get_split_count(void)
Get the split count of the stock.
std::list< Stock_event > get_events(void)
Return all the events that will apply to this stock specifically.
float price
Current price of the stock.
float delta_price(void)
Return the change of stock price using the most recent price and the current price.
std::string get_name(void)
Get the name of the stock.
std::string name
Name of the stock that we assigned to it.
float get_initial_price(void)
Get the initial price of the stock.
unsigned int get_history_size(void)
Get size of the history.
bool can_add_event(const Stock_event &event)
Check if we can add the event to the stock.
float delta_price_percentage(void)
Return the percentage of change of stock price.
std::list< Stock_event > events
Stores all the events that will apply to this stock specifically.
void update_history(void)
Update the history array with the current price.
void next_round(void)
Call this when the game proceed to next round.
std::vector< float > return_most_recent_history(unsigned int rounds)
Get the stock price of recent rounds.
unsigned int quantity
Number of stocks the player has purchased.
void save(const std::string &playerName, int i)
Save the stock from a file.
void remove_obselete_event(void)
Remove obselete events from the list events that durations are less than/equal to 0 (In other words,...
Stock(void)
Constructor of class Stock.
void load(const std::string &playerName, int i)
Load the stock from a file.
float calculateTradingFeesLost(const float &trading_fees_percent) const
Calculate the amount of money player lost due to trading fees.
std::vector< unsigned int > get_event_ids(void)
Get the event ids of all the events that will apply to this stock specifically.
float get_total_attribute(stock_modifiers attribute)
Sums up get_base_attribute() and get_event_attribute().
float purchase(float &balance, unsigned int amount, float trading_fees_percent)
Purchase a given number of stocks.
unsigned int get_quantity(void)
Get the quantity of the stock.
void change_mean(float delta_mean)
Change the mean of the stock by delta_mean.
float get_base_attribute(stock_modifiers attribute)
Get the base value of stock_attributes of the stock.
float get_price(void)
Get the price of the stock.
friend std::istream & operator>>(std::istream &fin, Stock &stock)
float get_event_attribute(stock_modifiers attribute)
Get the total change of attribute of the stock due to events only.
Stock_event setup_STOCK_SPLIT_EVENT(void)
Set up a getStockSplitEvent() with proper values.
Implements event-related data structures and (declarations of) such functions.
stock_modifiers
The attributes of a stock that Events will modify are hardcoded here.
@ mean
The expectation of the stock price percentage change.
const float trading_fees_percent
/ 100 means charging % more/portion of the money involved in stock operations.
float balance
Player's balance.
std::string playerName
Player's name.
Declaration of the name generating function.
const float STOCK_PRICE_LIMIT
The upper limit of the stock price.
void sortStocksList(std::vector< Stock > &stocks_list, SortingMethods sortMethod=by_category, SortingDirections sortDirection=ascending)
Sorts the stocks.
const int initial_stock_count
Initial stock count.
The data structure of an event that will be applied to the stocks.