The script will be asked to provide stock data and if the data is not in MySQL, the script needs to retrieve from Yahoo Finance CSV. Before data is outputted it has to be adjusted for splits (see below).
The script will receive the following inputs using GET:
interval = Daily | Weekly | Monthly
start = yyyymmdd
end = yyyymmdd
quote = stock symbol such as MSFT
out = DateAndTime, Open, High, Low, Close, Volume, AdjClose (list columns in db to be outputed)
The script will check MySQL and if the data is there, it will output it in this format:
<count>Number of total rows</count>
< DateAndTime >200808221700</ DateAndTime >
< AdjClose >55.98</ AdjClose>
If the data is not in MySQL, the script needs to retrieve it from Yahoo Finance Historical Prices. When you look up a stock in Yahoo, there is a link for Historical Prices: [url removed, login to view]
Click on "Download To Spreadsheet" on the bottom of the page to get this data is in CSV format. Do not parse the table, use the CSV data.
You can use curl or fgetcsv to grab the data.
After the data is download it save it in MySQL. Please make an SQL script to create the table with all the columns appropriately optimized. Include columns for Symbol, Interval, etc.
Note, that before the data is outputted, it has to be adjusted for splits. It&#8217;s pretty simple. Sometimes a price of a stock is split. Look here:
[url removed, login to view];a=02&b=10&c=2005&d=06&e=20&f=2008&g=d
It says that on 18-Jun-08, there was a 2 : 1 Stock Split
During output (NOT when saved in db), before displaying data, it should be adjusted for the split. Open, High, Low, Close have to be divided by two on dates BEFORE the split. So for that example, if I need dates between April and August 2008, the columns I mentioned have to be adjusted before June 18th.
There are also columns that for dividend (24-Dec-07 $ 0.9845 Dividend), they should be ignored and not added to MySQL.