Note that there are some explanatory texts on larger screens.

plurals
  1. POStock option price variations by users orders (buy/sell)
    text
    copied!<p>Following this question <a href="https://stackoverflow.com/questions/9353938/generate-a-fictitious-stock-option-price-variation">Generate a fictitious stock option price variation</a></p> <p>I wish to simulate that the price change, while users gives an order of buy or sell, like the real stock exchange. (I make a user case to help you to understand.)</p> <p><strong>Initial state "Stock option example"</strong> :</p> <p>Company X, price of the stock option $20,000</p> <p>A CRON task makes the price variation each second, with this PHP script :</p> <pre><code>function stockVariation($price,$max_up,$max_down) { // Variation calculate, with volatility max (10 to 100) $ratio=(mt_rand(0,$max_up)-mt_rand(0,$max_down))/10000; // New price $price+=$ratio; return round($price,5); } </code></pre> <p>Volatility is made by random news which makes $max_up > $max_down or $max_up &lt; max_down for a random time. Between, $max_up = $max_down.</p> <p>Result in picture (1hour by minutes) <img src="https://i.stack.imgur.com/yseVl.jpg" alt="Stock option price variation"></p> <p><strong>User case "Buy example"</strong> :</p> <ul> <li>A user send an order to buy 1000 of this option at $18,000</li> <li>The system store the order in database</li> <li>A CRON task verify each minute, if the price was &lt;= to a buy order, the last minute</li> <li>When the price of this option &lt;= to this order, the user gets this stock option.</li> </ul> <p><strong>User case "Sell example"</strong> :</p> <ul> <li>A user send an order to sell 1000 of this option at $22,000</li> <li>The system store the order in database</li> <li>A CRON task verify each minute, if the price was >= to a sell order, the last minute</li> <li>When the price of this option >= to this order, the user sells this stock option.</li> </ul> <p><strong>My problem</strong></p> <p>It works fine, but it is not a real variation of a stock exchange market.</p> <p><strong>My question</strong></p> <p>How to make the price variation by the prices and quantities of the orders ?</p> <p><em>Like the "law of supply and demand".</em></p> <p>For example (<strong>edit regarding Peter answer</strong>) :</p> <pre><code>function stockOrder($orderPrice,$orderQuantity,$type)//$type= buy or sell { // Record the order in database (ok) // Compare with other orders (ok) // $orderPrice&lt;=$dbSellPrice or $orderPrice&gt;=$dbBuyPrice if checks // Buy and sell at the best prices // for quantities available holded by users (ok) // Record/update the holding of the stock (ok) // Update the price of the stock end if } </code></pre> <p>Perhaps I'm a little bit crazy to think that it could be possible to automatize that, but I believe in it, any help will be greatly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload