I'm creating a system for an online game written in an uncommon language (PAWN), similar to C.
I've done some research and found some good information however it's not what I am fully looking for.
In the game there are several industries that I want there to be stocks and shares on.
For example:
Police Department Fish Market Housing Market
The volatility of shares is how much swing (+/-) in price change. The higher the volatility, the higher the swing.
In my game the price of each industry will update every minute.
An industry will will bankrupt when it reaches a minimum price per share. An industry stock will split when it reaches a maximum price per share.
Example:
Police Dept. - (Bankrupt every 220 price updates) (Stock Split every 660 price updates - if it doesn't bankrupt before then)
Fish Industry - (Bankrupt every 1000 price updates) (Stock Split every 220 price updates - if it doesn't bankrupt before then)
House Market - (Never Bankrupts)
I've found a function and altered it to the desired coding language which factors in volatility.
Float:GenerateNextPrice(stockid)
{
if(stockid < 0 || stockid >= sizeof(gStockMarket)) return -1.0; //
new Float:rnd;
MRandFloatRange(0, 1.0, rnd); // generate number, 0 <= x < 1.0
new Float:old_price = gStockMarket[stockid][gCurrentStockPrice];
new Float:volatility = gStockMarket[stockid][gStockVolatility]; // A stable stock would have a volatility number of perhaps 2. A volatility of 10 would show some pretty large swings.
new Float:change_percent = 2 * volatility * rnd;
if (change_percent > volatility)
{
change_percent -= (2 * volatility);
}
new Float:change_amount = (old_price / 100) * change_percent;
new Float:new_price = old_price + change_amount;
return new_price;
}
This function factors in volatility however the higher the volatility the more the swing.
How would I function where it replicates price increases/decreases but after a certain amount of calls it to eventually bankrupt or split as above?
I understand this may be confusing and happy to answer questions.