Stock market game

×

Overview

module url N/A
git repository https://bitbucket.org/arrizza-public/game-stocks
git command git clone git@bitbucket.org:arrizza-public/game-stocks.git
verification report https://arrizza.com/web-ver/game-stocks-report.html
version info
OS Language #Runs Last Run Cov%
Ubuntu 24.04 noble Ruby 3.2.3 140 2025-09-16 98.36%

Summary

This is a simple game of stocks. Can you make a million dollars in 40 years?

How to run

./doit

Typical output

  *** STOCK GAME :( ***
 week  :     0  year: 0.000
 profit:        0.00   cash:    10000.00 loan:        0.00

 name   price    delta   initial   overall holdings
------ -------- -------- -------- -------- --------
ibm      266.40     0.00   266.40     0.00        0
att       29.01     0.00    29.01     0.00        0
msft     517.93     0.00   517.93     0.00        0
bac       52.25     0.00    52.25     0.00        0
goog     255.24     0.00   255.24     0.00        0
appl     245.50     0.00   245.50     0.00        0
ko        66.43     0.00    66.43     0.00        0
wbd       19.33     0.00    19.33     0.00        0
verz      43.48     0.00    43.48     0.00        0
tsla     426.07     0.00   426.07     0.00        0
nvda     176.60     0.00   176.60     0.00        0
brkb     492.85     0.00   492.85     0.00        0

>> Enter a command (quit, buy, sell, done):

Typical commands:

buy ibm 2    # to buy 2 shares of IBM
b ibm 2      # ditto

b ibm 1000   # if you try to buy too many shares, it will tell you the max and how it will be paid for  
>> not enough cash or loan credit to buy 1000 stocks of ibm, try again
>> max ibm that can be purchased: 35 using cash

sell ibm 2   # to sell 2 shares of IBM
s ibm 2      # ditto

done         # done with this week
d            # ditto

quit         # quit the game
q            # ditto

# This will report your overall profit:
>> Enter a command (quit, buy, sell, done):
q
You made -6096.51 in 0.192 years.

Header info

# do some buys to use up cash and/or credit
b ibm 2      # uses cash
b msft 70    # causes a loan to issued (up to $40K)

 week  :     6  year: 0.115
  profit:        0.00   cash:     9462.66 loan:    39555.56
  
# losing money:  
 week  :     9  year: 0.173
 profit:    -2366.69   cash:    -2202.61 loan:    39555.56

The header shows:

  • you are on week 6, part way through the first year
  • you've no overall profit
  • you have $9,462.66 in cash available to play
  • you've taken out $39,5555.56 loan

Note: since you have a loan, a weekly interest payment is made. The amount is based on 10% annual rate taken out of cash.

- John Arrizza