CS21 Lab 8: searching through stock data

Due 11:59pm Sat, Nov 16, 2013

Run update21, if you haven't already, to create the cs21/labs/08 directory. Then cd into your cs21/labs/08 directory and create the python program for lab 08 in this directory (handin21 looks for your lab 08 assignments in your cs21/labs/08 directory).

$ update21
$ cd cs21/labs/08
$ vim searchstocks.py


This week's lab involves financial data for stocks. The file /usr/local/doc/nasdaq.data contains data from 11/4/2013 for most companies in the NASDAQ. The data was pulled from a free service provided by yahoo.com (YHOO). Here are the first few lines from nasdaq.data:

# Ticker,Name,Date,Open,High,Low,Close,Volume,Adj Close
AAME,Atlantic American Corporation,2013-11-04,4.04,4.05,4.01,4.05,5400,4.05
AAON,AAON  Inc.,2013-11-04,27.28,27.48,27.08,27.32,96300,27.32
AAPL,Apple Inc.,2013-11-04,521.10,526.82,518.81,526.75,8716100,526.75
AAWW,Atlas Air Worldwide Holdings,2013-11-04,38.65,39.48,38.65,38.93,490500,38.93

The very first line is a comment, explaining what information (Ticker,Name,Date,etc) is in the file. After that, each line contains data for a separate company. The lines in the file are in alphabetical order based on the ticker symbol.

Our program this week will read in the data for all companies listed in the file and allow the user to explore this dataset. You will implement a simple text-based menu system that allows the user to search through the data for certain items: ticker symbol, company name, or any company with a stock price (at the Close) greater than a user-chosen value.

Here's a quick example of some of the program's capabilities:

$ python searchstocks.py 

NASDAQ Stock Data for 2013-11-04

ticker(1),company(2),close(3),quit(4): 1
                           search for: goog
ticker search for GOOG

  Ticker: GOOG
    Name: Google Inc.
    Open: $1031.50
   Close: $1026.11
  Volume: 1138800
ticker(1),company(2),close(3),quit(4): 2
                           search for: computer
company search for computer
  CCUR: Concurrent Computer Corporation
  CPSI: Computer Programs and Systems  Inc.
  SMCI: Super Micro Computer  Inc.
ticker(1),company(2),close(3),quit(4): 1
                           search for: cpsi
ticker search for CPSI

  Ticker: CPSI
    Name: Computer Programs and Systems  Inc.
    Open: $60.03
   Close: $60.42
  Volume: 67800
ticker(1),company(2),close(3),quit(4): 3
                           search for: 300
search for close > $300.00
  AAPL: $ 526.75  
  AMZN: $ 358.74  
  GOOG: $1026.11  
 HBANP: $1265.50  
  ISRG: $ 382.23  
  NFLX: $ 337.60  
  PCLN: $1070.57  
ticker(1),company(2),close(3),quit(4): 1
                           search for: nflx
ticker search for NFLX

  Ticker: NFLX
    Name: Netflix  Inc.
    Open: $330.95
   Close: $337.60
  Volume: 3131300
ticker(1),company(2),close(3),quit(4): 4


In the above example the user can search for one of three things:

NOTE: in the above three searches, one can be done with a binary search algorithm (and should be!)

Requirements and tips

Here are the specifications for this program and a few helpful "tips". Make sure your program meets all of these specifications.

Below are some longer examples. Look them over and make sure you handle all cases shown (e.g, ticker symbol not found, invalid menu choice, etc).


Once you are satisfied with your program, hand it in by typing handin21 in a terminal window.