I'm trying to gain some insight into how orders on an exchange are matched to design a proof of concept matching system.  Am I correct in assuming market orders are immediately executed against the best priced limit order in the limit order book if there is not another market order at the same time to fill the opposite side ?  eg:  Limit order book  Time|Buy  |   Time|Sell  00:01|50  |   00:02|55  00:03|53  |   00:01|60  Market buy order comes in at 00:05   Would it match with the sell limit order at 55 (because $55 is the best price) or with the order at 60 since it's the oldest ?
9808
When I place my trade order in the stock exchanges, I know the price matching happens and only when there is a buyer and seller at the same price a trade happens.   But how does the quantity matching happen? For example, if I want to buy 1000 shares at $100, but there is only one seller to sell 10 shares at $100, what happens then?
46110
Is stock price determined only by the last trade that takes place?  For example, if a stock I own is trading at $3.42, and I place a Sell Limit order for $0.00, will the stock price temporarily dip to $0.00?  Likewise, if I place a Buy Limit order for $100.00 for a stock that is trading at $1.23, will the price spike to $100.00?  Is there some sort of "average price" that is reported on the stock ticker?  Thanks for your help in understanding this!
59876
Out of the following queries, which method would you consider the better one? What are your reasons (code efficiency, better maintainability, less WTFery)...  SELECT MIN(`field`) FROM `tbl`;  SELECT `field` FROM `tbl` ORDER BY `field` LIMIT 1;
67316
So, I understand that today's Spotify IPO isn't a traditional IPO. But I think my question extends beyond this. At about 12:45pm today, shares of Spotify finally started trading on NYSE. Opening bell was 9:30am though, and I thought that was the &quot;real&quot; open. What was happening before the first trade, in terms of stock exchange mechanics? Alibaba in 2014 did a regular IPO and also didn't trade until almost 12:00pm on its opening day.  Update: Following some WSJ live updates, it seems like they were waiting for the spread to narrow before trading would begin:  The price range of Spotify’s first trade has just narrowed to $167 to $170, a sign that the opening could be drawing closer. The range has moved up a few times, illustrating investor demand. ― Alexander Osipovich  What I don't understand is whether the exchange has put a barrier in place (e.g. like a pre-open or delayed-open state where only passive, liquidity-providing orders are allowed), or traders are choosing not to trade for whatever market reasons. I thought it had to be the former, but then this update makes it sound like the first trade was not a scheduled event:  Shouts and applause broke out on the floor of the New York Stock Exchange as Spotify shares started trading at $165.90. A total of 5.6 million shares changed hands in the first trade. ― Alexander Osipovich
124048
In order to better understand the SQL Server query processor, I've been thinking about how the ORDER BY clause works, and how SQL Server provides results.  It appears SQL Server will provide results in exactly the same order for any given set of data that remains the same and never, ever changes.  Once you introduce any kind of uncertainty such as developers changing something, the order of results can no longer be expected to be the same.  Simply seeing the results in the same order, each time you press F5 does not guarantee the results you expect.  Try this:  USE TempDB; DROP TABLE TestOrderBy; DROP TABLE TestOrderBy2; CREATE TABLE TestOrderBy (     ID INT NOT NULL CONSTRAINT PK_TestOrderBy PRIMARY KEY CLUSTERED IDENTITY(1,1)     , SomeData varchar(255) ); INSERT INTO TestOrderBy (SomeData) VALUES ('E'); INSERT INTO TestOrderBy (SomeData) VALUES ('D'); INSERT INTO TestOrderBy (SomeData) VALUES ('C'); INSERT INTO TestOrderBy (SomeData) VALUES ('B'); INSERT INTO TestOrderBy (SomeData) VALUES ('A');  CREATE TABLE TestOrderBy2 (     ID INT NOT NULL CONSTRAINT PK_TestOrderBy2 PRIMARY KEY CLUSTERED IDENTITY(1,1)     , SomeData varchar(255) ); INSERT INTO TestOrderBy2 (SomeData) VALUES ('E'); INSERT INTO TestOrderBy2 (SomeData) VALUES ('D'); INSERT INTO TestOrderBy2 (SomeData) VALUES ('C'); INSERT INTO TestOrderBy2 (SomeData) VALUES ('B'); INSERT INTO TestOrderBy2 (SomeData) VALUES ('A');  SELECT SomeData  FROM TestOrderBy UNION ALL SELECT SomeData FROM TestOrderBy2;  CREATE INDEX IX_TestOrderBy_SomeData ON TestOrderBy (SomeData); CREATE INDEX IX_TestOrderBy2_SomeData ON TestOrderBy2 (SomeData);  SELECT SomeData  FROM TestOrderBy UNION ALL SELECT SomeData FROM TestOrderBy2;   The results:    As you see, adding a simple index on the fields selected in the query alters the order of the results.  From here on, I'm adding ORDER BY unless I truly don't care.
20102
I hold a position in , an ETF tied to the S&amp;P 500 traded on the LSE. The closing price of CSPX was 262.68USD at a gain of 0.2%. The S&amp;P 500 itself closed higher at at 1.6%. There are a couple of reasons I can think of as to why they are not equal:   The S&amp;P 500, or rather the underlying assets, continued to be traded for several hours after the LSE ceased trading. If this is the case should I expect the value of the fund to rise on Monday morning? The fund manager for CSPX has elected to place more funds in some companies than others. In this case perhaps a higher tranche has gone into a company which has done poorly compared to the rest of the stocks in the index.   Generally speaking if a stock is bought a lot, the price goes up. Does the same ring true for ETFs? If a lot of people buy into the ETF will that affect the price at all or does the value of the ETF depend absolutely on the NAV of the underlying assets?
59093
For instance, at this current moment the SP500 index is at 2094 while the futures on this market, symbol /ES with a contract of June is at 2088.  Can someone please explain how traders and investors use this price difference to trade? And most importantly how the futures market affects subsequent moves in the stock market?
108684
Presumably items would follow each other back to front?  There is such a thing as 'back to back' agreements; for example when you have an agreement with a bank to fund a purchase but contingent on (or following) the sale of another.  Could this be it I wonder, as in 'one follows the other'?
63930
A company has made an application for new Ordinary Shares. The new Ordinary Shares will rank pari passu with the existing Ordinary Shares. Also the company issues Ordinary Shares in respect of the satisfaction of the initial tranche of deferred consideration for an acquisition to vendors at a strike price of 12.5 per Ordinary Share.   My understanding is that the above mentioned sellers bought the new issued shares at the price of 12.5. However the market price at the time was 8.37. Could you please explain what happened here as it is not likely that one will buy shares at a much higher price than one can buy on market.
31348
I frequently prefer to look for questions on superuser .    I have never been able to determine how these search results are ordered.  Typically, search results are returned in order of relevance and the search help says they are "weighted heavily towards question title matches", but in this case, you would think that the search would order them based on whatever tab is currently selected (newest, hot, active)?  I ordinarily never stray outside of 'newest', but it's clear the results are not sorted by age.
31707
We need to add a priority column to a table that gets hit about 250 times a second, approx 170 selects, 125 inserts and 60 updates. The column will be a simple number(1).  The priority does not matter for the inserts or updates i.e. not part of the primary key, which I'll enforce separately.  We basically don't want to have to do an order by over a range scan 170 times a second, as the number executed will drop massively.  Does an index organised table guarantee that priority = 1 will always come before priority = 9 when running the following query:  select *   from my_table  where rownum &lt; 2   For slightly more context a typical query would be:  select *   from my_table  where mod(to_number(to_char(tstamp,'ss')),1) = 0    and done is null    and country = 'gbr'    and rownum &lt; 2   The pk constraint, for the IOT, would become priority, rest of the pk with a separate constraint on the pk solely for structure. done is null in approximately 99% of the table so this isn't very selective anyway.  Main index used is, I think, country, done, to_number(to_char(tstamp,'ss'), we tested about 20 combinations and this came up top by a long way.  I am completely unwilling to add any time at all to these queries, 0.01s a day added by select is 41 minutes a day. We'd much rather settle for "good enough" than perfection.
47160
A similar question recently asked about stock sales and option buys triggering wash sale rules.  If an option expires, is that considered a buy/sale ?  What I mean is: let's assume I have a call option with a target date of August 16. Now I sell the underlying stock somewhere before that (after July 16th). Does that trigger wash sale rules (if the option expires in the money, exercised by default) ?  Is an option expiring out of the money considered a sale ?
80012
Using Google Analytics, I'm trying to create a "supported browsers" segment using the Conditions section, but the boolean order of operations isn't occurring as expected. A simple example is below.    AND usually takes precendence over OR, so I'd expect my segment above to be interpreted as (Safari AND v10) OR (Chrome AND v57), which would allow me to include a number of Browser/Version combinations.  However, it seems like that's not the case, here. I believe this because:   My results zero out with the segment configured as pictured, but if I remove either the first or fourth clause, I'll get results. This is consistent with my filters being interpreted as Safari AND (v10 OR Chrome) AND v57, such that Safari AND (v10 OR Chrome) and (v10 OR Chrome) AND v57 both return results. The horizontal line by each AND operator seems to divide the clauses as described above.   OR-precedence doesn't make any sense to me, since the "Add Filter" button already allows the user to add additional clauses which would be equivalent to an AND, allowing the user to choose OR-precedence if they needed to. As it is, there seems to be no way to construct an AND-precedent segment.
72539
I'm following an automated trading system. It gives me buy/sell signals periodically. I usually just add/subtract 0.5% from the current price (as reported by Google Finance) and buy/sell.  Last Monday, I did the same, but apparently the stock I was trying to sell fell in price quicker than my broker could sell it at my limit price. It fell about 3%. I wouldn't have minded selling at 1%, 2% or, frankly speaking, any percent lower. I just don't wanna hold on to it.  So, should I just use market orders instead of limit orders? Will it cost me more money to use market orders than limit orders with my current +/- 0.5% formula?
102409
I'm teaching a class in which I want to demonstrate to my students that queries are not guaranteed to return results in a specific order without an explicit ORDER BY. I've observed that SQL Server seems to return ordered results even when ORDER BY is not present in the query. This is a problem because I'm concerned that my students will become confused on this point.  Examples of observed behaviour:   By default, data appears to be ordered in primary key order, even if the primary key is nonclustered. If I use GROUP BY, the result set appears to be in order of the last column. For example GROUP BY this, that ends up with the data in order of that, which is weird, especially if there is no index on it.   I haven't observed this behavior in other databases such as MySQL, PostgreSQL and SQLite. Is there something fundamentally different about SQL Server which causes it to order results for some queries even without an ORDER BY?   Now it seems to me that ordering the data when not asked is an extra unnecessary step which wastes processing time. Is that true?  And is there some kind of global setting that disables this behavior? Is there a way to get SQL Server to stop ordering data?  It also makes it harder to demonstrate to students that data is not automatically ordered.  Can anyone give me a simple demo script that shows the order of the results changing from execution to execution?
27957
Motivation: I once had one surplus card on my hand, and knew the robbers would come soon. So I gave it to someone for free, to avoid losing more cards when they hit. I was surprised by how badly this was received. Two of the three other players (the hosts of the game) acted upset, like I had tried to cheat. I had to take the card back, get robbed the next turn and 'giving cards away for free' was banned immediately. (Oh, how I hate mid-game additions to the rules. But that's beside the point.)  So now the question: Is this really illegal in Settlers of Catan? Is it generally considered underhanded in any way? If so, why?   My reasoning was like this:        Consider players A and B.   A wants to give B a sheep.   A trades a sheep and one rock to B, in exchange for wheat.   A trades the received wheat for the (formerly his) rock.   A and B now both have the same resources they had in the beginning, only the sheep has moved from A to B.
68608
I don't quite yet understand how $\oplus$ (xor) works yet. I know that fundamentally in terms of truth tables it means only 1 value(p or q) can be true, but not both. But when it comes to solving problems with them or proving equalities I have no idea how to use $\oplus$.  For example: I'm trying to do a problem in which I have to prove or disprove with a counterexample whether or not $A \oplus B = A \oplus C$  implies $B = C$ is true.   I know that the venn diagram of $\oplus$ in this case includes the regions of A and B excluding the areas they overlap. And similarly it includes regions of A and C but not the areas they overlap. It would look something like this:    I feel the statement above would be true just by looking at the venn diagram since the area ABC is included in the $\oplus$, but I'm not sure if that's an adequate enough proof.  On the other hand, I could be completely wrong about my reasoning.    Also just for clarity's sake: Would $A\cup B = A \cup C$ and $A \cap B = A \cap C$ be proven in a similar way to show whether or not the conditions imply $B = C$? A counterexample/ proof of this would be appreciated as well.