This assignment asks you to write a program from scratch. The focus is on breaking a problem down and using the tools you have learned -- strings, functions, files, and lists -- to implement solutions to the problem.
Data mining is the process of sifting through data to find information and patterns. In the business world, it is used in an effort to make better management decisions. In the last decade, many sports organizations have begun to use it in an effort to find undervalued players. For this project, you will do basic data mining for financial analysis related to stock prices.
Write a program that finds the best six months and worst six months for a company, in terms of monthly average stock price.
What follows are instructions for getting stock data and advice for designing your program.
Getting Data.
The file should contain data that looks like this:
Date,Open,High,Low,Close,Volume,Adj Close 2014-11-26,540.88,541.55,537.04,540.37,1518800,540.37 2014-11-25,539.00,543.98,538.60,541.08,1784200,541.08 2014-11-24,537.65,542.70,535.62,539.27,1701300,539.27
Designing Your Program.
The main program can follow the simple input-process-output pattern that we've seen throughout the course. Each step in the pattern should be a function.
The data is in a CSV (comma-separated value) format, which you have worled with on several occasions. Split each line into a list of values. Remember to convert strings that are really numbers (all but the date) into the appropriate type of number. The resulting list is the record of a single day's stock activity.
This function should return a list of daily activity records.
Use the Date field and the Adj Close field to compute the average price for each month.
For each month, create a tuple containing the month's average stock price and the month-year part of the date. We use a tuple so that we don't accidentally change this data later.
This function should return a list of monthly average tuples.
You may want to break this task down into smaller tasks and write functions to perform the smaller tasks for you.
Find the six highest monthly averages and the six lowest monthly averages for the stock. Print each list in order: the highest averages from highest to lowest, and the lowest from lowest to highest. Format the output in columns with informative headers, with the averages shown to two decimal places.
This function should not return a value.
You may want to break this task down into smaller tasks and write functions to perform the smaller tasks for you.
Some Python advice:
I myself prefer to think of each list individually. So I usually create a variable like this:
daily_record = list_of_lists[i]after which, daily_record[3] retrieves the fourth element of the current record. You can use whichever you prefer, but the latter may help you read your code.
Name your program mine_stock_prices.py.
Start a fresh Python shell. Run the final version of your program on at least input files retrived from Yahoo! Finance.
Save your shell to a text file named interactions.py.
By the due date and time, submit:
Use the on-line submission system.
Make sure that your program meets the course programming standards.