Stock Market (New Owners Column, Lesson 10)
- Type
- Education
- Category
- Beginner's BASIC lesson program (strings) / stock-market simulation
- Author
- David Plotkin
- Published in
- Antic, January 1987 (Vol. 5, No. 9), New Owners Column, Lesson 10: Strings
- Year
- 1987
- Language
- Atari BASIC
- Requirements
- Any Atari 8-bit, Atari BASIC
About the program
Lesson 10 of David Plotkin's New Owners Column, in Antic for January 1987, is about strings: how to DIM them, fill them with INPUT or READ, measure them with LEN, cut them up with substrings, convert them with VAL and STR$, and compare them. The listing that goes with it was the series' longest program up to then, a stock-market simulation. "If you have ever wanted to play the stock market without endangering your life savings, here's your chance," Plotkin wrote. "I've made quite a bit in this stock market—and also lost my shirt."
You start with $10,000 and have six buying and selling sessions to make it grow. Before each session you get three newspaper headlines, and you have to guess how they'll move the shares of six imaginary companies: Shay-Dee Petroleum, Lemon Computers, Weapons 'R' Us, Admiral Motors, Worldwide Communications Network and Hottenkold Gas & Electric. Some headlines, Plotkin warned, are misleading.
Typing it in
The listing is plain BASIC except for the title. DRAW$ in line 380 is an asterisk, {CTRL-J}, an inverse {CTRL-J} and an inverse asterisk (the REM spells it out). Type the inverse ones with the Atari key, and {CTRL-J} by holding CTRL and pressing J. Line 2095's {LEFT}s are ESC then CTRL-left arrow. The headlines in the DATA lines are padded with spaces so that they break neatly at the 40-column screen edge, so keep the spacing exactly as shown. The article tells you to type "NEWOWN9.BAS". That's a leftover from a numbering mix-up (the December 1986 column should have been Lesson 8), and the disk file is NEWOWN10.BAS.
How to play
Press a key at the colour-cycling title. Each round shows three headlines, your holdings, prices, cash and total worth. Choose 1 to buy, 2 to sell or 3 to go on to the next round, then give the company number (1–6) and the number of shares. After six rounds, the program adds up your final worth.
How it works
- Strings used as arrays. Atari BASIC has no arrays of strings, so each set of headlines is one 700-character string divided into seven 100-character slots. Headline n is
EQHD$(n*100-99,n*100). Line 80 fills a string with spaces by the quick trick its REM explains: set the first and last characters, then copy the string onto itself one place along. - No repeats. When a headline is used, the first character of its slot is changed to
*(line 1080). The random picker in lines 1050–1060 skips any slot that starts with*. - Three kinds of news. The first headline affects the whole market (one multiplier for every price). The second affects each company differently (six multipliers, for example an oil embargo is good for Shay-Dee and bad for Hottenkold). The third concerns one company, and there's a catch. Line 1520 rolls a number, and if it's above that headline's threshold, the opposite factor is used. A follow-up headline (
CRHD$) then reveals what went wrong, such as the SEC blocking the merger. - Money. Prices are multiplied each round, and lines 1930–1990 cut everything to two decimal places with
INT(X*100)/100.
Since the program only checks that the number of shares isn't negative, it happily sells you fractions of a share.
Variations to try
Write your own headlines and multipliers in the DATA. If you want more than six rounds, you'll need more headlines too, because each one is used only once and with six rounds all six get used. Otherwise the search for an unused headline would never end. To make it a fairer market, reject fractional shares with IF CHC2<>INT(CHC2).
Listing
10 REM THE NEW OWNER'S COLUMN PART 10
20 REM BY DAVID PLOTKIN
30 REM (c) 1987, ANTIC PUBLISHING
35 GRAPHICS 2+16:POSITION 2,4:PRINT #6;"antic {inv}presents{/inv}"
40 DIM EQHD$(700),EQIMP(7),DFHD$(700),DFI1(7),DFI2(7),DFI3(7),DFI4(7)
50 DIM DFI5(7),DFI6(7),DFI7$(700),DFIN(7),DFFN(7),CRFC(7),CRHD$(700)
60 DIM PRC(6),NMSHR(6),CURI(6)
70 DIM RDHD$(100),RDH2$(100),RDH3$(100),RDH4$(100),ANSWER$(5),DRAW$(4)
80 EQHD$(1)=" ":EQHD$(700)=EQHD$:EQHD$(2)=EQHD$
81 REM LINE 80 IS A VERY QUICK WAY TO DO THIS: FOR LP=1 TO 700:EQHD$(LP,LP)=" ":NEXT LP
90 DFHD$=EQHD$:DFI7$=EQHD$:CRHD$=EQHD$:RDHD$=EQHD$:RDH2$=EQHD$:RDH3$=EQHD$:RDH4$=EQHD$
100 IN=1
110 FOR LP=1 TO 7
120 READ RDHD$,RDI
130 EQHD$(IN)=RDHD$:EQIMP(LP)=RDI
140 IN=IN+100
150 NEXT LP
160 IN=1
170 FOR LP=1 TO 7
180 READ RDH2$,RDI1,RDI2,RDI3,RDI4,RDI5,RDI6
190 DFHD$(IN)=RDH2$:DFI1(LP)=RDI1:DFI2(LP)=RDI2:DFI3(LP)=RDI3:DFI4(LP)=RDI4:DFI5(LP)=RDI5:DFI6(LP)=RDI6
200 IN=IN+100
210 NEXT LP
220 IN=1
230 FOR LP=1 TO 7
240 READ RDH3$,RDI7,RDI8,RDCR,RDH4$
250 DFI7$(IN)=RDH3$:DFIN(LP)=RDI7:DFFN(LP)=RDI8:CRFC(LP)=RDCR:CRHD$(IN)=RDH4$
260 IN=IN+100
270 NEXT LP
280 CASH=10000:REM CASH TO START
290 PRC(1)=20:REM STARTING PRICES OF STOCK
300 PRC(2)=30
310 PRC(3)=70
320 PRC(4)=40
330 PRC(5)=50
340 PRC(6)=40
350 FOR LP=1 TO 6
360 NMSHR(LP)=0
370 NEXT LP
380 DRAW$="*{CTRL-J}{inv}{CTRL-J}*{/inv}":REM ASTERISK,CONTROL-J,INVERSE CONTROL-J,INVERSE ASTERISK
390 FOR PS=0 TO 17 STEP 4:POSITION PS,3:PRINT #6;DRAW$:POSITION PS,8:PRINT #6;DRAW$:NEXT PS
400 POSITION 3,9:PRINT #6;"PRESS ANY {inv}KEY{/inv}";
410 POSITION 3,5:PRINT #6;"STOCK MARKET";:POKE 764,255
420 HLD=PEEK(708):POKE 708,PEEK(709):POKE 709,PEEK(710):POKE 710,PEEK(711):POKE 711,HLD
430 IF PEEK(764)=255 THEN FOR WT=1 TO 50:NEXT WT:GOTO 420
440 POKE 764,255
460 GRAPHICS 0:POKE 82,0:PRINT
920 REM MAIN PROGRAM
930 CYCLES=CYCLES+1
940 IF CYCLES=7 THEN 2010
950 GOSUB 1030
960 GOSUB 1290
970 GOSUB 1580
980 GOSUB 1470
990 IF CRIM=RDI8 THEN GRAPHICS 0:POSITION 0,10:PRINT CRHD$(IN2*100-99,IN2*100):FOR LP=1 TO 200:NEXT LP
1000 FOR LP=1 TO 150
1010 NEXT LP
1020 GOTO 920
1030 REM PRINT HEADLINES
1040 GRAPHICS 0
1050 GOSUB 1880
1060 IF EQHD$(FATE*100-99,FATE*100-99)="*" THEN 1050
1070 PRINT EQHD$(FATE*100-99,FATE*100)
1080 EQHD$(FATE*100-99,FATE*100)="*"
1090 RDI=EQIMP(FATE)
1100 GOSUB 1880
1110 IF DFHD$(FATE*100-99,FATE*100-99)="*" THEN 1100
1120 PRINT DFHD$(FATE*100-99,FATE*100)
1130 DFHD$(FATE*100-99,FATE*100)="*"
1140 CURI(1)=DFI1(FATE)
1150 CURI(2)=DFI2(FATE)
1160 CURI(3)=DFI3(FATE)
1170 CURI(4)=DFI4(FATE)
1180 CURI(5)=DFI5(FATE)
1190 CURI(6)=DFI6(FATE)
1200 GOSUB 1880
1210 IF DFI7$(FATE*100-99,FATE*100-99)="*" THEN 1200
1220 PRINT DFI7$(FATE*100-99,FATE*100)
1230 DFI7$(FATE*100-99,FATE*100)="*"
1240 RDI7=DFIN(FATE)
1250 RDI8=DFFN(FATE)
1260 RDCR=CRFC(FATE)
1270 IN2=FATE
1280 RETURN
1290 REM MENU
1300 STVAL=0
1310 FOR LP=1 TO 6
1320 STVAL=STVAL+NMSHR(LP)*PRC(LP)
1330 NEXT LP
1340 GOSUB 1930
1350 POSITION 0,22:? " ":POSITION 0,23:? " ";
1360 POSITION 0,9:PRINT " {inv}COMPANY{/inv} {inv}SHARES{/inv} {inv}PRICE{/inv}"
1370 PRINT "1. SHAY-DEE PET"," ";NMSHR(1),PRC(1)
1380 PRINT "2. LEMON COMP "," ";NMSHR(2),PRC(2)
1390 PRINT "3. WEAP R US "," ";NMSHR(3),PRC(3)
1400 PRINT "4. ADMIRAL MOT "," ";NMSHR(4),PRC(4)
1410 PRINT "5. WORLD COMM "," ";NMSHR(5),PRC(5)
1420 PRINT "6. HTKOLD G&E "," ";NMSHR(6),PRC(6)
1430 PRINT "CASH ON HAND: ";CASH;" "
1440 PRINT "VALUE OF STOCK: ";STVAL;" "
1450 PRINT "TOTAL WORTH: ";CASH+STVAL
1460 RETURN
1470 REM CALCULATE STOCK VALUE
1480 FOR LP=1 TO 6
1490 PRC(LP)=PRC(LP)*RDI*CURI(LP)
1500 NEXT LP
1510 GOSUB 1910
1520 IF FATE>RDCR THEN GOTO 1550
1530 CRIM=RDI7
1540 GOTO 1560
1550 CRIM=RDI8
1560 PRC(IN2)=PRC(IN2)*CRIM
1570 RETURN
1580 REM PURCHASE,SELL
1590 POSITION 0,19:PRINT "DO YOU WISH TO: "
1600 POSITION 0,20:PRINT "{inv}1. BUY {/inv} {inv}2. SELL {/inv} {inv}3. NEXT CYCLE {/inv}"
1610 POSITION 0,21:PRINT "ENTER 1, 2, OR 3"
1620 GOSUB 2095:INPUT CHC
1630 IF CHC<1 OR CHC>3 THEN 1610
1640 IF CHC=2 THEN 1770
1650 IF CHC=3 THEN RETURN
1660 POSITION 0,20:PRINT "BUY WHICH NUMBER? "
1670 POSITION 0,21:PRINT "ENTER A NUMBER 1 THROUGH 6. "
1680 GOSUB 2095:INPUT CHC:IF CHC<1 OR CHC>6 THEN 1670
1690 POSITION 0,21:PRINT "HOW MANY SHARES? "
1700 GOSUB 2095:INPUT CHC2:IF CHC2<0 THEN 1690
1710 IF PRC(CHC)*CHC2>CASH THEN 1750
1720 NMSHR(CHC)=NMSHR(CHC)+CHC2
1730 CASH=CASH-(PRC(CHC)*CHC2)
1740 POP :GOTO 960
1750 PRINT "YOU DON'T HAVE ENOUGH MONEY! ";:POSITION 0,22:? " ";
1760 GOTO 1580
1770 POSITION 0,20:PRINT "SELL WHICH NUMBER? "
1780 POSITION 0,21:PRINT "ENTER A NUMBER 1 THROUGH 6. "
1790 GOSUB 2095:INPUT CHC:IF CHC<1 OR CHC>6 THEN 1780
1800 POSITION 0,21:PRINT "HOW MANY SHARES? "
1810 INPUT CHC2:IF CHC2<0 THEN 1800
1820 IF CHC2>NMSHR(CHC) THEN 1860
1830 NMSHR(CHC)=NMSHR(CHC)-CHC2
1840 CASH=CASH+CHC2*PRC(CHC)
1850 POP :GOTO 960
1860 PRINT "YOU DON'T HAVE THAT MANY SHARES!";:POSITION 0,22:? " ";
1870 GOTO 1580
1880 REM RANDOMIZATION
1890 FATE=INT(RND(0)*6)+1
1900 RETURN
1910 FATE=INT(RND(0)*4)+1
1920 RETURN
1930 REM ROUNDING
1940 FOR LP=1 TO 6
1950 NMSHR(LP)=INT(NMSHR(LP)*100)/100
1960 PRC(LP)=INT(PRC(LP)*100)/100
1970 NEXT LP
1980 CASH=INT(CASH*100)/100
1990 STVAL=INT(STVAL*100)/100
2000 RETURN
2010 REM CLOSING
2020 GRAPHICS 0:GOSUB 1290
2030 PRINT "YOU HAVE COMPLETED SIX CYCLES!"
2040 PRINT "YOU STARTED WITH $10,000."
2050 PRINT "YOU NOW HAVE $";CASH;" CASH."
2060 PRINT "AND $";STVAL;" WORTH OF STOCK."
2070 PRINT "THIS IS A TOTAL VALUE OF $";CASH+STVAL;" ."
2080 PRINT "BYE FOR NOW!"
2090 END
2095 ? " {LEFT}{LEFT}{LEFT}{LEFT}";:RETURN
2100 REM DATA
2110 DATA INFLATION INCREASING!,.90
2120 DATA DOLLAR GAINS AGAINST FOREIGN CURRENCY,1.10
2130 DATA NEW INCOME TAX FAVORS LARGE COMPANIES,1.10
2140 DATA COUNTRY'S THREE LARGEST BANKS REPORT HEAVY LOSSES!,.95
2150 DATA PRIME RATE DOWN,1.10
2160 DATA ECONOMIC INDICATORS DOWN!,.85
2170 DATA DUMMY,0
2180 DATA OIL EMBARGO-LONG GAS LINES-HIGH PRICES!,1.3,1.0,.95,.90,1.10,.85
2190 DATA WAR IN CENTRAL AMERICA!,.95,1.0,1.05,1.0,1.2,1.0
2200 DATA NEW TRADE AGREEMENT WITH FAR EAST.,1.2,1.3,1.0,1.2,1.1,1.0
2210 DATA ALTERNATE ENERGY SOURCE FOUND BY LOCAL UTILITY,.8,1.0,1.0,1.2,1.1,1.4
2220 DATA ENVIRONMENTALLY SAFE COAL REMOVAL METHODFOUND,.8,1.0,1.1,1.1,1.0,1.2
2230 DATA PENTAGON GOES ON BUYING SPREE--MOST CONTRACTS AWARDED TO FOREIGN FIRMS!,1.0,.9,.85,1.0,1.2,1.0
2240 DATA DUMMY,0,0,0,0,0,0
2250 DATA SHAY-DEE PETROLEUM TO MERGE WITH VERY PROFITABLE OIL FIRM!,2.0,.4,1
2260 DATA SEC DOES NOT APPROVE SHAY-DEE PETRO MERGER.
2270 DATA NEW CLONE OF LEMON COMPUTER COSTS HALF AS MUCH,.5,2.1,3
2280 DATA CUSTOMS IMPOUNDS ALL LEMON CLONES!
2290 DATA BIG ARMS SALE BY WEAPONS 'R US TO CENTRAL AMERICA.,1.5,.7,3
2300 DATA CENTRAL AMERICAN COUNTRY REFUSES TO PAY FOR ARMS!
2310 DATA ADMIRAL MOTORS SALES HIT ALL-TIME HIGH AS REBATE PLAN ANNOUNCED.,1.8,.5,3
2320 DATA NEW KOREAN IMPORT LOOKS AND DRIVES JUST LIKE ADMIRAL MOTORS CARS--COSTS MUCH LESS.
2330 DATA WORLDWIDE REPORTERS HELD FOR RANSOM.,.8,1.2,2
2340 DATA WORLDWIDE REPORTERS FREED BY COMMANDO RAID!
2350 DATA HG&E WINS LARGE RATE HIKE,1.3,.75,2
2360 DATA PUC DISALLOWS RATE HIKE DUE TO IMPROPER MARKETING PRACTICES.
2370 DATA DUMMY,0,0,0,DUMMY
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: NEWOWN10.BAS.
Credits
- Program listing: Stock Market (New Owners Column, Lesson 10) — program listing (Antic, January 1987 (Vol. 5, No. 9), New Owners Column, Lesson 10: Strings) — David Plotkin
- Picture: The first trading round: three headlines, six stocks and $10,000 in cash. — David Plotkin (program); screenshot by the site
- Antic, January 1987 (Vol. 5 No. 9): New Owners Column, Lesson 10 - Strings, by David Plotkin (atarimagazines.com) — David Plotkin, 1987
- Antic Software Archive — January 1987 - Vol. 5 No. 9 disk: NEWOWN10.BAS — AtariMagazines.com (Kevin Savetz), 1987
