用户订购的股票期权价格变化(买/卖) [英] Stock option price variations by users orders (buy/sell)

查看:109
本文介绍了用户订购的股票期权价格变化(买/卖)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循此问题生成虚拟股票期权价格变化

我想模拟一下价格变化,而用户给出了购买或出售的订单,就像真实的证券交易所一样. (我提供了一个用户案例来帮助您理解.)

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.)

初始状态股票期权示例" :

X公司,股票期权的价格为20,000美元

Company X, price of the stock option $20,000

CRON任务使用此PHP脚本每秒使价格变动:

A CRON task makes the price variation each second, with this PHP script :

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< max_down随机时间.之间,$ max_up = $ max_down.

Volatility is made by random news which makes $max_up > $max_down or $max_up < max_down for a random time. Between, $max_up = $max_down.

图片显示结果(按小时显示1小时)

Result in picture (1hour by minutes)

用户案例购买示例" :

  • 用户发送订单以18,000美元的价格购买1000个该选项
  • 系统将订单存储在数据库中
  • CRON任务每分钟都要验证一次,如果价格是购买订单的< =,则是最后一分钟
  • 当此期权的价格为该订单的< =时,用户将获得此股票期权.

用户案例销售示例" :

  • 用户发送了一份定单,以22,000美元的价格卖出1000张该期权
  • 系统将订单存储在数据库中
  • CRON任务每分钟都要验证一次,如果价格大于或等于卖单,则是最后一分钟
  • 当此期权的价格> =此订单的价格时,用户将卖出该股票期权.

我的问题

它工作正常,但它并不是股票交易市场的真正变体.

It works fine, but it is not a real variation of a stock exchange market.

我的问题

如何通过订单的价格和数量来改变价格?

How to make the price variation by the prices and quantities of the orders ?

就像供求法则".

例如(关于彼得答案的编辑):

For example (edit regarding Peter answer) :

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       
}

也许我可能会自动化它有点疯狂,但是我相信,任何帮助将不胜感激.

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.

推荐答案

只想在我的评论中再扩大一点.这是一个基本方案;假设我们从数据库/系统中的零个未完成订单开始.

Just wanted to expand on my comment a bit more. Here is a basic scenario; assume we start from zero unfulfilled orders in the database/system.

  1. 用户A提交了一份20股股票X的限价卖单,价格为$ 10.
  2. 用户B提交了10股股票X的限价买单,价格为$ 12.

在第1步之后,系统中将有一个未完成的订单,因为没有匹配的未结订单.

After step 1, you will have one unfulfilled order in the system, since there are no open orders to match.

在步骤2之后,可以通过系统中的未结订单来履行用户B提交的订单 . (为简单起见,假设用户A的订单可以分解,即不是全部或无订单)

After step 2, the order User B submitted can be fulfilled by an open order in the system. (For simplicity, let's assume User A's order can be broken up, i.e. not an all-or-none order)

可以满足用户B的购买订单的原因有两个:

The reason User B's buy order can be fulfilled is for these two reasons:

  1. 存在一个数量大于或等于购买订单数量的未平仓卖出订单.
  2. 限价购买价格大于或等于限价出售价格,因此可以商定交易价格.

用户A不想以低于$ 10的价格出售,用户B不想以高于$ 12的价格购买.因此,在这种情况下,存在一系列合适的交易价格,即10至12美元之间的任何价格都是合适的.

User A doesn't want to sell for less than $10, and User B doesn't want to buy for more than $12. So in this case, there is a range of suitable transaction prices, i.e. any price between $10-12 is suitable.

问题在于找到合适的交易价格.如何确定呢?选择范围的中间吗?这仅是一种解决方案. (在具有大量流动性的市场中,您可能不会遇到同样的问题,因为会有很多不同价格的未结订单,有些会以市场价格.)

The problem is finding the suitable transaction price. How to determine it? Pick the middle of the range? This is only one solution. (In a market with a lot of liquidity, you may not have this same sort of problem since there will be a lot of open orders at different prices and some at market price.)

在此示例中,假设您选择了11美元的交易价格,即合适价格范围的中间价.现在将满足用户B的订单,并且由于仅部分满足了用户A的订单,因此系统中将剩下一个未结订单:用户A以$ 10的价格出售剩余的10个单位.最后交易价格将更新为$ 11.

For the sake of the example, let's say you picked a transaction price of $11, i.e. the middle of the suitable range. User B's order would now be fulfilled and since User A's order was only partially fulfilled, there would be one open order left in the system: User A to sell their remaining 10 units at $10. The last trade price would be updated to $11.

这篇关于用户订购的股票期权价格变化(买/卖)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆