New Forum

Visit the new forum at http://godelsmarket.com/bb

Tuesday, September 25, 2012

Using SQL to Generate Volume by Price

Sometimes you may want to know at which dollar level the most trades have taken place in your favorite stock. Here's an easy way to do this in MySQL using a simple SQL query:

SELECT ROUND(close,0), SUM(volume) FROM stocks.stock_prices_minute
WHERE SYMBOL = 'AAPL'
AND DATE(date) = '2012-09-21'
GROUP BY ROUND(close, 0)

Above, 'close' is the name of the column with 1-minute (or whatever you have) close prices, 'volume' is the name of the column with volume data, stocks is the database, and stock_prices_minute is the table.

Here's a graph of a similar query (I removed the date requirement in order to get all data within the period I had available).

No comments:

Post a Comment