The STOCK.PRG program maintains a database file that contains stock quotes. APPENDs a text file containing stock quotes to a database file and then. The text file is downloaded from a stock quote service periodically and imported to the database file. I normally run this program after the stock market closes each day.
In this application, the stock quotes are downloaded from the Prodigy Network. However, you can download stock quotes from other telecommunications services such as CompuServe.
Picking through the Prodigy menus to access the stock quotes takes time and effort. Therefore, I use a batch file that executes one of the available shareware keyboard macro programs that executes Prodigy and provides the necessary keystrokes to retrieve a list of stock quotes. I also use a shareware program that redirects printed output to a text file, STOCK.TXT. In Prodigy, you can create a list of up to thirty stocks (JUMP QUOTE TRACK 1). batch file STOCK.BAT is as follows:
d:
cd \
erase stock.txt
prn2file stock.txt
key /mc
key prodigy /ml
The following listing contains the keyboard macro script, PRODIGY.MAC that executes PRODIGY, signs on to the Prodigy network and retrieves the stock quotes:
<BEGDEF><alt.>
<AUTO>
<ENTER>
pr<ENTER>
(user-id)<ENTER>
(password)<ENTER>
j<ENTER>
Quote Track 1<ENTER>
C<ENTER>
j<ENTER>
Quote Track 2<ENTER>
C<ENTER>
<ENDDEF>
An example of the stock quote text file (STOCK.TXT) downloaded from prodigy is shown in Listing 14.3 of the book.
Next, FoxPro executes and STOCK.PRG, shown in Listing 14.4 in the book is executed. The STOCK.PRG procedure first appends the STOCK.TXT text file to the STOCK1.DBF database file. Stock quotes are presented as a whole number plus a fraction of a quote. These are converted to a decimal number. For example, 16 1/4 is converted to 16.25. Mutual fund values appear as a decimal number so no conversion is necessary.
You can use the STOCKS.DBF stock quote database to perform a variety of analysis operations. However, in this example, the data is simply plotted. The PLOT.PRG program plots all the stocks. However, you can access a menu to plot a single stock.
The PLOTTER procedure uses the CALCULATE command to compute the minimum and maximum values for plot scaling. Then it calls the PlotALine procedure to plot a line. The ShowHeader procedure displays the name and minimum and maximum stock quote and volume values.
The CHOOSE procedure displays a popup menu containing a selection bar for each stock symbol. When the user selects an option, the ACTION procedure is called that either QUITs the PLOT program or generates a plot for the selected stock. The program also features an option (Z) that toggles between two plot display modes. One mode displays all the available quotes entries in the database for a stock. If more entries to plot exist than lines on-screen, the display scrolls. The second mode compresses the plot so that all data for a stock displays on a single screen.
PROGRAM: CALC2.PRG
There are other analysis operations that you can perform on the stock quote database file, STOCK.DBF. Program CALC2.PRG illustrates the use of the CALCULATE command. this program computes stock market quote statistics for different companies.
Program CALC2.PRG calls procedure CalcStock, which calls the CALCULATE command to compute statistics based on daily stock values. It computes the stock high, low, and average stock value; the standard deviation; and the minimum and maximum value of the stock sales volume. The records in the STOCKS.DBF database are processed.
Each record in STOCKS.DBF contains a daily summary for selected stocks. It contains the daily volume, the high and low stock value, the last stock quote for the day and the stock symbol. Here is an example of output from program CALC2.PRG.
Stock: MSFT Stock Performance Statistics for last: 1254 days
Starting Date: 03/16/89 Ending Date: 08/21/92
High: 133.25 Low: 45.00
Average: 87.07 Standard Deviation: 22.28
Maximum Volume: 4712000.00 Minimum Volume: 188200.00
Today's Date: 08/24/92 --- Statistics for Previous 30 Days
High: 74.75 Low: 68.00
Average: 71.61 Standard Deviation: 1.50
Maximum Volume: 4539800.00 Minimum Volume: 857300.00