Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Designing a SQL database for stock market data

Author  Topic 

CSharpNewbie
Starting Member

39 Posts

Posted - 2012-12-22 : 05:29:13
I am designing a database that will host stock market data on a daily basis. There are about 3000 ticker sybmols that I will be tracking.

One table will have the company profile (CompanyID, CompanyName, TickerSymbol, Description)

Another table would be the one with that data. I need 5 fields for each ticker symbol for each day (OpeningPrice, ClosingPrice, Volumme, PriceToEarnings, EarningsPerShare). These five fields will be required for each ticker symbol for each business day (approximately 20 business days in a month).

What would be the best way to design this table?


My initial thought is:

TableName: 2013_Jan

ColumnNames: 02_Jan_Opening
,02_Jan_Closing
,02_Jan_Volume
,02_Jan_PriceToEarnings
,02_Jan_EarningsPerShare
,03_Jan_Opening
,03_Jan_Closing
,03_Jan_Volume
,03_Jan_PriceToEarnings
,03_Jan_EarningsPerShare
,04_Jan_Opening
,04_Jan_Closing
,04_Jan_Volume
,04_Jan_PriceToEarnings
,04_Jan_EarningsPerShare

and have similar columns for all remaining business days


Any other suggestions?

Thanks

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-12-22 : 06:27:28
I would strongly recommend against doing it the way you are proposing.
Think about how hard it would be if you were asked questions such as "what was the average volume last month", or "what was the lowest price during last year".

Instead create a table with Date, Opening Price, Volume etc.

I would caution against using Ticker as the primary identifier. Tickers can change, disappear (because of ticker changes, M&A's etc.), and can even be reissued to another company after a waiting period. So I would use an internal identifier as the primary identifier with ticker, cusip, sedol or any other street identifiers just being attributes. Do you have a need to keep track of ticker changes etc.? If so you will need to have validity dates for identifiers as well.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-22 : 06:32:56
nope. better way to design would be

(OpeningPrice, ClosingPrice, Volumme, PriceToEarnings, EarningsPerShare,datevalue,tickersymbol)

so that you store per ticker the 5 fields for each day as a row like

(OpeningPrice1, ClosingPrice1, Volumme1, PriceToEarnings1, EarningsPerShare1,01-01-2013,tickersymbol1)
(OpeningPrice2, ClosingPrice2, Volumme2, PriceToEarnings2, EarningsPerShare2,01-01-2013,tickersymbol2)
(OpeningPrice3, ClosingPrice3, Volumme3, PriceToEarnings3, EarningsPerShare3,01-01-2013,tickersymbol3)
....
(OpeningPrice1, ClosingPrice1, Volumme1, PriceToEarnings1, EarningsPerShare1,02-01-2013,tickersymbol1)
(OpeningPrice2, ClosingPrice2, Volumme2, PriceToEarnings2, EarningsPerShare2,02-01-2013,tickersymbol2)
(OpeningPrice3, ClosingPrice3, Volumme3, PriceToEarnings3, EarningsPerShare3,02-01-2013,tickersymbol3)
...
(OpeningPrice1, ClosingPrice1, Volumme1, PriceToEarnings1, EarningsPerShare1,03-01-2013,tickersymbol1)
(OpeningPrice2, ClosingPrice2, Volumme2, PriceToEarnings2, EarningsPerShare2,03-01-2013,tickersymbol2)
(OpeningPrice3, ClosingPrice3, Volumme3, PriceToEarnings3, EarningsPerShare3,03-01-2013,tickersymbol3)
....

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

CSharpNewbie
Starting Member

39 Posts

Posted - 2012-12-22 : 10:34:44
Thanks very much for your response. I agree, my initial idea was not the best way.
Go to Top of Page
   

- Advertisement -