$29
Problem Statement
Given Google stock’s historical prices, compute the monthly average prices of Google stock from 2004 to 2008 and output the 6 best and 6 worst months for Google.
Project Specifications
A file with Google stock's historical prices is given to you whose name is stocks.csv.
A template program (template.py) is given to you, which will be used for completing your program. There are three functions with their simple descriptions, and you are required to pad them to make them work correctly.
get_data_list(FILE_NAME)
In this function, you are required to read the file of stock's historical prices. After reading each line, you will split it into a list, and append this list to another main list, say “data_list”. So data_list is a list of lists. At the end of this function, return data_list. The function FILE_NAME as its parameter instead of hard code “stocks.csv”.
get_monthly_averages(data_list)
In this function, you will use the data_list generated by the first function as the parameter. Use Date, Volume, and Adj Close to calculate the average monthly prices. The monthly average is given by the sum of the daily total sales (Volume * Adj Close) divided by the sum of all the daily volumes.
For each month, create a tuple with 2 items, the average for that month, and the date (you only need the month and year). Append the tuple for each month to a list (e.g. monthly_averages_list), and after calculating all the monthly averages, return this list. We use tuples here because once these values are calculated we don’t want to accidentally change them!
print_info(monthly_averages_list)
In this function, you need to use the list of monthly averages calculated in the 2nd function. Here you will need to find and print (to a file) the 6 best (highest average price)
and 6 worst (lowest average price) months for Google stock. You will print to a file named “monthly_averages.txt”. This function does not return anything
If you don't call these functions, they are useless. Thus, you should write codes to call them. The steps are already given in the template program.
Project Outcome
A well commented source code file called project.py
An output file called monthly_averages.txt with the following output
6 best months for google stock:
12-2007, 693.76
11-2007, 676.55
10-2007, 637.38
01-2008, 599.42
05-2008, 576.29
06-2008, 555.34
6 worst months for Google stock:
09-2004, 116.38
10-2004, 164.52
11-2004, 177.09
12-2004, 181.01
03-2005, 181.18
01-2005, 192.96
Project Evaluation
1
get_data_list(FILE_NAME)
25
2
get_monthly_averages(data_list)
40
3
print_info(monthly_averages_list)
25
4
Function calling code, comments and outputs
10