// TODO private void changePrice(StockReader stock, double amount) { double percentage = 0; // fluctuate by ±amount * 0.4 ± skew if (Math.Abs(amount) < 30) { double skew = randomGenerator.NextDouble() * 2; skew *= randomGenerator.NextDouble() < 0.5 ? 1 : -1; double fluctuation = fluctuation = randomGenerator.NextDouble() * (amount * 0.4 + skew); fluctuation *= randomGenerator.NextDouble() < 0.5 ? 1 : -1; percentage = amount + fluctuation; } // fluctuate by ±amount * 0.3 ± skew else { double skew = randomGenerator.NextDouble() * 2; skew *= randomGenerator.NextDouble() < 0.5 ? 1 : -1; double fluctuation = fluctuation = randomGenerator.NextDouble() * (amount * 0.3 + skew); fluctuation *= randomGenerator.NextDouble() < 0.5 ? 1 : -1; percentage = amount + fluctuation; } // Update weight and percentage StockReader lists = GameObject.Find("StockList").GetComponent <StockReader>(); double weight = System.Math.Sqrt(percentage); lists.setWeight(weight); lists.setPercentage(percentage); }
private void PerturbAllStocks(double amount) { // Loop through all stocks for (int i = 0; i < stockInitialiser.stockList.Length; i++) { StockReader stock = stockInitialiser.stockList[i]; double percentage = 0; // fluctuate by ±amount * 0.4 ± skew if (Math.Abs(amount) < 30) { double skew = randomGenerator.NextDouble() * 2; skew *= randomGenerator.NextDouble() < 0.5 ? 1 : -1; double fluctuation = fluctuation = randomGenerator.NextDouble() * (amount * 0.4 + skew); fluctuation *= randomGenerator.NextDouble() < 0.5 ? 1 : -1; percentage = amount + fluctuation; } // fluctuate by ±amount * 0.3 ± skew else { double skew = randomGenerator.NextDouble() * 2; skew *= randomGenerator.NextDouble() < 0.5 ? 1 : -1; double fluctuation = fluctuation = randomGenerator.NextDouble() * (amount * 0.3 + skew); fluctuation *= randomGenerator.NextDouble() < 0.5 ? 1 : -1; percentage = amount + fluctuation; } // 3% of the time, the company will be hit very hard // |x| = |x| ± 10.0 if (randomGenerator.NextDouble() < 0.03) { percentage += Math.Sign(percentage) * randomGenerator.NextDouble() * 10.0; } StockReader lists = GameObject.Find("StockList").GetComponent <StockReader>(); double weight = System.Math.Sqrt(percentage); lists.setWeight(weight); lists.setPercentage(percentage); } }