继这个问题生成虚构的股票期权价格变化 https://stackoverflow.com/questions/9353938/generate-a-fictitious-stock-option-price-variation
我希望模拟价格变化,同时用户发出买入或卖出指令,就像真实的证券交易所一样。 (我做了一个用户案例来帮助你理解。)
初始状态“股票期权示例” :
X公司,股票期权价格$20,000
CRON 任务每秒都会产生价格变化,使用以下 PHP 脚本:
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);
}
波动性是由随机新闻造成的,它使 $max_up > $max_down 或 $max_up
Result in picture (1hour by minutes)
用户案例“购买示例” :
- 用户发送订单以 18,000 美元购买 1000 个该期权
- 系统将订单存储在数据库中
- CRON 任务每分钟验证一次,如果价格
- 当该期权的价格
用户案例“销售示例” :
- 用户发送订单以 22,000 美元出售 1000 个该期权
- 系统将订单存储在数据库中
- CRON 任务每分钟验证一次,如果价格 >= 卖出订单,则最后一分钟
- 当该期权的价格>=该订单时,用户卖出该股票期权。
我的问题
它运作良好,但它并不是股票交易市场的真正变体。
我的问题
如何根据订单的价格和数量进行价格变化?
就像“供需定律”一样。
例如 (编辑关于彼得的回答) :
function stockOrder($orderPrice,$orderQuantity,$type)//$type= buy or sell
{
// Record the order in database (ok)
// Compare with other orders (ok)
// $orderPrice<=$dbSellPrice or $orderPrice>=$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
}
也许我有点疯狂地认为可以将其自动化,但我相信这一点,任何帮助都将不胜感激。