CS21 Lab 9: sorting stock data

Due 11:59pm Fri, Apr 12, 2013

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

$ update21
$ cd cs21/labs/09
You will save your work in a file called stocks.py.
Introduction

This week's lab involves financial data for stocks. In /usr/local/doc/yahoo are files for most companies in the NASDAQ. The files are named after each company's ticker symbol. For example, Google's file is /usr/local/doc/yahoo/GOOG.txt, Apple's file is AAPL.txt. These data files are all pulled from a free service provided by yahoo.com (YHOO). Each file contains "end-of-day" data for that company. Here are the first 5 lines from GOOG.txt:

Date,Open,High,Low,Close,Volume,Adj Close
2013-04-02,804.54,814.83,804.00,813.04,2041500,813.04
2013-04-01,795.01,802.25,793.25,801.19,1807300,801.19
2013-03-28,803.99,805.37,793.30,794.19,2287800,794.19
2013-03-27,806.68,807.00,801.33,802.66,2163200,802.66

The first line of each file contains the same header information (Date,Open,High...). After that are the data for that company, for each day, going back in time for weeks or years.

Our program this week will read in the data for each company for the most-recent day and allow the user to explore this dataset. You will implement a simple text-based menu system that allows the user to sort the data on any column (Open,High,Low,Close...) and possibly get more detailed data on a particular company.

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

$ python stocks.py
==================================================
 SYMB    OPEN    HIGH     LOW   CLOSE   VOLUME  ADJCLS %CHANGE
 BOSC    3.23    4.74    3.12    4.73   882300    4.73  46.4
CRMBW    0.07    0.09    0.07    0.09    19500    0.09  28.6
 CNIT    1.24    1.69    1.20    1.47   314000    1.47  18.5
 OPTR   11.80   14.48   11.80   13.91  3686500   13.91  17.9
 TCCO    4.55    5.36    4.55    5.29    22200    5.29  16.3
==================================================

quit(q),reverse(r),sort(s),detail(d),number(N): r

==================================================
 SYMB    OPEN    HIGH     LOW   CLOSE   VOLUME  ADJCLS %CHANGE
SANWW    2.77    3.00    2.20    2.30    17500    2.30 -17.0
 PTIX    0.98    0.98    0.84    0.84      500    0.84 -14.3
 DSTI    0.73    0.73    0.61    0.63    23400    0.63 -13.7
 SPEX    8.42    8.42    7.29    7.29     2300    7.29 -13.4
 JRCC    1.70    1.70    1.46    1.49  2135100    1.49 -12.4
==================================================

quit(q),reverse(r),sort(s),detail(d),number(N): s

Sort By: 
ticker(t), open(o), high(h), low(l), close(c), volume(v), adjclose(a), percent(p)
 -----> v
==================================================
 SYMB    OPEN    HIGH     LOW   CLOSE   VOLUME  ADJCLS %CHANGE
 EEME   52.65   52.65   52.65   52.65        0   52.65   0.0
SENEB   33.25   33.25   33.25   33.25        0   33.25   0.0
ROICU   15.91   15.91   15.91   15.91        0   15.91   0.0
GMETP    6.49    6.49    6.49    6.49        0    6.49   0.0
 LSBI   21.42   21.42   21.42   21.42        0   21.42   0.0
==================================================

quit(q),reverse(r),sort(s),detail(d),number(N): r

==================================================
 SYMB    OPEN    HIGH     LOW   CLOSE   VOLUME  ADJCLS %CHANGE
  VOD   29.76   29.95   28.73   29.41 45344000   29.41  -1.2
   MU    9.51    9.71    9.25    9.30 36023200    9.30  -2.2
   FB   25.77   26.12   25.30   25.42 35126700   25.42  -1.4
 CSCO   20.96   21.29   20.90   21.22 34098100   21.22   1.2
 SIRI    3.08    3.09    3.07    3.08 31759400    3.08   0.0
==================================================

quit(q),reverse(r),sort(s),detail(d),number(N): 

Initially, in the above example, the top 5 items are displayed sorted by %Change. The user enters "r" to reverse the display (worst 5 %Change). The user then enters "s" to sort the data and chooses "v" to sort by volume. A final "r" reverses the display (largest Volume first).

Requirements and tips

Here are the specifications for this program. 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).


Submit

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