Classic Computer Magazine Archive ANTIC VOL. 2, NO. 11 / FEBRUARY 1984

FOLLOW THAT STOCK

A spreadsheet for your stock portfolio

by ERIC VERHEIDEN

The Stock Portfolio Spreadsheet makes it easy for you to keep track of your portfolio of stocks. It lists stocks alphabetically by ticker symbol and includes fields for all pertinent data. Room for 200 stocks is provided, and you can add other summary fields if you like. The final report can be listed to either the screen or a printer, or can be stored to disk. Cassette users can store this data by incorporating the changes noted later in the article. Stored reports can also be read and updated with this program.

ENTERING THE PROGRAM

Listing 1 below is the BASIC program. Listing 2 is the relocatable assembly-language sort routine found in the DATA statements at the end of listing 1, and need not be typed in to use the spreadsheet. After you type in listing 1, use TYPO to find any typing errors, and SAVE a backup copy for safety.

USING THE PROGRAM

The first prompt requests a U for "Update Old Dile" or C for "Create New File." C erases any previously saved data on the disk. For all prompts, press [RETURN] after responding.

The next prompt reads: ADD, CHANGE, LIST, PRINT, or SAVE.

ADDING ENTRIES

If you choose A in response to the last prompt, you are asked to input a symbol for your new stock. This can be from one to six characters long; different symbols must be supplied for multiple entries of a single stock (e.g., Atari1, Atari2, Atari3).

Next, you are prompted to enter the number of shares, cost per share, and current price of the stock. The next prompt asks you to supply the annual dividend per share. After doing this, you'll be returned to the main menu.

CHANGING AND DELETING ENTRIES

If you choose this option, you must specify which entry is to be changed by entering its symbol. Next, type D to delete the entry or M to modify it. If you choose the latter, you will be presented with the same series of prompts described above (under "Adding Entries"). To change a parameter, type in the new value followed by [RETURN]. If you simply press [RETURN] in response to any prompt, the old value will be retained.

LISTING, PRINTING, AND SAVING

To list your report to the screen, choose L from the main menu. On a 40-column screen, the entries for individual stocks are hard to read, but the summary figures are more legible. The "Print" option produces an 80-column listing on a printer.

Before ending a session with the spreadsheet, the updated listing should be stored to disk with the Save command. The program uses the file name STOCK.DAT. If a larger number of entires are to be added or modified, I recommend that you Save your data several times during the session to protect against its accidental loss.

CASSETTE OPERATION

You should reserve three cassettes for use with the Stock Portfolio Spreadsheet; one for the program, one for the old portfolio listing, and one for the new portfolio listing. Change lines 120 and 990 to read:

120 OPEN #3,4,0,"C:"
990 CLOSE #3: OPEN #3,8,0,"C:"

To update the old listing, select U from the main menu. After the beep, load the tape containing the old portfolio listing, press PLAY on the recorder, and then press [RETURN] on the computer.

To save the new listing to tape, load a blank cassette into the recorder and press RECORD and PLAY. Then choose S from the main menu. After the double beep, press [RETURN]. Patience is required for these operations, because cassette storage is quite slow.

ADDING NEW SUMMARY LINES

Insert new lines in the program starting with iine 1411. Quantities available for manipulation are GSHR (total shares), GCOS (total cost), GVAL (total current value), and GINC (total income). For example, if you call a new quantity GXXX, add these lines:

1411 GXXX=expression
1412 S$=STR$(GXXX):GOSUB 1430:PRINT #3;" description ";S$

This will display the quantity to within two decimal places of accuracy. For three-place accuracy, replace GOSUB 1430 with GOSUB 1460 in line 1412. If you want a percent symbol to appear after the new quantity, append ;"%" to line 1412.

MACHINE-LANGUAGE SORT ROUTINE

Listing 2 provides the source code for the sort routine used in the spreadsheet in Assembler Editor syntax. The routine is relocatable and can sort up to 255 items. Assuming that the sort routine is contained in a string A$ (as in the spreadsheet), the format for calling it is :

X= USR(ADR(A$),ADR(SYMB$),NREC,RECLEN)

Here, SYMB$ is a string that contains NREC fields of RECLEN characters each. NREC and RECLEN must not exceed 255. The ordering of the sorted records is stored at address X, as returned by the sort routine. The sorter produces record indices from zero to NREC - 1, so to load the Kth-ordered record you must set IREC = PEEK(X + K-l) + 1 and load record IREC.

The routine uses a version of a radix sort and is very fast, since it does not perform actual data movement, but computes an ordering.

Starting with the least-significant bytes of the entries, the program alternately counts the occurrences of each byte ($00-$FF), and then calculates a cumulative partial sum. This is used to take entries in the old ordering and put them into a new ordering, according to the byte under examination. The ordering is finished when this process has been completed for the most significant byte.

The program uses indirect addresses in FR0 for the "old ordering," FR1 for the "new ordering," and FR2 for the accumulated counts. The sign bit of FR0 + 2 is used as a flag for pass 1 or 2 (plus or minus). FR0 + 3 contains the current offset into the entries for sorting. Other floating-point registers are used for intermediate results. The entire sort routine is 151 bytes long.

Eric Verheiden is the author of Vervan's utility programs (CASDUP, CASDIS, FULMAP, DISASM, DISDUP, and DOWNLD) and of the forthcoming Secrets of Atari I/O (IJG). He holds a Ph. D. from the California Institute of Technology and works for an aerospace firm in Southern California.

Requires 16K cassette & 24K disk

Listing 1: STOCK.BAS Download

Listing 2: STOCK2.ASM Download / View