
*****************************************************************************************
			  Readme File

Title: Downloading Stock Information from Yahoo! Finance and
       storing it in database

Last update: 10th May 2008


Description: The readme file gives information about the program (written in PHP) 
             that will download stock information from Yahoo! Finance and store it in our 
             database. The readme also contains instructions to run the PHP script in 
             such a manner that the information in the database is correctly viewed.

******************************************************************************************


(I) REQUIREMENTS
    ------------

To run this code, PHP needs to be installed on the machine. The latest release of PHP 
can be downloaded from the official website of PHP-Hypertext Processor at

http://www.php.net/downloads.php#v4

The PHP script can be run in a Secure Shell Client (ssh). This can be downloaded from

http://www.ssh.com/support/downloads/secureshellwks/non-commercial.html


(II) CODE
     ----

The zipped folder contains:

(i)  readme.txt
(ii) autorun.sh
(iii)UpdateDbFinal.php
(iv)MonthPrice.php


(i) readme.txt

The readme file provides the information required to run the PHP script to obtain stock
information from Yahoo! Finance and to store and view it in the database.

(ii) autorun.sh

This file is the shell script for retrieving stock information from Yahoo! Finance website and storing
the retrieved information in the table created in the database recursively.

*---------------------------------------*-------------------------------------------*---------------------------------*
Note: This particular script  as of now retrieves and stores data every 15 minutes for 3 days.
      
      The script can be edited such that it can run continuously and keep refreshing the data. Also the time
      interval after which the information should be refreshed can be edited.
*---------------------------------------*-------------------------------------------*---------------------------------*

(iii) UpdateDbFinal.php

This is the PHP script which retrieves the data from Yahoo! Finance and stores the retrived information in the table
created in the database. This script can be run separately, it performs the same operation as the autorun.sh except for 
the timed auto refresh.

(iv)MonthPrice.php

This is the PHP script which retrieves the data from Yahoo! Finance for the last 2 years and stores the retrived information in the table created in the database. It needs to be run just once to populate old data. The rest of the daily data is updated int the table by the UpdateDbFinal.php

(III) RUNNING THE SCRIPT
      ------------------
  
1. Open Secure Shell Client and at the command prompt, enter the command to enter your database.

2. At the prompt, create a table with the following attributes:

     `ID` int(11) NOT NULL auto_increment
     `stock` varchar(64) NOT NULL default ''
     `value` varchar(16) NOT NULL default '0'
     `changepoints` varchar(16) NOT NULL default '0'
     `open` varchar(16) NOT NULL default ''
     `intra_top` varchar(16) NOT NULL default ''
     `intra_down` varchar(16) NOT NULL default ''
     `date` varchar(10) NOT NULL default ''
     `time` varchar(6) NOT NULL default ''
      PRIMARY KEY  (`ID`)
     
Create the MonthPrice table with following attributes 
StockID varchar(16), 
date datetime,
Closing_price varchar(16),
opening_price varchar(16)
volume_traded varchar(16).

Create a DayPrice table having columns 
Stock_ID
10AM varchar(16)
11AM varchar(16)
12PM varchar(16)
1PM varchar(16)
2PM varchar(16)
3PM varchar(16)
4PM varchar(16)

3. After the table has been created, run the php script for testing it once as follows

mysql> php UpdateDbFinal.php;
mysql> php MonthPrice.php;

After the script is run, the database gets updated.


4. To view the database, enter the following command at the prompt

mysql> select * from stocks;
mysql> select * from MonthPrice;

It should display the entire database. Individual columns could also be viewed if required. Also the contents from the table can be deleted.

5. For Auto update the php script can be run as a background process and made to wake out of sleep every 15 minutes or 
any other time interval for which the database need to be updated. This is done by the shell script autorun.sh which could be
edited as per requirement.To run this use the following command

sh autorun.sh


Our Webiste: http://www.software-ece.rutgers.edu/~group804
*-------------------------------*-----------------------------*

